CouplingBaseProblem2_cxx11.h 6.04 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
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

#include "AMDiS.h"

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

#include <tuple>
#include "GenericLoops_cxx11.h"

namespace AMDiS {

namespace detail {
  
  /// for generic loops this struct can be passed
  struct AddProblem {
    template<typename CouplingProblemStatType, typename BaseProblemType>
    static void call(CouplingProblemStatType& couplingProblemStat, BaseProblemType& baseProblem) {
      for (size_t j = 0; j < baseProblem.getNumProblems(); j++)
	couplingProblemStat.addProblem(baseProblem.getProblem(j));
    }
  };
    
  /// for generic loops this struct can be passed
  struct AddTimeInterface {
    template<typename CouplingProblemStatType, typename BaseProblemType>
    static void call(CouplingProblemStatType& couplingProblemStat, BaseProblemType& baseProblem) {
      couplingProblemStat.addTimeInterface(&baseProblem);
    }
  };
    
  /// for generic loops this struct can be passed
  struct AddIterationInterface {
    template<typename CouplingProblemStatType, typename BaseProblemType>
    static void call(CouplingProblemStatType& couplingProblemStat, BaseProblemType& baseProblem) {
      couplingProblemStat.addIterationInterface(&baseProblem);
    }
  };
    
  /// Functor for generic loops. Method initData() is called for each element in a sequence.
  struct InitData {
    template<typename BaseProblemType>
    static void call(BaseProblemType& baseProblem) { baseProblem.initData(); }
  };
    
Praetorius, Simon's avatar
Praetorius, Simon committed
53
54
55
56
57
58
  /// Functor for generic loops. Method initData() is called for each element in a sequence.
  struct FinalizeData {
    template<typename BaseProblemType>
    static void call(BaseProblemType& baseProblem) { baseProblem.finalizeData(); }
  };
    
Praetorius, Simon's avatar
Praetorius, Simon committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  /// Functor for generic loops. Method fillOperators() is called for each element in a sequence.
  struct FillOperators {
    template<typename BaseProblemType>
    static void call(BaseProblemType& baseProblem) { baseProblem.fillOperators(); }
  };
    
  /// Functor for generic loops. Method fillBoundaryConditions() is called for each element in a sequence.
  struct FillBoundaryConditions {
    template<typename BaseProblemType>
    static void call(BaseProblemType& baseProblem) { baseProblem.fillBoundaryConditions(); }
  };
  
} // end namespace detail

/**
  * \ingroup Problem 
  *
  * \brief Structur to couple BaseProblems of variouse types
  */
template<typename ProblemType=ProblemStat, typename... BaseProblemTypes >
Praetorius, Simon's avatar
Praetorius, Simon committed
79
class CouplingBaseProblem : public CouplingIterationInterface,
Praetorius, Simon's avatar
Praetorius, Simon committed
80
81
82
83
84
85
86
87
			   public CouplingTimeInterface,
			   public CouplingProblemStatImpl<ProblemType>
{
public:
  typedef CouplingProblemStatImpl<ProblemType> CProblemStat;
  typedef std::tuple<BaseProblemTypes&...> BaseProblemsTupleType;

  template<typename... BaseProblemTypes_>
Praetorius, Simon's avatar
Praetorius, Simon committed
88
  CouplingBaseProblem(std::string name_, BaseProblemTypes_&&... baseProblems_)
Praetorius, Simon's avatar
Praetorius, Simon committed
89
90
91
92
93
94
95
  : CProblemStat(name_),
    baseProblems(baseProblems_...),
    name(name_)
  {
    dow = Global::getGeo(WORLD); 
  }

Praetorius, Simon's avatar
Praetorius, Simon committed
96
  ~CouplingBaseProblem() { }  
97
98
99
100
101
102
103
104
105
106

  /**
   * Add the problems to the iterationInterface, timeInterface and couplingProblemStat.
   * As a consequence all problem can be initialized one after another and in the
   * adaption loop they are solved in rotation.
   *
   * In the adaption loop the problems are solved the same order as they are added to the
   * iterationInterface in this method. This order can be changed manually in the oneIteration
   * method.
   **/
Praetorius, Simon's avatar
Praetorius, Simon committed
107
  void initialize(Flag initFlag,
108
		  ProblemStatSeq *adoptProblem = NULL,
Praetorius, Simon's avatar
Praetorius, Simon committed
109
110
111
112
113
114
115
116
117
118
119
120
121
122
		  Flag adoptFlag = INIT_NOTHING) _OVERRIDE_
  {
    tools::FOR_EACH< detail::AddProblem >::loop2(*this, baseProblems);
    tools::FOR_EACH< detail::AddIterationInterface >::loop2(*this, baseProblems);
    tools::FOR_EACH< detail::AddTimeInterface >::loop2(*this, baseProblems);

    // initialize all ProblemStat
    CProblemStat::initialize(initFlag, adoptProblem, adoptFlag);
    
    // set mesh dimension
    dim = CProblemStat::getMesh(0)->getDim();
  }
  
  virtual void initData() {}  
Praetorius, Simon's avatar
Praetorius, Simon committed
123
  virtual void finalizeData() {}
124
125
126
127
128
129
  
  /**
   * At first the initData method is called for all baseProblems, then
   * the problems are filled with operators and coupling operators as well as
   * boundary conditions are added.
   **/
Praetorius, Simon's avatar
Praetorius, Simon committed
130
131
132
133
134
135
136
137
138
139
  virtual void initTimeInterface()
  {
    tools::FOR_EACH< detail::InitData >::loop(baseProblems);
    initData();
    
    tools::FOR_EACH< detail::FillOperators >::loop(baseProblems);
    fillCouplingOperators();
    
    tools::FOR_EACH< detail::FillBoundaryConditions >::loop(baseProblems);
    fillCouplingBoundaryConditions();
Praetorius, Simon's avatar
Praetorius, Simon committed
140
141
142
    
    tools::FOR_EACH< detail::FinalizeData >::loop(baseProblems);
    finalizeData();
Praetorius, Simon's avatar
Praetorius, Simon committed
143
144
145
146
147
148
149
150
151
152
  }
  
  
  virtual void fillCouplingOperators() {}
  virtual void fillCouplingBoundaryConditions() {}
  
  
  /// get the j-th solution-vector of the i-th problem
  template<int i>
  DOFVector<double> *getSolution(int j)
Praetorius, Simon's avatar
Praetorius, Simon committed
153
  { FUNCNAME("CouplingBaseProblem::getSolution<i>(j)");
Praetorius, Simon's avatar
Praetorius, Simon committed
154
155
156
157
158
159
160
161
162
163
    BOOST_STATIC_ASSERT_MSG(0 <= i && i < _LENGTH_<BaseProblemsTupleType>::value , "BaseProblem-index out of range");
    
    TEST_EXIT(0 <= j && j <= _GET_<i>(baseProblems).getNumComponents())("Indices out of range!\n");
    return _GET_<i>(baseProblems).getSolution()->getDOFVector(j);
  }
  
  
  /// pointer to the j-th feSpace of the i-th problem
  template<int i>
  inline const FiniteElemSpace* getFeSpace(int j=0) 
Praetorius, Simon's avatar
Praetorius, Simon committed
164
  { FUNCNAME("CouplingBaseProblem::getFeSpace<i>(j)");
Praetorius, Simon's avatar
Praetorius, Simon committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
    BOOST_STATIC_ASSERT_MSG(0 <= i && i < _LENGTH_<BaseProblemsTupleType>::value , "BaseProblem index out of range");
    
    TEST_EXIT(0 <= j && j <= _GET_<i>(baseProblems).getNumComponents())("Indices out of range!\n");
    return _GET_<i>(baseProblems).getFeSpace(j); 
  }
  
  std::string getName() { return name; }

protected:
  BaseProblemsTupleType baseProblems;

  unsigned dim;	// dimension of the meshes
  unsigned dow;	// dimension of the world
  
  std::string name;
};

} // end namespace AMDiS

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