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 #include "Util/Util.H"
27 #include "Set/Set.H"
28 
29 /// \brief Collection of boundary condition (BC) objects
30 namespace BC
31 {
33  All = -1,
34  AMREX_D_DECL(xlo = 0,
35  ylo = 1,
36  zlo = 2),
37  AMREX_D_DECL(xhi = 0 + AMREX_SPACEDIM,
38  yhi = 1 + AMREX_SPACEDIM,
39  zhi = 2 + AMREX_SPACEDIM)
40 };
41 
42 template<class T>
43 class BC
44 {
45 
46 public:
47  virtual ~BC() {};
48 
49  void define(const amrex::Geometry& a_geom) { m_geom = a_geom; };
50 
51  virtual void FillBoundary(amrex::BaseFab<T>& in,
52  const amrex::Box& box,
53  int ngrow, int dcomp, int ncomp,
54  amrex::Real time,
56  const amrex::Mask* mask = nullptr) = 0;
57 
58  virtual void FillBoundary(amrex::FabArray<amrex::BaseFab<T>>& mf,
59  int dcomp, int ncomp,
60  amrex::Real time, int /*bccomp*/)
61  {
62  mf.FillBoundary(m_geom.periodicity());
63  for (amrex::MFIter mfi(mf, true); mfi.isValid(); ++mfi)
64  {
65  const amrex::Box& box = mfi.tilebox();
66  amrex::BaseFab<T>& in = mf[mfi];
67  FillBoundary(in, box, mf.nGrow(), dcomp, ncomp, time);
68  }
69  }
70 
71  virtual void FillBoundary(amrex::FabArray<amrex::BaseFab<T>>& mf,
72  int dcomp, int ncomp, amrex::IntVect const& /*nghost*/,
73  amrex::Real time, int bccomp) //override
74  {
75  FillBoundary(mf, dcomp, ncomp, time, bccomp);
76  }
77 
78  void operator () (amrex::FabArray<amrex::BaseFab<T>>& mf,
79  int dcomp, int ncomp, amrex::IntVect const& /*nghost*/,
80  amrex::Real time, int bccomp)
81  {
82  FillBoundary(mf, dcomp, ncomp, time, bccomp);
83  }
84 
85 
86 
87  template <class Q = T>
88  typename std::enable_if<std::is_same<Q, amrex::Real>::value>::type
89  FillBoundary(amrex::MultiFab& mf,
90  int dcomp, int ncomp,
91  amrex::Real time, int /*bccomp*/)
92  {
93  mf.FillBoundary(m_geom.periodicity());
94  for (amrex::MFIter mfi(mf, true); mfi.isValid(); ++mfi)
95  {
96  const amrex::Box& box = mfi.tilebox();
97  amrex::BaseFab<T>& in = mf[mfi];
98  FillBoundary(in, box, mf.nGrow(), dcomp, ncomp, time);
99  }
100  }
101 
102  template <class Q = T>
103  typename std::enable_if<std::is_same<Q, amrex::Real>::value>::type
104  operator () (amrex::MultiFab& mf,
105  int dcomp, int ncomp, amrex::IntVect const& /*nghost*/,
106  amrex::Real time, int bccomp)
107  {
108  FillBoundary(mf, dcomp, ncomp, time, bccomp);
109  }
110 
111 
112  virtual amrex::BCRec GetBCRec() = 0;
113 
114  virtual amrex::Array<int, AMREX_SPACEDIM> IsPeriodic()
115  {
116  return { {AMREX_D_DECL(m_geom.isPeriodic(0),m_geom.isPeriodic(1),m_geom.isPeriodic(2))} };
117  }
118 
119  virtual amrex::Periodicity Periodicity() const {
120  return m_geom.periodicity();
121  }
122 
123  virtual amrex::Periodicity Periodicity(const amrex::Box& b) {
124  return m_geom.periodicity(b);
125  }
126 
127 
128 protected:
129  amrex::Geometry m_geom;
130  //std::vector<amrex::Geometry> &geom;
131  //int lev=0;
132 };
133 
134 namespace BCUtil
135 {
136 int ReadString(std::string bcstring);
137 bool IsPeriodic(int bctype);
138 bool IsNeumann(int bctype);
139 bool IsReflectEven(int bctype);
140 bool IsReflectOdd(int bctype);
141 bool IsDirichlet(int bctype);
142 }
143 
144 }
145 #endif
BC::BC::Periodicity
virtual amrex::Periodicity Periodicity() const
Definition: BC.H:119
BC::AMREX_D_DECL
@ AMREX_D_DECL
Definition: BC.H:34
BC::BC::define
void define(const amrex::Geometry &a_geom)
Definition: BC.H:49
Util.H
BC::BC::FillBoundary
virtual void FillBoundary(amrex::FabArray< amrex::BaseFab< T >> &mf, int dcomp, int ncomp, amrex::IntVect const &, amrex::Real time, int bccomp)
Definition: BC.H:71
BC::BC::FillBoundary
virtual void FillBoundary(amrex::FabArray< amrex::BaseFab< T >> &mf, int dcomp, int ncomp, amrex::Real time, int)
Definition: BC.H:58
BC::All
@ All
Definition: BC.H:33
BC::BC::IsPeriodic
virtual amrex::Array< int, AMREX_SPACEDIM > IsPeriodic()
Definition: BC.H:114
BC::BC::m_geom
amrex::Geometry m_geom
Definition: BC.H:129
BC::BCUtil::IsDirichlet
bool IsDirichlet(int bctype)
Definition: BC.cpp:48
BC::BCUtil::ReadString
int ReadString(std::string bcstring)
Definition: BC.cpp:8
BC::BC::Periodicity
virtual amrex::Periodicity Periodicity(const amrex::Box &b)
Definition: BC.H:123
BC::BCUtil::IsNeumann
bool IsNeumann(int bctype)
Definition: BC.cpp:41
BC::Orientation
Orientation
Definition: BC.H:32
BC
Collection of boundary condition (BC) objects.
Definition: BC.cpp:4
Set.H
BC::BCUtil::IsPeriodic
bool IsPeriodic(int bctype)
Definition: BC.cpp:33
BC::BC::FillBoundary
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:89
BC::BC::~BC
virtual ~BC()
Definition: BC.H:47
BC::BCUtil::IsReflectEven
bool IsReflectEven(int bctype)
Definition: BC.cpp:54
BC::BCUtil::IsReflectOdd
bool IsReflectOdd(int bctype)
Definition: BC.cpp:59