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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/PDEOps.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
PDEOps.H
Go to the documentation of this file.
1#ifndef PDEOPS_H
2#define PDEOPS_H
3
8#include "amr-wind/CFDSim.H"
9
10#include "AMReX_ParmParse.H"
11
12namespace amr_wind::pde {
13
33template <typename PDE, typename Scheme>
35{
36 explicit FieldRegOp(CFDSim& sim_in) : sim(sim_in) {}
37
45 {
46 auto fields = create_fields_instance<PDE, Scheme>(time, sim.repo());
47
48 // Register solution variable for this PDE as output/restart variable
49 sim.io_manager().register_io_var(fields.field.name());
50 return fields;
51 }
52
54};
55
67template <typename PDE>
69{
70 explicit SrcTermOpBase(PDEFields& fields_in)
71 : fields(fields_in), m_density(fields_in.repo.get_field("density"))
72 {}
73
78 void init_source_terms(const CFDSim& sim)
79 {
80 amrex::ParmParse pp(PDE::pde_name());
81 amrex::Vector<std::string> src_terms;
82 pp.queryarr("source_terms", src_terms);
83
84 for (auto& src_name : src_terms) {
85 // Prefer to use emplace_back here
86 sources.emplace_back(PDE::SrcTerm::create(src_name, sim));
87 }
88 }
89
91 void multiply_rho(const FieldState fstate)
92 {
93 BL_PROFILE("amr-wind::" + PDE::pde_name() + "::multiply_rho");
94 const auto rhostate = field_impl::phi_state(fstate);
95 const auto& density = m_density.state(rhostate);
96
97 const int nlevels = fields.repo.num_active_levels();
98 for (int lev = 0; lev < nlevels; ++lev) {
99 auto& src_term = fields.src_term(lev);
100#ifdef AMREX_USE_OMP
101#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
102#endif
103 for (amrex::MFIter mfi(src_term, amrex::TilingIfNotGPU());
104 mfi.isValid(); ++mfi) {
105 const auto& bx = mfi.tilebox();
106 const auto& vf = src_term.array(mfi);
107 const auto& rho = density(lev).array(mfi);
108
109 amrex::ParallelFor(
111 [=] AMREX_GPU_DEVICE(int i, int j, int k, int n) noexcept {
112 vf(i, j, k, n) *= rho(i, j, k);
113 });
114 }
115 }
116 }
117
119 virtual void
120 operator()(const FieldState fstate, const bool /* mesh_mapping */)
121 {
122 // Zero out source term
123 this->fields.src_term.setVal(0.0);
124
125 // Return early if there are no source terms to process
126 if (this->sources.empty()) {
127 return;
128 }
129
130 const int nlevels = this->fields.repo.num_active_levels();
131 for (int lev = 0; lev < nlevels; ++lev) {
132 auto& src_term = this->fields.src_term(lev);
133#ifdef AMREX_USE_OMP
134#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
135#endif
136 for (amrex::MFIter mfi(src_term, amrex::TilingIfNotGPU());
137 mfi.isValid(); ++mfi) {
138 const auto& bx = mfi.tilebox();
139 const auto& vf = src_term.array(mfi);
140
141 for (const auto& src : this->sources) {
142 (*src)(lev, mfi, bx, fstate, vf);
143 }
144 }
145 }
146
147 if (PDE::multiply_rho) {
148 this->multiply_rho(fstate);
149 }
150 }
151
154 amrex::Vector<std::unique_ptr<typename PDE::SrcTerm>> sources;
155};
156
160template <typename PDE>
162{
163 explicit SrcTermOp(PDEFields& fields_in) : SrcTermOpBase<PDE>(fields_in) {}
164};
165
166template <typename PDE, typename Scheme, typename = void>
168{};
169
170template <typename PDE, typename Scheme, typename = void>
172{};
173
177template <typename PDE>
179{
180 // cppcheck-suppress uninitMemberVar
182 : m_tmodel(tmodel), m_fields(fields)
183 {}
184
189
192};
193
197template <typename PDE, typename = void>
198struct BCOp;
199
203template <typename PDE>
205{
206 explicit PostSolveOp(CFDSim& sim, PDEFields& fields)
207 : m_sim(sim), m_fields(fields)
208 {}
209
210 void operator()(const amrex::Real time) { m_fields.field.fillpatch(time); }
211
214};
215
216} // namespace amr_wind::pde
217
218#endif /* PDEOPS_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
const std::string & name() const
Name of this field (including state information)
Definition Field.H:125
int num_comp() const
Number of components for this field.
Definition Field.H:134
void setVal(amrex::Real value) noexcept
Set the field to a constant value at all levels.
Definition Field.cpp:343
Field & state(const FieldState fstate)
Return field at a different time state.
Definition Field.cpp:114
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 TurbulenceModel.H:32
virtual void update_scalar_diff(Field &deff, const std::string &name)=0
Interface to update scalar diffusivity based on Schmidt number.
FieldState
Definition FieldDescTypes.H:14
FieldState phi_state(const FieldState fstate)
Definition FieldUtils.H:115
Definition AdvOp_Godunov.H:16
PDEFields create_fields_instance(const SimTime &time, FieldRepo &repo, const FieldInterpolator itype=FieldInterpolator::CellConsLinear)
Definition PDEHelpers.H:49
Definition PDEOps.H:168
Definition PDEOps.H:198
Definition PDEOps.H:172
Definition PDEOps.H:35
CFDSim & sim
Definition PDEOps.H:53
FieldRegOp(CFDSim &sim_in)
Definition PDEOps.H:36
PDEFields operator()(const SimTime &time)
Definition PDEOps.H:44
Definition PDEFields.H:27
Field & src_term
Source term for this PDE.
Definition PDEFields.H:39
Field & mueff
Effective visocity field (e.g., velocity_mueff)
Definition PDEFields.H:36
FieldRepo & repo
Reference to the field repository instance.
Definition PDEFields.H:31
Field & field
Solution variable (e.g., velocity, temperature)
Definition PDEFields.H:34
Definition PDEOps.H:205
CFDSim & m_sim
Definition PDEOps.H:212
PDEFields & m_fields
Definition PDEOps.H:213
void operator()(const amrex::Real time)
Definition PDEOps.H:210
PostSolveOp(CFDSim &sim, PDEFields &fields)
Definition PDEOps.H:206
Definition PDEOps.H:69
amrex::Vector< std::unique_ptr< typename PDE::SrcTerm > > sources
Definition PDEOps.H:154
PDEFields & fields
Definition PDEOps.H:152
void multiply_rho(const FieldState fstate)
Helper method to multiply the source terms with density.
Definition PDEOps.H:91
SrcTermOpBase(PDEFields &fields_in)
Definition PDEOps.H:70
virtual void operator()(const FieldState fstate, const bool)
Update source terms during time-integration procedure.
Definition PDEOps.H:120
Field & m_density
Definition PDEOps.H:153
void init_source_terms(const CFDSim &sim)
Definition PDEOps.H:78
Definition PDEOps.H:162
SrcTermOp(PDEFields &fields_in)
Definition PDEOps.H:163
Definition PDEOps.H:179
void operator()()
Definition PDEOps.H:185
turbulence::TurbulenceModel & m_tmodel
Definition PDEOps.H:190
TurbulenceOp(turbulence::TurbulenceModel &tmodel, PDEFields &fields)
Definition PDEOps.H:181
PDEFields & m_fields
Definition PDEOps.H:191