/home/runner/work/kynema-sgf/kynema-sgf/src/utilities/output_quantities/RANSConvergence.H Source File

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/utilities/output_quantities/RANSConvergence.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
RANSConvergence.H
Go to the documentation of this file.
1#ifndef RANSCONVERGENCE_H
2#define RANSCONVERGENCE_H
3
4#include <memory>
5#include <string>
6
7#include "src/CFDSim.H"
11#include "AMReX_REAL.H"
12#include "AMReX_Vector.H"
13
14using namespace amrex::literals;
15
17
26{
28 bool valid{false};
29
31 amrex::Real rate{0.0_rt};
32
34 amrex::Real amplitude{0.0_rt};
35
37 amrex::Real rsq{0.0_rt};
38
40 amrex::Real time_to_threshold{-1.0_rt};
41};
42
64class RANSConvergence : public PostProcessBase::Register<RANSConvergence>
65{
66public:
67 static std::string identifier() { return "RANSConvergence"; }
68
69 RANSConvergence(CFDSim& /*sim*/, std::string /*label*/);
70
71 ~RANSConvergence() override;
72
74 void pre_init_actions() override {}
75
77 void initialize() override;
78
80 void post_advance_work() override;
81
83 void output_actions() override {}
84
86 void post_regrid_actions() override;
87
105 const amrex::Vector<amrex::Real>& times,
106 const amrex::Vector<amrex::Real>& spreads,
107 amrex::Real threshold,
108 int min_samples);
109
121 static amrex::Real effective_tolerance(
122 const amrex::Real mean,
123 const amrex::Real abs_tol,
124 const amrex::Real rel_tol)
125 {
126 return amrex::max<amrex::Real>(abs_tol, rel_tol * std::abs(mean));
127 }
128
129private:
131 void check_turbulence_model() const;
132
134 void setup_container();
135
138
140 void take_sample();
141
144
146 void prepare_ascii_file();
147
149 void write_ascii(
150 int num_samples,
151 bool window_full,
152 amrex::Real hold_elapsed,
153 int num_converged,
154 int worst_vel_point,
155 amrex::Real worst_vel_spread,
156 amrex::Real worst_vel_tol,
157 int worst_tke_point,
158 amrex::Real worst_tke_spread,
159 amrex::Real worst_tke_tol,
160 amrex::Real eta);
161
164
166 const std::string m_label;
167
169 std::unique_ptr<sampling::SamplerBase> m_sampler;
170
172 std::unique_ptr<sampling::SamplingContainer> m_scontainer;
173
175 amrex::Vector<Field*> m_fields;
176
178 amrex::Vector<amrex::Real> m_point_coords;
179
181 int m_npts{0};
182
185
187 bool m_has_terrain{false};
188
190 amrex::Vector<amrex::Real> m_sample_buf;
191
193 amrex::Real m_start_time{-1.0_rt};
194
196 amrex::Real m_sample_interval{-1.0_rt};
197
199 amrex::Real m_window{-1.0_rt};
200
202 amrex::Real m_vel_abs_tol{0.01_rt};
203
205 amrex::Real m_vel_rel_tol{0.001_rt};
206
208 amrex::Real m_tke_abs_tol{0.001_rt};
209
211 amrex::Real m_tke_rel_tol{0.01_rt};
212
215
217 amrex::Real m_hold_time{-1.0_rt};
218
220 amrex::Real m_converged_since{-1.0_rt};
221
224
226 bool m_report_eta{true};
227
229 amrex::Real m_eta_fit_window{-1.0_rt};
230
233
235 amrex::Real m_eta_min_rsq{0.5_rt};
236
238 amrex::Real m_next_sample_time{0.0_rt};
239
241 amrex::Vector<amrex::Real> m_times;
242
244 amrex::Vector<amrex::Vector<amrex::Real>> m_samples;
245
247 amrex::Vector<amrex::Real> m_eta_times;
248
251 amrex::Vector<amrex::Real> m_eta_vel_ratio;
252
255 amrex::Vector<amrex::Real> m_eta_tke_ratio;
256
258 bool m_converged{false};
259
261 std::string m_out_fname;
262
264 int m_width{18};
265
267 int m_precision{10};
268};
269
270} // namespace kynema_sgf::rans_convergence
271
272#endif /* RANSCONVERGENCE_H */
Definition CFDSim.H:55
static std::string identifier()
Definition RANSConvergence.H:67
int m_npts
Number of monitor points.
Definition RANSConvergence.H:181
bool m_report_eta
Report an estimated time to convergence from an exponential fit.
Definition RANSConvergence.H:226
amrex::Real m_sample_interval
Physical time between samples.
Definition RANSConvergence.H:196
void post_advance_work() override
Sample the monitor points and test for convergence.
Definition RANSConvergence.cpp:262
void evaluate_convergence()
Test every point against tolerance and report.
Definition RANSConvergence.cpp:399
amrex::Real m_vel_abs_tol
Absolute tolerance on the horizontal wind speed envelope.
Definition RANSConvergence.H:202
const std::string m_label
Name of this post-processing object, used to read its inputs.
Definition RANSConvergence.H:166
amrex::Vector< amrex::Real > m_eta_tke_ratio
History of the largest tke spread over all points, normalized by each point's own tolerance so that c...
Definition RANSConvergence.H:255
amrex::Real m_tke_rel_tol
Relative tolerance on the turbulent kinetic energy envelope.
Definition RANSConvergence.H:211
int m_min_samples
Fewest samples in the window before convergence may be declared.
Definition RANSConvergence.H:214
amrex::Real m_eta_min_rsq
Smallest coefficient of determination for a reported estimate.
Definition RANSConvergence.H:235
std::string m_out_fname
Name of the ASCII diagnostics file.
Definition RANSConvergence.H:261
amrex::Real m_tke_abs_tol
Absolute tolerance on the turbulent kinetic energy envelope.
Definition RANSConvergence.H:208
amrex::Real m_vel_rel_tol
Relative tolerance on the horizontal wind speed envelope.
Definition RANSConvergence.H:205
bool m_stop_on_convergence
Ask the time integrator to stop once every point has converged.
Definition RANSConvergence.H:223
CFDSim & m_sim
Reference to the CFD simulation.
Definition RANSConvergence.H:163
amrex::Vector< amrex::Real > m_times
Sample times currently held in the window.
Definition RANSConvergence.H:241
amrex::Real m_window
Width of the trailing window over which the envelope is measured.
Definition RANSConvergence.H:199
static amrex::Real effective_tolerance(const amrex::Real mean, const amrex::Real abs_tol, const amrex::Real rel_tol)
Definition RANSConvergence.H:121
amrex::Real m_hold_time
How long every point must stay within tolerance before the run stops.
Definition RANSConvergence.H:217
int m_width
Field width in the ASCII output.
Definition RANSConvergence.H:264
int m_eta_min_samples
Fewest envelope samples that will be fitted.
Definition RANSConvergence.H:232
void check_turbulence_model() const
Abort unless the active turbulence model is KLAxell.
Definition RANSConvergence.cpp:36
static EnvelopeFit fit_envelope_decay(const amrex::Vector< amrex::Real > &times, const amrex::Vector< amrex::Real > &spreads, amrex::Real threshold, int min_samples)
Definition RANSConvergence.cpp:323
std::unique_ptr< sampling::SamplerBase > m_sampler
Probe sampler holding the monitor point locations.
Definition RANSConvergence.H:169
amrex::Real m_converged_since
Time at which all points most recently began passing, or -1 if not.
Definition RANSConvergence.H:220
void setup_container()
Build the probe sampler and the particle container.
Definition RANSConvergence.cpp:157
int m_precision
Precision in the ASCII output.
Definition RANSConvergence.H:267
amrex::Real m_start_time
Simulation time at which monitoring begins.
Definition RANSConvergence.H:193
amrex::Vector< amrex::Real > m_sample_buf
Buffer receiving the interpolated values, valid on the IO rank only.
Definition RANSConvergence.H:190
RANSConvergence(CFDSim &, std::string)
Definition RANSConvergence.cpp:30
amrex::Vector< Field * > m_fields
Fields interpolated at the monitor points: velocity and tke.
Definition RANSConvergence.H:175
amrex::Vector< amrex::Real > m_eta_times
Times at which envelope spreads were recorded, for the exponential fit.
Definition RANSConvergence.H:247
amrex::Real m_eta_fit_window
Trailing span of envelope history used for the exponential fit.
Definition RANSConvergence.H:229
void output_actions() override
Output is driven internally by the sampling cadence.
Definition RANSConvergence.H:83
amrex::Vector< amrex::Real > m_eta_vel_ratio
History of the largest wind speed spread over all points, normalized by each point's own tolerance so...
Definition RANSConvergence.H:251
amrex::Vector< amrex::Vector< amrex::Real > > m_samples
Sampled values, three per point per entry: u, v and tke.
Definition RANSConvergence.H:244
void pre_init_actions() override
Perform actions before mesh is created.
Definition RANSConvergence.H:74
amrex::Real m_next_sample_time
Next simulation time at which a sample will be taken.
Definition RANSConvergence.H:238
void take_sample()
Interpolate the monitored fields and append them to the window.
Definition RANSConvergence.cpp:286
bool m_has_terrain
True when a terrain height field is available for point validation.
Definition RANSConvergence.H:187
void initialize() override
Read user inputs, build the monitor points and validate them.
Definition RANSConvergence.cpp:51
void post_regrid_actions() override
Redistribute the monitor points after the mesh changes.
Definition RANSConvergence.cpp:254
bool m_converged
True once every point has satisfied both tolerances.
Definition RANSConvergence.H:258
void prepare_ascii_file()
Prepare the ASCII output file and write its header.
Definition RANSConvergence.cpp:599
void reject_terrain_points()
Abort if any monitor point lies inside the immersed terrain.
Definition RANSConvergence.cpp:210
std::unique_ptr< sampling::SamplingContainer > m_scontainer
Particle container performing the interpolation.
Definition RANSConvergence.H:172
amrex::Vector< amrex::Real > m_point_coords
Coordinates of the monitor points, gathered once at initialization.
Definition RANSConvergence.H:178
void write_ascii(int num_samples, bool window_full, amrex::Real hold_elapsed, int num_converged, int worst_vel_point, amrex::Real worst_vel_spread, amrex::Real worst_vel_tol, int worst_tke_point, amrex::Real worst_tke_spread, amrex::Real worst_tke_tol, amrex::Real eta)
Append one line of convergence diagnostics.
Definition RANSConvergence.cpp:623
int m_ncomp_total
Number of real components carried by the particle container.
Definition RANSConvergence.H:184
Definition RANSConvergence.cpp:18
Definition RANSConvergence.H:26
bool valid
True if the fit succeeded and the extrapolation is usable.
Definition RANSConvergence.H:28
amrex::Real rate
Decay rate in 1/s; positive means the envelope is shrinking.
Definition RANSConvergence.H:31
amrex::Real time_to_threshold
Estimated seconds from the last sample until the threshold is reached.
Definition RANSConvergence.H:40
amrex::Real amplitude
Amplitude of the fitted exponential.
Definition RANSConvergence.H:34
amrex::Real rsq
Coefficient of determination of the fit, computed in log space.
Definition RANSConvergence.H:37