ProblemInstat.cc 5.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#include "ProblemInstat.h"
#include "FileWriter.h"
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "Estimator.h"
#include "ProblemScal.h"
#include "StandardProblemIteration.h"

namespace AMDiS {

  ProblemInstat::~ProblemInstat()
12
  {}
13
14
15
16

  void ProblemInstat::initialize(Flag initFlag,
				 ProblemInstat *adoptProblem/* = NULL*/,
				 Flag adoptFlag /* = INIT_NOTHING*/) 
17
  {}
18
19
20
21

  void ProblemInstat::solveInitialProblem(AdaptInfo *adaptInfo)
  {
    AdaptStationary initialAdapt((name + "->initial->adapt").c_str(),
Thomas Witkowski's avatar
Thomas Witkowski committed
22
				 new StandardProblemIteration(initialProblem),
23
24
25
26
27
28
29
				 adaptInfo);

    initialAdapt.adapt();
  }

  void ProblemInstatScal::transferInitialSolution(AdaptInfo *adaptInfo)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
30
    TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime())
31
32
33
34
35
36
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }

  void ProblemInstatVec::transferInitialSolution(AdaptInfo *adaptInfo)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
37
    TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime())
38
39
40
41
42
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
43
  ProblemInstatScal::ProblemInstatScal(std::string sname, 
44
				       ProblemScal *prob, ProblemStatBase *initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
45
    : ProblemInstat(sname, initialProb), 
46
47
      problemStat(prob),
      oldSolution(NULL)
48
  {}
49

Thomas Witkowski's avatar
Thomas Witkowski committed
50
51
  ProblemInstatScal::ProblemInstatScal(std::string sname, ProblemScal& prob)
    : ProblemInstat(sname, NULL), 
52
53
54
55
      problemStat(&prob),
      oldSolution(NULL)
  {}

Thomas Witkowski's avatar
Thomas Witkowski committed
56
  ProblemInstatScal::ProblemInstatScal(std::string sname, 
57
				       ProblemScal& prob, ProblemStatBase& initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
58
    : ProblemInstat(sname, &initialProb), 
59
60
61
      problemStat(&prob),
      oldSolution(NULL)
  {}
62
63
64

  ProblemInstatScal::~ProblemInstatScal()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
65
    delete oldSolution;
66
67
68
  }

  void ProblemInstatScal::initialize(Flag initFlag,
Thomas Witkowski's avatar
Thomas Witkowski committed
69
70
				     ProblemInstat *adoptProblem,
				     Flag adoptFlag) 
71
72
73
74
75
76
77
78
79
  {
    FUNCNAME("ProblemInstat::initialize()");
  
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);

    // === create vector for old solution ===
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
80
      if (initFlag.isSet(INIT_UH_OLD))
81
	createUhOld();
82
      
83
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
84
85
86
87
	ProblemInstatScal* _adoptProblem 
	  = dynamic_cast<ProblemInstatScal*>(adoptProblem);
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and scalar");
88
89
90
91
92
93
94
95
96
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

    if (!oldSolution) 
      WARNING("no oldSolution created\n");
  }

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
97
98
  void ProblemInstatScal::createUhOld() 
  {
99
100
101
102
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
      // create oldSolution
103
      oldSolution = new DOFVector<double>(problemStat->getFeSpace(), name + "->uOld");
104
      oldSolution->setCoarsenOperation(COARSE_INTERPOL);
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
105
      if (problemStat->getEstimator())
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
	dynamic_cast<Estimator*>(problemStat->getEstimator())
	  ->addUhOldToSystem(0, oldSolution);
    }
  }


  void ProblemInstatScal::closeTimestep(AdaptInfo *adaptInfo) 
  {
    bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime());
    problemStat->writeFiles(adaptInfo, force);
  }

  void ProblemInstatVec::closeTimestep(AdaptInfo *adaptInfo) 
  {
    bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime());
    problemStat->writeFiles(adaptInfo, force);
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
124
  ProblemInstatVec::ProblemInstatVec(std::string sname, 
125
				     ProblemVec *prob, ProblemStatBase *initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
126
    : ProblemInstat(sname, initialProb), 
127
128
      problemStat(prob),
      oldSolution(NULL)
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
129
  {}
130

Thomas Witkowski's avatar
Thomas Witkowski committed
131
132
  ProblemInstatVec::ProblemInstatVec(std::string sname, ProblemVec &prob)
    : ProblemInstat(sname, NULL), 
133
134
135
136
      problemStat(&prob),
      oldSolution(NULL)
  {}

Thomas Witkowski's avatar
Thomas Witkowski committed
137
  ProblemInstatVec::ProblemInstatVec(std::string sname, 
138
				     ProblemVec &prob, ProblemStatBase &initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    : ProblemInstat(sname, &initialProb), 
140
141
142
143
      problemStat(&prob),
      oldSolution(NULL)
  {}

144
145
  ProblemInstatVec::~ProblemInstatVec()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
146
    delete oldSolution;
147
148
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
149
150
  void ProblemInstatVec::initialize(Flag initFlag, ProblemInstat *adoptProblem,
				    Flag adoptFlag) 
151
152
153
  {
    FUNCNAME("ProblemInstatVec::initialize()");
  
154
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);
155
156

    // === create vector for old solution ===
Thomas Witkowski's avatar
Thomas Witkowski committed
157
    if (oldSolution) {
158
159
      WARNING("oldSolution already created\n");
    } else {
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
160
      if (initFlag.isSet(INIT_UH_OLD))
161
	createUhOld();
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
162

Thomas Witkowski's avatar
Thomas Witkowski committed
163
164
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
	ProblemInstatVec* _adoptProblem = dynamic_cast<ProblemInstatVec*>(adoptProblem);
165
166
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and vectorial");
167
168
169
170
171
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

172
173
    if (!oldSolution) 
      WARNING("no oldSolution created\n");
174
175
  }

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
176
177
  void ProblemInstatVec::createUhOld() 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
178
179
180
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
181
182
      int size = problemStat->getNumComponents();
      // create oldSolution
183
      oldSolution = new SystemVector("old solution", problemStat->getFeSpaces(), size);
Thomas Witkowski's avatar
Thomas Witkowski committed
184
      for (int i = 0; i < size; i++) {
185
	oldSolution->setDOFVector(i, new DOFVector<double>(problemStat->getFeSpace(i), 
186
187
188
							   name + "->uOld"));
	oldSolution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
189
190
191
	if (problemStat->getEstimator(i))
	  problemStat->getEstimator(i)->
	    addUhOldToSystem(i, oldSolution->getDOFVector(i));
192
193
194
195
      }
    }
  }

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
196
197
  void ProblemInstatScal::initTimestep(AdaptInfo *adaptInfo) 
  {
198
199
200
    oldSolution->copy(*(problemStat->getSolution())); 
  }

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
201
202
  void ProblemInstatVec::initTimestep(AdaptInfo *adaptInfo) 
  {
203
204
    oldSolution->copy(*(problemStat->getSolution())); 
  }
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
205

206
}