Alamo
Affine.H
Go to the documentation of this file.
1 //
2 // Initialize a field to a value (alpha) on the positive side of a hyperplane
3 //
4 // .. WARNING::
5 //
6 // This is an old-fasioned IC that will soon be deleted.
7 //
8 
9 #ifndef IC_AFFINE_H_
10 #define IC_AFFINE_H_
11 
12 #include "AMReX_Vector.H"
13 
14 #include "IC/IC.H"
15 #include "Util/Util.H"
16 #include "Set/Set.H"
17 
18 namespace IC
19 {
20 /// \brief Initialize with the function \f$\alpha[(\mathbf{x}-\mathbf{b})\cdot\mathbf{n}]^m\f$
21 class Affine : public IC
22 {
23 public:
24  Affine (amrex::Vector<amrex::Geometry> &_geom) :
25  IC(_geom)
26  {
27  amrex::ParmParse pp("ic");
28  amrex::Vector<amrex::Real> ntmp; pp_queryarr("n",ntmp); // Normal vector for hyperplane
29  for (int i = 0; i < AMREX_SPACEDIM; i++) n(i) = ntmp[i];
30  Util::Warning(INFO,"This function is not complete");
31  pp_query("alpha",alpha); // Value of the field on the positive side of the hyperplane
32  }
33 
34  Affine (amrex::Vector<amrex::Geometry> &_geom,
35  Set::Vector a_n,
36  Set::Scalar a_alpha,
37  Set::Vector a_b = Set::Vector::Zero(),
38  bool a_halfspace = false,
39  Set::Scalar a_m = 1.0) :
40  IC(_geom), n(a_n), alpha(a_alpha), b(a_b), halfspace(a_halfspace), m(a_m)
41  {}
42 
43  void SetHalfspace(bool a_halfspace) {halfspace = a_halfspace;}
44 
45  void Add(const int &lev, Set::Field<Set::Scalar> &field)
46  {
47  bool cellcentered = (field[0]->boxArray().ixType() == amrex::IndexType(amrex::IntVect::TheCellVector()));
48 
49  for (amrex::MFIter mfi(*field[lev],true); mfi.isValid(); ++mfi)
50  {
51  const amrex::Box& box = mfi.tilebox();
52 
53  amrex::BaseFab<amrex::Real> &field_box = (*field[lev])[mfi];
54 
55  AMREX_D_TERM(for (int i = box.loVect()[0]-field[lev]->nGrow(); i<=box.hiVect()[0]+field[lev]->nGrow(); i++),
56  for (int j = box.loVect()[1]-field[lev]->nGrow(); j<=box.hiVect()[1]+field[lev]->nGrow(); j++),
57  for (int k = box.loVect()[2]-field[lev]->nGrow(); k<=box.hiVect()[2]+field[lev]->nGrow(); k++))
58  {
59  amrex::Real AMREX_D_DECL(x1,x2,x3);
60 
61  if (cellcentered)
62  {
63  AMREX_D_TERM(x1 = geom[lev].ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom[lev].CellSize()[0];,
64  x2 = geom[lev].ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom[lev].CellSize()[1];,
65  x3 = geom[lev].ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom[lev].CellSize()[2];);
66  }
67  {
68  AMREX_D_TERM(x1 = geom[lev].ProbLo()[0] + ((amrex::Real)(i)) * geom[lev].CellSize()[0];,
69  x2 = geom[lev].ProbLo()[1] + ((amrex::Real)(j)) * geom[lev].CellSize()[1];,
70  x3 = geom[lev].ProbLo()[2] + ((amrex::Real)(k)) * geom[lev].CellSize()[2];);
71  }
72 
73  Set::Vector x(AMREX_D_DECL(x1,x2,x3));
74 
75  field_box(amrex::IntVect(AMREX_D_DECL(i,j,k)),comp) = (x - b).dot(n);
76  Set::Scalar val = (x - b).dot(n);
77  if (halfspace)
78  {
79  if (val >= 0)
80  field_box(amrex::IntVect(AMREX_D_DECL(i,j,k)),comp) = alpha*std::pow(val,m);
81  else
82  field_box(amrex::IntVect(AMREX_D_DECL(i,j,k)),comp) = 0.0;
83  }
84  }
85  }
86 
87  };
88 
89 private:
90  Set::Vector n;
91  amrex::Real alpha;
93  bool halfspace = false;
94  amrex::Real m = 1.0;
95 };
96 }
97 #endif
IC::IC::geom
amrex::Vector< amrex::Geometry > & geom
Definition: IC.H:45
IC::Affine::m
amrex::Real m
Definition: Affine.H:94
IC::Affine::Add
void Add(const int &lev, Set::Field< Set::Scalar > &field)
Definition: Affine.H:45
BC::AMREX_D_DECL
@ AMREX_D_DECL
Definition: BC.H:34
Util.H
Set::Field< Set::Scalar >
Definition: Set.H:236
Set::Vector
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition: Base.H:20
pp_query
#define pp_query(...)
Definition: ParmParse.H:104
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
IC::Affine::SetHalfspace
void SetHalfspace(bool a_halfspace)
Definition: Affine.H:43
IC::Affine::halfspace
bool halfspace
Definition: Affine.H:93
IC::Affine::n
Set::Vector n
Definition: Affine.H:87
IC::Affine::Affine
Affine(amrex::Vector< amrex::Geometry > &_geom, Set::Vector a_n, Set::Scalar a_alpha, Set::Vector a_b=Set::Vector::Zero(), bool a_halfspace=false, Set::Scalar a_m=1.0)
Definition: Affine.H:34
IC::Affine::b
Set::Vector b
Definition: Affine.H:92
IC::IC::comp
int comp
Definition: IC.H:46
IC::Affine::alpha
amrex::Real alpha
Definition: Affine.H:91
Set.H
IC
Definition: Affine.H:18
Util::Warning
void Warning(std::string file, std::string func, int line, Args const &... args)
Definition: Util.H:171
IC::Affine::Affine
Affine(amrex::Vector< amrex::Geometry > &_geom)
Definition: Affine.H:24
INFO
#define INFO
Definition: Util.H:20
IC.H
IC::Affine
Initialize with the function .
Definition: Affine.H:21
pp_queryarr
#define pp_queryarr(...)
Definition: ParmParse.H:103