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