35#ifndef IC_EXPRESSION_H_
36#define IC_EXPRESSION_H_
40#include "AMReX_Parser.H"
50 std::vector<amrex::ParserExecutor<4>>
f;
53 static constexpr const char*
name =
"expression";
55 IC<
Set::Scalar>(_geom),
IC<
Set::Vector>(_geom) {}
69 for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
73 const int coord =
static_cast<int>(this->
coord);
77 amrex::IndexType type = a_field[lev]->ixType();
78 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
79 else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
82 amrex::Array4<Set::Scalar>
const& field = a_field[lev]->array(mfi);
83 for (
unsigned int n = 0; n <
f.size(); n++)
85 const auto f_n =
f[n];
86 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
92#if AMREX_SPACEDIM == 1
93 field(i, j, k, n) = f_n(x(0), 0.0, 0.0, a_time) *
unitfactor;
94#elif AMREX_SPACEDIM == 2
95 field(i, j, k, n) = f_n(x(0), x(1), 0.0, a_time) *
unitfactor;
96#elif AMREX_SPACEDIM == 3
97 field(i, j, k, n) = f_n(x(0), x(1), x(2), a_time) *
unitfactor;
103 field(i, j, k, n) = f_n(
104 sqrt(x(0)*x(0) + x(1)*x(1)),
105 std::atan2(x(1), x(0)),
106#
if AMREX_SPACEDIM > 2
117 a_field[lev]->FillBoundary();
124 for (amrex::MFIter mfi(*a_field[lev], amrex::TilingIfNotGPU()); mfi.isValid(); ++mfi)
128 const int coord =
static_cast<int>(this->
coord);
131 amrex::IndexType type = a_field[lev]->ixType();
132 if (type == amrex::IndexType::TheCellType()) bx = mfi.growntilebox();
133 else if (type == amrex::IndexType::TheNodeType()) bx = mfi.grownnodaltilebox();
137 for (
unsigned int n = 0; n < AMREX_SPACEDIM; n++)
139 const auto f_n =
f[n];
140 amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(
int i,
int j,
int k)
146#if AMREX_SPACEDIM == 1
147 field(i, j, k)(n) = f_n(x(0), 0.0, 0.0, a_time) *
unitfactor;
148#elif AMREX_SPACEDIM == 2
149 field(i, j, k)(n) = f_n(x(0), x(1), 0.0, a_time) *
unitfactor;
150#elif AMREX_SPACEDIM == 3
151 field(i, j, k)(n) = f_n(x(0), x(1), x(2), a_time) *
unitfactor;
157 field(i, j, k)(n) = f_n(
158 sqrt(x(0)*x(0) + x(1)*x(1)),
159 std::atan2(x(1), x(0)),
160#if AMREX_SPACEDIM > 2
171 a_field[lev]->FillBoundary();
176 std::string coordstr =
"";
193 catch (std::runtime_error &e)
198 std::vector<std::string> expression_strs;
203 for (
unsigned int i = 0; i < expression_strs.size(); i++)
205 value.
parser.push_back(amrex::Parser(expression_strs[i]));
211 std::set<std::string> entries = pp.getEntries(prefix +
".constant");
212 std::set<std::string>::iterator entry;
213 for (entry = entries.begin(); entry != entries.end(); entry++)
216 std::string fullname = *entry;
225 value.
parser.back().registerVariables({
"x",
"y",
"z",
"t" });
226 value.
f.push_back(value.
parser.back().compile<4>());
230 value.
parser.back().registerVariables({
"r",
"theta",
"z",
"t" });
231 value.
f.push_back(value.
parser.back().compile<4>());
#define pp_query_validate(...)
#define pp_queryclass(...)
static constexpr const char * name
virtual void Add(const int &lev, Set::Field< Set::Vector > &a_field, Set::Scalar a_time=0.0) override
virtual void Add(const int &lev, Set::Field< Set::Scalar > &a_field, Set::Scalar a_time=0.0) override
Expression(amrex::Vector< amrex::Geometry > &_geom, Unit a_unit, IO::ParmParse &pp, std::string name)
Expression::CoordSys coord
Expression(amrex::Vector< amrex::Geometry > &_geom, IO::ParmParse &pp, std::string name)
std::vector< amrex::ParserExecutor< 4 > > f
std::vector< amrex::Parser > parser
Expression(amrex::Vector< amrex::Geometry > &_geom)
static void Parse(Expression &value, IO::ParmParse &pp)
Pure abstract IC object from which all other IC objects inherit.
std::string getPrefix() const
int query_default(std::string name, T &value, T defaultvalue, const std::source_location &location=std::source_location::current())
int queryunit(std::string name, Unit &value, const std::source_location &location=std::source_location::current())
int query_enumerate(std::string a_name, std::vector< T > &value, int number=1, const std::source_location &location=std::source_location::current())
amrex::Array4< T > Patch(int lev, amrex::MFIter &mfi) const &
Initialize a spherical inclusion.
A collection of data types and symmetry-reduced data structures.
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
AMREX_FORCE_INLINE Vector Position(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
AMREX_FORCE_INLINE std::vector< std::string > Split(std::string &str, const char delim=' ')
AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE void Assert(const char *file, const char *func, int line, const char *smt, bool pass, Args const &... args)
AMREX_GPU_HOST_DEVICE void Abort(const char *msg)
void Exception(std::string file, std::string func, int line, Args const &... args)
bool isType(const Unit &test) const
static Unit Parse(double val, std::string unitstring, bool verbose=false)
double normalized_value() const