ProblemInstat.cc 5.57 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
				 adaptInfo);

    initialAdapt.adapt();
  }

  void ProblemInstatScal::transferInitialSolution(AdaptInfo *adaptInfo)
  {
    TEST_EXIT(adaptInfo->getTime() == 
	      adaptInfo->getStartTime())
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }

  void ProblemInstatVec::transferInitialSolution(AdaptInfo *adaptInfo)
  {
    TEST_EXIT(adaptInfo->getTime() == 
	      adaptInfo->getStartTime())
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }


45
  ProblemInstatScal::ProblemInstatScal(std::string name_, 
46
47
48
				       ProblemScal *prob,
				       ProblemStatBase *initialProb)
    : ProblemInstat(name_, initialProb), 
49
50
      problemStat(prob),
      oldSolution(NULL)
51
  {}
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
  ProblemInstatScal::ProblemInstatScal(std::string name_, 
				       ProblemScal& prob)
    : ProblemInstat(name_, NULL), 
      problemStat(&prob),
      oldSolution(NULL)
  {}

  ProblemInstatScal::ProblemInstatScal(std::string name_, 
				       ProblemScal& prob,
				       ProblemStatBase& initialProb)
    : ProblemInstat(name_, &initialProb), 
      problemStat(&prob),
      oldSolution(NULL)
  {}
67
68
69

  ProblemInstatScal::~ProblemInstatScal()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
70
    delete oldSolution;
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  }

  void ProblemInstatScal::initialize(Flag initFlag,
				     ProblemInstat *adoptProblem/* = NULL*/,
				     Flag adoptFlag /* = INIT_NOTHING*/) 
  {
    FUNCNAME("ProblemInstat::initialize()");
  
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);

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

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

Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
102
103
  void ProblemInstatScal::createUhOld() 
  {
104
105
106
107
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
      // create oldSolution
Thomas Witkowski's avatar
Thomas Witkowski committed
108
      oldSolution = new DOFVector<double>(problemStat->getFESpace(), name + "->uOld");
109
      oldSolution->setCoarsenOperation(COARSE_INTERPOL);
Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
110
      if (problemStat->getEstimator())
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
	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);
  }

129
  ProblemInstatVec::ProblemInstatVec(std::string name_, 
130
131
132
				     ProblemVec *prob,
				     ProblemStatBase *initialProb)
    : ProblemInstat(name_, initialProb), 
133
134
      problemStat(prob),
      oldSolution(NULL)
Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
135
  {}
136
137
138

  ProblemInstatVec::~ProblemInstatVec()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
139
    delete oldSolution;
140
141
142
143
144
145
146
147
  }

  void ProblemInstatVec::initialize(Flag initFlag,
				    ProblemInstat *adoptProblem/* = NULL*/,
				    Flag adoptFlag /* = INIT_NOTHING*/) 
  {
    FUNCNAME("ProblemInstatVec::initialize()");
  
148
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);
149
150

    // === create vector for old solution ===
Thomas Witkowski's avatar
Thomas Witkowski committed
151
    if (oldSolution) {
152
153
      WARNING("oldSolution already created\n");
    } else {
Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
154
      if (initFlag.isSet(INIT_UH_OLD))
155
	createUhOld();
Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
156

Thomas Witkowski's avatar
Thomas Witkowski committed
157
158
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
	ProblemInstatVec* _adoptProblem = dynamic_cast<ProblemInstatVec*>(adoptProblem);
159
160
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and vectorial");
161
162
163
164
165
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

166
167
    if (!oldSolution) 
      WARNING("no oldSolution created\n");
168
169
  }

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

Thomas Witkowski's avatar
nix.  
Thomas Witkowski committed
192
193
  void ProblemInstatScal::initTimestep(AdaptInfo *adaptInfo) 
  {
194
195
196
    oldSolution->copy(*(problemStat->getSolution())); 
  }

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

202
}