Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_MLMGBndry.H
Go to the documentation of this file.
1#ifndef AMREX_MLMGBNDRY_H_
2#define AMREX_MLMGBNDRY_H_
3#include <AMReX_Config.H>
4
6
7namespace amrex {
8
16template <typename MF>
19 : public InterpBndryDataT<MF>
20{
21public:
22
25
34 MLMGBndryT (const BoxArray& _grids, const DistributionMapping& _dmap,
35 int _ncomp, const Geometry& _geom);
36
37 ~MLMGBndryT () = default;
38
39 MLMGBndryT (MLMGBndryT<MF>&& rhs) = delete;
40 MLMGBndryT (const MLMGBndryT<MF>& rhs) = delete;
43
57 int ratio, const RealVect& a_loc,
58 LinOpBCType a_crse_fine_bc_type = LinOpBCType::Dirichlet);
59
73 IntVect const& ratio, const RealVect& a_loc,
74 LinOpBCType a_crse_fine_bc_type = LinOpBCType::Dirichlet);
75
94 static void setBoxBC (RealTuple& bloc, BCTuple& bctag, const Box& bx,
95 const Box& domain,
98 const Real* dx, IntVect const& ratio,
99 const RealVect& interior_bloc,
100 const Array<Real,AMREX_SPACEDIM>& domain_bloc_lo,
101 const Array<Real,AMREX_SPACEDIM>& domain_bloc_hi,
102 const GpuArray<int,AMREX_SPACEDIM>& is_periodic,
103 LinOpBCType a_crse_fine_bc_type);
104};
105
106template <typename MF>
108 int _ncomp, const Geometry& _geom)
109 : InterpBndryDataT<MF>(_grids,_dmap,_ncomp,_geom)
110{}
111
112template <typename MF>
113void
116 int ratio, const RealVect& a_loc,
117 LinOpBCType a_crse_fine_bc_type)
118{
119 setLOBndryConds(lo, hi, IntVect(ratio), a_loc, a_crse_fine_bc_type);
120}
121
122template <typename MF>
123void
126 IntVect const& ratio, const RealVect& a_loc,
127 LinOpBCType a_crse_fine_bc_type)
128{
129 const BoxArray& ba = this->boxes();
130 const Real* dx = this->geom.CellSize();
131 const Box& domain = this->geom.Domain();
132 const GpuArray<int,AMREX_SPACEDIM>& is_periodic = this->geom.isPeriodicArray();
133
134 AMREX_ASSERT(a_crse_fine_bc_type == LinOpBCType::Dirichlet ||
135 a_crse_fine_bc_type == LinOpBCType::Neumann);
136
137#ifdef AMREX_USE_OMP
138#pragma omp parallel
139#endif
140 for (FabSetIter fsi(this->bndry[Orientation(0,Orientation::low)]);
141 fsi.isValid(); ++fsi)
142 {
143 const int i = fsi.index();
144 const Box& grd = ba[i];
145 RealTuple& bloc = this->bcloc[fsi];
146 Vector< Vector<BoundCond> >& bctag = this->bcond[fsi];
147
148 for (int icomp = 0; icomp < this->nComp(); ++icomp) {
149 BCTuple bct;
150 setBoxBC(bloc, bct, grd, domain, lo[icomp], hi[icomp], dx, ratio, a_loc,
151 {{AMREX_D_DECL(Real(0.),Real(0.),Real(0.))}},
152 {{AMREX_D_DECL(Real(0.),Real(0.),Real(0.))}},
153 is_periodic, a_crse_fine_bc_type);
154 for (int idim = 0; idim < 2*AMREX_SPACEDIM; ++idim) {
155 bctag[idim][icomp] = bct[idim];
156 }
157 }
158 }
159}
160
161template <typename MF>
162void
164 const Box& bx, const Box& domain,
167 const Real* dx, IntVect const& ratio,
168 const RealVect& interior_bloc,
169 const Array<Real,AMREX_SPACEDIM>& domain_bloc_lo,
170 const Array<Real,AMREX_SPACEDIM>& domain_bloc_hi,
171 const GpuArray<int,AMREX_SPACEDIM>& is_periodic,
172 LinOpBCType a_crse_fine_bc_type)
173{
174 using T = typename MF::value_type;
175
176 for (OrientationIter fi; fi; ++fi)
177 {
178 const Orientation face = fi();
179 const int dir = face.coordDir();
180
181 if (domain[face] == bx[face] && !is_periodic[dir])
182 {
183 // All physical bc values are located on face.
184 bloc[face] = static_cast<T>
185 (face.isLow() ? domain_bloc_lo[dir] : domain_bloc_hi[dir]);
186 const auto linop_bc = face.isLow() ? lo[dir] : hi[dir];
187 if (linop_bc == LinOpBCType::Dirichlet) {
188 bctag[face] = AMREX_LO_DIRICHLET;
189 } else if (linop_bc == LinOpBCType::Neumann) {
190 bctag[face] = AMREX_LO_NEUMANN;
191 } else if (linop_bc == LinOpBCType::reflect_odd) {
192 bctag[face] = AMREX_LO_REFLECT_ODD;
193 } else {
194 amrex::Abort("MLMGBndry::setBoxBC: Unknown LinOpBCType");
195 }
196 }
197 else
198 {
199 // Internal bndry.
200 bctag[face] = static_cast<int>(a_crse_fine_bc_type);
201 bloc[face] = static_cast<T>(ratio[dir] > 0 ? Real(0.5)*static_cast<Real>(ratio[dir])*dx[dir]
202 : interior_bloc[dir]);
203 // If this is next to another same level box, BC type is wrong
204 // and bloc is wrong. But it doesn't matter, because we also
205 // have mask. It is used only if mask says it is next to coarse
206 // cells.
207 }
208 }
209}
210
212
213}
214
215#endif
#define AMREX_ASSERT(EX)
Definition AMReX_BLassert.H:38
Boundary data specialization that interpolates coarse data into fine ghost cells.
#define AMREX_LO_NEUMANN
Definition AMReX_LO_BCTYPES.H:6
#define AMREX_LO_DIRICHLET
Definition AMReX_LO_BCTYPES.H:5
#define AMREX_LO_REFLECT_ODD
Definition AMReX_LO_BCTYPES.H:7
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
Array< value_type, 2 *3 > RealTuple
Some useful typedefs.
Definition AMReX_BndryData.H:98
Reference-counted collection of Boxes.
Definition AMReX_BoxArray.H:676
Calculates the distribution of FABs to MPI processes.
Definition AMReX_DistributionMapping.H:51
Convenience iterator that reuses MFIter semantics for FabSet traversal.
Definition AMReX_FabSet.H:281
Rectangular problem domain geometry.
Definition AMReX_Geometry.H:75
An InterpBndryData object adds to a BndryData object the ability to manipulate and set the data store...
Definition AMReX_InterpBndryData.H:45
bool isValid() const noexcept
Is the iterator valid i.e. is it associated with a FAB?
Definition AMReX_MFIter.H:172
Boundary helper for MLMG that manages coarse/fine and physical BC metadata.
Definition AMReX_MLMGBndry.H:20
MLMGBndryT< MF > & operator=(const MLMGBndryT< MF > &rhs)=delete
typename BndryDataT< MF >::RealTuple RealTuple
Definition AMReX_MLMGBndry.H:24
~MLMGBndryT()=default
MLMGBndryT(const MLMGBndryT< MF > &rhs)=delete
void setLOBndryConds(const Vector< Array< LinOpBCType, 3 > > &lo, const Vector< Array< LinOpBCType, 3 > > &hi, int ratio, const RealVect &a_loc, LinOpBCType a_crse_fine_bc_type=LinOpBCType::Dirichlet)
Populate BC tags at coarse/fine and physical boundaries for an integer refinement ratio.
Definition AMReX_MLMGBndry.H:114
static void setBoxBC(RealTuple &bloc, BCTuple &bctag, const Box &bx, const Box &domain, const Array< LinOpBCType, 3 > &lo, const Array< LinOpBCType, 3 > &hi, const Real *dx, IntVect const &ratio, const RealVect &interior_bloc, const Array< Real, 3 > &domain_bloc_lo, const Array< Real, 3 > &domain_bloc_hi, const GpuArray< int, 3 > &is_periodic, LinOpBCType a_crse_fine_bc_type)
Helper that sets up BC tuples for a single box.
Definition AMReX_MLMGBndry.H:163
MLMGBndryT(const BoxArray &_grids, const DistributionMapping &_dmap, int _ncomp, const Geometry &_geom)
Allocate BC metadata for _grids/_geom.
Definition AMReX_MLMGBndry.H:107
MLMGBndryT(MLMGBndryT< MF > &&rhs)=delete
Array< BoundCond, 2 *3 > BCTuple
Definition AMReX_MLMGBndry.H:23
An Iterator over the Orientation of Faces of a Box.
Definition AMReX_Orientation.H:135
Encapsulation of the Orientation of the Faces of a Box.
Definition AMReX_Orientation.H:29
__host__ __device__ bool isLow() const noexcept
Returns true if Orientation is low.
Definition AMReX_Orientation.H:89
__host__ __device__ int coordDir() const noexcept
Returns the coordinate direction.
Definition AMReX_Orientation.H:83
@ low
Definition AMReX_Orientation.H:34
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
std::array< T, N > Array
Definition AMReX_Array.H:31
Definition AMReX_Amr.cpp:50
int nComp(FabArrayBase const &fa)
Definition AMReX_FabArrayBase.cpp:2852
LinOpBCType
Definition AMReX_LO_BCTYPES.H:27
IntVectND< 3 > IntVect
IntVect is an alias for amrex::IntVectND instantiated with AMREX_SPACEDIM.
Definition AMReX_BaseFwd.H:38
void Abort(const std::string &msg)
Print a fatal-error message to stderr and abort execution.
Definition AMReX.cpp:241
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52