15 #include "libmesh/fparser_ad.hh" 16 #include "libmesh/elem.h" 24 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
26 "expression",
"Parsed expression to determine the subdomain id of each involved element");
27 params.
addParam<std::vector<SubdomainName>>(
28 "excluded_subdomains",
29 "A set of subdomain names that will be immune to change if set. This cannot be used together " 30 "with included_subdomains.");
32 "excluded_subdomain_ids",
33 "A set of subdomain ids that will not changed even if " 34 "they are inside/outside the combinatorial geometry",
35 "excluded_subdomain_ids is deprecated, use excluded_subdomains (ids or names accepted)");
36 params.
addParam<std::vector<SubdomainName>>(
37 "included_subdomains",
38 "A set of subdomain names that will only be subjected to change if set. This cannot be used " 39 "together with excluded_subdomains.");
40 params.
addParam<std::vector<std::string>>(
41 "constant_names", {},
"Vector of constants used in the parsed function");
42 params.
addParam<std::vector<std::string>>(
43 "constant_expressions",
45 "Vector of values for the constants in constant_names (can be an FParser expression)");
46 params.
addParam<std::vector<ExtraElementIDName>>(
47 "extra_element_id_names", {},
"Extra element integers used in the parsed expression");
48 params.
addClassDescription(
"A base class for mesh generators that Use a parsed expression to " 49 "assign new subdomain id(s).");
57 _input(getMesh(
"input")),
58 _function(parameters.
get<
std::string>(
"expression")),
59 _excluded_ids(isParamValid(
"excluded_subdomain_ids")
62 _eeid_names(getParam<
std::vector<ExtraElementIDName>>(
"extra_element_id_names"))
67 "You cannot use both excluded_subdomains and included_subdomains at the same time.");
72 std::unique_ptr<MeshBase>
75 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
78 if (!
mesh->preparation().has_cached_elem_data)
79 mesh->cache_elem_data();
87 auto excluded_subdomains =
parameters().
get<std::vector<SubdomainName>>(
"excluded_subdomains");
90 for (
const auto &
name : excluded_subdomains)
92 paramError(
"excluded_subdomains",
"The block '",
name,
"' was not found in the mesh");
98 auto included_subdomains =
parameters().
get<std::vector<SubdomainName>>(
"included_subdomains");
101 for (
const auto &
name : included_subdomains)
103 paramError(
"included_subdomains",
"The block '",
name,
"' was not found in the mesh");
108 std::set<subdomain_id_type> mesh_sids;
109 mesh->subdomain_ids(mesh_sids);
112 for (
const auto & sid : mesh_sids)
113 if (
std::find(included_ids.begin(), included_ids.end(), sid) == included_ids.end())
118 for (
const auto & elem :
mesh->active_element_ptr_range())
124 mesh->unset_is_prepared();
132 std::string symbol_str =
"x,y,z";
134 symbol_str +=
"," + eeid_name;
137 _func_F = std::make_shared<SymFunction>();
141 getParam<std::vector<std::string>>(
"constant_names"),
142 getParam<std::vector<std::string>>(
"constant_expressions"),
std::vector< unsigned int > _eeid_indices
Indices of the extra element ids used in the parsed expression.
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
const std::vector< ExtraElementIDName > _eeid_names
Names of the extra element ids used in the parsed expression.
static InputParameters validParams()
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 ...
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
const InputParameters & parameters() const
Get the parameters of the object.
const std::string _function
function expression
std::vector< subdomain_id_type > _excluded_ids
A list of excluded subdomain ids that will not be changed even if they are in the combinatorial geome...
const Parallel::Communicator & comm() const
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
void functionInitialize(const std::string &function_expression)
Initialize the function parser object.
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
ParsedSubdomainGeneratorBase(const InputParameters ¶meters)
const std::string & name() const
Get the name of the class.
virtual void setBlockName(std::unique_ptr< MeshBase > &)
virtual void assignElemSubdomainID(Elem *elem)=0
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()
std::unique_ptr< MeshBase > & _input
mesh to set the subdomains on
SymFunctionPtr _func_F
function parser object describing the combinatorial geometry
bool hasSubdomainName(const MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
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.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
MeshGenerators are objects that can modify or add to an existing mesh.
const Elem & get(const ElemType type_in)