ProblemInstat.cc 3.63 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"
22 23

namespace AMDiS {
24 25
  
  using namespace std;
26

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

    initialAdapt.adapt();
  }

36

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

44

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

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

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

58

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

67

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

75

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

84

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

90

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

    // === create vector for old solution ===
97

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

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

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

117

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

138

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

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

148
}