ProblemInstat.cc 3.57 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
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
13
14
#include <mpi.h>
#endif
15

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

namespace AMDiS {

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

    initialAdapt.adapt();
  }

34

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

42

43
  void ProblemInstat::closeTimestep(AdaptInfo *adaptInfo) 
44
  {
45
    FUNCNAME("ProblemInstat::closeTimestep()");
46

47
48
    bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime());
    problemStat->writeFiles(adaptInfo, force);
49
50
51
52
53

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

56

57
58
59
  ProblemInstat::ProblemInstat(std::string sname, 
			       ProblemStat *prob, ProblemStatBase *initialProb)
    : ProblemInstatBase(sname, initialProb), 
60
61
      problemStat(prob),
      oldSolution(NULL)
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
62
  {}
63

64

65
66
  ProblemInstat::ProblemInstat(std::string sname, ProblemStat &prob)
    : ProblemInstatBase(sname, NULL), 
67
68
69
70
      problemStat(&prob),
      oldSolution(NULL)
  {}

71

72
73
74
  ProblemInstat::ProblemInstat(std::string sname, 
			       ProblemStat &prob, ProblemStatBase &initialProb)
    : ProblemInstatBase(sname, &initialProb), 
75
76
77
78
      problemStat(&prob),
      oldSolution(NULL)
  {}

79

80
  ProblemInstat::~ProblemInstat()
81
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
82
    delete oldSolution;
83
84
  }

85

86
87
  void ProblemInstat::initialize(Flag initFlag, ProblemInstat *adoptProblem,
				 Flag adoptFlag) 
88
  {
89
    FUNCNAME("ProblemInstat::initialize()");
90
91

    // === create vector for old solution ===
92

Thomas Witkowski's avatar
Thomas Witkowski committed
93
    if (oldSolution) {
94
95
      WARNING("oldSolution already created\n");
    } else {
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
96
      if (initFlag.isSet(INIT_UH_OLD))
97
	createUhOld();
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
98

Thomas Witkowski's avatar
Thomas Witkowski committed
99
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
100
	ProblemInstat* _adoptProblem = dynamic_cast<ProblemInstat*>(adoptProblem);
101
102
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and vectorial");
103
104
105
106
107
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

108
109
    if (!oldSolution) 
      WARNING("no oldSolution created\n");
110
111
  }

112

113
  void ProblemInstat::createUhOld() 
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
114
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
115
116
117
    if (oldSolution) {
      WARNING("oldSolution already created\n");
    } else {
118
119
      int size = problemStat->getNumComponents();
      // create oldSolution
120
      oldSolution = new SystemVector("old solution", problemStat->getFeSpaces(), size);
Thomas Witkowski's avatar
Thomas Witkowski committed
121
      for (int i = 0; i < size; i++) {
122
	oldSolution->setDOFVector(i, new DOFVector<double>(problemStat->getFeSpace(i), 
123
124
125
							   name + "->uOld"));
	oldSolution->getDOFVector(i)->setCoarsenOperation(COARSE_INTERPOL);
      
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
126
127
128
	if (problemStat->getEstimator(i))
	  problemStat->getEstimator(i)->
	    addUhOldToSystem(i, oldSolution->getDOFVector(i));
129
130
131
132
      }
    }
  }

133

134
  void ProblemInstat::initTimestep(AdaptInfo *adaptInfo) 
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
135
  {
136
137
138
139
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    lastTimepoint = MPI::Wtime();
#endif

140
141
    oldSolution->copy(*(problemStat->getSolution())); 
  }
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
142

143
}