https://mooseframework.inl.gov
ExtraElementIDCopyGenerator.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 "libmesh/elem.h"
13 
15 
18 {
20  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
21  params.addRequiredParam<std::string>("source_extra_element_id",
22  "The extra element ID to be copied");
23  params.addRequiredParam<std::vector<std::string>>("target_extra_element_ids",
24  "The target extra element IDs");
25  params.addClassDescription("Copy an extra element ID to other extra element IDs.");
26  return params;
27 }
28 
30  : MeshGenerator(params), _input(getMesh("input"))
31 {
32 }
33 
34 std::unique_ptr<MeshBase>
36 {
37  std::unique_ptr<MeshBase> mesh = std::move(_input);
38 
39  auto src_id_name = getParam<std::string>("source_extra_element_id");
40  bool copy_subdomain_id = (src_id_name == "subdomain_id");
41  bool copy_element_id = (src_id_name == "element_id");
42  unsigned int src_id = 0;
43  if (!copy_subdomain_id && !copy_element_id)
44  {
45  if (!mesh->has_elem_integer(src_id_name))
46  mooseError("The source element ID does not exist on the input mesh");
47  src_id = mesh->get_elem_integer_index(src_id_name);
48  }
49 
50  auto target_id_names = getParam<std::vector<std::string>>("target_extra_element_ids");
51 
52  std::vector<unsigned int> target_ids;
53  for (auto & name : target_id_names)
54  {
55  if (!mesh->has_elem_integer(name))
56  mesh->add_elem_integer(name);
57 
58  target_ids.push_back(mesh->get_elem_integer_index(name));
59  }
60 
61  for (auto & elem : mesh->element_ptr_range())
62  {
63  dof_id_type id;
64  if (copy_subdomain_id)
65  id = elem->subdomain_id();
66  else if (copy_element_id)
67  id = elem->id();
68  else
69  id = elem->get_extra_integer(src_id);
70 
71  for (auto & target_id : target_ids)
72  elem->set_extra_integer(target_id, id);
73  }
74 
75  return mesh;
76 }
static InputParameters validParams()
registerMooseObject("ReactorApp", ExtraElementIDCopyGenerator)
T & getMesh(MooseMesh &mesh)
function to cast mesh
Definition: SCM.h:35
MeshBase & mesh
std::unique_ptr< MeshBase > generate() override
std::unique_ptr< MeshBase > & _input
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
ExtraElementIDCopyGenerator(const InputParameters &params)
static InputParameters validParams()
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
uint8_t dof_id_type