ProblemInstat.cc 6.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
#include "ProblemInstat.h"
14
#include "io/FileWriter.h"
15
16
17
18
19
20
21
22
23
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "Estimator.h"
#include "ProblemScal.h"
#include "StandardProblemIteration.h"

namespace AMDiS {

  ProblemInstat::~ProblemInstat()
24
  {}
25
26
27
28

  void ProblemInstat::initialize(Flag initFlag,
				 ProblemInstat *adoptProblem/* = NULL*/,
				 Flag adoptFlag /* = INIT_NOTHING*/) 
29
  {}
30
31
32
33

  void ProblemInstat::solveInitialProblem(AdaptInfo *adaptInfo)
  {
    AdaptStationary initialAdapt((name + "->initial->adapt").c_str(),
Thomas Witkowski's avatar
Thomas Witkowski committed
34
				 new StandardProblemIteration(initialProblem),
35
36
37
38
39
40
41
				 adaptInfo);

    initialAdapt.adapt();
  }

  void ProblemInstatScal::transferInitialSolution(AdaptInfo *adaptInfo)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
42
    TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime())
43
44
45
46
47
48
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }

  void ProblemInstatVec::transferInitialSolution(AdaptInfo *adaptInfo)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
49
    TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime())
50
51
52
53
54
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }


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

Thomas Witkowski's avatar
Thomas Witkowski committed
62
63
  ProblemInstatScal::ProblemInstatScal(std::string sname, ProblemScal& prob)
    : ProblemInstat(sname, NULL), 
64
65
66
67
      problemStat(&prob),
      oldSolution(NULL)
  {}

Thomas Witkowski's avatar
Thomas Witkowski committed
68
  ProblemInstatScal::ProblemInstatScal(std::string sname, 
69
				       ProblemScal& prob, ProblemStatBase& initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
70
    : ProblemInstat(sname, &initialProb), 
71
72
73
      problemStat(&prob),
      oldSolution(NULL)
  {}
74
75
76

  ProblemInstatScal::~ProblemInstatScal()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
77
    delete oldSolution;
78
79
80
  }

  void ProblemInstatScal::initialize(Flag initFlag,
Thomas Witkowski's avatar
Thomas Witkowski committed
81
82
				     ProblemInstat *adoptProblem,
				     Flag adoptFlag) 
83
84
85
86
87
88
89
90
91
  {
    FUNCNAME("ProblemInstat::initialize()");
  
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);

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

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

109

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
110
111
  void ProblemInstatScal::createUhOld() 
  {
112
113
114
115
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
      // create oldSolution
116
      oldSolution = new DOFVector<double>(problemStat->getFeSpace(), name + "->uOld");
117
      oldSolution->setCoarsenOperation(COARSE_INTERPOL);
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
118
      if (problemStat->getEstimator())
119
120
121
122
123
124
125
126
127
128
129
130
	dynamic_cast<Estimator*>(problemStat->getEstimator())
	  ->addUhOldToSystem(0, oldSolution);
    }
  }


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

131

132
133
134
135
136
137
  void ProblemInstatVec::closeTimestep(AdaptInfo *adaptInfo) 
  {
    bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime());
    problemStat->writeFiles(adaptInfo, force);
  }

138

Thomas Witkowski's avatar
Thomas Witkowski committed
139
  ProblemInstatVec::ProblemInstatVec(std::string sname, 
140
				     ProblemVec *prob, ProblemStatBase *initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
141
    : ProblemInstat(sname, initialProb), 
142
143
      problemStat(prob),
      oldSolution(NULL)
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
144
  {}
145

146

Thomas Witkowski's avatar
Thomas Witkowski committed
147
148
  ProblemInstatVec::ProblemInstatVec(std::string sname, ProblemVec &prob)
    : ProblemInstat(sname, NULL), 
149
150
151
152
      problemStat(&prob),
      oldSolution(NULL)
  {}

153

Thomas Witkowski's avatar
Thomas Witkowski committed
154
  ProblemInstatVec::ProblemInstatVec(std::string sname, 
155
				     ProblemVec &prob, ProblemStatBase &initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
156
    : ProblemInstat(sname, &initialProb), 
157
158
159
160
      problemStat(&prob),
      oldSolution(NULL)
  {}

161

162
163
  ProblemInstatVec::~ProblemInstatVec()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
164
    delete oldSolution;
165
166
  }

167

Thomas Witkowski's avatar
Thomas Witkowski committed
168
169
  void ProblemInstatVec::initialize(Flag initFlag, ProblemInstat *adoptProblem,
				    Flag adoptFlag) 
170
171
172
  {
    FUNCNAME("ProblemInstatVec::initialize()");
  
173
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);
174
175

    // === create vector for old solution ===
Thomas Witkowski's avatar
Thomas Witkowski committed
176
    if (oldSolution) {
177
178
      WARNING("oldSolution already created\n");
    } else {
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
179
      if (initFlag.isSet(INIT_UH_OLD))
180
	createUhOld();
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
181

Thomas Witkowski's avatar
Thomas Witkowski committed
182
183
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
	ProblemInstatVec* _adoptProblem = dynamic_cast<ProblemInstatVec*>(adoptProblem);
184
185
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and vectorial");
186
187
188
189
190
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

191
192
    if (!oldSolution) 
      WARNING("no oldSolution created\n");
193
194
  }

195

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
196
197
  void ProblemInstatVec::createUhOld() 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
198
199
200
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
201
202
      int size = problemStat->getNumComponents();
      // create oldSolution
203
      oldSolution = new SystemVector("old solution", problemStat->getFeSpaces(), size);
Thomas Witkowski's avatar
Thomas Witkowski committed
204
      for (int i = 0; i < size; i++) {
205
	oldSolution->setDOFVector(i, new DOFVector<double>(problemStat->getFeSpace(i), 
206
207
208
							   name + "->uOld"));
	oldSolution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
209
210
211
	if (problemStat->getEstimator(i))
	  problemStat->getEstimator(i)->
	    addUhOldToSystem(i, oldSolution->getDOFVector(i));
212
213
214
215
      }
    }
  }

216

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
217
218
  void ProblemInstatScal::initTimestep(AdaptInfo *adaptInfo) 
  {
219
220
221
    oldSolution->copy(*(problemStat->getSolution())); 
  }

222

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
223
224
  void ProblemInstatVec::initTimestep(AdaptInfo *adaptInfo) 
  {
225
226
    oldSolution->copy(*(problemStat->getSolution())); 
  }
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
227

228
}