16 #include "libmesh/elem.h" 25 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The mesh we want to modify");
27 "The names of the boundaries to create");
29 params.
addParam<std::vector<unsigned int>>(
"nodes",
30 "The nodes you want to be in the nodeset " 31 "(Either this parameter or \"coord\" must be " 33 params.
addParam<std::vector<std::vector<Real>>>(
36 "The nodes with coordinates you want to be in the " 37 "nodeset. Separate multple coords with ';' (Either this parameter or \"nodes\" must be " 40 "tolerance", TOLERANCE,
"The tolerance in which two nodes are considered identical");
41 params.
addParam<
bool>(
"use_closest_node",
false,
"Use the node closest to the coordinate.");
43 "Creates a new node set and a new boundary made with the nodes the user provides.");
53 std::unique_ptr<MeshBase>
56 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
59 std::vector<BoundaryName> boundary_names = getParam<std::vector<BoundaryName>>(
"new_boundary");
60 std::vector<boundary_id_type> boundary_ids =
64 BoundaryInfo & boundary_info =
mesh->get_boundary_info();
68 for (
const auto & node_id :
getParam<std::vector<unsigned int>>(
"nodes"))
71 if (!
mesh->query_node_ptr(node_id))
74 for (
const auto & boundary_id : boundary_ids)
75 boundary_info.add_node(node_id, boundary_id);
79 const auto dim =
mesh->mesh_dimension();
81 std::unique_ptr<libMesh::PointLocatorBase> locator =
mesh->sub_point_locator();
82 locator->enable_out_of_mesh_mode();
84 const auto tolerance = getParam<Real>(
"tolerance");
85 const bool use_closest_node = getParam<bool>(
"use_closest_node");
86 const auto coords = getParam<std::vector<std::vector<Real>>>(
"coord");
87 if (use_closest_node && coords.empty())
88 paramError(
"coord",
"A coordinate should be specified to use 'use_closest_node'");
89 for (
const auto & c : coords)
96 " does not have enough components for a ",
104 " has too many components. Did you maybe forget to separate multiple coordinates " 107 for (
unsigned int j = 0; j < c.size(); ++j)
111 bool on_node =
false;
112 bool found_elem =
false;
113 const Elem * elem = (*locator)(p);
117 for (
unsigned int j = 0; j < elem->n_nodes(); ++j)
119 const Node * node = elem->node_ptr(j);
120 if (p.absolute_fuzzy_equals(*node, tolerance))
122 for (
const auto & boundary_id : boundary_ids)
123 boundary_info.add_node(node, boundary_id);
134 if (!
mesh->is_replicated())
141 if (use_closest_node && !on_node)
149 for (
const auto & node_iter :
as_range(
mesh->local_nodes_begin(),
mesh->local_nodes_end()))
155 dmin_id = node_iter->id();
164 const Node * node =
mesh->query_node_ptr(dmin_id);
166 for (
const auto & boundary_id : boundary_ids)
167 boundary_info.add_node(node, boundary_id);
171 mooseError(
"Unable to locate the following point within the domain, please check its " 178 "\nSet use_closest_node=true if you want to find the closest node.");
181 for (
unsigned int i = 0; i < boundary_ids.size(); ++i)
182 boundary_info.nodeset_name(boundary_ids[i]) = boundary_names[i];
186 mesh->set_isnt_prepared();
void minloc(T &r, unsigned int &min_id) const
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
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.
bool hasBreakMeshByBlockGenerator() const
auto max(const L &left, const R &right)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
uint8_t processor_id_type
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
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.
MooseApp & _app
The MOOSE application this is associated with.
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 ...
static InputParameters validParams()
std::string stringify(const T &t)
conversion to string
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void max(const T &r, T &o, Request &req) const
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
MeshGenerators are objects that can modify or add to an existing mesh.