/home/runner/work/amr-wind/amr-wind/amr-wind/core/FieldBCOps.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/core/FieldBCOps.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
FieldBCOps.H
Go to the documentation of this file.
1#ifndef FIELDBCOPS_H
2#define FIELDBCOPS_H
3
6
7#include "AMReX_Gpu.H"
8#include "AMReX_FArrayBox.H"
9#include "AMReX_Geometry.H"
10#include "AMReX_PhysBCFunct.H"
11
12namespace amr_wind {
13
14class Field;
15
32{
33public:
34 virtual ~FieldBCIface() = default;
35
36 virtual void operator()(Field& field, FieldState rho_state) = 0;
37};
38
43{
45
46 AMREX_GPU_HOST
47 constexpr FieldBCNoOp() = default;
48
49 AMREX_GPU_HOST
50 constexpr explicit FieldBCNoOp(const Field& /*unused*/) {}
51
52 FunctorType operator()(const int /*face_dir*/ = -1) const { return *this; }
53
54 AMREX_GPU_DEVICE
56 const amrex::IntVect& /* iv */,
57 amrex::Array4<amrex::Real> const& /* field */,
58 const int /* dcomp */,
59 const int /* numcomp */,
60 amrex::GeometryData const& /* geom */,
61 const amrex::Real /* time */,
62 const amrex::BCRec* /* bcr */,
63 const int /* bcomp */,
64 const int /* orig_comp */) const
65 {}
66
67 AMREX_GPU_DEVICE
69 const amrex::IntVect& /*unused*/,
70 amrex::Array4<amrex::Real> const& /*unused*/,
71 amrex::GeometryData const& /*unused*/,
72 const amrex::Real /*unused*/,
73 amrex::Orientation /*unused*/,
74 const int /*unused*/,
75 const int /*unused*/,
76 const int /*unused*/) const
77 {}
78};
79
81{
83
85 amrex::GpuArray<const amrex::Real*, AMREX_SPACEDIM * 2> m_bcv;
86
87 AMREX_GPU_HOST
88 explicit ConstDirichlet(const Field& fld)
89 : m_ncomp(fld.num_comp()), m_bcv(fld.bc_values_device())
90 {}
91
92 AMREX_GPU_HOST
93 // NOLINTNEXTLINE(modernize-use-nodiscard)
94 DeviceType device_instance() const { return *this; }
95
96 AMREX_GPU_DEVICE
98 const amrex::IntVect& iv,
99 amrex::Array4<amrex::Real> const& field,
100 amrex::GeometryData const& /*unused*/,
101 const amrex::Real /*unused*/,
102 amrex::Orientation ori,
103 const int comp,
104 const int dcomp,
105 const int orig_comp) const
106 {
107 field(iv[0], iv[1], iv[2], dcomp + comp) = m_bcv[ori][orig_comp + comp];
108 }
109};
110
114template <typename InflowOp, typename WallOp>
116{
117 using InflowOpType = InflowOp;
118 using WallOpType = WallOp;
119
121 amrex::GpuArray<BC, AMREX_SPACEDIM * 2> m_bc_type;
124 const int m_face_dir;
125
126 AMREX_GPU_HOST
127 constexpr explicit DirichletOp(const Field& fld, const int face_dir)
128 : m_ncomp(fld.num_comp())
129 , m_bc_type(fld.bc_type())
130 , m_inflow_op(fld)
131 , m_wall_op(fld)
132 , m_face_dir(face_dir)
133 {}
134
135 AMREX_GPU_HOST
137 const Field& fld,
138 const InflowOpType& inflow_op,
139 const WallOpType& wall_op,
140 const int face_dir)
141 : m_ncomp(fld.num_comp())
142 , m_bc_type(fld.bc_type())
143 , m_inflow_op(inflow_op)
144 , m_wall_op(wall_op)
145 , m_face_dir{face_dir}
146 {}
147
148 AMREX_GPU_DEVICE
150 const amrex::IntVect& iv,
151 amrex::Array4<amrex::Real> const& field,
152 const int dcomp,
153 const int numcomp,
154 amrex::GeometryData const& geom,
155 const amrex::Real time,
156 const amrex::BCRec* bcr,
157 const int bcomp,
158 const int orig_comp) const
159 {
160 // do something for external Dirichlet (amrex::BCType::ext_dir)
161 const amrex::Box& domain_box = geom.Domain();
162
163 for (int n = 0; n < numcomp; ++n) {
164 const amrex::BCRec& bc = bcr[bcomp + n];
165
166 for (amrex::OrientationIter oit; oit != nullptr; ++oit) {
167 auto ori = oit();
168 const int idir = ori.coordDir();
169
170 // Check if this boundary is a dirichlet or mixed type
171 const auto bctyp = (ori.isLow() ? bc.lo(idir) : bc.hi(idir));
172 if ((bctyp != amrex::BCType::ext_dir) &&
173 (bctyp != amrex::BCType::direction_dependent)) {
174 continue;
175 }
176
177 // Check if the point in question is on the boundary
178 const int big_end =
179 domain_box.bigEnd(idir) + ((idir == m_face_dir) ? 1 : 0);
180 const bool is_bndry =
181 (ori.isLow() ? (iv[idir] < domain_box.smallEnd(idir))
182 : (iv[idir] > big_end));
183 if (!is_bndry) {
184 continue;
185 }
186
187 if ((m_bc_type[ori] == BC::mass_inflow) ||
190 iv, field, geom, time, ori, n, dcomp, orig_comp);
191 } else {
192 m_wall_op(iv, field, geom, time, ori, n, dcomp, orig_comp);
193 }
194 }
195 }
196 }
197
198 AMREX_GPU_DEVICE
200 const amrex::IntVect& iv,
201 amrex::Array4<amrex::Real> const& field,
202 amrex::GeometryData const& geom,
203 const amrex::Real time,
204 amrex::Orientation ori,
205 const int comp,
206 const int dcomp,
207 const int orig_comp) const
208 {
209 m_inflow_op(iv, field, geom, time, ori, comp, dcomp, orig_comp);
210 }
211};
212
214{
216
217 explicit FieldBCDirichlet(const Field& fld) : m_field(fld) {}
218
219 FunctorType operator()(const int face_dir = -1) const
220 {
221 return FunctorType(m_field, face_dir);
222 }
223
225};
226
227template <typename InflowOp, typename WallOp>
229{
230 using InflowOpType = typename InflowOp::DeviceType;
231 using WallOpType = typename WallOp::DeviceType;
233
234 explicit BCOpCreator(const Field& fld)
235 : m_field(fld), m_inflow_op(fld), m_wall_op(fld)
236 {}
237
238 explicit BCOpCreator(
239 const Field& fld, const InflowOp& inflow_op, const WallOp& wall_op)
240 : m_field(fld), m_inflow_op(inflow_op), m_wall_op(wall_op)
241 {}
242
243 FunctorType operator()(const int face_dir = -1) const
244 {
245 return FunctorType{
246 m_field, m_inflow_op.device_instance(), m_wall_op.device_instance(),
247 face_dir};
248 }
249
251 InflowOp m_inflow_op;
252 WallOp m_wall_op;
253};
254
255} // namespace amr_wind
256
257#endif /* FIELDBCOPS_H */
Definition FieldBCOps.H:32
virtual void operator()(Field &field, FieldState rho_state)=0
virtual ~FieldBCIface()=default
Definition Field.H:112
FieldState
Definition FieldDescTypes.H:16
@ mass_inflow_outflow
Definition incflo_enums.H:16
@ mass_inflow
Definition incflo_enums.H:15
This test case is intended as an evaluation of the momentum advection scheme.
Definition BCInterface.cpp:10
BCOpCreator(const Field &fld)
Definition FieldBCOps.H:234
FunctorType operator()(const int face_dir=-1) const
Definition FieldBCOps.H:243
BCOpCreator(const Field &fld, const InflowOp &inflow_op, const WallOp &wall_op)
Definition FieldBCOps.H:238
const Field & m_field
Definition FieldBCOps.H:250
DirichletOp< InflowOpType, WallOpType > FunctorType
Definition FieldBCOps.H:232
WallOp m_wall_op
Definition FieldBCOps.H:252
InflowOp m_inflow_op
Definition FieldBCOps.H:251
typename InflowOp::DeviceType InflowOpType
Definition FieldBCOps.H:230
typename WallOp::DeviceType WallOpType
Definition FieldBCOps.H:231
amrex::GpuArray< const amrex::Real *, AMREX_SPACEDIM *2 > m_bcv
Definition FieldBCOps.H:85
AMREX_GPU_HOST ConstDirichlet(const Field &fld)
Definition FieldBCOps.H:88
int m_ncomp
Definition FieldBCOps.H:84
ConstDirichlet DeviceType
Definition FieldBCOps.H:82
AMREX_GPU_HOST DeviceType device_instance() const
Definition FieldBCOps.H:94
AMREX_GPU_DEVICE void operator()(const amrex::IntVect &iv, amrex::Array4< amrex::Real > const &field, amrex::GeometryData const &, const amrex::Real, amrex::Orientation ori, const int comp, const int dcomp, const int orig_comp) const
Definition FieldBCOps.H:97
Definition FieldBCOps.H:116
AMREX_GPU_DEVICE void set_inflow(const amrex::IntVect &iv, amrex::Array4< amrex::Real > const &field, amrex::GeometryData const &geom, const amrex::Real time, amrex::Orientation ori, const int comp, const int dcomp, const int orig_comp) const
Definition FieldBCOps.H:199
const int m_face_dir
Definition FieldBCOps.H:124
amrex::GpuArray< BC, AMREX_SPACEDIM *2 > m_bc_type
Definition FieldBCOps.H:121
AMREX_GPU_HOST constexpr DirichletOp(const Field &fld, const int face_dir)
Definition FieldBCOps.H:127
const InflowOpType m_inflow_op
Definition FieldBCOps.H:122
WallOp WallOpType
Definition FieldBCOps.H:118
const WallOpType m_wall_op
Definition FieldBCOps.H:123
AMREX_GPU_DEVICE void operator()(const amrex::IntVect &iv, amrex::Array4< amrex::Real > const &field, const int dcomp, const int numcomp, amrex::GeometryData const &geom, const amrex::Real time, const amrex::BCRec *bcr, const int bcomp, const int orig_comp) const
Definition FieldBCOps.H:149
AMREX_GPU_HOST DirichletOp(const Field &fld, const InflowOpType &inflow_op, const WallOpType &wall_op, const int face_dir)
Definition FieldBCOps.H:136
InflowOp InflowOpType
Definition FieldBCOps.H:117
const Field & m_field
Definition FieldBCOps.H:224
FieldBCDirichlet(const Field &fld)
Definition FieldBCOps.H:217
FunctorType operator()(const int face_dir=-1) const
Definition FieldBCOps.H:219
DirichletOp< ConstDirichlet, ConstDirichlet > FunctorType
Definition FieldBCOps.H:215
FunctorType operator()(const int=-1) const
Definition FieldBCOps.H:52
FieldBCNoOp FunctorType
Definition FieldBCOps.H:44
AMREX_GPU_HOST constexpr FieldBCNoOp(const Field &)
Definition FieldBCOps.H:50
AMREX_GPU_DEVICE void operator()(const amrex::IntVect &, amrex::Array4< amrex::Real > const &, const int, const int, amrex::GeometryData const &, const amrex::Real, const amrex::BCRec *, const int, const int) const
Definition FieldBCOps.H:55
AMREX_GPU_HOST constexpr FieldBCNoOp()=default
AMREX_GPU_DEVICE void set_inflow(const amrex::IntVect &, amrex::Array4< amrex::Real > const &, amrex::GeometryData const &, const amrex::Real, amrex::Orientation, const int, const int, const int) const
Definition FieldBCOps.H:68