Line data Source code
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 : 10 : #include "BlockToMeshConverterGenerator.h" 11 : #include "CastUniquePointer.h" 12 : #include "libmesh/elem.h" 13 : #include "MooseMeshUtils.h" 14 : 15 : registerMooseObject("MooseApp", BlockToMeshConverterGenerator); 16 : 17 : InputParameters 18 3387 : BlockToMeshConverterGenerator::validParams() 19 : { 20 3387 : InputParameters params = MeshGenerator::validParams(); 21 : 22 6774 : 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 13548 : params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify"); 27 10161 : 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 3387 : return params; 33 0 : } 34 : 35 163 : BlockToMeshConverterGenerator::BlockToMeshConverterGenerator(const InputParameters & parameters) 36 : : MeshGenerator(parameters), 37 163 : _input(getMesh("input")), 38 489 : _target_blocks(getParam<std::vector<SubdomainName>>("target_blocks")) 39 : { 40 163 : } 41 : 42 : std::unique_ptr<MeshBase> 43 163 : BlockToMeshConverterGenerator::generate() 44 : { 45 163 : std::unique_ptr<MeshBase> mesh = std::move(_input); 46 : 47 163 : auto new_mesh = buildMeshBaseObject(); 48 : 49 : try 50 : { 51 163 : MooseMeshUtils::convertBlockToMesh(*mesh, *new_mesh, _target_blocks); 52 : } 53 0 : catch (MooseException & e) 54 : { 55 0 : paramError("target_blocks", e.what()); 56 0 : } 57 : 58 320 : return dynamic_pointer_cast<MeshBase>(new_mesh); 59 160 : }