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<BoundaryName>(
"new_nodeset_name",
"The name of the new nodeset");
33 "Function expression describing the geometric constraints " 34 "that the node must meet to be included in the nodeset");
35 params.
addParam<std::vector<std::string>>(
36 "constant_names", {},
"Vector of constants used in the parsed function");
37 params.
addParam<std::vector<std::string>>(
38 "constant_expressions",
40 "Vector of values for the constants in constant_names (can be an FParser expression)");
46 "node satisfies the `expression` expression.");
55 _function(parameters.
get<
std::string>(
"expression"))
57 _nodeset_names.push_back(getParam<BoundaryName>(
"new_nodeset_name"));
60 _func_F = std::make_shared<SymFunction>();
64 getParam<std::vector<std::string>>(
"constant_names"),
65 getParam<std::vector<std::string>>(
"constant_expressions"),
71 std::unique_ptr<MeshBase>
74 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
77 if (!
mesh->is_replicated())
78 mooseError(
"Not implemented for distributed meshes");
81 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
84 const auto & nodeset_map = boundary_info.get_nodeset_map();
87 std::vector<boundary_id_type> nodeset_ids =
89 mooseAssert(nodeset_ids.size() == 1,
"Length of nodeset_ids should be one");
92 for (
const auto curr_node :
as_range(
mesh->active_nodes_begin(),
mesh->active_nodes_end()))
95 const auto & node_nodesets_iters = nodeset_map.equal_range(curr_node);
98 std::vector<BoundaryID> node_nodesets;
99 for (
auto i = node_nodesets_iters.first; i != node_nodesets_iters.second; ++i)
100 node_nodesets.push_back(i->second);
117 for (
const auto nodeset_id : node_nodesets)
118 boundary_info.remove_node(curr_node, nodeset_id);
120 boundary_info.add_node(curr_node, nodeset_ids[0]);
126 mesh->set_isnt_prepared();
SymFunctionPtr _func_F
function parser object describing the combinatorial geometry
GenericReal< is_ad > evaluate(SymFunctionPtr &, const std::string &object_name="")
Evaluate FParser object and check EvalError.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
std::string _function
function expression
ParsedGenerateNodeset(const InputParameters ¶meters)
bool nodeSatisfiesRequirements(const Node *node, const std::vector< BoundaryID > &node_nodesets, const std::vector< dof_id_type > &node_elems, const MeshBase &mesh) const
Determines whether the given node satisfies the user-specified constraints.
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
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.
std::vector< BoundaryName > _nodeset_names
The list of new nodeset names.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
MeshGenerator for defining a nodeset by a parsed expression.
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.
registerMooseObject("MooseApp", ParsedGenerateNodeset)
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
the mesh to add the nodesets to
const bool _replace
Whether or not to remove the old nodesets (all of them, if any) when adding nodesets.
std::vector< GenericReal< is_ad > > _func_params
Array to stage the parameters passed to the functions when calling Eval.
std::unordered_map< dof_id_type, std::vector< dof_id_type > > _node_to_elem_map
A map from nodes (ids) to local elements (ids) which comprise the node.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
void setup(MeshBase &mesh)
This method prepares a few attributes which are commonly needed for nodeset generation such as a map ...
static InputParameters validParams()
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()