Alamo
Step.H
Go to the documentation of this file.
1 //
2 // .. warning::
3 // This will be replaced by the more general :code:`BC::Expression`
4 //
5 
6 
7 
8 #ifndef BC_STEP_H_
9 #define BC_STEP_H_
10 
11 #include <AMReX_ParallelDescriptor.H>
12 #include <AMReX_ParmParse.H>
13 #include <AMReX_BCRec.H>
14 #include <AMReX_PhysBCFunct.H>
15 #include <AMReX_Array.H>
16 
17 #include "Set/Set.H"
18 #include "BC/BC.H"
19 #include "BC/Constant.H"
20 namespace BC
21 {
22 class Step
23  : public BC<Set::Scalar>
24 {
25 public:
26  Step() {}
27  Step(IO::ParmParse& pp, std::string name)
28  {
29  pp_queryclass(name, *this);
30  }
31 
32  void FillBoundary(amrex::BaseFab<Set::Scalar>& a_in,
33  const amrex::Box& a_box,
34  int ngrow, int /*dcomp*/, int /*ncomp*/, amrex::Real /*time*/,
35  Orientation face, const amrex::Mask* /*mask*/) override
36  {
37 
38  const amrex::Real* DX = m_geom.CellSize();
39 
40  amrex::Box box = a_box;
41  box.grow(ngrow);
42  const amrex::Dim3 lo = amrex::lbound(m_geom.Domain()), hi = amrex::ubound(m_geom.Domain());
43 
44  amrex::Array4<amrex::Real> const& in = a_in.array();
45 
46  amrex::ParallelFor(box, [=] AMREX_GPU_DEVICE(int i, int j, int k)
47  {
48  amrex::IntVect glevel;
49  AMREX_D_TERM(glevel[0] = std::max(std::min(0, i - lo.x), i - hi.x);,
50  glevel[1] = std::max(std::min(0, j - lo.y), j - hi.y);,
51  glevel[2] = std::max(std::min(0, k - lo.z), k - hi.z); );
52 
53  Set::Vector x;
54  AMREX_D_TERM(x(0) = m_geom.ProbLo()[0] + ((Set::Scalar)(i)+0.5) * DX[0];,
55  x(1) = m_geom.ProbLo()[1] + ((Set::Scalar)(j)+0.5) * DX[1];,
56  x(2) = m_geom.ProbLo()[2] + ((Set::Scalar)(k)+0.5) * DX[2];);
57 
58 
59  if (glevel[0] < 0 && (face == Orientation::xlo || face == Orientation::All))
60  {
61  if (x(1) > m_h1)
62  {
63  in(i, j, k, 0) = 0.;
64  in(i, j, k, 1) = 1.;
65  }
66  else
67  {
68  in(i, j, k, 0) = 1.;
69  in(i, j, k, 1) = 0.;
70  }
71  }
72  else if (glevel[0] > 0)
73  {
74  if (x(1) > m_h2)
75  {
76  in(i, j, k, 0) = 0.;
77  in(i, j, k, 1) = 1.;
78  }
79  else
80  {
81  in(i, j, k, 0) = 1.;
82  in(i, j, k, 1) = 0.;
83  }
84  }
85  else if (glevel[1] < 0) // Bottom boundary
86  {
87  in(i, j, k, 0) = 1.;
88  in(i, j, k, 1) = 0.;
89  }
90  else if (glevel[1] > 0 && (face == Orientation::yhi || face == Orientation::All)) // Top boundary
91  {
92  in(i, j, k, 0) = 0.;
93  in(i, j, k, 1) = 1.;
94  }
95  });
96 
97 
98  }
99  amrex::BCRec GetBCRec() override
100  {
101  int bc_lo[AMREX_SPACEDIM] =
102  { AMREX_D_DECL(amrex::BCType::mathematicalBndryTypes::int_dir,
103  amrex::BCType::mathematicalBndryTypes::int_dir,
104  amrex::BCType::mathematicalBndryTypes::int_dir) };
105  int bc_hi[AMREX_SPACEDIM] =
106  { AMREX_D_DECL(amrex::BCType::mathematicalBndryTypes::int_dir,
107  amrex::BCType::mathematicalBndryTypes::int_dir,
108  amrex::BCType::mathematicalBndryTypes::int_dir) };
109 
110  return amrex::BCRec(bc_lo, bc_hi);
111  }
112 
113 private:
114  Set::Scalar m_h1 = NAN, m_h2 = NAN;
115 
116 public:
117  static void Parse(Step& value, amrex::ParmParse& pp)
118  {
119  pp_query("h1", value.m_h1); // Location of the step on the xlo edge/face
120  pp_query("h2", value.m_h2); // Location of the step on the xhi edge/face
121  }
122 
123 };
124 }
125 #endif
BC::AMREX_D_DECL
@ AMREX_D_DECL
Definition: BC.H:34
BC::Step::m_h2
Set::Scalar m_h2
Definition: Step.H:114
BC::Step::GetBCRec
amrex::BCRec GetBCRec() override
Definition: Step.H:99
BC::Step::Step
Step()
Definition: Step.H:26
BC::All
@ All
Definition: BC.H:33
Set::Vector
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition: Base.H:20
Constant.H
BC::Step::Step
Step(IO::ParmParse &pp, std::string name)
Definition: Step.H:27
pp_query
#define pp_query(...)
Definition: ParmParse.H:104
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
pp_queryclass
#define pp_queryclass(...)
Definition: ParmParse.H:105
BC::Step::FillBoundary
void FillBoundary(amrex::BaseFab< Set::Scalar > &a_in, const amrex::Box &a_box, int ngrow, int, int, amrex::Real, Orientation face, const amrex::Mask *) override
Definition: Step.H:32
BC::BC< Set::Scalar >::m_geom
amrex::Geometry m_geom
Definition: BC.H:129
BC::Orientation
Orientation
Definition: BC.H:32
BC
Collection of boundary condition (BC) objects.
Definition: BC.cpp:4
BC::Step
Definition: Step.H:22
BC::Step::Parse
static void Parse(Step &value, amrex::ParmParse &pp)
Definition: Step.H:117
Set.H
BC.H
IO::ParmParse
Definition: ParmParse.H:110
BC::Step::m_h1
Set::Scalar m_h1
Definition: Step.H:114