35 #ifndef IC_EXPRESSION_H_
36 #define IC_EXPRESSION_H_
40 #include "AMReX_Parser.H"
49 std::vector<amrex::ParserExecutor<4>>
f;
52 static constexpr
const char*
name =
"expression";
61 for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
65 amrex::IndexType type = a_field[lev]->ixType();
66 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
67 else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
70 amrex::Array4<Set::Scalar>
const& field = a_field[lev]->array(mfi);
71 for (
unsigned int n = 0; n <
f.size(); n++)
73 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
76 if (
coord == Expression::CoordSys::Cartesian)
78 #if AMREX_SPACEDIM == 1
79 field(i, j, k, n) =
f[n](x(0), 0.0, 0.0, a_time);
80 #elif AMREX_SPACEDIM == 2
81 field(i, j, k, n) =
f[n](x(0), x(1), 0.0, a_time);
82 #elif AMREX_SPACEDIM == 3
83 field(i, j, k, n) =
f[n](x(0), x(1), x(2), a_time);
87 else if (
coord == Expression::CoordSys::Polar)
89 field(i, j, k, n) =
f[n](sqrt(x(0)* x(0) + x(1) * x(1)), std::atan2(x(1), x(0)), x(2), a_time);
95 a_field[lev]->FillBoundary();
102 for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
105 amrex::IndexType type = a_field[lev]->ixType();
106 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
107 else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
111 for (
unsigned int n = 0; n < AMREX_SPACEDIM; n++)
113 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
116 if (
coord == Expression::CoordSys::Cartesian)
118 #if AMREX_SPACEDIM == 1
119 field(i, j, k)(n) =
f[n](x(0), 0.0, 0.0, a_time);
120 #elif AMREX_SPACEDIM == 2
121 field(i, j, k)(n) =
f[n](x(0), x(1), 0.0, a_time);
122 #elif AMREX_SPACEDIM == 3
123 field(i, j, k)(n) =
f[n](x(0), x(1), x(2), a_time);
127 else if (
coord == Expression::CoordSys::Polar)
129 field(i, j, k)(n) =
f[n](sqrt(x(0)* x(0) + x(1) * x(1)), std::atan2(x(1), x(0)), x(2), a_time);
135 a_field[lev]->FillBoundary();
140 for (
int i = 0;
true; i++)
142 std::string coordstr =
"cartesian";
146 if (coordstr ==
"cartesian") value.
coord = Expression::CoordSys::Cartesian;
147 else if (coordstr ==
"polar") value.
coord = Expression::CoordSys::Polar;
150 std::string func =
"0.0";
151 std::string
name =
"region" + std::to_string(i);
156 value.
parser.push_back(amrex::Parser(func));
162 std::set<std::string> entries = pp.getEntries(prefix +
".constant");
163 std::set<std::string>::iterator entry;
164 for (entry = entries.begin(); entry != entries.end(); entry++)
167 std::string fullname = *entry;
174 if (value.
coord == Expression::CoordSys::Cartesian)
176 value.
parser.back().registerVariables({
"x",
"y",
"z",
"t" });
177 value.
f.push_back(value.
parser.back().compile<4>());
179 else if (value.
coord == Expression::CoordSys::Polar)
181 value.
parser.back().registerVariables({
"r",
"theta",
"z",
"t" });
182 value.
f.push_back(value.
parser.back().compile<4>());