15 #include "libmesh/fparser_ad.hh" 16 #include "libmesh/elem.h" 26 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
28 "expression",
"Function expression to return the extra element ID based on element centroid");
30 "extra_elem_integer_name",
"Name of the extra element integer to be added by this generator");
31 params.
addParam<std::vector<SubdomainName>>(
"restricted_subdomains",
32 "Only set ids for elements within these restricted " 33 "subdomains (empty means the entire domain)");
34 params.
addParam<std::vector<std::string>>(
35 "constant_names", {},
"Vector of constants used in the parsed function");
36 params.
addParam<std::vector<std::string>>(
37 "constant_expressions",
39 "Vector of values for the constants in constant_names (can be an FParser expression)");
40 params.
addParam<std::vector<ExtraElementIDName>>(
41 "extra_element_id_names", {},
"Extra element integers used in the parsed expression");
43 "Uses a parsed expression to set an extra element id for elements (via their centroids).");
51 _input(getMesh(
"input")),
52 _function(parameters.
get<
std::string>(
"expression")),
53 _eeid_names(getParam<
std::vector<ExtraElementIDName>>(
"extra_element_id_names")),
54 _elem_id_name(getParam<
std::string>(
"extra_elem_integer_name"))
57 auto c_names = getParam<std::vector<std::string>>(
"constant_names");
58 auto c_defs = getParam<std::vector<std::string>>(
"constant_expressions");
59 c_names.push_back(
"invalid_elem_id");
60 c_defs.push_back(std::to_string(DofObject::invalid_id));
61 c_names.push_back(
"pi");
63 c_names.push_back(
"e");
67 std::string symbol_str =
"x,y,z";
69 symbol_str +=
"," + eeid_name;
72 _func_F = std::make_shared<SymFunction>();
78 std::unique_ptr<MeshBase>
81 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
87 bool has_restriction =
isParamValid(
"restricted_subdomains");
88 std::set<SubdomainID> restricted_blocks;
91 auto names = getParam<std::vector<SubdomainName>>(
"restricted_subdomains");
92 for (
auto &
name : names)
96 paramError(
"restricted_subdomains",
"The block '",
name,
"' was not found in the mesh");
108 for (
const auto & elem :
mesh->active_element_ptr_range())
110 if (has_restriction && restricted_blocks.count(elem->subdomain_id()) == 0)
113 const auto centroid = elem->true_centroid();
123 if (id_real == (
Real)DofObject::invalid_id)
124 id = DofObject::invalid_id;
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
const Parallel::Communicator & comm() const
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
const std::string & name() const
Get the name of the class.
void parsedFunctionSetup(SymFunctionPtr &function, const std::string &expression, const std::string &variables, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions, const libMesh::Parallel::Communicator &comm) const
Performs setup steps on a SymFunction.
static InputParameters validParams()
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
static InputParameters validParams()
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MeshGenerators are objects that can modify or add to an existing mesh.
auto index_range(const T &sizable)