https://mooseframework.inl.gov
BlockToMeshConverterGenerator.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 #include "CastUniquePointer.h"
12 #include "libmesh/elem.h"
13 #include "MooseMeshUtils.h"
14 
16 
19 {
21 
22  params.addClassDescription(
23  "Converts one or more blocks (subdomains) from a mesh into a stand-alone mesh with a "
24  "single block in it.");
25 
26  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
27  params.addRequiredParam<std::vector<SubdomainName>>(
28  "target_blocks",
29  "The (list of) blocks (or 'subdomains') we wish to have moved to a new mesh (by name, not "
30  "ID)");
31 
32  return params;
33 }
34 
36  : MeshGenerator(parameters),
37  _input(getMesh("input")),
38  _target_blocks(getParam<std::vector<SubdomainName>>("target_blocks"))
39 {
40 }
41 
42 std::unique_ptr<MeshBase>
44 {
45  std::unique_ptr<MeshBase> mesh = std::move(_input);
46 
47  auto new_mesh = buildMeshBaseObject();
48 
49  try
50  {
52  }
53  catch (MooseException & e)
54  {
55  paramError("target_blocks", e.what());
56  }
57 
58  return dynamic_pointer_cast<MeshBase>(new_mesh);
59 }
BlockToMeshConverterGenerator(const InputParameters &parameters)
virtual const char * what() const
Get out the error message.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
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.
std::unique_ptr< MeshBase > & _input
Mesh that comes from another generator.
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...
Creates a new mesh out of one or more subdomains/blocks from another mesh.
const std::vector< SubdomainName > _target_blocks
Blocks to extract to form a mesh.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
Definition: MeshGenerator.C:23
registerMooseObject("MooseApp", BlockToMeshConverterGenerator)
Provides a way for users to bail out of the current solve.
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...
std::unique_ptr< MeshBase > buildMeshBaseObject(unsigned int dim=libMesh::invalid_uint)
Build a MeshBase object whose underlying type will be determined by the Mesh input file block...
void convertBlockToMesh(std::unique_ptr< MeshBase > &source_mesh, std::unique_ptr< MeshBase > &target_mesh, const std::vector< SubdomainName > &target_blocks)
Convert a list of blocks in a given mesh to a standalone new mesh.
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32