CouplingBaseProblem.h 3.21 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/** \file CoupledBaseProblem.h */

#ifndef COUPLED_BASE_PROBLEM_H
#define COUPLED_BASE_PROBLEM_H

#include "AMDiS.h"

// coupling structures
#include "CouplingIterationInterface.h"
#include "CouplingTimeInterface.h"
#include "CouplingProblemStat.h"
#include "BaseProblem.h"
#include "ProblemInstat.h"

using namespace AMDiS;


/**
  * \ingroup Problem 
  *
  * \brief
  */
template<class ProblemType=ProblemStat, class BaseProblemType=BaseProblem<ProblemStat> >
class CoupledBaseProblem : public CouplingIterationInterface,
			   public CouplingTimeInterface,
			   public CouplingProblemStatImpl<ProblemType>
{
public:
  typedef CouplingProblemStatImpl<ProblemType> CProblemStat;

  CoupledBaseProblem(std::string name_, 
		     BaseProblemType *prob0_,
		     BaseProblemType *prob1_=NULL, 
		     BaseProblemType *prob2_=NULL, 
		     BaseProblemType *prob3_=NULL, 
		     BaseProblemType *prob4_=NULL)
  : CProblemStat(name_)
  {
    dow = Global::getGeo(WORLD);
    baseProblems.push_back(prob0_);
    if (prob1_) baseProblems.push_back(prob1_);
    if (prob2_) baseProblems.push_back(prob2_);
    if (prob3_) baseProblems.push_back(prob3_);
    if (prob4_) baseProblems.push_back(prob4_);
  }

  ~CoupledBaseProblem() { }  
  
  virtual void initialize(Flag initFlag,
			  ProblemStat *adoptProblem = NULL,
			  Flag adoptFlag = INIT_NOTHING)
  {  
    for (size_t i = 0; i < baseProblems.size(); i++) {
      for (size_t j = 0; j < baseProblems[i]->getNumProblems(); j++)
55
	this->addProblem(dynamic_cast<ProblemType*>(baseProblems[i]->getProblem(j)));
Praetorius, Simon's avatar
Praetorius, Simon committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
      
      addIterationInterface(baseProblems[i]);
      addTimeInterface(baseProblems[i]);
    }

    // initialize all ProblemStat
    CProblemStat::initialize(initFlag, adoptProblem, adoptFlag);
    
    // set mesh dimension
    dim = CProblemStat::getMesh(0)->getDim();
  }  
  
  virtual void initData() {}  
  
  virtual void initTimeInterface()
  {
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->initData();
    initData();
    
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->fillOperators();
    fillCouplingOperators();
    
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->fillBoundaryConditions();
    fillCouplingBoundaryConditions();
  }
  
  
  virtual void fillCouplingOperators() {}
  virtual void fillCouplingBoundaryConditions() {}
  
  
  /// get the j-th solution-vector of the i-th problem
  DOFVector<double> *getSolution(int i, int j)
  { FUNCNAME("CoupledBaseProblem::getSolution(i,j)");
    TEST_EXIT(0<=i && 0<=j && i<baseProblems.size() && j<=baseProblems[i]->getNumComponents())
      ("Indices out of range!\n");
    return baseProblems[i]->getSolution()->getDOFVector(j);
  }
  
  
  /// pointer to the j-th feSpace of the i-th problem
  inline const FiniteElemSpace* getFeSpace(int i, int j=0) 
  { FUNCNAME("CoupledBaseProblem::getFeSpace(i,j)");
    TEST_EXIT(0<=i && 0<=j && i<baseProblems.size() && j<=baseProblems[i]->getNumComponents())
      ("Indices out of range!\n");
    return baseProblems[i]->getFeSpace(j); 
  }

protected:
  std::vector<BaseProblemType*> baseProblems;

  unsigned dim;	// dimension of the meshes
111
  unsigned dow;	// dimension of the world
Praetorius, Simon's avatar
Praetorius, Simon committed
112
113
114
115
};


#endif // COUPLED_BASE_PROBLEM_H