/home/runner/work/amr-wind/amr-wind/amr-wind/core/SimTime.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/SimTime.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
SimTime.H
Go to the documentation of this file.
1#ifndef SIMTIME_H
2#define SIMTIME_H
3
4#include "AMReX_REAL.H"
5#include "AMReX_GpuQualifiers.H"
6#include "AMReX_Extension.H"
7#include "AMReX_Vector.H"
8#include <algorithm>
9#include <cmath>
10
11namespace {
12AMREX_FORCE_INLINE amrex::Real get_enforced_dt_for_output(
13 const amrex::Real dt,
14 const amrex::Real cur_time,
15 const amrex::Real interval,
16 const amrex::Real tol)
17{
18 // Tolerance for being slightly under is relative to requested interval
19 return std::min(
20 dt, (std::floor(cur_time / interval + tol) + 1) * interval - cur_time);
21}
22} // namespace
23
24namespace amr_wind {
25
30{
31public:
32 static constexpr int max_time_states = 3;
33
34 SimTime() = default;
35
36 ~SimTime() = default;
37
42 bool new_timestep();
43
46 bool continue_simulation() const;
47
50 bool do_regrid() const;
51
54 bool write_plot_file() const;
55
58 bool write_checkpoint() const;
59
62 bool write_last_plot_file() const;
63
66 bool write_last_checkpoint() const;
67
71 void set_current_cfl(
72 const amrex::Real conv_cfl,
73 const amrex::Real diff_cfl,
74 const amrex::Real src_cfl);
75
81 void set_restart_time(int tidx, amrex::Real time);
82
83 AMREX_FORCE_INLINE
84 amrex::Real delta_t() const { return m_dt[0]; }
85
86 AMREX_FORCE_INLINE
87 amrex::Real& delta_t() { return m_dt[0]; }
88
89 AMREX_FORCE_INLINE
90 amrex::Real delta_t_nm1() const { return m_dt[1]; }
91
92 AMREX_FORCE_INLINE
93 amrex::Real delta_t_nm2() const { return m_dt[2]; }
94
95 AMREX_FORCE_INLINE
96 amrex::Real& delta_t_nm1() { return m_dt[1]; }
97
98 AMREX_FORCE_INLINE
99 amrex::Real& delta_t_nm2() { return m_dt[2]; }
100
101 AMREX_FORCE_INLINE
102 amrex::Real current_time() const { return m_cur_time; }
103
104 AMREX_FORCE_INLINE
105 amrex::Real& current_time() { return m_cur_time; }
106
107 AMREX_FORCE_INLINE
108 amrex::Real new_time() const { return m_new_time; }
109
110 AMREX_FORCE_INLINE
111 amrex::Real max_cfl() const { return m_max_cfl; }
112
113 AMREX_FORCE_INLINE
114 int time_index() const { return m_time_index; }
115
116 AMREX_FORCE_INLINE
117 int& time_index() { return m_time_index; }
118
119 AMREX_FORCE_INLINE
120 bool adaptive_timestep() const { return m_adaptive; }
121
122 AMREX_FORCE_INLINE
123 bool use_force_cfl() const { return m_use_force_cfl; }
124
125 AMREX_FORCE_INLINE
126 int regrid_interval() const { return m_regrid_interval; }
127
128 AMREX_FORCE_INLINE
129 amrex::Real start_time() const { return m_start_time; }
130
131 AMREX_FORCE_INLINE
132 amrex::Real stop_time() const { return m_stop_time; }
133
134 AMREX_FORCE_INLINE
135 int start_time_index() const { return m_start_time_index; }
136
137 AMREX_FORCE_INLINE
138 int stop_time_index() const { return m_stop_time_index; }
139
140 AMREX_FORCE_INLINE
141 int chkpt_interval() const { return m_chkpt_interval; }
142
144 void parse_parameters();
145
146private:
148 amrex::Vector<amrex::Real> m_dt =
149 amrex::Vector<amrex::Real>(max_time_states, 0.0);
150
152 amrex::Real m_cur_time{0.0};
153
155 amrex::Real m_new_time{0.0};
156
158 amrex::Real m_start_time{0.0};
159
161 amrex::Real m_stop_time{-1.0};
162
164 amrex::Real m_max_cfl{0.5};
165
167 amrex::Real m_fixed_dt{-1.0};
168
170 amrex::Real m_initial_dt{-1.0};
171
173 amrex::Real m_current_cfl{0.0};
174
176 amrex::Real m_init_shrink{0.1};
177
179 amrex::Real m_dt_growth{0.1};
180
182 amrex::Real m_chkpt_t_interval{-1.0};
183
185 amrex::Real m_chkpt_t_delay{0.0};
186
188 amrex::Real m_chkpt_t_tol{1e-8};
189
191 amrex::Real m_force_chkpt_tol{1e-3};
192
194 amrex::Real m_plt_t_interval{-1.0};
195
197 amrex::Real m_plt_t_delay{0.0};
198
200 amrex::Real m_plt_t_tol{1e-8};
201
203 amrex::Real m_force_plt_tol{1e-3};
204
207
210
213
216
219
222
225
229
232
235
238
240 int m_verbose{0};
241
243 bool m_adaptive{false};
244
246 bool m_is_init{true};
247
249 bool m_use_force_cfl{true};
250
252 bool m_force_chkpt_dt{false};
253
255 bool m_force_plt_dt{false};
256};
257
258} // namespace amr_wind
259
260#endif /* SIMTIME_H */
Definition SimTime.H:30
amrex::Real m_plt_t_interval
Time interval for plot file output.
Definition SimTime.H:194
void set_current_cfl(const amrex::Real conv_cfl, const amrex::Real diff_cfl, const amrex::Real src_cfl)
Definition SimTime.cpp:147
int m_time_index
Counter for the number of timesteps since start of simulation.
Definition SimTime.H:206
bool write_plot_file() const
Definition SimTime.cpp:281
int m_plt_interval
Time step interval for plot file output.
Definition SimTime.H:231
AMREX_FORCE_INLINE amrex::Real & delta_t_nm2()
Definition SimTime.H:99
int m_chkpt_start_index
Initial starting time index for generating checkpoint files.
Definition SimTime.H:212
amrex::Real m_chkpt_t_tol
Relative (to dt) tolerance for checkpoint time interval output.
Definition SimTime.H:188
bool continue_simulation() const
Definition SimTime.cpp:253
int m_chkpt_interval
Time step interval for writing checkpoint/restart files.
Definition SimTime.H:224
AMREX_FORCE_INLINE int time_index() const
Definition SimTime.H:114
AMREX_FORCE_INLINE amrex::Real delta_t_nm1() const
Definition SimTime.H:90
amrex::Real m_current_cfl
Current CFL.
Definition SimTime.H:173
int m_stop_time_index
Maximum timesteps for simulation.
Definition SimTime.H:221
int m_verbose
Verbosity.
Definition SimTime.H:240
AMREX_FORCE_INLINE amrex::Real new_time() const
Definition SimTime.H:108
bool m_is_init
Flag indicating if this is initialization.
Definition SimTime.H:246
amrex::Real m_chkpt_t_delay
Time delay for checkpoint/restart output.
Definition SimTime.H:185
bool m_force_chkpt_dt
Bool for if checkpoint time interval should be forced.
Definition SimTime.H:252
~SimTime()=default
int m_plt_start_index
Initial starting time index for generating output files.
Definition SimTime.H:215
amrex::Real m_force_chkpt_tol
Relative (to chkpt_t_interval) tolerance for enforcing dt.
Definition SimTime.H:191
int m_regrid_start_index
Initial starting time index for regriding.
Definition SimTime.H:218
bool write_last_plot_file() const
Definition SimTime.cpp:324
bool m_force_plt_dt
Bool for if plt time interval should be forced.
Definition SimTime.H:255
AMREX_FORCE_INLINE amrex::Real delta_t_nm2() const
Definition SimTime.H:93
amrex::Real m_new_time
Time where a new timestep will advance to.
Definition SimTime.H:155
amrex::Real m_start_time
Starting simulation time (to track restart)
Definition SimTime.H:158
AMREX_FORCE_INLINE amrex::Real max_cfl() const
Definition SimTime.H:111
bool new_timestep()
Definition SimTime.cpp:97
int m_regrid_interval
Time interval for regridding.
Definition SimTime.H:237
AMREX_FORCE_INLINE int start_time_index() const
Definition SimTime.H:135
AMREX_FORCE_INLINE amrex::Real stop_time() const
Definition SimTime.H:132
amrex::Real m_fixed_dt
Fixed delta_t indicated by user.
Definition SimTime.H:167
AMREX_FORCE_INLINE amrex::Real delta_t() const
Definition SimTime.H:84
AMREX_FORCE_INLINE amrex::Real & current_time()
Definition SimTime.H:105
AMREX_FORCE_INLINE amrex::Real & delta_t_nm1()
Definition SimTime.H:96
bool m_adaptive
Flag indicating whether timestep is adaptive.
Definition SimTime.H:243
amrex::Real m_max_cfl
Maximum CFL constraint.
Definition SimTime.H:164
int m_chkpt_delay
Definition SimTime.H:228
AMREX_FORCE_INLINE int stop_time_index() const
Definition SimTime.H:138
amrex::Real m_dt_growth
Maximum growth of dt between timesteps.
Definition SimTime.H:179
amrex::Real m_plt_t_tol
Relative (to dt) tolerance for plot time interval output.
Definition SimTime.H:200
AMREX_FORCE_INLINE int & time_index()
Definition SimTime.H:117
bool write_last_checkpoint() const
Definition SimTime.cpp:331
static constexpr int max_time_states
Definition SimTime.H:32
amrex::Real m_init_shrink
Initial reduction in timestep size for startup.
Definition SimTime.H:176
void parse_parameters()
Read user defined options from input file.
Definition SimTime.cpp:8
AMREX_FORCE_INLINE int chkpt_interval() const
Definition SimTime.H:141
bool write_checkpoint() const
Definition SimTime.cpp:303
amrex::Vector< amrex::Real > m_dt
Timestep sizes.
Definition SimTime.H:148
AMREX_FORCE_INLINE int regrid_interval() const
Definition SimTime.H:126
bool m_use_force_cfl
Flag indicating if forcing should be included in CFL calculation.
Definition SimTime.H:249
AMREX_FORCE_INLINE bool adaptive_timestep() const
Definition SimTime.H:120
void set_restart_time(int tidx, amrex::Real time)
Definition SimTime.cpp:338
AMREX_FORCE_INLINE bool use_force_cfl() const
Definition SimTime.H:123
AMREX_FORCE_INLINE amrex::Real & delta_t()
Definition SimTime.H:87
amrex::Real m_force_plt_tol
Relative (to plt_t_interval) tolerance for enforcing dt.
Definition SimTime.H:203
AMREX_FORCE_INLINE amrex::Real current_time() const
Definition SimTime.H:102
amrex::Real m_chkpt_t_interval
Time interval for writing checkpoint/restart files.
Definition SimTime.H:182
AMREX_FORCE_INLINE amrex::Real start_time() const
Definition SimTime.H:129
bool do_regrid() const
Definition SimTime.cpp:273
amrex::Real m_plt_t_delay
Time delay for plot file output.
Definition SimTime.H:197
amrex::Real m_stop_time
Max time for simulation.
Definition SimTime.H:161
int m_plt_delay
Time step delay for plot file output.
Definition SimTime.H:234
amrex::Real m_cur_time
Current simulation time.
Definition SimTime.H:152
int m_start_time_index
Initial starting time index.
Definition SimTime.H:209
amrex::Real m_initial_dt
Initial delta_t indicated by user.
Definition SimTime.H:170
Definition BCInterface.cpp:7