ProblemInstat.h 4.88 KB
Newer Older
1 2 3 4 5 6 7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9 10 11 12 13 14 15 16 17
 * 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.
18
 *
19
 ******************************************************************************/
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
#if 0
56
    virtual void initialize(Flag initFlag,
57
			    ProblemInstat *adoptProblem = NULL,
58 59
			    Flag adoptFlag = INIT_NOTHING)
    {}
60
#endif
61

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

69 70
    virtual void solve(AdaptInfo* adaptInfo) {}

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

76
    virtual void estimate(AdaptInfo *adaptInfo) {}
77

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

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

82
    virtual void buildAfterCoarsen(AdaptInfo *adaptInfo, Flag, bool, bool) {}
83

84 85 86
    virtual Flag markElements(AdaptInfo *adaptInfo)
    {
      return 0;
87
    }
88

89 90 91
    virtual Flag refineMesh(AdaptInfo *adaptInfo)
    {
      return 0;
92
    }
93

94 95 96
    virtual Flag coarsenMesh(AdaptInfo *adaptInfo)
    {
      return 0;
97
    }
98

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

103
    /// Returns \ref name.
104 105 106
    inline std::string getName()
    {
      return name;
107
    }
108

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

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

    double* getTau()
    {
      return τ
    }

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

127 128 129 130
    virtual void serialize(std::ostream &out) {}

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

131
  protected:
132
    /// Name of the problem.
133
    std::string name;
134 135

    ProblemStatBase *initialProblem;
136 137 138 139 140 141 142 143 144

    /// Time
    double cTime;

    /// Timestep
    double tau;

    /// 1 / timestep
    double invTau;
145 146 147 148 149 150 151
  };


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

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

165
    ProblemInstat(std::string name, ProblemStatSeq &prob, ProblemStatBase &initialProb);
166

167
    /// Destructor.
168
    virtual ~ProblemInstat();
169

170
    /// Initialisation of the problem.
171
    virtual void initialize(Flag initFlag,
172
			    ProblemInstat *adoptProblem = NULL,
173
			    Flag adoptFlag = INIT_NOTHING);
174

175
    /// Used in \ref initialize().
176
    virtual void createUhOld();
177

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

181
    /// Implementation of ProblemTimeInterface::closeTimestep().
182
    virtual void closeTimestep(AdaptInfo *adaptInfo);
183

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

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

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

201
    /// Used by \ref problemInitial
202
    virtual void transferInitialSolution(AdaptInfo *adaptInfo);
203 204

  protected:
205
    /// Space problem solved in each timestep.
206
    ProblemStatSeq* problemStat;
207

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

    /// 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
216 217 218 219 220
  };

}

#endif