/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, const 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
68 inline void set_inflow(
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 DeviceType device_instance() const { return *this; }
94
95 AMREX_GPU_DEVICE
96 inline void operator()(
97 const amrex::IntVect& iv,
98 amrex::Array4<amrex::Real> const& field,
99 amrex::GeometryData const& /*unused*/,
100 const amrex::Real /*unused*/,
101 amrex::Orientation ori,
102 const int comp,
103 const int dcomp,
104 const int orig_comp) const
105 {
106 field(iv[0], iv[1], iv[2], dcomp + comp) = m_bcv[ori][orig_comp + comp];
107 }
108};
109
113template <typename InflowOp, typename WallOp>
115{
116 using InflowOpType = InflowOp;
117 using WallOpType = WallOp;
118
120 amrex::GpuArray<BC, AMREX_SPACEDIM * 2> m_bc_type;
123 const int m_face_dir;
124
125 AMREX_GPU_HOST
126 constexpr explicit DirichletOp(const Field& fld, const int face_dir)
127 : m_ncomp(fld.num_comp())
128 , m_bc_type(fld.bc_type())
129 , m_inflow_op(fld)
130 , m_wall_op(fld)
131 , m_face_dir(face_dir)
132 {}
133
134 AMREX_GPU_HOST
136 const Field& fld,
137 const InflowOpType& inflow_op,
138 const WallOpType& wall_op,
139 const int face_dir)
140 : m_ncomp(fld.num_comp())
141 , m_bc_type(fld.bc_type())
142 , m_inflow_op(inflow_op)
143 , m_wall_op(wall_op)
144 , m_face_dir{face_dir}
145 {}
146
147 AMREX_GPU_DEVICE
148 inline void operator()(
149 const amrex::IntVect& iv,
150 amrex::Array4<amrex::Real> const& field,
151 const int dcomp,
152 const int numcomp,
153 amrex::GeometryData const& geom,
154 const amrex::Real time,
155 const amrex::BCRec* bcr,
156 const int bcomp,
157 const int orig_comp) const
158 {
159 // do something for external Dirichlet (amrex::BCType::ext_dir)
160 const amrex::Box& domain_box = geom.Domain();
161
162 for (int n = 0; n < numcomp; ++n) {
163 const amrex::BCRec& bc = bcr[bcomp + n];
164
165 for (amrex::OrientationIter oit; oit != nullptr; ++oit) {
166 auto ori = oit();
167 const int idir = ori.coordDir();
168
169 // Check if this boundary is a dirichlet or mixed type
170 const auto bctyp = (ori.isLow() ? bc.lo(idir) : bc.hi(idir));
171 if ((bctyp != amrex::BCType::ext_dir) &&
172 (bctyp != amrex::BCType::direction_dependent)) {
173 continue;
174 }
175
176 // Check if the point in question is on the boundary
177 const int big_end =
178 domain_box.bigEnd(idir) + ((idir == m_face_dir) ? 1 : 0);
179 const bool is_bndry =
180 (ori.isLow() ? (iv[idir] < domain_box.smallEnd(idir))
181 : (iv[idir] > big_end));
182 if (!is_bndry) {
183 continue;
184 }
185
186 if ((m_bc_type[ori] == BC::mass_inflow) ||
189 iv, field, geom, time, ori, n, dcomp, orig_comp);
190 } else {
191 m_wall_op(iv, field, geom, time, ori, n, dcomp, orig_comp);
192 }
193 }
194 }
195 }
196
197 AMREX_GPU_DEVICE
198 inline void set_inflow(
199 const amrex::IntVect& iv,
200 amrex::Array4<amrex::Real> const& field,
201 amrex::GeometryData const& geom,
202 const amrex::Real time,
203 amrex::Orientation ori,
204 const int comp,
205 const int dcomp,
206 const int orig_comp) const
207 {
208 m_inflow_op(iv, field, geom, time, ori, comp, dcomp, orig_comp);
209 }
210};
211
213{
215
216 explicit FieldBCDirichlet(const Field& fld) : m_field(fld) {}
217
218 inline FunctorType operator()(const int face_dir = -1) const
219 {
220 return FunctorType(m_field, face_dir);
221 }
222
224};
225
226template <typename InflowOp, typename WallOp>
228{
229 using InflowOpType = typename InflowOp::DeviceType;
230 using WallOpType = typename WallOp::DeviceType;
232
233 explicit BCOpCreator(const Field& fld)
234 : m_field(fld), m_inflow_op(fld), m_wall_op(fld)
235 {}
236
237 explicit BCOpCreator(
238 const Field& fld, const InflowOp& inflow_op, const WallOp& wall_op)
239 : m_field(fld), m_inflow_op(inflow_op), m_wall_op(wall_op)
240 {}
241
242 inline FunctorType operator()(const int face_dir = -1) const
243 {
244 return FunctorType{
245 m_field, m_inflow_op.device_instance(), m_wall_op.device_instance(),
246 face_dir};
247 }
248
250 InflowOp m_inflow_op;
251 WallOp m_wall_op;
252};
253
254} // namespace amr_wind
255
256#endif /* FIELDBCOPS_H */
Definition FieldBCOps.H:32
virtual void operator()(Field &field, const FieldState rho_state)=0
virtual ~FieldBCIface()=default
Definition Field.H:116
FieldState
Definition FieldDescTypes.H:14
@ mass_inflow_outflow
@ mass_inflow
Definition BCInterface.cpp:7
Definition FieldBCOps.H:228
BCOpCreator(const Field &fld)
Definition FieldBCOps.H:233
FunctorType operator()(const int face_dir=-1) const
Definition FieldBCOps.H:242
BCOpCreator(const Field &fld, const InflowOp &inflow_op, const WallOp &wall_op)
Definition FieldBCOps.H:237
const Field & m_field
Definition FieldBCOps.H:249
WallOp m_wall_op
Definition FieldBCOps.H:251
InflowOp m_inflow_op
Definition FieldBCOps.H:250
typename InflowOp::DeviceType InflowOpType
Definition FieldBCOps.H:229
typename WallOp::DeviceType WallOpType
Definition FieldBCOps.H:230
Definition FieldBCOps.H:81
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
AMREX_GPU_HOST DeviceType device_instance() const
Definition FieldBCOps.H:93
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:96
Definition FieldBCOps.H:115
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:198
const int m_face_dir
Definition FieldBCOps.H:123
amrex::GpuArray< BC, AMREX_SPACEDIM *2 > m_bc_type
Definition FieldBCOps.H:120
int m_ncomp
Definition FieldBCOps.H:119
AMREX_GPU_HOST constexpr DirichletOp(const Field &fld, const int face_dir)
Definition FieldBCOps.H:126
const InflowOpType m_inflow_op
Definition FieldBCOps.H:121
WallOp WallOpType
Definition FieldBCOps.H:117
const WallOpType m_wall_op
Definition FieldBCOps.H:122
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:148
AMREX_GPU_HOST DirichletOp(const Field &fld, const InflowOpType &inflow_op, const WallOpType &wall_op, const int face_dir)
Definition FieldBCOps.H:135
InflowOp InflowOpType
Definition FieldBCOps.H:116
Definition FieldBCOps.H:213
const Field & m_field
Definition FieldBCOps.H:223
FieldBCDirichlet(const Field &fld)
Definition FieldBCOps.H:216
FunctorType operator()(const int face_dir=-1) const
Definition FieldBCOps.H:218
DirichletOp< ConstDirichlet, ConstDirichlet > FunctorType
Definition FieldBCOps.H:214
Definition FieldBCOps.H:43
FunctorType operator()(const int=-1) const
Definition FieldBCOps.H:52
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