/home/runner/work/amr-wind/amr-wind/amr-wind/wind_energy/actuator/turbine/fast/turbine_fast_ops.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/wind_energy/actuator/turbine/fast/turbine_fast_ops.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
turbine_fast_ops.H
Go to the documentation of this file.
1#ifndef TURBINE_FAST_OPS_H
2#define TURBINE_FAST_OPS_H
3
6#include "AMReX_REAL.H"
7
8using namespace amrex::literals;
9
11
12template <typename SrcTrait>
13struct ReadInputsOp<TurbineFast, SrcTrait>
14{
16 {
18
19 auto& tf = data.meta().ext_data;
20
21 pp.get("openfast_start_time", tf.start_time);
22 pp.get("openfast_stop_time", tf.stop_time);
23
24 std::string sim_mode = (tf.start_time > 0.0_rt) ? "restart" : "init";
25 pp.query("openfast_sim_mode", sim_mode);
26
27 if (sim_mode == "init") {
28 tf.sim_mode = ::ext_turb::SimMode::init;
29 amrex::Print() << "Initializing turbine:" << tf.tlabel << std::endl;
30 } else if (sim_mode == "replay") {
31 tf.sim_mode = ::ext_turb::SimMode::replay;
32 amrex::Print() << "Replaying turbine:" << tf.tlabel << std::endl;
33 } else if (sim_mode == "restart") {
34 tf.sim_mode = ::ext_turb::SimMode::restart;
35 amrex::Print() << "Restarting turbine:" << tf.tlabel << std::endl;
36 } else {
37 amrex::Abort(
38 "Actuator: Invalid OpenFAST simulation mode: " + sim_mode);
39 }
40
41 // If we are using OpenFAST restart file, require that the user provide
42 // the path to the checkpoint file.
43 if (tf.sim_mode == ::ext_turb::SimMode::restart) {
44 pp.get("openfast_restart_file", tf.checkpoint_file);
45 } else {
46 pp.get("openfast_input_file", tf.input_file);
47 }
48
49 // Check if user wants to override density checks
50 bool override_density_check = false;
51 pp.query("override_density_check", override_density_check);
52 // Check if simulation is a restart
53 bool is_restart = data.sim().io_manager().is_restart();
54
55 perform_checks(data);
56
58 data.meta().density, override_density_check, is_restart);
59 }
60
62 {
63 const auto& time = data.sim().time();
64 // Ensure that we are using fixed timestepping scheme
65 AMREX_ALWAYS_ASSERT(!time.adaptive_timestep());
66 }
67
68 // Check other density parsing arguments against turbine air density
70 const amrex::Real rho_tdef, const bool no_check, const bool is_rst)
71 {
72 // Check if other arguments are in input file
73 amrex::ParmParse pp_incflo("incflo");
74 amrex::ParmParse pp_cstdns("ConstValue.density");
75 bool is_incflo = pp_incflo.contains("density");
76 bool is_cstdns = pp_cstdns.contains("value");
77 // Flags for detecting conflicts
78 bool cft_incflo = false;
79 bool cft_cstdns = false;
80
81 // Do warnings or aborts depending on values
82 const amrex::Real tiny = std::numeric_limits<amrex::Real>::epsilon();
83 if (is_incflo) {
84 amrex::Real rho_incflo = 1.0_rt;
85 pp_incflo.query("density", rho_incflo);
86 if (std::abs(rho_incflo - rho_tdef) > tiny) {
87 cft_incflo = true;
88 if (!no_check) {
89 amrex::Abort(
90 "Density conflict detected between TurbineFast "
91 "density and incflo.density.\n----- Values are " +
92 std::to_string(rho_tdef) + " and " +
93 std::to_string(rho_incflo) +
94 ", respectively. Check the problem setup and the "
95 "turbine definition.\n----- If this difference is "
96 "intended, set the override_density_check flag to "
97 "true.\n");
98 } else {
99 amrex::Print()
100 << "WARNING: Density conflict detected between FAST "
101 "Turbine density and incflo.density.\n----- Values "
102 "are " +
103 std::to_string(rho_tdef) + " and " +
104 std::to_string(rho_incflo) +
105 ", respectively. Abort overridden by flag.\n";
106 }
107 }
108 }
109 if (is_cstdns) {
110 amrex::Real rho_cstdns = 1.0_rt;
111 pp_cstdns.query("value", rho_cstdns);
112 if (std::abs(rho_cstdns - rho_tdef) > tiny) {
113 cft_cstdns = true;
114 if (!no_check) {
115 amrex::Abort(
116 "Density conflict detected between TurbineFast "
117 "density and ConstValue.density.value.\n----- Values "
118 "are " +
119 std::to_string(rho_tdef) + " and " +
120 std::to_string(rho_cstdns) +
121 ", respectively. Check the problem setup and the "
122 "turbine definition.\n----- If this difference is "
123 "intended, set the override_density_check flag to "
124 "true.\n");
125 } else {
126 amrex::Print()
127 << "WARNING: Density conflict detected between "
128 "TurbineFast "
129 "density and "
130 "ConstValue.density.value.\n----- Values are " +
131 std::to_string(rho_tdef) + " and " +
132 std::to_string(rho_cstdns) +
133 ", respectively. Abort overridden by flag.\n";
134 }
135 }
136 }
137 if (!is_incflo && !is_cstdns) {
138 amrex::Print()
139 << "TurbineFast: no density conflict detected, but no density "
140 "arguments found to check against.\n";
141 } else if (!cft_incflo && !cft_cstdns) {
142 amrex::Print() << "TurbineFast: no density conflict detected.\n";
143 }
144 if (is_rst) {
145 amrex::Print()
146 << "TurbineFast: simulation begins using a checkpoint file, "
147 "density compatibility must be manually confirmed between "
148 "the precursor simulation and the specified TurbineFast "
149 "density, " +
150 std::to_string(rho_tdef)
151 << ".\n";
152 }
153 }
154};
155
156template <>
162
163template <>
165 typename TurbineFast::DataType& data, amrex::Vector<int>& act_proc_count)
166{
169 ::ext_turb::FastSolverData>(data, act_proc_count);
170}
171
172template <typename SrcTrait>
173struct InitDataOp<TurbineFast, SrcTrait>
174{
176 {
177 BL_PROFILE("amr-wind::InitDataOp<TurbineFast>");
178 // Ensure that FAST simulation time is set properly before doing any
179 // initialization tasks. We perform this check here to account for
180 // restart which is only known after reading the checkpoint file.
182
184 }
185
187 {
188 const auto& time = data.sim().time();
189
190 // Set OpenFAST solver end time to be at least as long as the CFD time.
191 // User can choose a longer duration in input file.
192 const amrex::Real stop1 = time.stop_time() > 0.0_rt
193 ? time.stop_time()
194 : std::numeric_limits<amrex::Real>::max();
195 const amrex::Real stop2 = time.stop_time_index() > -1
196 ? time.stop_time_index() * time.delta_t()
197 : std::numeric_limits<amrex::Real>::max();
198 const amrex::Real cfd_stop = amrex::min(stop1, stop2);
199 const amrex::Real cfd_start = time.current_time();
200 const amrex::Real cfd_sim = cfd_stop - cfd_start - 1.0e-6_rt;
201
202 // Ensure that the user specified stop_time is not shorter than CFD sim
203 const auto& tf = data.meta().ext_data;
204 const amrex::Real fast_sim = tf.stop_time - tf.start_time;
205 AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
206 fast_sim > cfd_sim,
207 "OpenFAST simulation time is shorter than AMR-Wind duration");
208 }
209};
210
211template <typename SrcTrait>
212struct UpdatePosOp<TurbineFast, SrcTrait>
213{
215 {
216 BL_PROFILE("amr-wind::actuator::UpdatePosOp<TurbineFast>");
218 }
219};
220
221template <typename SrcTrait>
222struct UpdateVelOp<TurbineFast, SrcTrait>
223{
225 {
226 BL_PROFILE("amr-wind::actuator::UpdateVelOp<TurbineFast>");
228 }
229};
230
231template <typename SrcTrait>
233{
235 {
236 BL_PROFILE("amr-wind::actuator::ComputeForceOp<TurbineFast>");
238 }
239};
240
241template <typename SrcTrait>
243{
244private:
246
248 std::string m_out_dir;
249
251 std::string m_nc_filename;
252
254 int m_out_freq{10};
255
256public:
258 : m_data(data)
259 {}
260
262 {
263 pp.query("output_frequency", m_out_freq);
264 }
265
266 void prepare_outputs(const std::string& out_dir)
267 {
268 m_nc_filename = out_dir + "/" + m_data.info().label + ".nc";
270 m_nc_filename, m_data.meta(), m_data.info(), m_data.grid());
271 }
272
274 {
275 const auto& time = m_data.sim().time();
276 const int tidx = time.time_index();
277 if ((m_out_freq > 0) && (tidx % m_out_freq != 0)) {
278 return;
279 }
280
282 m_nc_filename, m_data.meta(), m_data.info(), m_data.grid(),
283 time.new_time());
284 }
285};
286
287} // namespace amr_wind::actuator::ops
288
289#endif /* TURBINE_FAST_OPS_H */
SimTime & time()
Return simulation time control.
Definition CFDSim.H:65
IOManager & io_manager()
Definition CFDSim.H:102
bool is_restart() const
Definition IOManager.H:85
AMREX_FORCE_INLINE amrex::Real stop_time() const
Definition SimTime.H:146
CFDSim & sim()
Definition actuator_types.H:214
ActTrait::MetaType & meta()
Definition actuator_types.H:223
void get(const std::string &name, vs::Vector &value) const
Definition MultiParser.H:41
void query(const std::string &name, vs::Vector &value) const
Definition MultiParser.H:56
Definition ActSrcLineOp.H:12
void determine_influenced_procs< TurbineFast >(typename TurbineFast::DataType &data)
Definition turbine_fast_ops.H:158
void update_pos_op(datatype &data)
Definition turbine_external_ops.H:151
void compute_force_op(datatype &data)
Definition turbine_external_ops.H:215
void external_determine_influenced_procs(datatype &data)
Definition turbine_external_ops.H:47
void read_ops(datatype &data, const utils::ActParser &pp)
Definition turbine_external_ops.H:16
void update_vel_op(datatype &data)
Definition turbine_external_ops.H:175
void init_data_op(datatype &data)
Definition turbine_external_ops.H:96
void external_determine_root_proc(datatype &data, amrex::Vector< int > &act_proc_count)
Definition turbine_external_ops.H:67
void determine_root_proc< TurbineFast >(typename TurbineFast::DataType &data, amrex::Vector< int > &act_proc_count)
Definition turbine_fast_ops.H:164
void write_netcdf(const std::string &ncfile, const TurbineBaseData &meta, const TurbineInfo &info, const ActGrid &grid, const amrex::Real time)
Definition turbine_utils.cpp:130
void prepare_netcdf_file(const std::string &ncfile, const TurbineBaseData &meta, const TurbineInfo &info, const ActGrid &grid)
Definition turbine_utils.cpp:63
::amr_wind::utils::MultiParser ActParser
Definition ActParser.H:8
TurbineFromExtSolver<::ext_turb::FastTurbine, ::ext_turb::FastSolverData > TurbineFast
Definition TurbineFast.H:9
@ restart
Restart using external checkpoint files.
Definition external_base_types.H:14
@ replay
Replay using velocities stored in file.
Definition external_base_types.H:13
@ init
Clean start.
Definition external_base_types.H:12
ActDataHolder< TurbineFromExtSolver< ::ext_turb::FastTurbine, ::ext_turb::FastSolverData > > DataType
Definition TurbineExternal.H:30
void operator()(typename TurbineFast::DataType &data)
Definition turbine_fast_ops.H:234
Definition actuator_ops.H:61
void operator()(TurbineFast::DataType &data)
Definition turbine_fast_ops.H:175
void check_fast_sim_time(TurbineFast::DataType &data)
Definition turbine_fast_ops.H:186
Definition actuator_ops.H:32
ProcessOutputsOp(typename TurbineFast::DataType &data)
Definition turbine_fast_ops.H:257
std::string m_nc_filename
NetCDF output filename for this turbine.
Definition turbine_fast_ops.H:251
TurbineFast::DataType & m_data
Definition turbine_fast_ops.H:245
void prepare_outputs(const std::string &out_dir)
Definition turbine_fast_ops.H:266
std::string m_out_dir
Path to the output directory (specified by Actuator physics class)
Definition turbine_fast_ops.H:248
void read_io_options(const utils::ActParser &pp)
Definition turbine_fast_ops.H:261
int m_out_freq
Output frequency (specified in input file)
Definition turbine_fast_ops.H:254
void perform_checks(typename TurbineFast::DataType &data)
Definition turbine_fast_ops.H:61
void perform_density_checks(const amrex::Real rho_tdef, const bool no_check, const bool is_rst)
Definition turbine_fast_ops.H:69
void operator()(TurbineFast::DataType &data, const utils::ActParser &pp)
Definition turbine_fast_ops.H:15
Definition actuator_ops.H:19
void operator()(typename TurbineFast::DataType &data)
Definition turbine_fast_ops.H:214
Definition actuator_ops.H:43
void operator()(typename TurbineFast::DataType &data)
Definition turbine_fast_ops.H:224
Definition actuator_ops.H:54
Definition fast_types.H:93
Definition fast_types.H:17