Skip to content

Commit

Permalink
Merge pull request #25742 from farscape-project/rm_elem_lists
Browse files Browse the repository at this point in the history
Avoid redundancy and use libMesh::Elem::build() for shorter code
  • Loading branch information
lindsayad authored Oct 13, 2023
2 parents 0177403 + e49e306 commit 3b5aaca
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 129 deletions.
9 changes: 9 additions & 0 deletions framework/include/mesh/MooseMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class BoundingBox;
// Useful typedefs
typedef StoredRange<std::set<Node *>::iterator, Node *> SemiLocalNodeRange;

// List of supported geometrical elements
const std::string LIST_GEOM_ELEM = "EDGE EDGE2 EDGE3 EDGE4 "
"QUAD QUAD4 QUAD8 QUAD9 "
"TRI TRI3 TRI6 "
"HEX HEX8 HEX20 HEX27 "
"TET TET4 TET10 "
"PRISM PRISM6 PRISM15 PRISM18 "
"PYRAMID PYRAMID5 PYRAMID13 PYRAMID14";

/**
* Helper object for holding qp mapping info.
*/
Expand Down
4 changes: 1 addition & 3 deletions framework/src/mesh/GeneratedMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ GeneratedMesh::validParams()
{
InputParameters params = MooseMesh::validParams();

MooseEnum elem_types(
"EDGE EDGE2 EDGE3 EDGE4 QUAD QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX HEX8 HEX20 HEX27 TET4 TET10 "
"PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14"); // no default
MooseEnum elem_types(LIST_GEOM_ELEM); // no default

MooseEnum dims("1=1 2 3");
params.addRequiredParam<MooseEnum>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ DistributedRectilinearMeshGenerator::validParams()
params.addParam<MooseEnum>(
"partition", partition, "Which method (graph linear square) use to partition mesh");

MooseEnum elem_types(
"EDGE EDGE2 EDGE3 EDGE4 QUAD QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX HEX8 HEX20 HEX27 TET4 TET10 "
"PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14"); // no default
MooseEnum elem_types(LIST_GEOM_ELEM); // no default
params.addParam<MooseEnum>("elem_type",
elem_types,
"The type of element from libMesh to "
Expand Down
102 changes: 3 additions & 99 deletions framework/src/meshgenerators/ElementGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "CastUniquePointer.h"

#include "libmesh/replicated_mesh.h"
#include "libmesh/string_to_enum.h"

#include "MooseEnum.h"

Expand Down Expand Up @@ -41,8 +42,7 @@ ElementGenerator::validParams()
{
InputParameters params = MeshGenerator::validParams();

MooseEnum elem_types("EDGE2 EDGE3 EDGE4 QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX8 HEX20 HEX27 TET4 TET10 "
"PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14");
MooseEnum elem_types(LIST_GEOM_ELEM); // no default

params.addParam<MeshGeneratorName>("input", "Optional input mesh to add the elements to");

Expand Down Expand Up @@ -72,103 +72,7 @@ ElementGenerator::ElementGenerator(const InputParameters & parameters)
Elem *
ElementGenerator::getElemType(const std::string & type)
{
if (type == "EDGE2")
{
Elem * elem = new Edge2;
return elem;
}
if (type == "EDGE3")
{
Elem * elem = new Edge3;
return elem;
}
if (type == "EDGE4")
{
Elem * elem = new Edge4;
return elem;
}
if (type == "QUAD4")
{
Elem * elem = new Quad4;
return elem;
}
if (type == "QUAD8")
{
Elem * elem = new Quad8;
return elem;
}
if (type == "QUAD9")
{
Elem * elem = new Quad9;
return elem;
}
if (type == "TRI3")
{
Elem * elem = new Tri3;
return elem;
}
if (type == "TRI6")
{
Elem * elem = new Tri6;
return elem;
}
if (type == "HEX8")
{
Elem * elem = new Hex8;
return elem;
}
if (type == "HEX20")
{
Elem * elem = new Hex20;
return elem;
}
if (type == "HEX27")
{
Elem * elem = new Hex27;
return elem;
}
if (type == "TET4")
{
Elem * elem = new Tet4;
return elem;
}
if (type == "TET10")
{
Elem * elem = new Tet10;
return elem;
}
if (type == "PRISM6")
{
Elem * elem = new Prism6;
return elem;
}
if (type == "PRISM15")
{
Elem * elem = new Prism15;
return elem;
}
if (type == "PRISM18")
{
Elem * elem = new Prism18;
return elem;
}
if (type == "PYRAMID5")
{
Elem * elem = new Pyramid5;
return elem;
}
if (type == "PYRAMID13")
{
Elem * elem = new Pyramid13;
return elem;
}
if (type == "PYRAMID14")
{
Elem * elem = new Pyramid14;
return elem;
}

mooseError("This element type is not available.");
return Elem::build(Utility::string_to_enum<ElemType>(type)).release();
}

std::unique_ptr<MeshBase>
Expand Down
4 changes: 1 addition & 3 deletions framework/src/meshgenerators/GeneratedMeshGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ GeneratedMeshGenerator::validParams()
{
InputParameters params = MeshGenerator::validParams();

MooseEnum elem_types(
"EDGE EDGE2 EDGE3 EDGE4 QUAD QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX HEX8 HEX20 HEX27 TET4 TET10 "
"PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14"); // no default
MooseEnum elem_types(LIST_GEOM_ELEM); // no default

MooseEnum dims("1=1 2 3");
params.addRequiredParam<MooseEnum>("dim", dims, "The dimension of the mesh to be generated");
Expand Down
26 changes: 5 additions & 21 deletions modules/heat_conduction/src/meshgenerators/PatchSidesetGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -381,25 +381,9 @@ PatchSidesetGenerator::sidesetNameHelper(const std::string & base_name) const
Elem *
PatchSidesetGenerator::boundaryElementHelper(MeshBase & mesh, libMesh::ElemType type) const
{
switch (type)
{
case 0:
return mesh.add_elem(new libMesh::Edge2);
case 1:
return mesh.add_elem(new libMesh::Edge3);
case 2:
return mesh.add_elem(new libMesh::Edge4);
case 3:
return mesh.add_elem(new libMesh::Tri3);
case 4:
return mesh.add_elem(new libMesh::Tri6);
case 5:
return mesh.add_elem(new libMesh::Quad4);
case 6:
return mesh.add_elem(new libMesh::Quad8);
case 7:
return mesh.add_elem(new libMesh::Quad9);
default:
mooseError("Unsupported element type (libMesh elem_type enum): ", type);
}
std::unique_ptr<Elem> elem = libMesh::Elem::build(type);
if (elem->dim() < 3)
return mesh.add_elem(std::move(elem));

mooseError("Unsupported element type (libMesh elem_type enum): ", type);
}

0 comments on commit 3b5aaca

Please sign in to comment.