ProblemInstat.cc 6.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
//
// 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.

12
13
14
#ifndef HAVE_PARALLEL_DOMAIN_AMDIS
#include <mpi.h>
#endif
15

16
#include "ProblemInstat.h"
17
#include "io/FileWriter.h"
18
19
20
21
22
23
24
25
26
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "Estimator.h"
#include "ProblemScal.h"
#include "StandardProblemIteration.h"

namespace AMDiS {

  ProblemInstat::~ProblemInstat()
27
  {}
28

29

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

35

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

    initialAdapt.adapt();
  }

45

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

53

54
55
  void ProblemInstatVec::transferInitialSolution(AdaptInfo *adaptInfo)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
56
    TEST_EXIT(adaptInfo->getTime() == adaptInfo->getStartTime())
57
58
59
60
61
      ("after initial solution: time != start time\n");
    problemStat->writeFiles(adaptInfo, true);
  }


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

69

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

76

Thomas Witkowski's avatar
Thomas Witkowski committed
77
  ProblemInstatScal::ProblemInstatScal(std::string sname, 
78
				       ProblemScal& prob, ProblemStatBase& initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
79
    : ProblemInstat(sname, &initialProb), 
80
81
82
      problemStat(&prob),
      oldSolution(NULL)
  {}
83

84

85
86
  ProblemInstatScal::~ProblemInstatScal()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
87
    delete oldSolution;
88
89
  }

90

91
  void ProblemInstatScal::initialize(Flag initFlag,
Thomas Witkowski's avatar
Thomas Witkowski committed
92
93
				     ProblemInstat *adoptProblem,
				     Flag adoptFlag) 
94
95
96
97
98
99
100
101
102
  {
    FUNCNAME("ProblemInstat::initialize()");
  
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);

    // === create vector for old solution ===
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
103
      if (initFlag.isSet(INIT_UH_OLD))
104
	createUhOld();
105
      
106
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
107
108
109
110
	ProblemInstatScal* _adoptProblem 
	  = dynamic_cast<ProblemInstatScal*>(adoptProblem);
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and scalar");
111
112
113
114
115
116
117
118
119
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

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

120

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
121
122
  void ProblemInstatScal::createUhOld() 
  {
123
124
125
126
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
      // create oldSolution
127
      oldSolution = new DOFVector<double>(problemStat->getFeSpace(), name + "->uOld");
128
      oldSolution->setCoarsenOperation(COARSE_INTERPOL);
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
129
      if (problemStat->getEstimator())
130
131
132
133
134
135
136
137
138
139
140
141
	dynamic_cast<Estimator*>(problemStat->getEstimator())
	  ->addUhOldToSystem(0, oldSolution);
    }
  }


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

142

143
144
  void ProblemInstatVec::closeTimestep(AdaptInfo *adaptInfo) 
  {
145
146
    FUNCNAME("ProblemInstatVec::closeTimestep()");

147
148
    bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime());
    problemStat->writeFiles(adaptInfo, force);
149
150
151
152
153

#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    MSG("Computational time for timestep: %.5f seconds\n", 
	(MPI::Wtime() - lastTimepoint));
#endif
154
155
  }

156

Thomas Witkowski's avatar
Thomas Witkowski committed
157
  ProblemInstatVec::ProblemInstatVec(std::string sname, 
158
				     ProblemVec *prob, ProblemStatBase *initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
159
    : ProblemInstat(sname, initialProb), 
160
161
      problemStat(prob),
      oldSolution(NULL)
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
162
  {}
163

164

Thomas Witkowski's avatar
Thomas Witkowski committed
165
166
  ProblemInstatVec::ProblemInstatVec(std::string sname, ProblemVec &prob)
    : ProblemInstat(sname, NULL), 
167
168
169
170
      problemStat(&prob),
      oldSolution(NULL)
  {}

171

Thomas Witkowski's avatar
Thomas Witkowski committed
172
  ProblemInstatVec::ProblemInstatVec(std::string sname, 
173
				     ProblemVec &prob, ProblemStatBase &initialProb)
Thomas Witkowski's avatar
Thomas Witkowski committed
174
    : ProblemInstat(sname, &initialProb), 
175
176
177
178
      problemStat(&prob),
      oldSolution(NULL)
  {}

179

180
181
  ProblemInstatVec::~ProblemInstatVec()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
182
    delete oldSolution;
183
184
  }

185

Thomas Witkowski's avatar
Thomas Witkowski committed
186
187
  void ProblemInstatVec::initialize(Flag initFlag, ProblemInstat *adoptProblem,
				    Flag adoptFlag) 
188
189
190
  {
    FUNCNAME("ProblemInstatVec::initialize()");
  
191
    ProblemInstat::initialize(initFlag, adoptProblem, adoptFlag);
192
193

    // === create vector for old solution ===
Thomas Witkowski's avatar
Thomas Witkowski committed
194
    if (oldSolution) {
195
196
      WARNING("oldSolution already created\n");
    } else {
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
197
      if (initFlag.isSet(INIT_UH_OLD))
198
	createUhOld();
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
199

Thomas Witkowski's avatar
Thomas Witkowski committed
200
201
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
	ProblemInstatVec* _adoptProblem = dynamic_cast<ProblemInstatVec*>(adoptProblem);
202
203
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and vectorial");
204
205
206
207
208
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

209
210
    if (!oldSolution) 
      WARNING("no oldSolution created\n");
211
212
  }

213

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
214
215
  void ProblemInstatVec::createUhOld() 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
216
217
218
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
219
220
      int size = problemStat->getNumComponents();
      // create oldSolution
221
      oldSolution = new SystemVector("old solution", problemStat->getFeSpaces(), size);
Thomas Witkowski's avatar
Thomas Witkowski committed
222
      for (int i = 0; i < size; i++) {
223
	oldSolution->setDOFVector(i, new DOFVector<double>(problemStat->getFeSpace(i), 
224
225
226
							   name + "->uOld"));
	oldSolution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
227
228
229
	if (problemStat->getEstimator(i))
	  problemStat->getEstimator(i)->
	    addUhOldToSystem(i, oldSolution->getDOFVector(i));
230
231
232
233
      }
    }
  }

234

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
235
236
  void ProblemInstatScal::initTimestep(AdaptInfo *adaptInfo) 
  {
237
238
239
    oldSolution->copy(*(problemStat->getSolution())); 
  }

240

Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
241
242
  void ProblemInstatVec::initTimestep(AdaptInfo *adaptInfo) 
  {
243
244
245
246
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    lastTimepoint = MPI::Wtime();
#endif

247
248
    oldSolution->copy(*(problemStat->getSolution())); 
  }
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
249

250
}