AdaptInstationary.h 5.93 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
23
24
25
26
27
28
29
30
31

/** \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"
32
#include "AMDiS_fwd.h"
33
34
35
36
37
38
39
40
41
42
43
44
45
46

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

56
57
58
59
60
61
62
63
64
    /** \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,
65
                      time_t initialTimestampSet = 0);
66
67
68
69
70
71
72
73
74
75

    /** \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,
76
			 time_t initialTimestampSet);
77

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

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

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

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

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


  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
114
    /// Initialisation of this AdaptInstationary object
Thomas Witkowski's avatar
Thomas Witkowski committed
115
    void initialize(std::string aName);
116

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
123
124
125
126
127
128
129
    /** \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();

130
131
132
133
134
135
136
137
138
139
140
    /** \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
141
    /// Strategy for choosing one timestep
142
143
    int strategy; 

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

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

    /** \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
155
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
156
    bool fixedTimestep;
157
158
159
160
161

    /** \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
162
    int queueRuntime;
163

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

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

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

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

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

}

#endif // AMDIS_ADAPTINSTATIONARY_H