/home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/tke/tke_ops.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/tke/tke_ops.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
tke_ops.H
Go to the documentation of this file.
1#ifndef TKE_OPS_H
2#define TKE_OPS_H
3
6
7namespace amr_wind::pde {
8
12template <>
14{
16 : m_tmodel(tmodel), m_fields(fields)
17 {}
18
20 {
21 auto& mueff = m_fields.mueff;
23 }
24
27};
28
32template <>
34{
35 PostSolveOp(CFDSim& /*unused*/, PDEFields& fields) : m_fields(fields) {}
36
37 void operator()(const amrex::Real time)
38 {
39 // cppcheck-suppress constVariableReference
40 auto& field = m_fields.field;
41 const auto& repo = field.repo();
42 const int nlevels = repo.num_active_levels();
43 const auto clip_value = m_clip_value;
44 for (int lev = 0; lev < nlevels; ++lev) {
45 for (amrex::MFIter mfi(field(lev)); mfi.isValid(); ++mfi) {
46 const auto& bx = mfi.tilebox();
47 const auto& field_arr = field(lev).array(mfi);
48
49 amrex::ParallelFor(
50 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept {
51 field_arr(i, j, k) = (field_arr(i, j, k) < 0.0)
52 ? clip_value
53 : field_arr(i, j, k);
54 });
55 }
56 }
58 }
59
61 amrex::Real m_clip_value{1.0e-8};
62};
63
64template <typename Scheme>
65struct FieldRegOp<TKE, Scheme>
66{
67 explicit FieldRegOp(CFDSim& sim_in) : sim(sim_in)
68 {
69 amrex::ParmParse pp("TKE");
70
71 std::string interpolation;
72 pp.query("interpolation", interpolation);
73
74 if (interpolation == "PiecewiseConstant") {
76 amrex::Print()
77 << "using PiecewiseConstant interpolation for TKE fillpatch"
78 << std::endl;
79 } else {
80 amrex::Print() << "using default CellConsLinear interpolation for "
81 "TKE fillpatch"
82 << std::endl;
83 }
84 }
85
87 {
88 auto& repo = sim.repo();
89 auto fields = create_fields_instance<TKE, Scheme>(time, repo, m_itype);
90
91 repo.declare_cc_field(
92 TKE::var_name() + "_lhs_src_term", TKE::ndim, 1, 1);
93
94 sim.io_manager().register_io_var(fields.field.name());
95
96 return fields;
97 }
98
101};
102
106template <typename Scheme>
107struct DiffusionOp<TKE, Scheme> : public DiffSolverIface<typename TKE::MLDiffOp>
108{
109 static_assert(
110 TKE::ndim == 1, "DiffusionOp invoked for non-scalar TKE type");
111 static_assert(
112 std::is_same_v<typename TKE::MLDiffOp, amrex::MLABecLaplacian>,
113 "Invalid linear operator for scalar diffusion operator");
114
116 PDEFields& fields, const bool has_overset, const bool mesh_mapping)
117 : DiffSolverIface<typename TKE::MLDiffOp>(
118 fields, has_overset, mesh_mapping)
119 , m_lhs_src_term(
120 fields.repo.get_field(TKE::var_name() + "_lhs_src_term"))
121 {
122 this->m_solver->setDomainBC(
124 this->m_pdefields.field, amrex::Orientation::low),
126 this->m_pdefields.field, amrex::Orientation::high));
127 this->m_applier->setDomainBC(
129 this->m_pdefields.field, amrex::Orientation::low),
131 this->m_pdefields.field, amrex::Orientation::high));
132
133 m_lhs_src_term.setVal(0.0);
134 }
135
137 void compute_diff_term(const FieldState fstate)
138 {
139 this->setup_operator(*this->m_applier, 0.0, -1.0, fstate);
140
141 auto tau_state = std::is_same<Scheme, fvm::Godunov>::value
143 : fstate;
144 amrex::MLMG mlmg(*this->m_applier);
145 mlmg.apply(
146 this->m_pdefields.diff_term.state(tau_state).vec_ptrs(),
147 this->m_pdefields.field.vec_ptrs());
148 }
149
150 void
151 set_acoeffs(typename TKE::MLDiffOp& linop, const FieldState fstate) override
152 {
153 BL_PROFILE("amr-wind::pde::set_acoeffs");
154 auto& repo = m_pdefields.repo;
155
156 const int nlevels = repo.num_active_levels();
157 auto& density = m_density.state(fstate);
158 auto lhs_total = repo.create_scratch_field(1, 1);
160 *lhs_total, 1.0, m_lhs_src_term, 0, 1.0, density, 0, 0, 1, 1);
161
162 for (int lev = 0; lev < nlevels; ++lev) {
163 linop.setACoeffs(lev, (*lhs_total)(lev));
164 }
165 }
166
168};
169
170} // namespace amr_wind::pde
171
172#endif /* TKE_OPS_H */
Definition CFDSim.H:47
FieldRepo & repo()
Return the field repository.
Definition CFDSim.H:62
IOManager & io_manager()
Definition CFDSim.H:83
Definition Field.H:116
FieldRepo & repo() const
FieldRepo instance that manages this field.
Definition Field.H:159
void fillpatch(const amrex::Real time) noexcept
Definition Field.cpp:206
int num_active_levels() const noexcept
Total number of levels currently active in the AMR mesh.
Definition FieldRepo.H:361
void register_io_var(const std::string &fname)
Convenience function to register a variable for both output and restart.
Definition IOManager.H:76
Definition SimTime.H:30
Definition DiffusionOps.H:30
Definition TurbulenceModel.H:32
virtual void update_scalar_diff(Field &deff, const std::string &name)=0
Interface to update scalar diffusivity based on Schmidt number.
void lincomb(T1 &dst, const amrex::Real a, const T2 &x, const int xcomp, const amrex::Real b, const T3 &y, const int ycomp, const int dstcomp, const int numcomp, const amrex::IntVect &nghost)
Definition field_ops.H:317
FieldState
Definition FieldDescTypes.H:14
FieldInterpolator
Definition FieldDescTypes.H:37
@ New
Same as FieldState::NP1.
@ PiecewiseConstant
Constant across cell.
@ CellConsLinear
Linear interpolation.
Definition AdvOp_Godunov.H:16
PDEFields create_fields_instance(const SimTime &time, FieldRepo &repo, const FieldInterpolator itype=FieldInterpolator::CellConsLinear)
Definition PDEHelpers.H:49
amrex::Array< amrex::LinOpBCType, AMREX_SPACEDIM > get_diffuse_scalar_bc(amr_wind::Field &scalar, amrex::Orientation::Side side) noexcept
void compute_diff_term(const FieldState fstate)
Computes the diffusion term that goes in the RHS.
Definition tke_ops.H:137
Field & m_lhs_src_term
Definition tke_ops.H:167
void set_acoeffs(typename TKE::MLDiffOp &linop, const FieldState fstate) override
Definition tke_ops.H:151
DiffusionOp(PDEFields &fields, const bool has_overset, const bool mesh_mapping)
Definition tke_ops.H:115
Definition PDEOps.H:172
CFDSim & sim
Definition tke_ops.H:99
PDEFields operator()(const SimTime &time)
Definition tke_ops.H:86
FieldRegOp(CFDSim &sim_in)
Definition tke_ops.H:67
Definition PDEOps.H:35
CFDSim & sim
Definition PDEOps.H:53
Definition PDEFields.H:27
Field & mueff
Effective visocity field (e.g., velocity_mueff)
Definition PDEFields.H:36
Field & field
Solution variable (e.g., velocity, temperature)
Definition PDEFields.H:34
PostSolveOp(CFDSim &, PDEFields &fields)
Definition tke_ops.H:35
void operator()(const amrex::Real time)
Definition tke_ops.H:37
PDEFields & m_fields
Definition tke_ops.H:60
Definition PDEOps.H:205
PDEFields & m_fields
Definition PDEOps.H:213
Definition TKE.H:33
static std::string var_name()
Definition TKE.H:38
static constexpr int ndim
Definition TKE.H:42
amrex::MLABecLaplacian MLDiffOp
Definition TKE.H:34
TurbulenceOp(turbulence::TurbulenceModel &tmodel, PDEFields &fields)
Definition tke_ops.H:15
void operator()()
Definition tke_ops.H:19
PDEFields & m_fields
Definition tke_ops.H:26
turbulence::TurbulenceModel & m_tmodel
Definition tke_ops.H:25
Definition PDEOps.H:179
turbulence::TurbulenceModel & m_tmodel
Definition PDEOps.H:190
PDEFields & m_fields
Definition PDEOps.H:191