13 #include "libmesh/replicated_mesh.h" 14 #include "libmesh/string_to_enum.h" 15 #include "libmesh/face_c0polygon.h" 16 #include "libmesh/cell_c0polyhedron.h" 29 params.
addParam<MeshGeneratorName>(
"input",
"Optional input mesh to add the elements to");
33 "The x,y,z positions of the nodes");
34 params.
addParam<std::vector<dof_id_type>>(
"element_connectivity",
35 "List of nodes to use for each element.");
36 params.
addParam<std::vector<std::vector<dof_id_type>>>(
37 "polygon_faces_connectivity",
38 "List of nodes to use for each face of the polygon faces of the polyhedron. Only use this " 39 "parameter for a polyhedron 'elem_type'");
41 "elem_type",
elem_types,
"The type of element from libMesh to generate");
44 params.
addParam<SubdomainName>(
"subdomain_name",
"Subdomain name");
47 params.
addParam<
bool>(
"create_sidesets",
49 "Create separate sidesets for each side. " 50 "The side index is used as the boundary ID for each sideset.");
52 params.
addClassDescription(
"Generates individual elements given a list of nodal positions.");
59 _input(getMesh(
"input", true)),
60 _nodal_positions(getParam<
std::vector<Point>>(
"nodal_positions")),
61 _element_connectivity(
62 isParamValid(
"polygon_faces_connectivity")
66 _elem_type(getParam<
MooseEnum>(
"elem_type"))
69 paramError(
"element_connectivity",
"Must be of size 1 for all element types but polyhedra");
72 "Either 'element_connectivity' or 'polygon_faces_connectivity' must be specified");
78 return Elem::build(Utility::string_to_enum<ElemType>(
type));
81 std::unique_ptr<MeshBase>
84 std::unique_ptr<MeshBase>
mesh = std::move(
_input);
92 std::unique_ptr<Elem> elem;
98 std::vector<Node *> nodes;
108 auto n = elem->n_nodes();
116 std::vector<std::shared_ptr<libMesh::Polygon>>
sides;
117 sides.reserve(n_sides);
123 sides.push_back(side);
127 std::unique_ptr<libMesh::Node> mid_elem_node;
128 elem = std::make_unique<libMesh::C0Polyhedron>(
sides, mid_elem_node);
130 mesh->add_node(std::move(mid_elem_node));
134 elem->subdomain_id() = getParam<SubdomainID>(
"subdomain_id");
136 mesh->subdomain_name(getParam<SubdomainID>(
"subdomain_id")) =
137 getParam<SubdomainName>(
"subdomain_name");
139 mesh->set_mesh_dimension(
std::max((
unsigned int)elem->dim(),
mesh->mesh_dimension()));
141 if (getParam<bool>(
"create_sidesets"))
142 for (
const auto i_side :
make_range(elem->n_sides()))
143 mesh->get_boundary_info().add_side(elem.get(), i_side, i_side);
145 mesh->add_elem(std::move(elem));
147 mesh->unset_is_prepared();
const std::string LIST_GEOM_ELEM
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 ...
std::unique_ptr< Elem > getElemType(const std::string &type)
Creates the base element of the given type.
std::unique_ptr< MeshBase > & _input
Mesh that possibly comes from another generator.
const std::vector< Point > & _nodal_positions
The nodal positions.
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.
const MooseEnum & _elem_type
The type of element to build.
ElementGenerator(const InputParameters ¶meters)
auto max(const L &left, const R &right)
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Generates individual elements given a list of nodal positions.
registerMooseObject("MooseApp", ElementGenerator)
const std::string & type() const
Get the type of this class.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static InputParameters validParams()
static InputParameters validParams()
const std::vector< std::vector< dof_id_type > > _element_connectivity
The connectivity of the elements to the nodes.
IntRange< T > make_range(T beg, T end)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block...
MeshGenerators are objects that can modify or add to an existing mesh.
auto index_range(const T &sizable)