Alamo
BC.H
Go to the documentation of this file.
1//
2// This is the mechanism for impositing boundary conditions on :code:`Set::Field` objects of
3// scalar type.
4// Typical convention is for :code:`[prefix]` to be given by the field name. For instance,
5//
6// .. code-block:: make
7//
8// bc.temp.type.xhi = dirichlet dirichlet dirichlet
9// bc.temp.val.xhi = 0.0 1.0 0.0
10//
11// corresponds to the boundary condition for temperature. See the specific integrator
12// for details.
13//
14
15#ifndef BC_BC_H_
16#define BC_BC_H_
17
18#include <AMReX_ParallelDescriptor.H>
19#include <AMReX_ParmParse.H>
20#include <AMReX_BCRec.H>
21#include <AMReX_PhysBCFunct.H>
22#include <AMReX_LO_BCTYPES.H>
23#include <AMReX_Mask.H>
24#include <AMReX_Periodicity.H>
25
26
27/// \brief Collection of boundary condition (BC) objects
28namespace BC
29{
31 All = -1,
32 AMREX_D_DECL(xlo = 0,
33 ylo = 1,
34 zlo = 2),
35 AMREX_D_DECL(xhi = 0 + AMREX_SPACEDIM,
36 yhi = 1 + AMREX_SPACEDIM,
37 zhi = 2 + AMREX_SPACEDIM)
38};
39
40template<class T>
41class BC
42{
43
44public:
45 virtual ~BC() {};
46
47 void define(const amrex::Geometry& a_geom) { m_geom = a_geom; };
48
49 virtual void FillBoundary(amrex::BaseFab<T>& in,
50 const amrex::Box& box,
51 int ngrow, int dcomp, int ncomp,
52 amrex::Real time,
54 const amrex::Mask* mask = nullptr) = 0;
55
56 virtual void FillBoundary(amrex::FabArray<amrex::BaseFab<T>>& mf,
57 int dcomp, int ncomp,
58 amrex::Real time, int /*bccomp*/)
59 {
60 mf.FillBoundary(m_geom.periodicity());
61 for (amrex::MFIter mfi(mf, true); mfi.isValid(); ++mfi)
62 {
63 const amrex::Box& box = mfi.tilebox();
64 amrex::BaseFab<T>& in = mf[mfi];
65 FillBoundary(in, box, mf.nGrow(), dcomp, ncomp, time);
66 }
67 }
68
69 virtual void FillBoundary(amrex::FabArray<amrex::BaseFab<T>>& mf,
70 int dcomp, int ncomp, amrex::IntVect const& /*nghost*/,
71 amrex::Real time, int bccomp) //override
72 {
73 FillBoundary(mf, dcomp, ncomp, time, bccomp);
74 }
75
76 void operator () (amrex::FabArray<amrex::BaseFab<T>>& mf,
77 int dcomp, int ncomp, amrex::IntVect const& /*nghost*/,
78 amrex::Real time, int bccomp)
79 {
80 FillBoundary(mf, dcomp, ncomp, time, bccomp);
81 }
82
83
84
85 template <class Q = T>
86 typename std::enable_if<std::is_same<Q, amrex::Real>::value>::type
87 FillBoundary(amrex::MultiFab& mf,
88 int dcomp, int ncomp,
89 amrex::Real time, int /*bccomp*/)
90 {
91 mf.FillBoundary(m_geom.periodicity());
92 for (amrex::MFIter mfi(mf, true); mfi.isValid(); ++mfi)
93 {
94 const amrex::Box& box = mfi.tilebox();
95 amrex::BaseFab<T>& in = mf[mfi];
96 FillBoundary(in, box, mf.nGrow(), dcomp, ncomp, time);
97 }
98 }
99
100 template <class Q = T>
101 typename std::enable_if<std::is_same<Q, amrex::Real>::value>::type
102 operator () (amrex::MultiFab& mf,
103 int dcomp, int ncomp, amrex::IntVect const& /*nghost*/,
104 amrex::Real time, int bccomp)
105 {
106 FillBoundary(mf, dcomp, ncomp, time, bccomp);
107 }
108
109
110 virtual amrex::BCRec GetBCRec() = 0;
111
112 virtual amrex::Array<int, AMREX_SPACEDIM> IsPeriodic()
113 {
114 return { {AMREX_D_DECL(m_geom.isPeriodic(0),m_geom.isPeriodic(1),m_geom.isPeriodic(2))} };
115 }
116
117 virtual amrex::Periodicity Periodicity() const {
118 return m_geom.periodicity();
119 }
120
121 virtual amrex::Periodicity Periodicity(const amrex::Box& b) {
122 return m_geom.periodicity(b);
123 }
124
125
126protected:
127 amrex::Geometry m_geom;
128 //std::vector<amrex::Geometry> &geom;
129 //int lev=0;
130};
131
132namespace BCUtil
133{
134int ReadString(std::string bcstring);
135bool IsPeriodic(int bctype);
136bool IsNeumann(int bctype);
137bool IsReflectEven(int bctype);
138bool IsReflectOdd(int bctype);
139bool IsDirichlet(int bctype);
140}
141
142}
143#endif
virtual amrex::Array< int, AMREX_SPACEDIM > IsPeriodic()
Definition BC.H:112
virtual void FillBoundary(amrex::FabArray< amrex::BaseFab< T > > &mf, int dcomp, int ncomp, amrex::Real time, int)
Definition BC.H:56
virtual ~BC()
Definition BC.H:45
void define(const amrex::Geometry &a_geom)
Definition BC.H:47
virtual void FillBoundary(amrex::BaseFab< T > &in, const amrex::Box &box, int ngrow, int dcomp, int ncomp, amrex::Real time, Orientation face=Orientation::All, const amrex::Mask *mask=nullptr)=0
virtual amrex::Periodicity Periodicity(const amrex::Box &b)
Definition BC.H:121
virtual amrex::BCRec GetBCRec()=0
amrex::Geometry m_geom
Definition BC.H:127
std::enable_if< std::is_same< Q, amrex::Real >::value >::type FillBoundary(amrex::MultiFab &mf, int dcomp, int ncomp, amrex::Real time, int)
Definition BC.H:87
virtual void FillBoundary(amrex::FabArray< amrex::BaseFab< T > > &mf, int dcomp, int ncomp, amrex::IntVect const &, amrex::Real time, int bccomp)
Definition BC.H:69
virtual amrex::Periodicity Periodicity() const
Definition BC.H:117
bool IsDirichlet(int bctype)
Definition BC.cpp:48
bool IsPeriodic(int bctype)
Definition BC.cpp:33
bool IsNeumann(int bctype)
Definition BC.cpp:41
bool IsReflectOdd(int bctype)
Definition BC.cpp:59
bool IsReflectEven(int bctype)
Definition BC.cpp:54
int ReadString(std::string bcstring)
Definition BC.cpp:8
Collection of boundary condition (BC) objects.
Definition BC.cpp:5
Orientation
Definition BC.H:30
@ All
Definition BC.H:31
@ AMREX_D_DECL
Definition BC.H:32