ProblemInstat.cc 3.66 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
#include "ProblemInstat.h"
#include "AdaptStationary.h"
#include "AdaptInstationary.h"
#include "StandardProblemIteration.h"
20
#include "est/Estimator.h"
21
#include "io/FileWriter.h"
Praetorius, Simon's avatar
Praetorius, Simon committed
22
#include "io/FileWriter.hh"
23
24

namespace AMDiS {
25
26
  
  using namespace std;
27

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

    initialAdapt.adapt();
  }

37

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

45

46
  void ProblemInstat::closeTimestep(AdaptInfo *adaptInfo) 
47
  {
48
    FUNCNAME("ProblemInstat::closeTimestep()");
49

50
51
    bool force = (adaptInfo->getTime() >= adaptInfo->getEndTime());
    problemStat->writeFiles(adaptInfo, force);
52
53
54
55
56

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

59

60
61
62
  ProblemInstat::ProblemInstat(string sname, 
			       ProblemStatSeq *prob, 
			       ProblemStatBase *initialProb)
63
    : ProblemInstatBase(sname, initialProb), 
64
65
      problemStat(prob),
      oldSolution(NULL)
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
66
  {}
67

68

69
70
  ProblemInstat::ProblemInstat(string sname, 
			       ProblemStatSeq &prob)
71
    : ProblemInstatBase(sname, NULL), 
72
73
74
75
      problemStat(&prob),
      oldSolution(NULL)
  {}

76

77
78
79
  ProblemInstat::ProblemInstat(string sname, 
			       ProblemStatSeq &prob, 
			       ProblemStatBase &initialProb)
80
    : ProblemInstatBase(sname, &initialProb), 
81
82
83
84
      problemStat(&prob),
      oldSolution(NULL)
  {}

85

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

91

92
93
  void ProblemInstat::initialize(Flag initFlag, ProblemInstat *adoptProblem,
				 Flag adoptFlag) 
94
  {
95
    FUNCNAME("ProblemInstat::initialize()");
96
97

    // === create vector for old solution ===
98

Thomas Witkowski's avatar
Thomas Witkowski committed
99
    if (oldSolution) {
100
101
      WARNING("oldSolution already created\n");
    } else {
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
102
      if (initFlag.isSet(INIT_UH_OLD))
103
	createUhOld();
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
104

Thomas Witkowski's avatar
Thomas Witkowski committed
105
      if (adoptProblem && adoptFlag.isSet(INIT_UH_OLD)) {
106
	ProblemInstat* _adoptProblem = dynamic_cast<ProblemInstat*>(adoptProblem);
107
108
	TEST_EXIT(_adoptProblem)
	  ("can't adopt oldSolution from problem which is not instationary and vectorial");
109
110
111
112
113
	TEST_EXIT(!oldSolution)("oldSolution already created");
	oldSolution = _adoptProblem->getOldSolution();
      }
    }

114
115
    if (!oldSolution) 
      WARNING("no oldSolution created\n");
116
117
  }

118

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

139

140
  void ProblemInstat::initTimestep(AdaptInfo *adaptInfo) 
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
141
  {
142
143
144
145
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    lastTimepoint = MPI::Wtime();
#endif

146
147
    oldSolution->copy(*(problemStat->getSolution())); 
  }
Thomas Witkowski's avatar
nix.    
Thomas Witkowski committed
148

149
}