15 #include "libmesh/fparser_ad.hh" 16 #include "libmesh/distributed_mesh.h" 17 #include "libmesh/elem.h" 18 #include "libmesh/fe_base.h" 30 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
32 "Function expression encoding a combinatorial geometry");
33 params.
addRequiredParam<BoundaryName>(
"new_sideset_name",
"The name of the new sideset");
34 params.
addParam<std::vector<BoundaryName>>(
35 "included_boundaries",
36 "A set of boundary names or ids whose sides will be included in the new sidesets");
37 params.
addParam<std::vector<SubdomainName>>(
38 "included_subdomains",
39 "A set of subdomain names or ids whose sides will be included in the new sidesets");
41 "included_subdomain_ids",
42 "A set of subdomain ids whose sides will be included in the new sidesets",
43 "included_subdomain_ids is deprecated, use included_subdomains with names or ids");
44 params.
addParam<std::vector<SubdomainName>>(
"included_neighbors",
45 "A set of neighboring subdomain names or ids. A face " 46 "is only added if the subdomain id of the " 47 "neighbor is in this set");
49 "included_neighbor_ids",
50 "A set of neighboring subdomain ids. A face is only added if the subdomain id of the " 51 "neighbor is in this set",
52 "included_neighbor_ids is deprecated, use included_neighbors with names or ids");
54 "include_only_external_sides",
56 "Whether to only include external sides when considering sides to add to the sideset");
60 "If provided specifies the normal vector on sides that are added to the new ");
61 params.
addParam<std::vector<std::string>>(
62 "constant_names", {},
"Vector of constants used in the parsed function");
63 params.
addParam<std::vector<std::string>>(
64 "constant_expressions",
66 "Vector of values for the constants in constant_names (can be an FParser expression)");
68 "centroid satisfies the `combinatorial_geometry` expression. " 69 "Optionally, element sides are also added if they are included in " 70 "`included_subdomain_ids` and if they feature the designated normal.");
78 _input(getMesh(
"input")),
79 _function(parameters.
get<
std::string>(
"combinatorial_geometry")),
80 _sideset_name(getParam<BoundaryName>(
"new_sideset_name")),
81 _check_boundaries(isParamValid(
"included_boundaries")),
82 _check_subdomains(isParamValid(
"included_subdomain_ids") ||
83 isParamValid(
"included_subdomains")),
84 _check_neighbor_subdomains(isParamValid(
"included_neighbor_ids") ||
85 isParamValid(
"included_neighbors")),
86 _check_normal(parameters.isParamSetByUser(
"normal")),
87 _included_ids(isParamValid(
"included_subdomain_ids")
90 _included_neighbor_ids(isParamValid(
"included_neighbor_ids")
93 _include_only_external_sides(getParam<bool>(
"include_only_external_sides")),
94 _normal(getParam<Point>(
"normal"))
99 "included_subdomain_ids is deprecated, only specify included_subdomains");
102 "included_neighbor_ids is deprecated, only specify included_neighbors");
106 paramError(
"include_only_external_sides",
"External sides dont have neighbors");
109 const auto & included_boundaries = getParam<std::vector<BoundaryName>>(
"included_boundaries");
110 if (std::find(included_boundaries.begin(), included_boundaries.end(),
_sideset_name) !=
111 included_boundaries.end())
114 "A boundary cannot be both the new boundary and be included in the list of included " 115 "boundaries. If you are trying to restrict an existing boundary, you must use a " 116 "different name for 'new_boundary', delete the old boundary, and then rename the " 117 "new boundary to the old boundary.");
120 _func_F = std::make_shared<SymFunction>();
127 getParam<std::vector<std::string>>(
"constant_names"),
128 getParam<std::vector<std::string>>(
"constant_expressions"));
134 "\nin ParsedAddSideset ",
142 std::unique_ptr<MeshBase>
145 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
146 if (!
mesh->is_replicated())
148 "ParsedGenerateSideset is not implemented for distributed meshes. Make sure the " 149 "parsed sideset does NOT cross any mesh distribution boundaries, using the ProcessorAux");
154 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
160 const auto subdomains = getParam<std::vector<SubdomainName>>(
"included_subdomains");
161 for (
const auto &
name : subdomains)
163 paramError(
"included_subdomains",
"The block '",
name,
"' was not found in the mesh");
171 const auto subdomains = getParam<std::vector<SubdomainName>>(
"included_neighbors");
172 for (
const auto &
name : subdomains)
174 paramError(
"included_neighbors",
"The block '",
name,
"' was not found in the mesh");
179 std::vector<boundary_id_type> restricted_boundary_ids;
182 *
mesh,
getParam<std::vector<BoundaryName>>(
"included_boundaries"),
true);
185 std::vector<boundary_id_type> boundary_ids =
187 mooseAssert(boundary_ids.size() == 1,
"Length of boundary_ids should be one");
189 for (
const auto & elem :
mesh->active_element_ptr_range())
199 for (
unsigned int side = 0; side < elem->n_sides(); ++side)
201 const std::vector<Point> & normals =
_fe_face->get_normals();
207 const Elem * neighbor = elem->neighbor_ptr(side);
227 bool in_included_boundaries =
false;
228 for (
auto bid : restricted_boundary_ids)
229 if (boundary_info.has_boundary_id(elem, side, bid))
230 in_included_boundaries =
true;
231 if (!in_included_boundaries)
240 std::unique_ptr<Elem> curr_side = elem->side_ptr(side);
246 boundary_info.add_side(elem, side, boundary_ids[0]);
254 mesh->set_isnt_prepared();
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
SymFunctionPtr _func_F
function parser object describing the combinatorial geometry
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
ParsedGenerateSideset(const InputParameters ¶meters)
const bool _check_subdomains
whether to check subdomain ids when adding sides or not
std::unique_ptr< MeshBase > & _input
mesh to add the sidesets to
std::string _function
function expression
static InputParameters validParams()
const bool _check_neighbor_subdomains
whether to check neighbor subdomain ids when adding sides or not
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
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.
MeshGenerator for defining a Sideset by a parsed expression and optionally by looking at the subdomai...
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.
void addFParserConstants(SymFunctionPtr &parser, const std::vector< std::string > &constant_names, const std::vector< std::string > &constant_expressions)
add constants (which can be complex expressions) to the parser object
virtual const std::string & name() const
Get the name of the class.
void mooseWarning(Args &&... args) const
Emits a warning prefixed with object name and type.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
const bool _include_only_external_sides
Whether to consider internal sides or not when building the sideset.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
std::unique_ptr< FEBase > _fe_face
bool hasSubdomainName(MeshBase &input_mesh, const SubdomainName &name)
Whether a particular subdomain name exists in the mesh.
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
Gets the boundary IDs with their names.
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 ...
void finalize()
This method finalizes the object, setting names back in the boundary_info object and releasing memory...
static InputParameters validParams()
BoundaryName _sideset_name
name of the new sideset
const bool _check_normal
whether to check normals when adding sides or not
std::vector< subdomain_id_type > _included_neighbor_ids
A list of included neighbor subdomain ids.
const bool _check_boundaries
whether to check boundary ids when adding sides or not
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
static InputParameters validParams()
std::vector< subdomain_id_type > _included_ids
A list of included subdomain ids that the side has to be part of.
registerMooseObject("MooseApp", ParsedGenerateSideset)
Point _normal
A normal vector that (if provided) is compared against side's normals.
void setup(MeshBase &mesh)
This method is used to construct the FE object so we can compute normals of faces.
void setParserFeatureFlags(SymFunctionPtr &)
apply input paramters to internal feature flags of the parser object