ProblemInstat.h 4.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20 21


22 23 24

/** \file ProblemInstat.h */

25 26
#ifndef AMDIS_PROBLEM_INSTAT_H
#define AMDIS_PROBLEM_INSTAT_H
27

28
#include "ProblemStat.h"
29 30 31 32 33 34 35 36 37
#include "ProblemTimeInterface.h"
#include "AdaptInstationary.h"

namespace AMDiS {

  /**
   * \ingroup Problem
   *
   * \brief
38
   * Base class for \ref ProblemInstat.
39
   */
40 41
  class ProblemInstatBase : public ProblemTimeInterface,
			    public ProblemStatBase
42 43
  {
  public:
44
    /// Constructor.
45 46
    ProblemInstatBase(std::string probName,
		      ProblemStatBase *initialProb)
47
      : name(probName),
48
	initialProblem(initialProb ? initialProb : this)
49
    {}
50

51
    /// Destructor.
52
    virtual ~ProblemInstatBase() {}
53

54
    /// Initialisation of the problem.
55 56
    virtual void initialize(Flag initFlag,
			    ProblemInstat *adoptProblem = NULL,
57 58
			    Flag adoptFlag = INIT_NOTHING)
    {}
59

60 61 62 63 64 65 66
    virtual void setTime(AdaptInfo* adaptInfo) 
    {
      cTime = adaptInfo->getTime();
      tau = adaptInfo->getTimestep();
      invTau = 1.0 / tau;
    }

67 68
    virtual void solve(AdaptInfo* adaptInfo) {}

69
    virtual void solve(AdaptInfo *adaptInfo, bool, bool) 
70
    {
71 72
      solve(adaptInfo);
    }
73

74
    virtual void estimate(AdaptInfo *adaptInfo) {}
75

76
    virtual void buildBeforeRefine(AdaptInfo *adaptInfo, Flag) {}
77

78
    virtual void buildBeforeCoarsen(AdaptInfo *adaptInfo, Flag) {}
79

80
    virtual void buildAfterCoarsen(AdaptInfo *adaptInfo, Flag, bool, bool) {}
81

82 83
    virtual Flag markElements(AdaptInfo *adaptInfo) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
84
      return 0; 
85
    }
86

87 88
    virtual Flag refineMesh(AdaptInfo *adaptInfo) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
89
      return 0; 
90
    }
91

92 93
    virtual Flag coarsenMesh(AdaptInfo *adaptInfo) 
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
94
      return 0; 
95
    }
96

97
    /// Implementation of ProblemTimeInterface::closeTimestep().
98 99
    virtual void closeTimestep(AdaptInfo *adaptInfo) 
    {}
100

101
    /// Returns \ref name.
Thomas Witkowski's avatar
Thomas Witkowski committed
102
    inline std::string getName() 
103
    { 
Thomas Witkowski's avatar
Thomas Witkowski committed
104
      return name; 
105
    }
106

107
    /// Used by \ref problemInitial
108 109
    virtual void solveInitialProblem(AdaptInfo *adaptInfo);  

110 111 112 113 114 115 116 117 118 119 120 121 122 123
    double* getTime()
    {
      return &cTime;
    }

    double* getTau()
    {
      return τ
    }

    double* getInvTau()
    {
      return &invTau;
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
124

125
  protected:
126
    /// Name of the problem.
127
    std::string name;
128 129

    ProblemStatBase *initialProblem;
130 131 132 133 134 135 136 137 138

    /// Time
    double cTime;

    /// Timestep
    double tau;

    /// 1 / timestep
    double invTau;
139 140 141 142 143 144 145
  };


  /**
   * \ingroup Problem
   *
   * \brief
146 147
   * Standard implementation of ProblemTimeInterface for a time
   * dependent problems.
148
   */
149
  class ProblemInstat : public ProblemInstatBase
150 151
  {
  public:
152
    /// Constructs a ProblemInstatVec with prob as its stationary problem.
153
    ProblemInstat(std::string name, 
154
		  ProblemStatSeq *prob,
155
		  ProblemStatBase *initialProb = NULL);
156

157
    ProblemInstat(std::string name, ProblemStatSeq &prob);
158

159
    ProblemInstat(std::string name, ProblemStatSeq &prob, ProblemStatBase &initialProb);
160

161
    /// Destructor.
162
    virtual ~ProblemInstat();
163

164
    /// Initialisation of the problem.
165 166 167
    void initialize(Flag initFlag,
		    ProblemInstat *adoptProblem = NULL,
		    Flag adoptFlag = INIT_NOTHING);
168

169
    /// Used in \ref initialize().
170
    virtual void createUhOld();
171

172
    /// Implementation of ProblemTimeInterface::initTimestep().
173
    virtual void initTimestep(AdaptInfo *adaptInfo);
174

175
    /// Implementation of ProblemTimeInterface::closeTimestep().
176
    virtual void closeTimestep(AdaptInfo *adaptInfo);
177
  
178
    /// Returns \ref problemStat.
179
    inline ProblemStatSeq* getStatProblem() 
180
    {
181
      return problemStat; 
Thomas Witkowski's avatar
Thomas Witkowski committed
182
    }
183

184 185 186
    /// Returns \ref oldSolution.
    inline SystemVector *getOldSolution() 
    { 
187
      return oldSolution; 
Thomas Witkowski's avatar
Thomas Witkowski committed
188
    }
189

190 191 192 193 194
    inline DOFVector<double> *getOldSolution(int i)
    {
      return oldSolution->getDOFVector(i);
    }

195
    /// Used by \ref problemInitial
196
    virtual void transferInitialSolution(AdaptInfo *adaptInfo);  
197

198
    virtual void serialize(std::ostream &out) {}
Thomas Witkowski's avatar
Thomas Witkowski committed
199

200
    virtual void deserialize(std::istream &in) {}
201 202

  protected:
203
    /// Space problem solved in each timestep.
204
    ProblemStatSeq* problemStat;
205

206
    /// Solution of the last timestep.
207
    SystemVector *oldSolution;
208 209 210 211 212 213

    /// In parallel computations, we want to print the overall computational time
    /// that is used for one timestep.
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
    double lastTimepoint;
#endif
214 215 216 217 218
  };

}

#endif