CouplingBaseProblem.h 3.42 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
/** \file CouplingBaseProblem.h */
Praetorius, Simon's avatar
Praetorius, Simon committed
2

Praetorius, Simon's avatar
Praetorius, Simon committed
3
4
#ifndef COUPLING_BASE_PROBLEM_H
#define COUPLING_BASE_PROBLEM_H
Praetorius, Simon's avatar
Praetorius, Simon committed
5
6
7
8
9
10
11
12
13
14

#include "AMDiS.h"

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

15
namespace AMDiS { namespace base_problems {
Praetorius, Simon's avatar
Praetorius, Simon committed
16
17

/**
18
  * \ingroup Problem
Praetorius, Simon's avatar
Praetorius, Simon committed
19
20
21
22
  *
  * \brief
  */
template<class ProblemType=ProblemStat, class BaseProblemType=BaseProblem<ProblemStat> >
Praetorius, Simon's avatar
Praetorius, Simon committed
23
class CouplingBaseProblem : public CouplingIterationInterface,
Praetorius, Simon's avatar
Praetorius, Simon committed
24
			   public CouplingTimeInterface,
25
			   public detail::CouplingProblemStat<ProblemType>
Praetorius, Simon's avatar
Praetorius, Simon committed
26
27
{
public:
28
  typedef detail::CouplingProblemStat<ProblemType> CProblemStat;
Praetorius, Simon's avatar
Praetorius, Simon committed
29

30
  CouplingBaseProblem(std::string name_,
Praetorius, Simon's avatar
Praetorius, Simon committed
31
		     BaseProblemType *prob0_,
32
33
34
		     BaseProblemType *prob1_=NULL,
		     BaseProblemType *prob2_=NULL,
		     BaseProblemType *prob3_=NULL,
Praetorius, Simon's avatar
Praetorius, Simon committed
35
		     BaseProblemType *prob4_=NULL)
Praetorius, Simon's avatar
Praetorius, Simon committed
36
  : CProblemStat(name_), name(name_)
Praetorius, Simon's avatar
Praetorius, Simon committed
37
38
39
40
41
42
43
44
45
  {
    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_);
  }

46
47
  ~CouplingBaseProblem() { }

48
49
50
  void initialize(Flag initFlag,
		  ProblemStatSeq *adoptProblem = NULL,
		  Flag adoptFlag = INIT_NOTHING) override
51
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
52
53
    for (size_t i = 0; i < baseProblems.size(); i++) {
      for (size_t j = 0; j < baseProblems[i]->getNumProblems(); j++)
54
	this->addProblem(dynamic_cast<ProblemType*>(baseProblems[i]->getProblem(j)));
55

Praetorius, Simon's avatar
Praetorius, Simon committed
56
57
58
59
60
61
      addIterationInterface(baseProblems[i]);
      addTimeInterface(baseProblems[i]);
    }

    // initialize all ProblemStat
    CProblemStat::initialize(initFlag, adoptProblem, adoptFlag);
62

Praetorius, Simon's avatar
Praetorius, Simon committed
63
64
    // set mesh dimension
    dim = CProblemStat::getMesh(0)->getDim();
65
66
67
68
69
  }

  virtual void initData() {}
  virtual void finalizeData() {}

Praetorius, Simon's avatar
Praetorius, Simon committed
70
71
72
73
74
  virtual void initTimeInterface()
  {
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->initData();
    initData();
75

Praetorius, Simon's avatar
Praetorius, Simon committed
76
77
78
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->fillOperators();
    fillCouplingOperators();
79

Praetorius, Simon's avatar
Praetorius, Simon committed
80
81
82
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->fillBoundaryConditions();
    fillCouplingBoundaryConditions();
83

Praetorius, Simon's avatar
Praetorius, Simon committed
84
    for (size_t i = 0; i < baseProblems.size(); i++)
85
      baseProblems[i]->finalizeData();
Praetorius, Simon's avatar
Praetorius, Simon committed
86
    finalizeData();
Praetorius, Simon's avatar
Praetorius, Simon committed
87
  }
88
89


Praetorius, Simon's avatar
Praetorius, Simon committed
90
91
  virtual void fillCouplingOperators() {}
  virtual void fillCouplingBoundaryConditions() {}
92
93


Praetorius, Simon's avatar
Praetorius, Simon committed
94
95
  /// get the j-th solution-vector of the i-th problem
  DOFVector<double> *getSolution(int i, int j)
Praetorius, Simon's avatar
Praetorius, Simon committed
96
  { FUNCNAME("CouplingBaseProblem::getSolution(i,j)");
Praetorius, Simon's avatar
Praetorius, Simon committed
97
98
99
100
    TEST_EXIT(0<=i && 0<=j && i<baseProblems.size() && j<=baseProblems[i]->getNumComponents())
      ("Indices out of range!\n");
    return baseProblems[i]->getSolution()->getDOFVector(j);
  }
101
102


Praetorius, Simon's avatar
Praetorius, Simon committed
103
  /// pointer to the j-th feSpace of the i-th problem
104
  inline const FiniteElemSpace* getFeSpace(int i, int j=0)
Praetorius, Simon's avatar
Praetorius, Simon committed
105
  { FUNCNAME("CouplingBaseProblem::getFeSpace(i,j)");
Praetorius, Simon's avatar
Praetorius, Simon committed
106
107
    TEST_EXIT(0<=i && 0<=j && i<baseProblems.size() && j<=baseProblems[i]->getNumComponents())
      ("Indices out of range!\n");
108
    return baseProblems[i]->getFeSpace(j);
Praetorius, Simon's avatar
Praetorius, Simon committed
109
  }
110

Praetorius, Simon's avatar
Praetorius, Simon committed
111
  std::string getName() { return name; }
Praetorius, Simon's avatar
Praetorius, Simon committed
112
113
114
115
116

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

  unsigned dim;	// dimension of the meshes
117
  unsigned dow;	// dimension of the world
118

Praetorius, Simon's avatar
Praetorius, Simon committed
119
  std::string name;
Praetorius, Simon's avatar
Praetorius, Simon committed
120
121
};

122
} }
Praetorius, Simon's avatar
Praetorius, Simon committed
123

Praetorius, Simon's avatar
Praetorius, Simon committed
124
#endif // COUPLING_BASE_PROBLEM_H