ProblemInstat.h 4.97 KB
Newer Older
1 2 3 4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6 7
// ==                                                                        ==
// ============================================================================
8 9 10 11 12 13 14 15 16 17 18 19
//
// 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.


20 21 22

/** \file ProblemInstat.h */

23 24
#ifndef AMDIS_PROBLEM_INSTAT_H
#define AMDIS_PROBLEM_INSTAT_H
25

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

namespace AMDiS {

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

49
    /// Destructor.
50
    virtual ~ProblemInstatBase() {}
51

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

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

65 66
    virtual void solve(AdaptInfo* adaptInfo) {}

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

72
    virtual void estimate(AdaptInfo *adaptInfo) {}
73

74
    virtual void buildBeforeRefine(AdaptInfo *adaptInfo, Flag) {}
75

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

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

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

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

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

95
    /// Implementation of ProblemTimeInterface::closeTimestep().
96
    virtual void closeTimestep() {}
97

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

104
    /// Used by \ref problemInitial
105 106
    virtual void solveInitialProblem(AdaptInfo *adaptInfo);  

107 108 109 110 111 112 113 114 115 116 117 118 119 120
    double* getTime()
    {
      return &cTime;
    }

    double* getTau()
    {
      return τ
    }

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

122
  protected:
123
    /// Name of the problem.
124
    std::string name;
125 126

    ProblemStatBase *initialProblem;
127 128 129 130 131 132 133 134 135

    /// Time
    double cTime;

    /// Timestep
    double tau;

    /// 1 / timestep
    double invTau;
136 137 138 139 140 141 142
  };


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

154
    ProblemInstat(std::string name, ProblemStatSeq &prob);
155

156
    ProblemInstat(std::string name, ProblemStatSeq &prob, ProblemStatBase &initialProb);
157

158
    /// Destructor.
159
    virtual ~ProblemInstat();
160

161
    /// Initialisation of the problem.
162 163 164
    void initialize(Flag initFlag,
		    ProblemInstat *adoptProblem = NULL,
		    Flag adoptFlag = INIT_NOTHING);
165

166
    /// Used in \ref initialize().
167
    virtual void createUhOld();
168

169
    /// Implementation of ProblemTimeInterface::initTimestep().
170
    virtual void initTimestep(AdaptInfo *adaptInfo);
171

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

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

187 188 189 190 191
    inline DOFVector<double> *getOldSolution(int i)
    {
      return oldSolution->getDOFVector(i);
    }

192
    /// Used by \ref problemInitial
193
    virtual void transferInitialSolution(AdaptInfo *adaptInfo);  
194

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

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

  protected:
200
    /// Space problem solved in each timestep.
201
    ProblemStatSeq* problemStat;
202

203
    /// Solution of the last timestep.
204
    SystemVector *oldSolution;
205 206 207 208 209 210

    /// 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
211 212 213 214 215
  };

}

#endif