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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/equation_systems/icns/icns_ops.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
icns_ops.H
Go to the documentation of this file.
1#ifndef ICNS_OPS_H
2#define ICNS_OPS_H
3
11#include "AMReX_MultiFabUtil.H"
12
13namespace amr_wind::pde {
14
26template <typename Scheme>
27struct FieldRegOp<ICNS, Scheme>
28{
29 explicit FieldRegOp(CFDSim& sim_in) : sim(sim_in) {}
30
32 {
33 auto& repo = sim.repo();
34 auto fields = create_fields_instance<ICNS, Scheme>(time, repo);
35
36 auto& rho = repo.declare_cc_field(
37 "density", 1, Scheme::nghost_state, Scheme::num_states);
38 auto& grad_p = repo.declare_cc_field("gp", ICNS::ndim, 0, 1);
39 auto& pressure = repo.declare_nd_field("p", 1, Scheme::nghost_state, 1);
40 repo.declare_face_normal_field(
41 {"u_mac", "v_mac", "w_mac"}, 1, Scheme::nghost_mac, 1);
42
43 rho.template register_fill_patch_op<
44 FieldFillPatchOps<FieldBCDirichlet>>(repo.mesh(), time);
45 grad_p.template register_fill_patch_op<FieldFillPatchOps<FieldBCNoOp>>(
46 repo.mesh(), time);
47 // pressure.template register_fill_patch_op<FieldFillConstScalar>(0.0);
48 // fixme this is only necessary since tioga does not fill in ghosts
49 // convert back later
50 pressure
51 .template register_fill_patch_op<FieldFillPatchOps<FieldBCNoOp>>(
52 repo.mesh(), time);
53 rho.fillpatch_on_regrid() = true;
54 grad_p.fillpatch_on_regrid() = true;
55
56 // Density always requires half state
57 rho.create_state(FieldState::NPH);
58
59 // Register fields for output/restart
60 auto& iomgr = sim.io_manager();
61 iomgr.register_io_var(fields.field.name());
62 iomgr.register_io_var(rho.name());
63 iomgr.register_io_var(pressure.name());
64 iomgr.register_io_var(grad_p.name());
65 return fields;
66 }
67
69};
70
74template <>
76{
77 explicit SrcTermOp(PDEFields& fields_in)
78 : SrcTermOpBase<ICNS>(fields_in), grad_p(fields_in.repo.get_field("gp"))
79 {}
80
81 void operator()(const FieldState fstate, const bool mesh_mapping) override
82 {
83 const auto rhostate = field_impl::phi_state(fstate);
84 const auto& density = m_density.state(rhostate);
85 Field const* mesh_fac =
86 mesh_mapping
88 : nullptr;
89
90 const int nlevels = this->fields.repo.num_active_levels();
91 for (int lev = 0; lev < nlevels; ++lev) {
92 auto& src_term = this->fields.src_term(lev);
93#ifdef AMREX_USE_OMP
94#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
95#endif
96 for (amrex::MFIter mfi(src_term, amrex::TilingIfNotGPU());
97 mfi.isValid(); ++mfi) {
98 const auto& bx = mfi.tilebox();
99 const auto& vf = src_term.array(mfi);
100 const auto& rho = density(lev).const_array(mfi);
101 const auto& gp = grad_p(lev).const_array(mfi);
102 amrex::Array4<amrex::Real const> fac =
103 mesh_mapping ? ((*mesh_fac)(lev).const_array(mfi))
104 : amrex::Array4<amrex::Real const>();
105
106 amrex::ParallelFor(
107 bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
108 amrex::Real rhoinv = 1.0 / rho(i, j, k);
109 amrex::Real fac_x =
110 mesh_mapping ? (fac(i, j, k, 0)) : 1.0;
111 amrex::Real fac_y =
112 mesh_mapping ? (fac(i, j, k, 1)) : 1.0;
113 amrex::Real fac_z =
114 mesh_mapping ? (fac(i, j, k, 2)) : 1.0;
115
116 vf(i, j, k, 0) =
117 -(1.0 / fac_x * gp(i, j, k, 0)) * rhoinv;
118 vf(i, j, k, 1) =
119 -(1.0 / fac_y * gp(i, j, k, 1)) * rhoinv;
120 vf(i, j, k, 2) =
121 -(1.0 / fac_z * gp(i, j, k, 2)) * rhoinv;
122 });
123
124 for (const auto& src : this->sources) {
125 (*src)(lev, mfi, bx, fstate, vf);
126 }
127 }
128 }
129 // Multiply velocity src terms by density for momentum equation
130 this->multiply_rho(fstate);
131 }
132
134};
135
139template <>
151
152} // namespace amr_wind::pde
153
154#endif /* ICNS_OPS_H */
Definition CFDSim.H:47
FieldRepo & repo()
Return the field repository.
Definition CFDSim.H:62
IOManager & io_manager()
Definition CFDSim.H:83
Definition FieldFillPatchOps.H:174
Definition Field.H:116
Field & state(const FieldState fstate)
Return field at a different time state.
Definition Field.cpp:114
int num_active_levels() const noexcept
Total number of levels currently active in the AMR mesh.
Definition FieldRepo.H:361
Field & get_mesh_mapping_field(FieldLoc floc) const
Definition FieldRepo.cpp:165
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_mueff(Field &mueff)=0
FieldState
Definition FieldDescTypes.H:14
@ CELL
Cell-centered (default)
@ NPH
State at (n + 1/2) (intermediate) timestep.
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
FieldRegOp(CFDSim &sim_in)
Definition icns_ops.H:29
PDEFields operator()(const SimTime &time)
Definition icns_ops.H:31
CFDSim & sim
Definition icns_ops.H:68
Definition PDEOps.H:35
CFDSim & sim
Definition PDEOps.H:53
Definition icns.H:34
static constexpr int ndim
Definition icns.H:40
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
void operator()(const FieldState fstate, const bool mesh_mapping) override
Update source terms during time-integration procedure.
Definition icns_ops.H:81
SrcTermOp(PDEFields &fields_in)
Definition icns_ops.H:77
Field & grad_p
Definition icns_ops.H:133
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
Field & m_density
Definition PDEOps.H:153
Definition PDEOps.H:162
TurbulenceOp(turbulence::TurbulenceModel &tmodel, PDEFields &fields)
Definition icns_ops.H:142
void operator()()
Definition icns_ops.H:146
turbulence::TurbulenceModel & m_tmodel
Definition icns_ops.H:148
PDEFields & m_fields
Definition icns_ops.H:149
Definition PDEOps.H:179
turbulence::TurbulenceModel & m_tmodel
Definition PDEOps.H:190
PDEFields & m_fields
Definition PDEOps.H:191