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