www.mooseframework.org
GuaranteeConsumer.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
7 
8 #include "GuaranteeConsumer.h"
9 #include "GuaranteeProvider.h"
10 
11 #include "MooseObject.h"
12 #include "Material.h"
13 #include "MooseMesh.h"
14 #include "FEProblemBase.h"
15 #include "InputParameters.h"
16 #include "BlockRestrictable.h"
17 
18 GuaranteeConsumer::GuaranteeConsumer(MooseObject * moose_object)
19  : _gc_params(moose_object->parameters()),
20  _gc_feproblem(_gc_params.get<FEProblemBase *>("_fe_problem_base")),
21  _gc_block_restrict(dynamic_cast<BlockRestrictable *>(moose_object))
22 {
23 }
24 
25 bool
26 GuaranteeConsumer::hasGuaranteedMaterialProperty(const MaterialPropertyName & prop_name,
27  Guarantee guarantee)
28 {
29  if (!_gc_feproblem->startedInitialSetup())
30  mooseError("hasGuaranteedMaterialProperty() needs to be called in initialSetup()");
31 
32  // Reference to MaterialWarehouse for testing and retrieving block ids
33  const auto & warehouse = _gc_feproblem->getMaterialWarehouse();
34 
35  // Complete set of ids that this object is active
36  const auto & ids = (_gc_block_restrict && _gc_block_restrict->blockRestricted())
37  ? _gc_block_restrict->blockIDs()
38  : _gc_feproblem->mesh().meshSubdomains();
39 
40  // Loop over each id for this object
41  for (const auto & id : ids)
42  {
43  // If block materials exist, look if any issue the required guarantee
44  if (warehouse.hasActiveBlockObjects(id))
45  {
46  const std::vector<std::shared_ptr<Material>> & mats = warehouse.getActiveBlockObjects(id);
47  for (const auto & mat : mats)
48  {
49  const auto & mat_props = mat->getSuppliedItems();
50  if (mat_props.count(prop_name))
51  {
52  auto guarantee_mat = dynamic_cast<GuaranteeProvider *>(mat.get());
53  if (guarantee_mat && !guarantee_mat->hasGuarantee(prop_name, guarantee))
54  {
55  // we found at least one material on the set of block we operate on
56  // that does _not_ provide the requested guarantee
57  return false;
58  }
59  }
60  }
61  }
62  }
63 
64  return true;
65 }
Add-on class that provides the functionality to issue guarantees for declared material properties...
BlockRestrictable *const _gc_block_restrict
Access block restrictions of the object with this interface.
GuaranteeConsumer(MooseObject *moose_object)
FEProblemBase *const _gc_feproblem
Reference to the FEProblemBase class.
Guarantee
Enum values for guarantees that can be demanded for material properties.
Definition: Guarantee.h:15
bool hasGuaranteedMaterialProperty(const MaterialPropertyName &prop, Guarantee guarantee)