www.mooseframework.org
SubdomainIDGenerator.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 "SubdomainIDGenerator.h"
11 #include "CastUniquePointer.h"
12 
13 #include "libmesh/elem.h"
14 
16 
19 {
21 
22  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
23  params.addRequiredParam<SubdomainID>("subdomain_id", "New subdomain IDs of all elements");
24  params.addClassDescription("Sets all the elements of the input mesh to a unique subdomain ID.");
25 
26  return params;
27 }
28 
30  : MeshGenerator(parameters),
31  _input(getMesh("input")),
32  _subdomain_id(getParam<SubdomainID>("subdomain_id"))
33 {
34 }
35 
36 std::unique_ptr<MeshBase>
38 {
39  std::unique_ptr<MeshBase> mesh = std::move(_input);
40 
41  for (auto & elem : mesh->element_ptr_range())
42  elem->subdomain_id() = _subdomain_id;
43 
44  mesh->set_isnt_prepared();
45  return dynamic_pointer_cast<MeshBase>(mesh);
46 }
MeshBase & 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.
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...
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
Definition: MeshGenerator.C:23
MeshGenerator for assigning a subdomain ID to all elements.
registerMooseObject("MooseApp", SubdomainIDGenerator)
SubdomainID _subdomain_id
The subdomain ID to assign to every elemennt.
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...
static InputParameters validParams()
std::unique_ptr< MeshBase > & _input
the input mesh, which may be output by another mesh generator
SubdomainIDGenerator(const InputParameters &parameters)
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32