https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
11#include "MooseMeshUtils.h"
12#include "MooseEnum.h"
13
14#include "libmesh/elem.h"
15
17
20{
22
23 MooseEnum operation("remove keep", "remove");
24 params.addParam<MooseEnum>("operation",
25 operation,
26 "Whether to remove or keep the listed blocks. If keep, all blocks not "
27 "in the list will be removed.");
28
29 params.addClassDescription("Mesh generator which removes elements from the specified subdomains");
30 params.addParam<std::vector<SubdomainName>>(
31 "block", "The list of blocks to be processed (deleted or kept)");
33 "block_id", "The block to be deleted.", "Use block instead");
34
35 return params;
36}
37
39 : ElementDeletionGeneratorBase(parameters), _operation(getParam<MooseEnum>("operation"))
40{
41 // Handle deprecated parameter
42 if (isParamValid("block_id"))
43 _block_ids.push_back(getParam<SubdomainID>("block_id"));
44 if (!isParamValid("block_id") && !isParamValid("block"))
45 mooseError("Must provide the blocks to be processed in the 'block' parameter");
46 if (isParamValid("block_id") && isParamValid("block"))
47 paramError("block_id", "Cannot use with the parameter 'block'. Please use just 'block'.");
48}
49
50std::unique_ptr<MeshBase>
52{
53 // We're querying subdomain id caches from our input mesh
54 if (!_input->preparation().has_cached_elem_data)
55 _input->cache_elem_data();
56
57 if (isParamValid("block"))
58 // Get the list of block ids from the block names
60 MooseMeshUtils::getSubdomainIDs(*_input, getParam<std::vector<SubdomainName>>("block"));
61
62 // Check that the block ids/names exist in the mesh
63 for (std::size_t i = 0; i < _block_ids.size(); ++i)
65 {
66 if (isParamValid("block"))
67 paramError("block",
68 "The block '",
69 getParam<std::vector<SubdomainName>>("block")[i],
70 "' was not found within the mesh");
71 else
72 paramError("block_id",
73 "The block '",
74 getParam<SubdomainID>("block_id"),
75 "' was not found within the mesh");
76 }
77
79}
80
81bool
83{
84 bool in_list =
85 std::find(_block_ids.begin(), _block_ids.end(), elem->subdomain_id()) != _block_ids.end();
86
87 if ((int)_operation == 0)
88 return in_list;
89 else
90 return !in_list;
91}
registerMooseObject("MooseApp", BlockDeletionGenerator)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MeshGenerator for removing blocks from the mesh.
BlockDeletionGenerator(const InputParameters &parameters)
std::vector< SubdomainID > _block_ids
Ids of the blocks to be removed.
virtual std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
MooseEnum _operation
Whether to remove or keep the specified blocks.
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...
std::unique_ptr< MeshBase > & _input
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
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 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:457
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
bool hasSubdomainID(const MeshBase &input_mesh, const SubdomainID &id)
Whether a particular subdomain ID exists in the mesh.
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.