www.mooseframework.org
MeshCollectionGenerator.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 
11 
12 #include "CastUniquePointer.h"
13 #include "MooseUtils.h"
14 
15 #include "libmesh/replicated_mesh.h"
16 #include "libmesh/unstructured_mesh.h"
17 
19 
20 template <>
23 {
25  params.addClassDescription("Collects multiple meshes into a single (unconnected) mesh.");
26  params.addRequiredParam<std::vector<MeshGeneratorName>>("inputs", "The input MeshGenerators.");
27  return params;
28 }
29 
31  : MeshGenerator(parameters), _input_names(getParam<std::vector<MeshGeneratorName>>("inputs"))
32 {
33  // error check
34  if (_input_names.empty())
35  paramError("input_names", "You need to specify at least one MeshGenerator as an input.");
36 
37  // Grab the input mesh references as pointers
38  for (auto & input_name : _input_names)
39  _meshes.push_back(&getMeshByName(input_name));
40 }
41 
42 std::unique_ptr<MeshBase>
44 {
45  // merge all meshes into the first one
46  auto mesh = dynamic_pointer_cast<UnstructuredMesh>(*_meshes[0]);
47  if (!mesh)
48  paramError("inputs", _input_names[0], " is not a valid unstructured mesh");
49 
50  // Read in all of the other meshes
51  for (MooseIndex(_meshes) i = 1; i < _meshes.size(); ++i)
52  {
53  auto other_mesh = dynamic_cast<UnstructuredMesh *>(_meshes[i]->get());
54  if (!other_mesh)
55  paramError("inputs", _input_names[i], " is not a valid unstructured mesh");
56 
57  dof_id_type node_delta = mesh->max_node_id();
58  dof_id_type elem_delta = mesh->max_elem_id();
59 
60  unique_id_type unique_delta =
61 #ifdef LIBMESH_ENABLE_UNIQUE_ID
62  mesh->parallel_max_unique_id();
63 #else
64  0;
65 #endif
66 
67  // Copy mesh data over from the other mesh
68  mesh->copy_nodes_and_elements(*other_mesh,
69  /*skip_find_neighbors = */ false,
70  elem_delta,
71  node_delta,
72  unique_delta);
73  }
74 
75  return dynamic_pointer_cast<MeshBase>(mesh);
76 }
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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::unique_ptr< MeshBase > & getMeshByName(const MeshGeneratorName &input_mesh_generator_parameter_name)
Takes the name of another MeshGenerator directly.
Definition: MeshGenerator.C:47
registerMooseObject("MooseApp", MeshCollectionGenerator)
std::vector< std::unique_ptr< MeshBase > * > _meshes
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...
InputParameters validParams< MeshCollectionGenerator >()
void paramError(const std::string &param, Args... args)
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseObject.h:108
MeshCollectionGenerator(const InputParameters &parameters)
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
Collects multiple meshes into a single (unconnected) mesh.
InputParameters validParams< MeshGenerator >()
Definition: MeshGenerator.C:16
const std::vector< MeshGeneratorName > & _input_names
The mesh generators to read.
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:30