AdaptInstationary.h 5.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \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
46
47

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 
     * dependent problem problemInstat.
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
48
    AdaptInstationary(std::string name, 
49
		      ProblemIterationInterface *problemStat,
50
51
52
53
		      AdaptInfo *info,
		      ProblemTimeInterface *problemInstat,
		      AdaptInfo *initialInfo,
                      time_t initialTimestamp = 0);
54

Thomas Witkowski's avatar
Thomas Witkowski committed
55
    /// Destructor
56
57
    virtual ~AdaptInstationary();

Thomas Witkowski's avatar
Thomas Witkowski committed
58
    /// Sets \ref strategy to aStrategy
59
60
    inline void setStrategy(int aStrategy) { 
      strategy = aStrategy; 
61
    }
62

Thomas Witkowski's avatar
Thomas Witkowski committed
63
    /// Returns \ref strategy
64
65
    const int getStrategy() const {
      return strategy;
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
66
    }
67

Thomas Witkowski's avatar
Thomas Witkowski committed
68
    /// Implementation of AdaptBase::adapt()
69
70
    virtual int adapt();

Thomas Witkowski's avatar
Thomas Witkowski committed
71
    /// Serialization
72
    virtual void serialize(std::ostream &out);
73

Thomas Witkowski's avatar
Thomas Witkowski committed
74
    /// deserialization
75
    virtual void deserialize(std::istream &in);
76
77
78
79
80
81
82
83
84
85
86
87
88
89


  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
90
    /// Initialisation of this AdaptInstationary object
91
    void initialize(const std::string& aName);
92

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

Thomas Witkowski's avatar
Thomas Witkowski committed
96
    /// Implements the implicit time strategy. Used by \ref oneTimestep().
97
98
99
100
101
102
103
104
105
106
107
108
109
    virtual void implicitTimeStrategy();

    /** \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
110
    /// Strategy for choosing one timestep
111
112
    int strategy; 

Thomas Witkowski's avatar
Thomas Witkowski committed
113
    /// Parameter \f$ \delta_1 \f$ used in time step reduction
114
    double time_delta_1;
115

Thomas Witkowski's avatar
Thomas Witkowski committed
116
    /// Parameter \f$ \delta_2 \f$ used in time step enlargement
117
    double time_delta_2;
118
119
120
121
122
123
124

    /** \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
125
    ///
126
127
128
129
130
131
132
133
    bool fixedTimestep_;

    /** \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.
     */
    int queueRuntime_;

Thomas Witkowski's avatar
Thomas Witkowski committed
134
    /// Name of the file used to automatically serialize the problem.
135
    std::string queueSerializationFilename_;
136
137

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
138
139
     * Timestamp at the beginning of all calculations. It is used to calculate the 
     * overall runtime of the problem.
140
141
142
143
     */
    time_t initialTimestamp_;

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
144
145
     * Timestamp at the beginning of the last timestep iteration. Is is used to 
     * calculate the runtime of the last timestep.
146
147
148
     */
    time_t iterationTimestamp_;

Thomas Witkowski's avatar
Thomas Witkowski committed
149
    /// Stores the runtime (in seconds) of some last timestep iterations.
150
    std::queue<int> lastIterationsDuration_;
151
152

    /** \brief
Thomas Witkowski's avatar
Thomas Witkowski committed
153
154
     * In debug mode, the adapt loop will print information about timestep decreasing 
     * and increasing.
155
156
     */
    bool dbgMode;
157
158
159
160
161
  };

}

#endif // AMDIS_ADAPTINSTATIONARY_H