https://mooseframework.inl.gov
BlockDeletionGenerator.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 
10 #include "BlockDeletionGenerator.h"
11 #include "MooseMeshUtils.h"
12 
13 #include "libmesh/elem.h"
14 
16 
19 {
21 
22  params.addClassDescription("Mesh generator which removes elements from the specified subdomains");
23  params.addParam<std::vector<SubdomainName>>("block", "The list of blocks to be deleted");
25  "block_id", "The block to be deleted.", "Use block instead");
26 
27  return params;
28 }
29 
31  : ElementDeletionGeneratorBase(parameters)
32 {
33  // Handle deprecated parameter
34  if (isParamValid("block_id"))
35  _block_ids.push_back(getParam<SubdomainID>("block_id"));
36  if (!isParamValid("block_id") && !isParamValid("block"))
37  mooseError("Must provide the blocks to be deleted in the 'block' parameter");
38  if (isParamValid("block_id") && isParamValid("block"))
39  paramError("block_id", "Cannot use with the parameter 'block'. Please use just 'block'.");
40 }
41 
42 std::unique_ptr<MeshBase>
44 {
45  if (isParamValid("block"))
46  // Get the list of block ids from the block names
47  _block_ids =
48  MooseMeshUtils::getSubdomainIDs(*_input, getParam<std::vector<SubdomainName>>("block"));
49 
50  // Check that the block ids/names exist in the mesh
51  for (std::size_t i = 0; i < _block_ids.size(); ++i)
53  {
54  if (isParamValid("block"))
55  paramError("block",
56  "The block '",
57  getParam<std::vector<SubdomainName>>("block")[i],
58  "' was not found within the mesh");
59  else
60  paramError("block_id",
61  "The block '",
62  getParam<SubdomainID>("block_id"),
63  "' was not found within the mesh");
64  }
65 
67 }
68 
69 bool
71 {
72  return std::find(_block_ids.begin(), _block_ids.end(), elem->subdomain_id()) != _block_ids.end();
73 }
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_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
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:384
static InputParameters validParams()
virtual bool shouldDelete(const Elem *elem) override
Method that returns a Boolean indicating whether an element should be removed from the mesh...
This class deletes elements from the mesh data structure after it has been generated or read but befo...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< subdomain_id_type > getSubdomainIDs(const libMesh::MeshBase &mesh, const std::vector< SubdomainName > &subdomain_name)
Get the associated subdomainIDs for the subdomain names that are passed in.
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.
std::unique_ptr< MeshBase > & _input
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::vector< SubdomainID > _block_ids
Ids of the blocks to be removed.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:195
registerMooseObject("MooseApp", BlockDeletionGenerator)
BlockDeletionGenerator(const InputParameters &parameters)
MeshGenerator for removing blocks from the mesh.