www.mooseframework.org
ElementGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "ElementGenerator.h"
11 #include "CastUniquePointer.h"
12 
13 #include "libmesh/replicated_mesh.h"
14 
15 #include "MooseEnum.h"
16 
17 #include "libmesh/edge_edge2.h"
18 #include "libmesh/edge_edge3.h"
19 #include "libmesh/edge_edge4.h"
20 #include "libmesh/face_quad4.h"
21 #include "libmesh/face_quad8.h"
22 #include "libmesh/face_quad9.h"
23 #include "libmesh/face_tri3.h"
24 #include "libmesh/face_tri6.h"
25 #include "libmesh/cell_hex8.h"
26 #include "libmesh/cell_hex20.h"
27 #include "libmesh/cell_hex27.h"
28 #include "libmesh/cell_tet4.h"
29 #include "libmesh/cell_tet10.h"
30 #include "libmesh/cell_prism6.h"
31 #include "libmesh/cell_prism15.h"
32 #include "libmesh/cell_prism18.h"
33 #include "libmesh/cell_pyramid5.h"
34 #include "libmesh/cell_pyramid13.h"
35 #include "libmesh/cell_pyramid14.h"
36 
38 
40 
43 {
45 
46  MooseEnum elem_types("EDGE2 EDGE3 EDGE4 QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX8 HEX20 HEX27 TET4 TET10 "
47  "PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14");
48 
49  params.addParam<MeshGeneratorName>("input", "Optional input mesh to add the elements to");
50 
51  params.addRequiredParam<std::vector<Point>>("nodal_positions",
52  "The x,y,z positions of the nodes");
53 
54  params.addRequiredParam<std::vector<dof_id_type>>("element_connectivity",
55  "List of nodes to use for each element");
56 
57  params.addParam<MooseEnum>("elem_type",
58  elem_types,
59  "The type of element from libMesh to "
60  "generate");
61 
62  return params;
63 }
64 
66  : MeshGenerator(parameters),
67  _input(getMesh("input")),
68  _nodal_positions(getParam<std::vector<Point>>("nodal_positions")),
69  _element_connectivity(getParam<std::vector<dof_id_type>>("element_connectivity")),
70  _elem_type(getParam<MooseEnum>("elem_type"))
71 {
72 }
73 
74 Elem *
75 ElementGenerator::getElemType(const std::string & type)
76 {
77  if (type == "EDGE2")
78  {
79  Elem * elem = new Edge2;
80  return elem;
81  }
82  if (type == "EDGE3")
83  {
84  Elem * elem = new Edge3;
85  return elem;
86  }
87  if (type == "EDGE4")
88  {
89  Elem * elem = new Edge4;
90  return elem;
91  }
92  if (type == "QUAD4")
93  {
94  Elem * elem = new Quad4;
95  return elem;
96  }
97  if (type == "QUAD8")
98  {
99  Elem * elem = new Quad8;
100  return elem;
101  }
102  if (type == "QUAD9")
103  {
104  Elem * elem = new Quad9;
105  return elem;
106  }
107  if (type == "TRI3")
108  {
109  Elem * elem = new Tri3;
110  return elem;
111  }
112  if (type == "TRI6")
113  {
114  Elem * elem = new Tri6;
115  return elem;
116  }
117  if (type == "HEX8")
118  {
119  Elem * elem = new Hex8;
120  return elem;
121  }
122  if (type == "HEX20")
123  {
124  Elem * elem = new Hex20;
125  return elem;
126  }
127  if (type == "HEX27")
128  {
129  Elem * elem = new Hex27;
130  return elem;
131  }
132  if (type == "TET4")
133  {
134  Elem * elem = new Tet4;
135  return elem;
136  }
137  if (type == "TET10")
138  {
139  Elem * elem = new Tet10;
140  return elem;
141  }
142  if (type == "PRISM6")
143  {
144  Elem * elem = new Prism6;
145  return elem;
146  }
147  if (type == "PRISM15")
148  {
149  Elem * elem = new Prism15;
150  return elem;
151  }
152  if (type == "PRISM18")
153  {
154  Elem * elem = new Prism18;
155  return elem;
156  }
157  if (type == "PYRAMID5")
158  {
159  Elem * elem = new Pyramid5;
160  return elem;
161  }
162  if (type == "PYRAMID13")
163  {
164  Elem * elem = new Pyramid13;
165  return elem;
166  }
167  if (type == "PYRAMID14")
168  {
169  Elem * elem = new Pyramid14;
170  return elem;
171  }
172 
173  mooseError("This element type is not available.");
174 }
175 
176 std::unique_ptr<MeshBase>
178 {
179  std::unique_ptr<MeshBase> mesh = std::move(_input);
180 
181  // If there was no input mesh then let's just make a new one
182  if (!mesh)
183  mesh = _mesh->buildMeshBaseObject();
184 
185  MooseEnum elem_type_enum = getParam<MooseEnum>("elem_type");
186  auto elem = getElemType(elem_type_enum);
187 
188  mesh->set_mesh_dimension(std::max((unsigned int)elem->dim(), mesh->mesh_dimension()));
189 
190  std::vector<Node *> nodes;
191 
192  nodes.reserve(_nodal_positions.size());
193 
194  // Add all the nodes
195  for (auto & point : _nodal_positions)
196  nodes.push_back(mesh->add_point(point));
197 
198  mesh->add_elem(elem);
199 
200  auto n = elem->n_nodes();
201 
202  for (dof_id_type i = 0; i < _element_connectivity.size(); i += n)
203  {
204  for (unsigned int j = 0; j < n; j++)
205  {
206  elem->set_node(j) = nodes[_element_connectivity[j + i]];
207  }
208  elem->subdomain_id() = 0;
209  }
210 
211  return dynamic_pointer_cast<MeshBase>(mesh);
212 }
ElementGenerator::ElementGenerator
ElementGenerator(const InputParameters &parameters)
Definition: ElementGenerator.C:65
type
MatType type
Definition: PetscDMMoose.C:1477
ElementGenerator::validParams
static InputParameters validParams()
Definition: ElementGenerator.C:42
MooseObject::mooseError
void mooseError(Args &&... args) const
Definition: MooseObject.h:141
MooseObject::type
const std::string & type() const
Get the type of this object.
Definition: MooseObject.h:63
MeshGenerator
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
MooseEnum
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
ElementGenerator.h
InputParameters::addParam
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object.
Definition: InputParameters.h:1198
defineLegacyParams
defineLegacyParams(ElementGenerator)
MeshGenerator::_mesh
std::shared_ptr< MooseMesh > & _mesh
References to the mesh and displaced mesh (currently in the ActionWarehouse)
Definition: MeshGenerator.h:87
registerMooseObject
registerMooseObject("MooseApp", ElementGenerator)
InputParameters
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Definition: InputParameters.h:53
ElementGenerator::getElemType
Elem * getElemType(const std::string &type)
Definition: ElementGenerator.C:75
ElementGenerator
Generates individual elements given a list of nodal positions.
Definition: ElementGenerator.h:23
ElementGenerator::_nodal_positions
const std::vector< Point > & _nodal_positions
The nodal positions.
Definition: ElementGenerator.h:39
MooseEnum.h
std
Definition: TheWarehouse.h:80
MeshGenerator::validParams
static InputParameters validParams()
Constructor.
Definition: MeshGenerator.C:17
ElementGenerator::_element_connectivity
const std::vector< dof_id_type > & _element_connectivity
The connectivity of the elements to the nodes.
Definition: ElementGenerator.h:42
CastUniquePointer.h
ElementGenerator::_input
std::unique_ptr< MeshBase > & _input
Mesh that possibly comes from another generator.
Definition: ElementGenerator.h:36
ElementGenerator::generate
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
Definition: ElementGenerator.C:177
InputParameters::addRequiredParam
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
Definition: InputParameters.h:1176
n
PetscInt n
Definition: PetscDMMoose.C:1504