www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
BlockRestrictable Class Reference

An interface that restricts an object to subdomains via the 'blocks' input parameter. More...

#include <BlockRestrictable.h>

Inheritance diagram for BlockRestrictable:
[legend]

Public Member Functions

 BlockRestrictable (const MooseObject *moose_object, bool initialize=true)
 Class constructor Populates the 'block' input parameters, see the general class documentation for details. More...
 
 BlockRestrictable (const MooseObject *moose_object, const std::set< BoundaryID > &boundary_ids)
 Class constructor Populates the 'block' input parameters when an object is also boundary restricted, see the general class documentation for details. More...
 
virtual ~BlockRestrictable ()
 Destructor: does nothing but needs to be marked as virtual since this class defines virtual functions. More...
 
const std::vector< SubdomainName > & blocks () const
 Return the block names for this object. More...
 
unsigned int numBlocks () const
 Return the number of blocks for this object. More...
 
virtual const std::set< SubdomainID > & blockIDs () const
 Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids. More...
 
unsigned int blocksMaxDimension () const
 Return the largest mesh dimension of the elements in the blocks for this object. More...
 
bool hasBlocks (const SubdomainName &name) const
 Test if the supplied block name is valid for this object. More...
 
bool hasBlocks (const std::vector< SubdomainName > &names) const
 Test if the supplied vector of block names are valid for this object. More...
 
bool hasBlocks (SubdomainID id) const
 Test if the supplied block ids are valid for this object. More...
 
bool hasBlocks (const std::vector< SubdomainID > &ids) const
 Test if the supplied vector block ids are valid for this object. More...
 
bool hasBlocks (const std::set< SubdomainID > &ids) const
 Test if the supplied set of block ids are valid for this object. More...
 
bool isBlockSubset (const std::set< SubdomainID > &ids) const
 Test if the class block ids are a subset of the supplied objects. More...
 
bool isBlockSubset (const std::vector< SubdomainID > &ids) const
 Test if the class block ids are a subset of the supplied objects. More...
 
template<typename T , bool is_ad = false>
bool hasBlockMaterialProperty (const std::string &prop_name)
 Check if a material property is valid for all blocks of this object. More...
 
const std::set< SubdomainID > & meshBlockIDs () const
 Return all of the SubdomainIDs for the mesh. More...
 
virtual bool blockRestricted () const
 Returns true if this object has been restricted to a block. More...
 
virtual void checkVariable (const MooseVariableFieldBase &variable) const
 Helper for checking that the ids for this object are in agreement with the variables on the supplied variable. More...
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

virtual bool hasBlockMaterialPropertyHelper (const std::string &prop_name)
 A helper method to allow the Material object to specialize the behavior of hasBlockMaterialProperty. More...
 
void initializeBlockRestrictable (const MooseObject *moose_object)
 An initialization routine needed for dual constructors. More...
 
Moose::CoordinateSystemType getBlockCoordSystem ()
 Check if the blocks this object operates on all have the same coordinate system, and if so return it. More...
 

Protected Attributes

const MaterialData_blk_material_data
 Pointer to the MaterialData class for this object. More...
 

Private Attributes

std::set< SubdomainID_blk_ids
 Set of block ids supplied by the user via the input file (for error checking) More...
 
std::vector< SubdomainID_vec_ids
 Vector of block ids supplied by the user via the input file (for error reporting) More...
 
std::vector< SubdomainName > _blocks
 Vector the block names supplied by the user via the input file. More...
 
const bool _blk_dual_restrictable
 Flag for allowing dual restriction. More...
 
FEProblemBase_blk_feproblem
 Pointer to FEProblemBase. More...
 
MooseMesh_blk_mesh
 Pointer to Mesh. More...
 
const std::set< BoundaryID_empty_boundary_ids
 An empty set for referencing when boundary_ids is not included. More...
 
const std::set< BoundaryID > & _boundary_ids
 Reference to the boundary_ids, defaults to an empty set if not provided. More...
 
THREAD_ID _blk_tid
 Thread id for this object. More...
 
const std::string & _blk_name
 Name of the object. More...
 
unsigned int _blk_dim
 Largest mesh dimension of the elements in the blocks for this object. More...
 

Detailed Description

An interface that restricts an object to subdomains via the 'blocks' input parameter.

This class adds the 'blocks' input parameter and checks that it is populated, if it is not populated it will be populated with all valid block ids via two methods:

  1. If a 'variable' parameter is present in the input parameters then by default the 'block' input is set to all blocks associated with the variable.
  2. If no 'variable' parameter is present then it utilizes all available blocks for the associated mesh.

When using with an object with a 'variable' parameter (e.g., Kernel), the following must also exist within the input parameters for the class to operate correctly

In the general case (i.e., no 'variable') either one of the following must also exist within the input parameters for proper operation of the class:

When creating a new object, generally, this class should be inherited following MooseObject. Also, the BlockRestricted::validParams() must be added to any other parameters for the the class being created, since this is where the 'blocks' input parameter is created.

See also
Kernel
SideSetsAroundSubdomain

Definition at line 57 of file BlockRestrictable.h.

Constructor & Destructor Documentation

◆ BlockRestrictable() [1/2]

BlockRestrictable::BlockRestrictable ( const MooseObject moose_object,
bool  initialize = true 
)

Class constructor Populates the 'block' input parameters, see the general class documentation for details.

Parameters
parametersThe input parameters (see the detailed help for additional information)
initializeDisable initialization, MooseVariableBase was converted to a MooseObject, this flag allows it to be constructed as if it wasn't to maintain backward compatibility, this will be removed in the fugure. TODO:MooseVariableToMooseObject (see #10601)

Definition at line 40 of file BlockRestrictable.C.

41  : _blk_dual_restrictable(moose_object->getParam<bool>("_dual_restrictable")),
42  _blk_feproblem(moose_object->isParamValid("_fe_problem_base")
43  ? moose_object->getParam<FEProblemBase *>("_fe_problem_base")
44  : NULL),
45  _blk_mesh(moose_object->isParamValid("_mesh") ? moose_object->getParam<MooseMesh *>("_mesh")
46  : NULL),
48  _blk_tid(moose_object->isParamValid("_tid") ? moose_object->getParam<THREAD_ID>("_tid") : 0),
49  _blk_name(moose_object->getParam<std::string>("_object_name")),
51 {
52  if (initialize)
53  initializeBlockRestrictable(moose_object);
54 }
unsigned int _blk_dim
Largest mesh dimension of the elements in the blocks for this object.
const bool _blk_dual_restrictable
Flag for allowing dual restriction.
const unsigned int invalid_uint
FEProblemBase * _blk_feproblem
Pointer to FEProblemBase.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
void initializeBlockRestrictable(const MooseObject *moose_object)
An initialization routine needed for dual constructors.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
THREAD_ID _blk_tid
Thread id for this object.
const std::set< BoundaryID > _empty_boundary_ids
An empty set for referencing when boundary_ids is not included.
const std::set< BoundaryID > & _boundary_ids
Reference to the boundary_ids, defaults to an empty set if not provided.
const std::string & _blk_name
Name of the object.
MooseMesh * _blk_mesh
Pointer to Mesh.
unsigned int THREAD_ID
Definition: MooseTypes.h:198

◆ BlockRestrictable() [2/2]

BlockRestrictable::BlockRestrictable ( const MooseObject moose_object,
const std::set< BoundaryID > &  boundary_ids 
)

Class constructor Populates the 'block' input parameters when an object is also boundary restricted, see the general class documentation for details.

Parameters
parametersThe input parameters (see the detailed help for additional information)
boundary_idsThe boundary ids that the object is restricted to

Definition at line 57 of file BlockRestrictable.C.

59  : _blk_dual_restrictable(moose_object->getParam<bool>("_dual_restrictable")),
60  _blk_feproblem(moose_object->isParamValid("_fe_problem_base")
61  ? moose_object->getParam<FEProblemBase *>("_fe_problem_base")
62  : NULL),
63  _blk_mesh(moose_object->isParamValid("_mesh") ? moose_object->getParam<MooseMesh *>("_mesh")
64  : NULL),
65  _boundary_ids(boundary_ids),
66  _blk_tid(moose_object->isParamValid("_tid") ? moose_object->getParam<THREAD_ID>("_tid") : 0),
67  _blk_name(moose_object->getParam<std::string>("_object_name")),
69 {
70  initializeBlockRestrictable(moose_object);
71 }
unsigned int _blk_dim
Largest mesh dimension of the elements in the blocks for this object.
const bool _blk_dual_restrictable
Flag for allowing dual restriction.
const unsigned int invalid_uint
FEProblemBase * _blk_feproblem
Pointer to FEProblemBase.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
void initializeBlockRestrictable(const MooseObject *moose_object)
An initialization routine needed for dual constructors.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
Definition: MooseMesh.h:88
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
THREAD_ID _blk_tid
Thread id for this object.
const std::set< BoundaryID > & _boundary_ids
Reference to the boundary_ids, defaults to an empty set if not provided.
const std::string & _blk_name
Name of the object.
MooseMesh * _blk_mesh
Pointer to Mesh.
unsigned int THREAD_ID
Definition: MooseTypes.h:198

◆ ~BlockRestrictable()

virtual BlockRestrictable::~BlockRestrictable ( )
inlinevirtual

Destructor: does nothing but needs to be marked as virtual since this class defines virtual functions.

Definition at line 86 of file BlockRestrictable.h.

86 {}

Member Function Documentation

◆ blockIDs()

const std::set< SubdomainID > & BlockRestrictable::blockIDs ( ) const
virtual

Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.

Returns
a set of SubdomainIDs that are valid for this object

Definition at line 190 of file BlockRestrictable.C.

Referenced by FunctorMaterial::addFunctorProperty(), DiracKernelBase::addPoint(), DiracKernelBase::addPointWithValidId(), NodalPatchRecoveryAuxBase::blockRestrictElements(), MooseMesh::cacheFaceInfoVariableOwnership(), ElementGroupCentroidPositions::ElementGroupCentroidPositions(), ExtraIDIntegralVectorPostprocessor::ExtraIDIntegralVectorPostprocessor(), getBlockCoordSystem(), MaterialBase::getGenericZeroMaterialPropertyByName(), hasBlockMaterialPropertyHelper(), SubdomainsDivision::initialize(), ElementCentroidPositions::initialize(), MooseVariableBase::MooseVariableBase(), NodalPatchRecoveryAux::NodalPatchRecoveryAux(), PointwiseRenormalizeVector::PointwiseRenormalizeVector(), ProjectedMaterialPropertyNodalPatchRecoveryAux::ProjectedMaterialPropertyNodalPatchRecoveryAux(), MaterialBase::registerPropName(), and FVPointValueConstraint::setMyElem().

191 {
192  if (_blk_ids.find(Moose::ANY_BLOCK_ID) != _blk_ids.end())
193  return _blk_mesh->meshSubdomains();
194  else
195  return _blk_ids;
196 }
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)
MooseMesh * _blk_mesh
Pointer to Mesh.
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
Definition: MooseMesh.C:2922

◆ blockRestricted()

bool BlockRestrictable::blockRestricted ( ) const
virtual

◆ blocks()

const std::vector< SubdomainName > & BlockRestrictable::blocks ( ) const

Return the block names for this object.

Note, if the 'blocks' input parameter was not utilized this will return an empty vector.

Returns
vector of SubdomainNames that are valid for this object

Definition at line 184 of file BlockRestrictable.C.

Referenced by MaterialOutputAction::getParams(), SubdomainsDivision::initialize(), and SolutionIC::initialSetup().

185 {
186  return _blocks;
187 }
std::vector< SubdomainName > _blocks
Vector the block names supplied by the user via the input file.

◆ blocksMaxDimension()

unsigned int BlockRestrictable::blocksMaxDimension ( ) const

Return the largest mesh dimension of the elements in the blocks for this object.

Definition at line 360 of file BlockRestrictable.C.

361 {
362  mooseAssert(_blk_dim != libMesh::invalid_uint, "Block restriction not initialized");
363  return _blk_dim;
364 }
unsigned int _blk_dim
Largest mesh dimension of the elements in the blocks for this object.
const unsigned int invalid_uint

◆ checkVariable()

void BlockRestrictable::checkVariable ( const MooseVariableFieldBase variable) const
virtual

Helper for checking that the ids for this object are in agreement with the variables on the supplied variable.

Parameters
variableThe variable to check against.

Reimplemented in DomainUserObject.

Definition at line 333 of file BlockRestrictable.C.

Referenced by DomainUserObject::checkVariable().

334 {
335  // a variable defined on all internal sides does not need this check because
336  // it can be coupled with other variables in DG kernels
337  if (variable.activeSubdomains().count(Moose::INTERNAL_SIDE_LOWERD_ID) > 0)
338  return;
339 
340  if (!isBlockSubset(variable.activeSubdomains()))
341  {
342  std::string var_ids = Moose::stringify(variable.activeSubdomains(), ", ");
343  std::string obj_ids = Moose::stringify(blockRestricted() ? _blk_ids : meshBlockIDs(), ", ");
344  mooseError("The 'block' parameter of the object '",
345  _blk_name,
346  "' must be a subset of the 'block' parameter of the variable '",
347  variable.name(),
348  "':\n Object '",
349  _blk_name,
350  "': ",
351  obj_ids,
352  "\n Variable '",
353  variable.name(),
354  "': ",
355  var_ids);
356  }
357 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
const std::string & name() const override
Get the variable name.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
bool isBlockSubset(const std::set< SubdomainID > &ids) const
Test if the class block ids are a subset of the supplied objects.
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:62
const std::set< SubdomainID > & activeSubdomains() const
The subdomains the variable is active on.
const SubdomainID INTERNAL_SIDE_LOWERD_ID
Definition: MooseTypes.C:20
const std::set< SubdomainID > & meshBlockIDs() const
Return all of the SubdomainIDs for the mesh.
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)
const std::string & _blk_name
Name of the object.

◆ getBlockCoordSystem()

Moose::CoordinateSystemType BlockRestrictable::getBlockCoordSystem ( )
protected

Check if the blocks this object operates on all have the same coordinate system, and if so return it.

Definition at line 311 of file BlockRestrictable.C.

312 {
313  if (!_blk_mesh)
314  mooseError("No mesh available in BlockRestrictable::checkCoordSystem()");
315  if (!_blk_feproblem)
316  mooseError("No problem available in BlockRestrictable::checkCoordSystem()");
317 
318  const auto & subdomains = blockRestricted() ? blockIDs() : meshBlockIDs();
319 
320  if (subdomains.empty())
321  mooseError("No subdomains found in the problem.");
322 
323  // make sure all subdomains are using the same coordinate system
324  auto coord_system = _blk_feproblem->getCoordSystem(*subdomains.begin());
325  for (auto subdomain : subdomains)
326  if (_blk_feproblem->getCoordSystem(subdomain) != coord_system)
327  mooseError("This object requires all subdomains to have the same coordinate system.");
328 
329  return coord_system;
330 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
FEProblemBase * _blk_feproblem
Pointer to FEProblemBase.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
const std::set< SubdomainID > & meshBlockIDs() const
Return all of the SubdomainIDs for the mesh.
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
Definition: SubProblem.C:1235
MooseMesh * _blk_mesh
Pointer to Mesh.

◆ hasBlockMaterialProperty()

template<typename T , bool is_ad>
bool BlockRestrictable::hasBlockMaterialProperty ( const std::string &  prop_name)

Check if a material property is valid for all blocks of this object.

This method returns true if the supplied property name has been declared in a Material object on the block ids for this object.

Template Parameters
TThe type of material property
Parameters
prop_namethe name of the property to query
Returns
true if the property exists for all block ids of the object, otherwise false
See also
Material::hasBlockMaterialProperty

Definition at line 264 of file BlockRestrictable.h.

265 {
266  mooseAssert(_blk_material_data != NULL, "MaterialData pointer is not defined");
267  return hasBlockMaterialPropertyHelper(prop_name) &&
268  _blk_material_data->haveGenericProperty<T, is_ad>(prop_name);
269 }
bool haveGenericProperty(const std::string &prop_name) const
Definition: MaterialData.h:253
const MaterialData * _blk_material_data
Pointer to the MaterialData class for this object.
virtual bool hasBlockMaterialPropertyHelper(const std::string &prop_name)
A helper method to allow the Material object to specialize the behavior of hasBlockMaterialProperty.

◆ hasBlockMaterialPropertyHelper()

bool BlockRestrictable::hasBlockMaterialPropertyHelper ( const std::string &  prop_name)
protectedvirtual

A helper method to allow the Material object to specialize the behavior of hasBlockMaterialProperty.

It also avoid circular #include problems.

See also
hasBlockMaterialProperty

Definition at line 275 of file BlockRestrictable.C.

Referenced by hasBlockMaterialProperty().

276 {
277 
278  // Reference to MaterialWarehouse for testing and retrieving block ids
280 
281  // Complete set of ids that this object is active
282  const std::set<SubdomainID> & ids = blockRestricted() ? blockIDs() : meshBlockIDs();
283 
284  // Loop over each id for this object
285  for (const auto & id : ids)
286  {
287  // Storage of material properties that have been DECLARED on this id
288  std::set<std::string> declared_props;
289 
290  // If block materials exist, populated the set of properties that were declared
291  if (warehouse.hasActiveBlockObjects(id))
292  {
293  const std::vector<std::shared_ptr<MaterialBase>> & mats = warehouse.getActiveBlockObjects(id);
294  for (const auto & mat : mats)
295  {
296  const std::set<std::string> & mat_props = mat->getSuppliedItems();
297  declared_props.insert(mat_props.begin(), mat_props.end());
298  }
299  }
300 
301  // If the supplied property is not in the list of properties on the current id, return false
302  if (declared_props.find(prop_name) == declared_props.end())
303  return false;
304  }
305 
306  // If you get here the supplied property is defined on all blocks
307  return true;
308 }
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
FEProblemBase * _blk_feproblem
Pointer to FEProblemBase.
virtual const std::set< SubdomainID > & blockIDs() const
Return the block subdomain ids for this object Note, if this is not block restricted, this function returns all mesh subdomain ids.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
MaterialBase objects are special in that they have additional objects created automatically (see FEPr...
const MaterialWarehouse & getMaterialWarehouse() const
const std::set< SubdomainID > & meshBlockIDs() const
Return all of the SubdomainIDs for the mesh.

◆ hasBlocks() [1/5]

bool BlockRestrictable::hasBlocks ( const SubdomainName &  name) const

Test if the supplied block name is valid for this object.

Parameters
nameA SubdomainName to check
Returns
True if the given id is valid for this object

Definition at line 205 of file BlockRestrictable.C.

Referenced by LinearFVFluxKernel::addMatrixContribution(), DiracKernelBase::addPoint(), LinearFVFluxKernel::addRightHandSideContribution(), MultiAppVariableValueSamplePostprocessorTransfer::cacheElemToPostprocessorData(), DomainUserObject::checkVariable(), ComputeJacobianThread::compute(), DomainUserObject::DomainUserObject(), ExtraIDIntegralVectorPostprocessor::execute(), MeshDivisionFunctorReductionVectorPostprocessor::execute(), MultiAppVariableValueSamplePostprocessorTransfer::execute(), ExtraIDIntegralVectorPostprocessor::ExtraIDIntegralVectorPostprocessor(), QuadraturePointMultiApp::fillPositions(), CentroidMultiApp::fillPositions(), hasBlocks(), MooseVariableField< Real >::hasBlocks(), FVFluxKernel::hasFaceSide(), and PointwiseRenormalizeVector::PointwiseRenormalizeVector().

206 {
207  // Create a vector and utilize the getSubdomainIDs function, which
208  // handles the ANY_BLOCK_ID (getSubdomainID does not)
209  std::vector<SubdomainName> names(1);
210  names[0] = name;
211  return hasBlocks(_blk_mesh->getSubdomainIDs(names));
212 }
std::string name(const ElemQuality q)
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_name) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition: MooseMesh.C:1520
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
MooseMesh * _blk_mesh
Pointer to Mesh.

◆ hasBlocks() [2/5]

bool BlockRestrictable::hasBlocks ( const std::vector< SubdomainName > &  names) const

Test if the supplied vector of block names are valid for this object.

Parameters
namesA vector of SubdomainNames to check
Returns
True if the given ids are valid for this object

Definition at line 215 of file BlockRestrictable.C.

216 {
217  return hasBlocks(_blk_mesh->getSubdomainIDs(names));
218 }
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_name) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition: MooseMesh.C:1520
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
MooseMesh * _blk_mesh
Pointer to Mesh.

◆ hasBlocks() [3/5]

bool BlockRestrictable::hasBlocks ( SubdomainID  id) const

Test if the supplied block ids are valid for this object.

Parameters
idA SubdomainID to check
Returns
True if the given id is valid for this object

Definition at line 221 of file BlockRestrictable.C.

222 {
223  if (_blk_ids.empty() || _blk_ids.find(Moose::ANY_BLOCK_ID) != _blk_ids.end())
224  return true;
225  else
226  return _blk_ids.find(id) != _blk_ids.end();
227 }
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)

◆ hasBlocks() [4/5]

bool BlockRestrictable::hasBlocks ( const std::vector< SubdomainID > &  ids) const

Test if the supplied vector block ids are valid for this object.

Parameters
idsA vector of SubdomainIDs ids to check
Returns
True if all of the given ids are found within the ids for this object

Definition at line 230 of file BlockRestrictable.C.

231 {
232  std::set<SubdomainID> ids_set(ids.begin(), ids.end());
233  return hasBlocks(ids_set);
234 }
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.

◆ hasBlocks() [5/5]

bool BlockRestrictable::hasBlocks ( const std::set< SubdomainID > &  ids) const

Test if the supplied set of block ids are valid for this object.

Parameters
idsA std::set of SubdomainIDs to check
Returns
True if all of the given ids are found within the ids for this object
See also
isSubset

Definition at line 237 of file BlockRestrictable.C.

238 {
239  if (_blk_ids.empty() || _blk_ids.find(Moose::ANY_BLOCK_ID) != _blk_ids.end())
240  return true;
241  else
242  return std::includes(_blk_ids.begin(), _blk_ids.end(), ids.begin(), ids.end());
243 }
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)

◆ initializeBlockRestrictable()

void BlockRestrictable::initializeBlockRestrictable ( const MooseObject moose_object)
protected

An initialization routine needed for dual constructors.

Definition at line 74 of file BlockRestrictable.C.

Referenced by BlockRestrictable().

75 {
76  // If the mesh pointer is not defined, but FEProblemBase is, get it from there
77  if (_blk_feproblem != NULL && _blk_mesh == NULL)
79 
80  // Check that the mesh pointer was defined, it is required for this class to operate
81  if (_blk_mesh == NULL)
82  mooseError("The input parameters must contain a pointer to FEProblem via '_fe_problem' or a "
83  "pointer to the MooseMesh via '_mesh'");
84 
85  // Populate the MaterialData pointer
86  if (_blk_feproblem != NULL)
88 
89  // The 'block' input is defined
90  if (moose_object->isParamValid("block"))
91  {
92  // Extract the blocks from the input
93  _blocks = moose_object->getParam<std::vector<SubdomainName>>("block");
94 
95  // Store the IDs in a set, handling ANY_BLOCK_ID if supplied
96  if (std::find(_blocks.begin(), _blocks.end(), "ANY_BLOCK_ID") != _blocks.end())
98  else
99  {
100  // Get the IDs from the supplied names
102  _blk_ids.insert(_vec_ids.begin(), _vec_ids.end());
103  }
104  }
105 
106  // When 'blocks' is not set and there is a "variable", use the blocks from the variable
107  else if (moose_object->isParamValid("variable"))
108  {
109  std::string variable_name = moose_object->parameters().getMooseType("variable");
110  if (!variable_name.empty())
112  ->getVariable(_blk_tid,
113  variable_name,
116  .activeSubdomains();
117  }
118 
119  // Produce error if the object is not allowed to be both block and boundary restricted
120  if (!_blk_dual_restrictable && !_boundary_ids.empty() && !_boundary_ids.empty())
121  if (!_boundary_ids.empty() && _boundary_ids.find(Moose::ANY_BOUNDARY_ID) == _boundary_ids.end())
122  moose_object->paramError("block",
123  "Attempted to restrict the object '",
124  _blk_name,
125  "' to a block, but the object is already restricted by boundary");
126 
127  // If no blocks were defined above, specify that it is valid on all blocks
128  if (_blk_ids.empty() && !moose_object->isParamValid("boundary"))
129  {
131  _blocks = {"ANY_BLOCK_ID"};
132  }
133 
134  // If this object is block restricted, check that defined blocks exist on the mesh
135  if (_blk_ids.find(Moose::ANY_BLOCK_ID) == _blk_ids.end())
136  {
137  const std::set<SubdomainID> & valid_ids = _blk_mesh->meshSubdomains();
138  std::vector<SubdomainID> diff;
139 
140  std::set_difference(_blk_ids.begin(),
141  _blk_ids.end(),
142  valid_ids.begin(),
143  valid_ids.end(),
144  std::back_inserter(diff));
145 
146  if (!diff.empty())
147  {
148  std::ostringstream msg;
149  auto sep = " ";
150  msg << "the following blocks (ids) do not exist on the mesh:";
151  for (const auto & id : diff)
152  {
153  if (_blk_name.size() > 0)
154  {
155  auto & name =
156  _blocks.at(std::find(_vec_ids.begin(), _vec_ids.end(), id) - _vec_ids.begin());
157  if (std::to_string(id) != name)
158  msg << sep << name << " (" << id << ")";
159  else
160  msg << sep << id;
161  }
162  else
163  msg << sep << id;
164  sep = ", ";
165  }
166  moose_object->paramError("block", msg.str());
167  }
168  }
169 
170  // Get the mesh dimension for the blocks
171  if (blockRestricted())
173  else
175 }
std::string name(const ElemQuality q)
std::string getMooseType(const std::string &name) const
Utility functions for retrieving one of the MooseTypes variables into the common "string" base class...
unsigned int _blk_dim
Largest mesh dimension of the elements in the blocks for this object.
const bool _blk_dual_restrictable
Flag for allowing dual restriction.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
MaterialData & getMaterialData(Moose::MaterialDataType type, const THREAD_ID tid=0)
FEProblemBase * _blk_feproblem
Pointer to FEProblemBase.
virtual bool blockRestricted() const
Returns true if this object has been restricted to a block.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
std::vector< SubdomainID > _vec_ids
Vector of block ids supplied by the user via the input file (for error reporting) ...
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition: MooseMesh.C:2679
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
THREAD_ID _blk_tid
Thread id for this object.
std::vector< SubdomainName > _blocks
Vector the block names supplied by the user via the input file.
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 ...
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
unsigned int getBlocksMaxDimension(const std::vector< SubdomainName > &blocks) const
Returns the maximum element dimension on the given blocks.
Definition: MooseMesh.C:2700
const MaterialData * _blk_material_data
Pointer to the MaterialData class for this object.
virtual MooseMesh & mesh() override
const std::set< BoundaryID > & _boundary_ids
Reference to the boundary_ids, defaults to an empty set if not provided.
const InputParameters & parameters() const
Get the parameters of the object.
std::vector< SubdomainID > getSubdomainIDs(const std::vector< SubdomainName > &subdomain_name) const
Get the associated subdomainIDs for the subdomain names that are passed in.
Definition: MooseMesh.C:1520
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)
const std::string & _blk_name
Name of the object.
MooseMesh * _blk_mesh
Pointer to Mesh.
const BoundaryID ANY_BOUNDARY_ID
Definition: MooseTypes.C:23
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
Definition: MooseMesh.C:2922

◆ isBlockSubset() [1/2]

bool BlockRestrictable::isBlockSubset ( const std::set< SubdomainID > &  ids) const

Test if the class block ids are a subset of the supplied objects.

Parameters
idsA std::set of Subdomains to check
Returns
True if all of the block ids for this class are found within the given ids (opposite of hasBlocks)
See also
hasBlocks

Definition at line 246 of file BlockRestrictable.C.

Referenced by checkVariable(), isBlockSubset(), NodalPatchRecoveryAux::NodalPatchRecoveryAux(), and ProjectedMaterialPropertyNodalPatchRecoveryAux::ProjectedMaterialPropertyNodalPatchRecoveryAux().

247 {
248  // An empty input is assumed to be ANY_BLOCK_ID
249  if (ids.empty() || ids.find(Moose::ANY_BLOCK_ID) != ids.end())
250  return true;
251 
252  if (_blk_ids.find(Moose::ANY_BLOCK_ID) != _blk_ids.end())
253  return std::includes(ids.begin(),
254  ids.end(),
255  _blk_mesh->meshSubdomains().begin(),
256  _blk_mesh->meshSubdomains().end());
257  else
258  return std::includes(ids.begin(), ids.end(), _blk_ids.begin(), _blk_ids.end());
259 }
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.C:19
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)
MooseMesh * _blk_mesh
Pointer to Mesh.
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
Definition: MooseMesh.C:2922

◆ isBlockSubset() [2/2]

bool BlockRestrictable::isBlockSubset ( const std::vector< SubdomainID > &  ids) const

Test if the class block ids are a subset of the supplied objects.

Parameters
idsA std::vector of Subdomains to check
Returns
True if all of the block ids for this class are found within the given ids (opposite of hasBlocks)
See also
hasBlocks

Definition at line 262 of file BlockRestrictable.C.

263 {
264  std::set<SubdomainID> ids_set(ids.begin(), ids.end());
265  return isBlockSubset(ids_set);
266 }
bool isBlockSubset(const std::set< SubdomainID > &ids) const
Test if the class block ids are a subset of the supplied objects.

◆ meshBlockIDs()

const std::set< SubdomainID > & BlockRestrictable::meshBlockIDs ( ) const

Return all of the SubdomainIDs for the mesh.

Returns
A set of all subdomians for the entire mesh

Definition at line 269 of file BlockRestrictable.C.

Referenced by checkVariable(), ElementGroupCentroidPositions::ElementGroupCentroidPositions(), getBlockCoordSystem(), hasBlockMaterialPropertyHelper(), and SolutionIC::initialSetup().

270 {
271  return _blk_mesh->meshSubdomains();
272 }
MooseMesh * _blk_mesh
Pointer to Mesh.
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
Definition: MooseMesh.C:2922

◆ numBlocks()

unsigned int BlockRestrictable::numBlocks ( ) const

Return the number of blocks for this object.

Returns
The number of subdomains

Definition at line 199 of file BlockRestrictable.C.

Referenced by ElementCentroidPositions::initialize().

200 {
201  return (unsigned int)_blk_ids.size();
202 }
std::set< SubdomainID > _blk_ids
Set of block ids supplied by the user via the input file (for error checking)

◆ validParams()

InputParameters BlockRestrictable::validParams ( )
static

Definition at line 21 of file BlockRestrictable.C.

Referenced by SubdomainsDivision::validParams(), QuadraturePointMultiApp::validParams(), CentroidMultiApp::validParams(), ElementCentroidPositions::validParams(), ElementGroupCentroidPositions::validParams(), KernelBase::validParams(), ProjectedStatefulMaterialStorageAction::validParams(), DiracKernelBase::validParams(), LinearFVKernel::validParams(), InternalSideUserObject::validParams(), NodalUserObject::validParams(), NodalKernelBase::validParams(), Indicator::validParams(), ElementUserObject::validParams(), FVKernel::validParams(), MooseVariableBase::validParams(), LineMaterialSamplerBase< Real >::validParams(), DGKernelBase::validParams(), Marker::validParams(), FVInitialConditionBase::validParams(), DomainUserObject::validParams(), InitialConditionBase::validParams(), AuxKernelTempl< Real >::validParams(), and MaterialBase::validParams().

22 {
23  // Create InputParameters object that will be appended to the parameters for the inheriting object
25 
26  // Add the user-facing 'block' input parameter
27  params.addParam<std::vector<SubdomainName>>(
28  "block", "The list of blocks (ids or names) that this object will be applied");
29 
30  // A parameter for disabling error message for objects restrictable by boundary and block,
31  // if the parameter is valid it was already set so don't do anything
32  if (!params.have_parameter<bool>("_dual_restrictable"))
33  params.addPrivateParam<bool>("_dual_restrictable", false);
34 
35  // Return the parameters
36  return params;
37 }
void addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...

Member Data Documentation

◆ _blk_dim

unsigned int BlockRestrictable::_blk_dim
private

Largest mesh dimension of the elements in the blocks for this object.

Definition at line 259 of file BlockRestrictable.h.

Referenced by blocksMaxDimension(), and initializeBlockRestrictable().

◆ _blk_dual_restrictable

const bool BlockRestrictable::_blk_dual_restrictable
private

Flag for allowing dual restriction.

Definition at line 238 of file BlockRestrictable.h.

Referenced by initializeBlockRestrictable().

◆ _blk_feproblem

FEProblemBase* BlockRestrictable::_blk_feproblem
private

◆ _blk_ids

std::set<SubdomainID> BlockRestrictable::_blk_ids
private

Set of block ids supplied by the user via the input file (for error checking)

Definition at line 229 of file BlockRestrictable.h.

Referenced by blockIDs(), blockRestricted(), checkVariable(), hasBlocks(), initializeBlockRestrictable(), isBlockSubset(), and numBlocks().

◆ _blk_material_data

const MaterialData* BlockRestrictable::_blk_material_data
protected

Pointer to the MaterialData class for this object.

Definition at line 207 of file BlockRestrictable.h.

Referenced by hasBlockMaterialProperty(), and initializeBlockRestrictable().

◆ _blk_mesh

MooseMesh* BlockRestrictable::_blk_mesh
private

◆ _blk_name

const std::string& BlockRestrictable::_blk_name
private

Name of the object.

Definition at line 256 of file BlockRestrictable.h.

Referenced by checkVariable(), and initializeBlockRestrictable().

◆ _blk_tid

THREAD_ID BlockRestrictable::_blk_tid
private

Thread id for this object.

Definition at line 253 of file BlockRestrictable.h.

Referenced by initializeBlockRestrictable().

◆ _blocks

std::vector<SubdomainName> BlockRestrictable::_blocks
private

Vector the block names supplied by the user via the input file.

Definition at line 235 of file BlockRestrictable.h.

Referenced by blocks(), and initializeBlockRestrictable().

◆ _boundary_ids

const std::set<BoundaryID>& BlockRestrictable::_boundary_ids
private

Reference to the boundary_ids, defaults to an empty set if not provided.

Definition at line 250 of file BlockRestrictable.h.

Referenced by initializeBlockRestrictable().

◆ _empty_boundary_ids

const std::set<BoundaryID> BlockRestrictable::_empty_boundary_ids
private

An empty set for referencing when boundary_ids is not included.

Definition at line 247 of file BlockRestrictable.h.

◆ _vec_ids

std::vector<SubdomainID> BlockRestrictable::_vec_ids
private

Vector of block ids supplied by the user via the input file (for error reporting)

Definition at line 232 of file BlockRestrictable.h.

Referenced by initializeBlockRestrictable().


The documentation for this class was generated from the following files: