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