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