CouplingBaseProblem_RB.h 4.09 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
/** \file CoupledBaseProblem_RB.h */

#ifndef COUPLED_BASE_PROBLEM_RB_H
#define COUPLED_BASE_PROBLEM_RB_H

#include "AMDiS.h"

// coupling structures
#include "CouplingIterationInterface.h"
#include "CouplingTimeInterface.h"
#include "CouplingProblemStat.h"
#include "BaseProblem_RB.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
13
#include "CouplingBaseProblem.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
14
15
16
17
18
19
20
21
22
23
#include "time/ExtendedRosenbrockStationary.h"

using namespace AMDiS;


/**
  * \ingroup Problem 
  *
  * \brief
  */
Praetorius, Simon's avatar
Praetorius, Simon committed
24
class CouplingBaseProblem_RB : public CouplingBaseProblem<ExtendedRosenbrockStationary, BaseProblem_RB>
Praetorius, Simon's avatar
Praetorius, Simon committed
25
26
{
public:
Praetorius, Simon's avatar
Praetorius, Simon committed
27
  typedef CouplingBaseProblem<ExtendedRosenbrockStationary, BaseProblem_RB> super;
Praetorius, Simon's avatar
Praetorius, Simon committed
28
29
30
  typedef BaseProblem_RB BaseProblemType;
  typedef CouplingProblemStatImpl<ExtendedRosenbrockStationary> CProblemStat;

31
  CouplingBaseProblem_RB(std::string name_, 
Praetorius, Simon's avatar
Praetorius, Simon committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
			BaseProblemType *prob0_,
			BaseProblemType *prob1_=NULL, 
			BaseProblemType *prob2_=NULL, 
			BaseProblemType *prob3_=NULL, 
			BaseProblemType *prob4_=NULL)
  : super(name_,prob0_,prob1_,prob2_,prob3_,prob4_)
  {
    int componentShift = 0;
    for (size_t i = 0; i < baseProblems.size(); i++) {
      baseProblems[i]->setProblem(new ExtendedRosenbrockStationary(baseProblems[i]->getName() + "->space", componentShift));
      componentShift += baseProblems[i]->getNumComponents();
    }
  }

46
  ~CouplingBaseProblem_RB() { }  
Praetorius, Simon's avatar
Praetorius, Simon committed
47
48
49
  
  /// get the j-th stage-solution-vector of the i-th problem
  DOFVector<double> *getStageSolution(int i, int j)
50
  { FUNCNAME("CouplingBaseProblem_RB::getStageSolution(i,j)");
Praetorius, Simon's avatar
Praetorius, Simon committed
51
52
53
54
55
56
57
58
  
    TEST_EXIT(0<=i && 0<=j && i<baseProblems.size() && j<=baseProblems[i]->getNumComponents())
      ("Indices out of range!\n");
    return baseProblems[i]->getStageSolution(j);
  }  
  
  /// get the j-th unVec-vector of the i-th problem
  DOFVector<double> *getUnVec(int i, int j=0) 
59
  { FUNCNAME("CouplingBaseProblem_RB::getUnVec(i,j)");
Praetorius, Simon's avatar
Praetorius, Simon committed
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  
    TEST_EXIT(0<=i && 0<=j && i<baseProblems.size() && j<=baseProblems[i]->getNumComponents())
      ("Indices out of range!\n");
    return baseProblems[i]->getUnVec(j);
  }
  
  virtual double estimateTimeError(AdaptInfo* adaptInfo)
  {
    double errorEst = 0.0;
    for (size_t i = 0; i < CProblemStat::getNumProblems(); i++)
      errorEst = std::max(errorEst, CProblemStat::getProblem(i)->estimateTimeError(adaptInfo));
    
    adaptInfo->setTimeEst(errorEst);
    return errorEst;
  }
  
  double getNewTimestep(double tol, double tau, bool restrict = true)
  {
    double newTimestep = 1.e15;
    for (size_t i = 0; i < baseProblems.size(); i++)
      newTimestep = std::min(newTimestep, baseProblems[i]->getNewTimestep(tol, tau, restrict));
    return newTimestep;
  }
  
  double getNewTimestep(double tol, double oldTau, double tau, bool restrict = true)
  {
    double newTimestep = 1.e15;
    for (size_t i = 0; i < baseProblems.size(); i++)
      newTimestep = std::min(newTimestep, baseProblems[i]->getNewTimestep(tol, oldTau, tau, restrict));
    return newTimestep;
  }

  // Rosenbrock methods
  //_________________________________________________________________________

  void acceptTimestep(AdaptInfo* adaptInfo)
  {
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->acceptTimestep(adaptInfo);
  }

//   void reset()
//   {
//     for (size_t i = 0; i < CProblemStat::getNumProblems(); i++)
//       CProblemStat::getProblem(i)->reset();
//     for (size_t i = 0; i < baseProblems.size(); i++)
//       baseProblems[i]->reset();
//   }

  void setTau(double *ptr)
  {
    for (size_t i = 0; i < CProblemStat::getNumProblems(); i++)
      CProblemStat::getProblem(i)->setTau(ptr);
  }
  
  void setOldTime(double t)
  {
    for (size_t i = 0; i < CProblemStat::getNumProblems(); i++)
      CProblemStat::getProblem(i)->setOldTime(t);
  }
  
  void setTime(AdaptInfo* adaptInfo)
  {
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->setTime(adaptInfo);
  }
	
  void reduceOrder(double tauRej, double tau)
  {
    for (size_t i = 0; i < baseProblems.size(); i++)
      baseProblems[i]->reduceOrder(tauRej, tau);
  }
  
  double* getOldTimePtr()
  {
    return CProblemStat::getProblem(0)->getOldTimePtr();
  }
};


#endif // COUPLED_BASE_PROBLEM_RB_H