Skip to content

Commit

Permalink
Add multi block deletion to BlockDeletionGenerator idaholab#17052
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud authored and aeslaughter committed Jun 2, 2021
1 parent eed7c80 commit e190218
Show file tree
Hide file tree
Showing 43 changed files with 258 additions and 65 deletions.
8 changes: 4 additions & 4 deletions framework/include/meshgenerators/BlockDeletionGenerator.h
Expand Up @@ -18,7 +18,7 @@ template <>
InputParameters validParams<BlockDeletionGenerator>();

/**
* MeshGenerator for
* MeshGenerator for removing blocks from the mesh
*/
class BlockDeletionGenerator : public ElementDeletionGeneratorBase
{
Expand All @@ -28,10 +28,10 @@ class BlockDeletionGenerator : public ElementDeletionGeneratorBase
BlockDeletionGenerator(const InputParameters & parameters);

protected:
virtual std::unique_ptr<MeshBase> generate() override;
virtual bool shouldDelete(const Elem * elem) override;

private:
///Defines the block to be removed
const SubdomainID _block_id;
/// Ids of the blocks to be removed
std::vector<SubdomainID> _block_ids;
};

5 changes: 4 additions & 1 deletion framework/include/meshgenerators/PatternedMeshGenerator.h
Expand Up @@ -44,7 +44,10 @@ class PatternedMeshGenerator : public MeshGenerator
/// The pattern, starting with the upper left corner
const std::vector<std::vector<unsigned int>> & _pattern;

/// Holds the pointers to the meshes
/// Holds pointers to the meshes before they are generated
std::vector<std::unique_ptr<MeshBase> *> _mesh_ptrs;

/// Holds the pointers to the input generated meshes
std::vector<std::unique_ptr<ReplicatedMesh>> _meshes;

/// Holds a mesh for each row, these will be stitched together in the end
Expand Down
49 changes: 44 additions & 5 deletions framework/src/meshgenerators/BlockDeletionGenerator.C
Expand Up @@ -8,6 +8,7 @@
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "BlockDeletionGenerator.h"
#include "MooseMeshUtils.h"

#include "libmesh/elem.h"

Expand All @@ -20,20 +21,58 @@ BlockDeletionGenerator::validParams()
{
InputParameters params = ElementDeletionGeneratorBase::validParams();

params.addClassDescription(
"Mesh generator which removes elements with the specified subdomain ID");
params.addRequiredParam<SubdomainID>("block_id", "The block to be deleted");
params.addClassDescription("Mesh generator which removes elements from the specified subdomains");
params.addParam<std::vector<SubdomainName>>("block", "The list of blocks to be deleted");
params.addDeprecatedParam<SubdomainID>(
"block_id", "The block to be deleted.", "Use block instead");

return params;
}

BlockDeletionGenerator::BlockDeletionGenerator(const InputParameters & parameters)
: ElementDeletionGeneratorBase(parameters), _block_id(getParam<SubdomainID>("block_id"))
: ElementDeletionGeneratorBase(parameters)
{
// Handle deprecated parameter
if (isParamValid("block_id"))
_block_ids.push_back(getParam<SubdomainID>("block_id"));
if (!isParamValid("block_id") && !isParamValid("block"))
mooseError("Must provide the blocks to be deleted in the 'block' parameter");
if (isParamValid("block_id") && isParamValid("block"))
paramError("block_id", "Cannot use with the parameter 'block'. Please use just 'block'.");
}

std::unique_ptr<MeshBase>
BlockDeletionGenerator::generate()
{
if (isParamValid("block"))
// Get the list of block ids from the block names
_block_ids =
MooseMeshUtils::getSubdomainIDs(*_input, getParam<std::vector<SubdomainName>>("block"));

// Check that the block ids/names exist in the mesh
std::set<SubdomainID> mesh_blocks;
_input->subdomain_ids(mesh_blocks);

for (std::size_t i = 0; i < _block_ids.size(); ++i)
if (_block_ids[i] == Moose::INVALID_BLOCK_ID || !mesh_blocks.count(_block_ids[i]))
{
if (isParamValid("block"))
paramError("block",
"The block '",
getParam<std::vector<SubdomainName>>("block")[i],
"' was not found within the mesh");
else
paramError("block_id",
"The block '",
getParam<SubdomainID>("block_id"),
"' was not found within the mesh");
}

return ElementDeletionGeneratorBase::generate();
}

bool
BlockDeletionGenerator::shouldDelete(const Elem * elem)
{
return elem->subdomain_id() == _block_id;
return std::find(_block_ids.begin(), _block_ids.end(), elem->subdomain_id()) != _block_ids.end();
}
14 changes: 9 additions & 5 deletions framework/src/meshgenerators/PatternedMeshGenerator.C
Expand Up @@ -70,13 +70,21 @@ PatternedMeshGenerator::PatternedMeshGenerator(const InputParameters & parameter
" is larger than the the maximum possible index, which is determined by the "
"number of MeshGenerators provided in inputs");

_mesh_ptrs.reserve(_input_names.size());
for (auto & input_name : _input_names)
_mesh_ptrs.push_back(&getMeshByName(input_name));
}

std::unique_ptr<MeshBase>
PatternedMeshGenerator::generate()
{
// Reserve spaces for all the meshes
_meshes.reserve(_input_names.size());

// Read in all of the meshes
for (MooseIndex(_input_names) i = 0; i < _input_names.size(); ++i)
{
std::unique_ptr<ReplicatedMesh> mesh = dynamic_pointer_cast<ReplicatedMesh>(getMeshByName(_input_names[i]));
std::unique_ptr<ReplicatedMesh> mesh = dynamic_pointer_cast<ReplicatedMesh>(*_mesh_ptrs[i]);
if (!mesh)
paramError("inputs",
"The input mesh '",
Expand All @@ -87,11 +95,7 @@ PatternedMeshGenerator::PatternedMeshGenerator(const InputParameters & parameter
"Try running without distributed mesh.");
_meshes.push_back(std::move(mesh));
}
}

std::unique_ptr<MeshBase>
PatternedMeshGenerator::generate()
{
// Data structure that holds each row
_row_meshes.resize(_pattern.size());

Expand Down
Expand Up @@ -15,7 +15,7 @@
[ring]
type = BlockDeletionGenerator
input = disk
block_id = 1
block = 1
new_boundary = 'inner'
[]
[cylinder]
Expand Down
Expand Up @@ -22,12 +22,12 @@ offset = 1e-2
[./delete_3]
type = BlockDeletionGenerator
input = original_file_mesh
block_id = 3
block = 3
[../]
[./revised_file_mesh]
type = BlockDeletionGenerator
input = delete_3
block_id = 4
block = 4
[../]
[]

Expand Down
Expand Up @@ -23,7 +23,7 @@

[./block_deleter]
type = BlockDeletionGenerator
block_id = 2
block = 2
input = add_iss_1
[../]
[]
Expand Down
Expand Up @@ -19,7 +19,7 @@

[./remove_1]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = cartesian
[../]

Expand Down
Expand Up @@ -111,7 +111,7 @@
[]
[hole]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = roof
[]
[]
Expand Down
Expand Up @@ -113,7 +113,7 @@
[]
[hole]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = roof
[]
[]
Expand Down
Expand Up @@ -115,7 +115,7 @@
[]
[hole]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = roof
[]
[]
Expand Down
Expand Up @@ -113,7 +113,7 @@
[]
[hole]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = roof
[]
[]
Expand Down
Expand Up @@ -54,7 +54,7 @@
[]
[remove_block]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = block_to_remove_ymax
[]
[]
Expand Down
Expand Up @@ -54,7 +54,7 @@
[]
[remove_block]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = block_to_remove_ymax
[]
[]
Expand Down
Expand Up @@ -54,7 +54,7 @@
[]
[remove_block]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = block_to_remove_ymax
[]
[]
Expand Down
Expand Up @@ -54,7 +54,7 @@
[]
[remove_block]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = block_to_remove_ymax
[]
[]
Expand Down
Expand Up @@ -54,7 +54,7 @@
[]
[remove_block]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = block_to_remove_ymax
[]
[]
Expand Down
Expand Up @@ -21,7 +21,7 @@
[ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox
block_id = 1
block = 1
[]
[]

Expand Down
Expand Up @@ -42,7 +42,7 @@
[ed0]
type = BlockDeletionGenerator
input = new_block_number
block_id = 3
block = 3
[]
[]

Expand Down
Expand Up @@ -21,7 +21,7 @@
[delete]
type = BlockDeletionGenerator
input = mark
block_id = 1
block = 1
new_boundary = cut_surface
[]
[]
Expand Down
Expand Up @@ -23,7 +23,7 @@
[]
[ed0]
type = BlockDeletionGenerator
block_id = 1
block = 1
input = SubdomainBoundingBox
[]
[]
Expand Down
Expand Up @@ -21,7 +21,7 @@
[ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox
block_id = 1
block = 1
[]
[]

Expand Down
3 changes: 1 addition & 2 deletions test/tests/mesh_modifiers/block_deleter/BlockDeleterTest4.i
Expand Up @@ -24,8 +24,7 @@
[ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox

block_id = 1
block = 1
[]
[]

Expand Down
Expand Up @@ -38,7 +38,7 @@
[ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox3
block_id = 1
block = 1
[]
[]

Expand Down
Expand Up @@ -28,7 +28,7 @@
[ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox2
block_id = 1
block = 1
[]
[]

Expand Down
Expand Up @@ -21,7 +21,7 @@
[ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox1
block_id = 1
block = 1
[]
[]

Expand Down
Expand Up @@ -21,7 +21,7 @@
[./ed0]
type = BlockDeletionGenerator
input = SubdomainBoundingBox
block_id = 1
block = 1
[../]

[]
Expand Down
Expand Up @@ -40,7 +40,7 @@
[../]
[./ed0]
type = BlockDeletionGenerator
block_id = 3
block = 3
input = 'new_block_number'
[../]
[]
Expand Down

0 comments on commit e190218

Please sign in to comment.