AdaptInstationary.h 5.77 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

namespace AMDiS {

36
37
  using namespace std;

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

Thomas Witkowski's avatar
Thomas Witkowski committed
56
57
    /// Creates a AdaptInstationary object with the given name for the time 
    /// dependent problem problemInstat.
58
    AdaptInstationary(string name, 
59
60
61
62
		      ProblemIterationInterface &problemStat,
		      AdaptInfo &info,
		      ProblemTimeInterface &problemInstat,
		      AdaptInfo &initialInfo,
63
                      time_t initialTimestampSet = 0);
64
65
66
67
68
69
70
71
72
73

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

Thomas Witkowski's avatar
Thomas Witkowski committed
76
    /// Destructor
77
    virtual ~AdaptInstationary() {}
78

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

Thomas Witkowski's avatar
Thomas Witkowski committed
85
    /// Returns \ref strategy
86
    int getStrategy() const 
Thomas Witkowski's avatar
Thomas Witkowski committed
87
    {
88
      return strategy;
Thomas Witkowski's avatar
* Bla    
Thomas Witkowski committed
89
    }
Thomas Witkowski's avatar
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(ostream &out);
96

Thomas Witkowski's avatar
Thomas Witkowski committed
97
    /// deserialization
98
    virtual void deserialize(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
114
    void initialize(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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
153
    ///
Thomas Witkowski's avatar
Thomas Witkowski committed
154
    bool fixedTimestep;
155

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

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

Thomas Witkowski's avatar
Thomas Witkowski committed
163
164
    /// 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
165
    time_t initialTimestamp;
166

Thomas Witkowski's avatar
Thomas Witkowski committed
167
168
    /// 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
169
    time_t iterationTimestamp;
170

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

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

}

#endif // AMDIS_ADAPTINSTATIONARY_H