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 "Unit/Unit.H"
27
28/// \brief Collection of boundary condition (BC) objects
29namespace BC
30{
32 All = -1,
33 AMREX_D_DECL(xlo = 0,
34 ylo = 1,
35 zlo = 2),
36 AMREX_D_DECL(xhi = 0 + AMREX_SPACEDIM,
37 yhi = 1 + AMREX_SPACEDIM,
38 zhi = 2 + AMREX_SPACEDIM)
39};
40
41template<class T>
42class BC
43{
44
45public:
46 virtual ~BC() {};
47
48 void define(const amrex::Geometry& a_geom)
49 { 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
128protected:
129 amrex::Geometry m_geom;
130 //std::vector<amrex::Geometry> &geom;
131 //int lev=0;
133};
134
135namespace BCUtil
136{
137int ReadString(std::string bcstring);
138bool IsPeriodic(int bctype);
139bool IsNeumann(int bctype);
140bool IsReflectEven(int bctype);
141bool IsReflectOdd(int bctype);
142bool IsDirichlet(int bctype);
143}
144
145}
146#endif
virtual amrex::Array< int, AMREX_SPACEDIM > IsPeriodic()
Definition BC.H:114
virtual void FillBoundary(amrex::FabArray< amrex::BaseFab< T > > &mf, int dcomp, int ncomp, amrex::Real time, int)
Definition BC.H:58
virtual ~BC()
Definition BC.H:46
void define(const amrex::Geometry &a_geom)
Definition BC.H:48
Unit unit
Definition BC.H:132
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:123
virtual amrex::BCRec GetBCRec()=0
amrex::Geometry m_geom
Definition BC.H:129
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
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
virtual amrex::Periodicity Periodicity() const
Definition BC.H:119
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:31
@ All
Definition BC.H:32
@ AMREX_D_DECL
Definition BC.H:33
Definition Unit.H:20