/home/runner/work/amr-wind/amr-wind/amr-wind/transport_models/ConstTransport.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/transport_models/ConstTransport.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
ConstTransport.H
Go to the documentation of this file.
1#ifndef CONSTTRANSPORT_H
2#define CONSTTRANSPORT_H
3
5#include "AMReX_ParmParse.H"
6#include "AMReX_REAL.H"
7
8using namespace amrex::literals;
9
10namespace amr_wind::transport {
11
15class ConstTransport : public TransportModel::Register<ConstTransport>
16{
17public:
18 static constexpr bool constant_properties = true;
19
20 static std::string identifier() { return "ConstTransport"; }
21
22 explicit ConstTransport(const CFDSim& sim) : m_repo(sim.repo())
23 {
24 amrex::ParmParse pp("transport");
25 pp.query("viscosity", m_mu);
26 pp.query("laminar_prandtl", m_Pr);
27 pp.query("turbulent_prandtl", m_Prt);
28
29 // Backwards compatibility
30 amrex::ParmParse pp_boussinesq_buoyancy("BoussinesqBuoyancy");
31 amrex::ParmParse pp_abl("ABL");
32 if (pp.contains("thermal_expansion_coefficient")) {
33 pp.get("thermal_expansion_coefficient", m_constant_beta);
34 if (pp_boussinesq_buoyancy.contains("thermal_expansion_coeff")) {
35 amrex::Print()
36 << "WARNING: BoussinesqBuoyancy.thermal_expansion_coeff "
37 "option has been deprecated in favor of "
38 "transport.thermal_expansion_coefficient. Ignoring the "
39 "BoussinesqBuoyancy option in favor of the transport "
40 "option."
41 << '\n';
42 }
43 } else if (pp_boussinesq_buoyancy.contains("thermal_expansion_coeff")) {
44 amrex::Print()
45 << "WARNING: BoussinesqBuoyancy.thermal_expansion_coeff option "
46 "has been deprecated in favor of "
47 "transport.thermal_expansion_coefficient. Please replace "
48 "this option."
49 << '\n';
50 pp_boussinesq_buoyancy.get(
51 "thermal_expansion_coeff", m_constant_beta);
52 }
53
54 if (pp.contains("reference_temperature")) {
55 pp.get("reference_temperature", m_reference_temperature);
56 if (pp_boussinesq_buoyancy.contains("reference_temperature")) {
57 amrex::Print()
58 << "WARNING: BoussinesqBuoyancy.reference_temperature "
59 "option has been deprecated in favor of "
60 "transport.reference_temperature. Ignoring the "
61 "BoussinesqBuoyancy option in favor of the transport "
62 "option."
63 << '\n';
64 } else if (pp_abl.contains("reference_temperature")) {
65 amrex::Print()
66 << "WARNING: ABL.reference_temperature "
67 "option has been deprecated in favor of "
68 "transport.reference_temperature. Ignoring the "
69 "ABL option in favor of the transport "
70 "option."
71 << '\n';
72 }
73 } else if (pp_boussinesq_buoyancy.contains("reference_temperature")) {
74 amrex::Print()
75 << "WARNING: BoussinesqBuoyancy.reference_temperature option "
76 "has been deprecated in favor of "
77 "transport.reference_temperature. Please replace "
78 "this option."
79 << '\n';
80 pp_boussinesq_buoyancy.get(
81 "reference_temperature", m_reference_temperature);
82 } else if (pp_abl.contains("reference_temperature")) {
83 amrex::Print() << "WARNING: ABL.reference_temperature option "
84 "has been deprecated in favor of "
85 "transport.reference_temperature. Please replace "
86 "this option."
87 << '\n';
88 pp_abl.get("reference_temperature", m_reference_temperature);
89 }
90 }
91
92 ~ConstTransport() override = default;
93
94 [[nodiscard]] amrex::Real viscosity() const { return m_mu; }
95
96 [[nodiscard]] amrex::Real thermal_diffusivity() const
97 {
98 return m_mu / m_Pr;
99 }
100
101 [[nodiscard]] amrex::Real laminar_prandtl() const { return m_Pr; }
102
103 [[nodiscard]] amrex::Real turbulent_prandtl() const { return m_Prt; }
104
105 static amrex::Real laminar_schmidt(const std::string& scalar_name)
106 {
107 amrex::ParmParse pp("transport");
108 const std::string key = scalar_name + "_laminar_schmidt";
109 amrex::Real lam_schmidt = 1.0_rt;
110 pp.query(key, lam_schmidt);
111 return lam_schmidt;
112 }
113
114 static amrex::Real turbulent_schmidt(const std::string& scalar_name)
115 {
116 amrex::ParmParse pp("transport");
117 const std::string key = scalar_name + "_turbulent_schmidt";
118 amrex::Real turb_schmidt = 1.0_rt;
119 pp.query(key, turb_schmidt);
120 return turb_schmidt;
121 }
122
124 std::unique_ptr<ScratchField> mu() override
125 {
126 auto mu = m_repo.create_scratch_field(1, m_ngrow);
127 for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
128 (*mu)(lev).setVal(m_mu);
129 }
130 return mu;
131 }
132
134 std::unique_ptr<ScratchField> alpha() override
135 {
136 auto alpha = mu();
137 amrex::Real inv_Pr = 1.0_rt / m_Pr;
138 for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
139 (*alpha)(lev).mult(inv_Pr);
140 }
141 return alpha;
142 }
143
144 std::unique_ptr<ScratchField>
145 scalar_diffusivity(const std::string& scalar_name) override
146 {
147 amrex::Real lam_schmidt = laminar_schmidt(scalar_name);
148
149 amrex::Real inv_schmidt = 1.0_rt / lam_schmidt;
150 auto diff = mu();
151 for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
152 (*diff)(lev).mult(inv_schmidt);
153 }
154
155 return diff;
156 }
157
159 [[nodiscard]] std::unique_ptr<ScratchField> beta() const override
160 {
161 auto beta = m_repo.create_scratch_field(1, m_ngrow);
162 for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
163#ifdef AMREX_USE_OMP
164#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
165#endif
166 for (amrex::MFIter mfi((*beta)(lev)); mfi.isValid(); ++mfi) {
167 const auto& bx = mfi.tilebox();
168 const auto& beta_arr = (*beta)(lev).array(mfi);
169 beta_impl(lev, mfi, bx, beta_arr);
170 }
171 }
172 return beta;
173 }
174
177 const int lev,
178 const amrex::MFIter& mfi,
179 const amrex::Box& bx,
180 const amrex::Array4<amrex::Real>& beta) const override
181 {
182
183 if (m_constant_beta > 0.0_rt) {
184 const amrex::Real beta_val = m_constant_beta;
185 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
186 beta(i, j, k) = beta_val;
187 });
188 } else if (m_repo.field_exists("reference_temperature")) {
189 const auto& temp0 = m_repo.get_field("reference_temperature");
190 const auto& temp0_arr = temp0(lev).const_array(mfi);
191 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
192 beta(i, j, k) = 1.0_rt / temp0_arr(i, j, k);
193 });
194 } else {
195 const amrex::Real beta_val = 1.0_rt / m_reference_temperature;
196 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
197 beta(i, j, k) = beta_val;
198 });
199 }
200
201 if (m_repo.field_exists("vof")) {
202 const auto& vof = m_repo.get_field("vof");
203 const auto& vof_arr = vof(lev).const_array(mfi);
204 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
205 if (vof_arr(i, j, k) > constants::TIGHT_TOL) {
206 beta(i, j, k) = 0.0_rt;
207 }
208 });
209 }
210 }
211
212 [[nodiscard]] amrex::Real reference_temperature() const override
213 {
215 }
216
218 [[nodiscard]] std::unique_ptr<ScratchField> ref_theta() const override
219 {
220 if (m_reference_temperature < 0.0_rt) {
221 amrex::Abort("Reference temperature was not set");
222 }
223
224 auto ref_theta = m_repo.create_scratch_field(1, m_ngrow);
225 for (int lev = 0; lev < m_repo.num_active_levels(); ++lev) {
226#ifdef AMREX_USE_OMP
227#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
228#endif
229 for (amrex::MFIter mfi((*ref_theta)(lev)); mfi.isValid(); ++mfi) {
230 const auto& bx = mfi.tilebox();
231 const auto& ref_theta_arr = (*ref_theta)(lev).array(mfi);
232 ref_theta_impl(lev, mfi, bx, ref_theta_arr);
233 }
234 }
235 return ref_theta;
236 }
237
240 const int lev,
241 const amrex::MFIter& mfi,
242 const amrex::Box& bx,
243 const amrex::Array4<amrex::Real>& ref_theta) const override
244 {
245 if (m_reference_temperature < 0.0_rt) {
246 amrex::Abort("Reference temperature was not set");
247 }
248
249 if (m_repo.field_exists("reference_temperature")) {
250 auto& temp0 = m_repo.get_field("reference_temperature");
251 const auto& temp0_arr = temp0(lev).const_array(mfi);
252 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
253 ref_theta(i, j, k) = temp0_arr(i, j, k);
254 });
255 } else {
256 const amrex::Real ref_theta_val = m_reference_temperature;
257 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
258 ref_theta(i, j, k) = ref_theta_val;
259 });
260 }
261 }
262
263private:
266
268 amrex::Real m_mu{1.0e-5_rt};
269
271 amrex::Real m_Pr{1.0_rt};
272
274 amrex::Real m_Prt{1.0_rt};
275
277 amrex::Real m_constant_beta{0.0_rt};
278
280 amrex::Real m_reference_temperature{-1.0_rt};
281};
282
283} // namespace amr_wind::transport
284
285#endif /* CONSTTRANSPORT_H */
Definition CFDSim.H:54
Definition FieldRepo.H:86
void ref_theta_impl(const int lev, const amrex::MFIter &mfi, const amrex::Box &bx, const amrex::Array4< amrex::Real > &ref_theta) const override
Compute the reference temperature.
Definition ConstTransport.H:239
amrex::Real m_mu
(Laminar) dynamic viscosity
Definition ConstTransport.H:268
amrex::Real thermal_diffusivity() const
Definition ConstTransport.H:96
FieldRepo & m_repo
Reference to the field repository (for creating scratch fields)
Definition ConstTransport.H:265
amrex::Real reference_temperature() const override
Definition ConstTransport.H:212
amrex::Real turbulent_prandtl() const
Definition ConstTransport.H:103
void beta_impl(const int lev, const amrex::MFIter &mfi, const amrex::Box &bx, const amrex::Array4< amrex::Real > &beta) const override
Compute the thermal expansion coefficient.
Definition ConstTransport.H:176
amrex::Real m_Prt
Turbulent Prandtl number.
Definition ConstTransport.H:274
static constexpr bool constant_properties
Definition ConstTransport.H:18
amrex::Real viscosity() const
Definition ConstTransport.H:94
static amrex::Real turbulent_schmidt(const std::string &scalar_name)
Definition ConstTransport.H:114
amrex::Real m_Pr
Prandtl number.
Definition ConstTransport.H:271
amrex::Real laminar_prandtl() const
Definition ConstTransport.H:101
static std::string identifier()
Definition ConstTransport.H:20
ConstTransport(const CFDSim &sim)
Definition ConstTransport.H:22
std::unique_ptr< ScratchField > beta() const override
Return the thermal expansion coefficient.
Definition ConstTransport.H:159
amrex::Real m_constant_beta
Constant thermal expansion coefficient.
Definition ConstTransport.H:277
static amrex::Real laminar_schmidt(const std::string &scalar_name)
Definition ConstTransport.H:105
amrex::Real m_reference_temperature
Reference temperature.
Definition ConstTransport.H:280
std::unique_ptr< ScratchField > ref_theta() const override
Return the reference temperature.
Definition ConstTransport.H:218
std::unique_ptr< ScratchField > scalar_diffusivity(const std::string &scalar_name) override
Definition ConstTransport.H:145
std::unique_ptr< ScratchField > alpha() override
Return the thermal diffusivity field.
Definition ConstTransport.H:134
std::unique_ptr< ScratchField > mu() override
Return the dynamic visocity field.
Definition ConstTransport.H:124
static constexpr amrex::Real TIGHT_TOL
A tight tolerance.
Definition constants.H:17
Definition CFDSim.H:26