Alamo
Sphere.H
Go to the documentation of this file.
1 #ifndef IC_SPHERE_H_
2 #define IC_SPHERE_H_
3 
4 #include <cmath>
5 
6 #include "IC/IC.H"
7 #include "Util/Util.H"
8 
9 /// \class Sphere
10 /// \brief Initialize a spherical inclusion
11 namespace IC
12 {
13 class Sphere: public IC
14 {
15 public:
16  static constexpr const char* name = "sphere";
17 
18  /// Sphere is also used for a cylindrical case, but switching from the default type to the desired orientation.
19  /// For instance, XY refers to a cylinder with the circular faces in the XY plane.
20  enum Type
21  {
22  XYZ,
23  YZ,
24  ZX,
26  };
27 
28  Sphere(amrex::Vector<amrex::Geometry>& _geom): IC(_geom) {}
29  Sphere(amrex::Vector<amrex::Geometry>& _geom, IO::ParmParse& pp): IC(_geom)
30  {
31  pp_queryclass(*this);
32  }
33  Sphere(amrex::Vector<amrex::Geometry>& _geom, IO::ParmParse& pp, std::string name): IC(_geom)
34  {
35  pp_queryclass(name, *this);
36  }
37  /// Constructor defining radius, center, dimension/orientation, and field values within and outside of the area.
38  Sphere(amrex::Vector<amrex::Geometry>& _geom, Set::Scalar _radius, Set::Vector _center, Type _type = Type::XYZ, Set::Scalar _alpha_in = 1, Set::Scalar _alpha_out = 0)
39  : IC(_geom)
40  {
41  Define(_radius, _center, _type, _alpha_in, _alpha_out);
42  }
43 
44  void Define(Set::Scalar a_radius,
45  Set::Vector a_center,
46  Type a_type,
47  Set::Scalar a_alpha_in,
48  Set::Scalar a_alpha_out)
49  {
50  radius = a_radius;
51  center = a_center;
52  type = a_type;
53  alpha_in = a_alpha_in;
54  alpha_out = a_alpha_out;
55  }
56 
57  void Add(const int& lev, Set::Field<Set::Scalar>& a_field, Set::Scalar)
58  {
59  bool cellcentered = (a_field[0]->boxArray().ixType() == amrex::IndexType(amrex::IntVect::TheCellVector()));
60  int ncomp = a_field[0]->nComp();
61 
62  for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
63  {
64  amrex::Box bx = mfi.tilebox();
65  // bx.grow(a_field[lev]->nGrow());
66 
67  amrex::Array4<Set::Scalar> const& field = a_field[lev]->array(mfi);
68  amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k)
69  {
70 
71  Set::Scalar AMREX_D_DECL(x, y, z);
72  if (cellcentered)
73  {
74  AMREX_D_TERM(x = geom[lev].ProbLo()[0] + ((amrex::Real)(i)+0.5) * geom[lev].CellSize()[0];,
75  y = geom[lev].ProbLo()[1] + ((amrex::Real)(j)+0.5) * geom[lev].CellSize()[1];,
76  z = geom[lev].ProbLo()[2] + ((amrex::Real)(k)+0.5) * geom[lev].CellSize()[2];);
77  }
78  else
79  {
80  AMREX_D_TERM(x = geom[lev].ProbLo()[0] + (amrex::Real)(i)*geom[lev].CellSize()[0];,
81  y = geom[lev].ProbLo()[1] + (amrex::Real)(j)*geom[lev].CellSize()[1];,
82  z = geom[lev].ProbLo()[2] + (amrex::Real)(k)*geom[lev].CellSize()[2];);
83  }
84 
85  Set::Scalar rsq = NAN;
86 
87  if (type == Type::XYZ)
88  {
89  // 3D Sphere
90  rsq =
91  AMREX_D_TERM((x - center(0)) * (x - center(0)),
92  +(y - center(1)) * (y - center(1)),
93  +(z - center(2)) * (z - center(2)));
94  }
95  else if (type == Type::XY)
96  {
97  // Cylinder along Z axis
98  rsq =
99  AMREX_D_TERM((x - center(0)) * (x - center(0)),
100  +(y - center(1)) * (y - center(1)),
101  );
102  }
103  else if (type == Type::YZ)
104  {
105  // Cylinder along X axis
106  rsq =
107  AMREX_D_TERM(,
108  +(y - center(1)) * (y - center(1)),
109  +(z - center(2)) * (z - center(2)));
110  }
111  else if (type == Type::ZX)
112  {
113  // Cylinder along Y axis
114  rsq =
115  AMREX_D_TERM((x - center(0)) * (x - center(0)),
116  ,
117  +(z - center(2)) * (z - center(2)));
118  }
119 
120  if (rsq < radius * radius)
121  {
122  field(i, j, k, 0) = alpha_in;
123  if (ncomp > 1) field(i, j, k, 1) = 0.;
124  }
125  else
126  {
127  field(i, j, k, 0) = alpha_out;
128  if (ncomp > 1) field(i, j, k, 1) = 1;
129  }
130  });
131  }
132  };
133  // This is a somewhat antiquated IC that will eventually be replaced
134  // with the Expression IC.
135  static void Parse(Sphere& value, IO::ParmParse& pp)
136  {
137  pp_query("radius", value.radius); // Radius of the sphere
138  pp_queryarr("center", value.center); // Vector location of the sphere center
139  pp_query("inside", value.alpha_in); // Value of the field inside the sphere
140  pp_query("outside", value.alpha_out); // Value of the field outside teh sphere
141  std::string type;
142  pp_query("type", type); // Type - can be cylinder oriented along the x, y, z directions or full sphere.
143  if (type == "yz")
144  value.type = Type::YZ;
145  if (type == "zx")
146  value.type = Type::ZX;
147  if (type == "xy")
148  value.type = Type::XY;
149  if (type == "xyz")
150  value.type = Type::XYZ;
151  }
152 
153 private:
154  Set::Vector center = Set::Vector::Zero();
158  Type type = Type::XYZ;
159 };
160 }
161 #endif
IC::IC::geom
amrex::Vector< amrex::Geometry > & geom
Definition: IC.H:54
IC::Sphere::Type
Type
Definition: Sphere.H:20
IC::Sphere::YZ
@ YZ
Definition: Sphere.H:23
BC::AMREX_D_DECL
@ AMREX_D_DECL
Definition: BC.H:34
Util.H
IC::Sphere::type
Type type
Definition: Sphere.H:158
Set::Field< Set::Scalar >
Definition: Set.H:236
IC::Sphere::XYZ
@ XYZ
Definition: Sphere.H:22
Set::Vector
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition: Base.H:20
pp_query
#define pp_query(...)
Definition: ParmParse.H:105
IC::Sphere::center
Set::Vector center
Definition: Sphere.H:154
Set::Scalar
amrex::Real Scalar
Definition: Base.H:19
pp_queryclass
#define pp_queryclass(...)
Definition: ParmParse.H:106
IC::Sphere::XY
@ XY
Definition: Sphere.H:25
IC::Sphere::Sphere
Sphere(amrex::Vector< amrex::Geometry > &_geom, Set::Scalar _radius, Set::Vector _center, Type _type=Type::XYZ, Set::Scalar _alpha_in=1, Set::Scalar _alpha_out=0)
Constructor defining radius, center, dimension/orientation, and field values within and outside of th...
Definition: Sphere.H:38
IC::Sphere::Sphere
Sphere(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp)
Definition: Sphere.H:29
IC::Sphere::Define
void Define(Set::Scalar a_radius, Set::Vector a_center, Type a_type, Set::Scalar a_alpha_in, Set::Scalar a_alpha_out)
Definition: Sphere.H:44
IC::Sphere::alpha_out
Set::Scalar alpha_out
Definition: Sphere.H:157
IC::Sphere::ZX
@ ZX
Definition: Sphere.H:24
IC::Sphere::alpha_in
Set::Scalar alpha_in
Definition: Sphere.H:156
IC
Definition: BMP.H:18
IC::Sphere::radius
Set::Scalar radius
Definition: Sphere.H:155
IO::ParmParse
Definition: ParmParse.H:112
IC::Sphere::Parse
static void Parse(Sphere &value, IO::ParmParse &pp)
Definition: Sphere.H:135
IC::Sphere::Sphere
Sphere(amrex::Vector< amrex::Geometry > &_geom)
Definition: Sphere.H:28
IC::Sphere::Add
void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar)
Definition: Sphere.H:57
IC::Sphere::Sphere
Sphere(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
Definition: Sphere.H:33
IC.H
IC::Sphere
Definition: Sphere.H:13
IC::Sphere::name
static constexpr const char * name
Definition: Sphere.H:16
pp_queryarr
#define pp_queryarr(...)
Definition: ParmParse.H:103