ProblemInstat.h 4.89 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
    virtual void initialize(Flag initFlag,
56
			    ProblemInstat *adoptProblem = nullptr,
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 126 127 128
    virtual void serialize(std::ostream &out) {}

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

129
  protected:
130
    /// Name of the problem.
131
    std::string name;
132 133

    ProblemStatBase *initialProblem;
134 135 136 137 138 139 140 141 142

    /// Time
    double cTime;

    /// Timestep
    double tau;

    /// 1 / timestep
    double invTau;
143 144 145 146 147 148 149
  };


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

161
    ProblemInstat(std::string name, ProblemStatSeq &prob);
162

163
    ProblemInstat(std::string name, ProblemStatSeq &prob, ProblemStatBase &initialProb);
164

165
    /// Destructor.
166
    virtual ~ProblemInstat();
167

168
    /// Initialisation of the problem.
169
    void initialize(Flag initFlag,
170
		    ProblemInstat *adoptProblem = nullptr,
171
		    Flag adoptFlag = INIT_NOTHING);
172

173
    /// Used in \ref initialize().
174
    virtual void createUhOld();
175

176
    /// Implementation of ProblemTimeInterface::initTimestep().
177
    virtual void initTimestep(AdaptInfo *adaptInfo);
178

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

188 189 190
    /// Returns \ref oldSolution.
    inline SystemVector *getOldSolution() 
    { 
191
      return oldSolution; 
Thomas Witkowski's avatar
Thomas Witkowski committed
192
    }
193

194 195 196 197 198
    inline DOFVector<double> *getOldSolution(int i)
    {
      return oldSolution->getDOFVector(i);
    }

199
    /// Used by \ref problemInitial
200
    virtual void transferInitialSolution(AdaptInfo *adaptInfo);  
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