AdaptInstationary.h 6.54 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut für Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ==                                                                        ==
// ============================================================================

/** \file AdaptInstationary.h */

#ifndef AMDIS_ADAPTINSTATIONARY_H
#define AMDIS_ADAPTINSTATIONARY_H

#include <string>
#include <ctime>
#include <queue>
#include "Flag.h"
#include "AdaptInfo.h"
#include "AdaptBase.h"
31
#include "AMDiS_fwd.h"
32
33
34
35
36
37
38
39
40
41
42
43
44
45

namespace AMDiS {

  /** \ingroup Adaption  
   * \brief
   * AdaptInstationary implements the adaptive procdure for time dependent 
   * problems (see ProblemInstat). It contains a pointer to a ProblemInstat
   * object.
   */
  class AdaptInstationary : public AdaptBase
  {
  public:
    /** \brief
     * Creates a AdaptInstationary object with the given name for the time 
46
     * dependent problem problemInstat. TODO: Make obsolete!
47
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
48
    AdaptInstationary(std::string name, 
49
		      ProblemIterationInterface *problemStat,
50
51
52
		      AdaptInfo *info,
		      ProblemTimeInterface *problemInstat,
		      AdaptInfo *initialInfo,
53
                      time_t initialTimestampSet = 0);
54

55
56
57
58
59
60
61
62
63
    /** \brief
     * Creates a AdaptInstationary object with the given name for the time 
     * dependent problem problemInstat.
     */
    AdaptInstationary(std::string name, 
		      ProblemIterationInterface &problemStat,
		      AdaptInfo &info,
		      ProblemTimeInterface &problemInstat,
		      AdaptInfo &initialInfo,
64
                      time_t initialTimestampSet = 0);
65
66
67
68
69
70
71
72
73
74

    /** \brief
     * This funciton is used only to avoid double code in both constructors. If the
     * obsolte constructure, which uses pointers instead of references, will be
     * removed, remove also this function.
     * TODO: Remove if obsolete constructor will be removed.
     */
    void initConstructor(ProblemIterationInterface *problemStat,  
			 AdaptInfo *info,
			 AdaptInfo *initialInfo,
75
			 time_t initialTimestampSet);
76

Thomas Witkowski's avatar
Thomas Witkowski committed
77
    /// Destructor
78
79
    virtual ~AdaptInstationary();

Thomas Witkowski's avatar
Thomas Witkowski committed
80
    /// Sets \ref strategy to aStrategy
Thomas Witkowski's avatar
Thomas Witkowski committed
81
82
    inline void setStrategy(int aStrategy) 
    { 
83
      strategy = aStrategy; 
84
    }
85

Thomas Witkowski's avatar
Thomas Witkowski committed
86
    /// Returns \ref strategy
Thomas Witkowski's avatar
Thomas Witkowski committed
87
88
    const int getStrategy() const 
    {
89
      return strategy;
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
90
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
91
    /// Implementation of AdaptBase::adapt()
92
93
    virtual int adapt();

Thomas Witkowski's avatar
Thomas Witkowski committed
94
    /// Serialization
95
    virtual void serialize(std::ostream &out);
96

Thomas Witkowski's avatar
Thomas Witkowski committed
97
    /// deserialization
98
    virtual void deserialize(std::istream &in);
99
100
101
102
103
104
105
106
107
108
109
110
111
112


  protected:
    /** \brief
     * Implements one (maybe adaptive) timestep. Both the explicit and the 
     * implicit time strategy are implemented. The semi-implicit strategy 
     * is only a special case of the implicit strategy with a limited number of 
     * iterations (exactly one).
     * The routine uses the parameter \ref strategy to select the strategy:
     * strategy 0: Explicit strategy, 
     * strategy 1: Implicit strategy.
     */
    virtual void oneTimestep();

Thomas Witkowski's avatar
Thomas Witkowski committed
113
    /// Initialisation of this AdaptInstationary object
Thomas Witkowski's avatar
Thomas Witkowski committed
114
    void initialize(std::string aName);
115

Thomas Witkowski's avatar
Thomas Witkowski committed
116
    /// Implements the explit time strategy. Used by \ref oneTimestep().
117
118
    virtual void explicitTimeStrategy();

Thomas Witkowski's avatar
Thomas Witkowski committed
119
    /// Implements the implicit time strategy. Used by \ref oneTimestep().
120
121
    virtual void implicitTimeStrategy();

Thomas Witkowski's avatar
Thomas Witkowski committed
122
123
124
125
126
127
128
    /** \brief
     * This iteration strategy allows the timestep and the mesh to be adapted 
     * after each timestep solution. There are no inner loops for mesh adaption and
     * no refused timesteps.
     */
    void simpleAdaptiveTimeStrategy();

129
130
131
132
133
134
135
136
137
138
139
    /** \brief
     * Checks whether the runtime of the queue (of the servers batch system) requires
     * to stop the calculation and to reschedule the problem to the batch system.
     *
     * The function return true, if there will be a timeout in the near future, and
     * therefore the problem should be rescheduled. Otherwise, the return value is
     * false.
     */
    bool checkQueueRuntime();

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
140
    /// Strategy for choosing one timestep
141
142
    int strategy; 

Thomas Witkowski's avatar
Thomas Witkowski committed
143
    /// Parameter \f$ \delta_1 \f$ used in time step reduction
Thomas Witkowski's avatar
Thomas Witkowski committed
144
    double timeDelta1;
145

Thomas Witkowski's avatar
Thomas Witkowski committed
146
    /// Parameter \f$ \delta_2 \f$ used in time step enlargement
Thomas Witkowski's avatar
Thomas Witkowski committed
147
    double timeDelta2;
148
149
150
151
152
153

    /** \brief
     * If this parameter is 1 and the instationary problem is stable, hence the number
     * of solver iterations to solve the problem is zero, the adaption loop will stop.
     */
    int breakWhenStable;
Thomas Witkowski's avatar
Thomas Witkowski committed
154
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
155
    bool fixedTimestep;
156
157
158
159
160

    /** \brief
     * Runtime of the queue (of the servers batch system) in seconds. If the problem
     * runs on a computer/server without a time limited queue, the value is -1.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
161
    int queueRuntime;
162

Thomas Witkowski's avatar
Thomas Witkowski committed
163
    /// Name of the file used to automatically serialize the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
164
    std::string queueSerializationFilename;
165
166

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
167
168
     * Timestamp at the beginning of all calculations. It is used to calculate the 
     * overall runtime of the problem.
169
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
170
    time_t initialTimestamp;
171
172

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
173
174
     * Timestamp at the beginning of the last timestep iteration. Is is used to 
     * calculate the runtime of the last timestep.
175
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
176
    time_t iterationTimestamp;
177

Thomas Witkowski's avatar
Thomas Witkowski committed
178
    /// Stores the runtime (in seconds) of some last timestep iterations.
Thomas Witkowski's avatar
Thomas Witkowski committed
179
    std::queue<int> lastIterationsDuration;
180
181

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
182
183
     * In debug mode, the adapt loop will print information about timestep decreasing 
     * and increasing.
184
185
     */
    bool dbgMode;
186
187
188
189
190
  };

}

#endif // AMDIS_ADAPTINSTATIONARY_H