AdaptInstationary.h 5.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * 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.
 * 
 ******************************************************************************/
20
21


22
23
24
25
26
27
28
29
30
31
32
33

/** \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"
34
#include "AMDiS_fwd.h"
35
36
37

namespace AMDiS {

38
39
  using namespace std;

40
41
42
43
44
45
46
47
48
  /** \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:
Thomas Witkowski's avatar
Thomas Witkowski committed
49
50
    /// Creates a AdaptInstationary object with the given name for the time 
    /// dependent problem problemInstat. TODO: Make obsolete!
51
    AdaptInstationary(string name, 
52
		      ProblemIterationInterface *problemStat,
53
54
55
		      AdaptInfo *info,
		      ProblemTimeInterface *problemInstat,
		      AdaptInfo *initialInfo,
56
                      time_t initialTimestampSet = 0);
57

Thomas Witkowski's avatar
Thomas Witkowski committed
58
59
    /// Creates a AdaptInstationary object with the given name for the time 
    /// dependent problem problemInstat.
60
    AdaptInstationary(string name, 
61
62
63
64
		      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
    virtual ~AdaptInstationary() {}
80

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
88
    int getStrategy() const 
Thomas Witkowski's avatar
Thomas Witkowski committed
89
    {
90
      return strategy;
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
91
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
92

Thomas Witkowski's avatar
Thomas Witkowski committed
93
    /// Implementation of AdaptBase::adapt()
94
95
    virtual int adapt();

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

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


  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
115
    /// Initialisation of this AdaptInstationary object
116
    void initialize(string aName);
117

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

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

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

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

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
151
152
    /// 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.
153
    int breakWhenStable;
Thomas Witkowski's avatar
Thomas Witkowski committed
154

Thomas Witkowski's avatar
Thomas Witkowski committed
155
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
156
    bool fixedTimestep;
157

Thomas Witkowski's avatar
Thomas Witkowski committed
158
159
    /// 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
160
    int queueRuntime;
161

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

Thomas Witkowski's avatar
Thomas Witkowski committed
165
166
    /// Timestamp at the beginning of all calculations. It is used to calculate the 
    /// overall runtime of the problem.
Thomas Witkowski's avatar
Thomas Witkowski committed
167
    time_t initialTimestamp;
168

Thomas Witkowski's avatar
Thomas Witkowski committed
169
170
    /// Timestamp at the beginning of the last timestep iteration. Is is used to 
    /// calculate the runtime of the last timestep.
Thomas Witkowski's avatar
Thomas Witkowski committed
171
    time_t iterationTimestamp;
172

Thomas Witkowski's avatar
Thomas Witkowski committed
173
    /// Stores the runtime (in seconds) of some last timestep iterations.
174
    queue<int> lastIterationsDuration;
175

Thomas Witkowski's avatar
Thomas Witkowski committed
176
177
    /// In debug mode, the adapt loop will print information about timestep decreasing 
    /// and increasing.
178
    bool dbgMode;
179
180
181
182
183
  };

}

#endif // AMDIS_ADAPTINSTATIONARY_H