www.mooseframework.org
GuaranteeConsumer.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "GuaranteeConsumer.h"
11 #include "GuaranteeProvider.h"
12 
13 #include "MooseObject.h"
14 #include "Material.h"
15 #include "MooseMesh.h"
16 #include "FEProblemBase.h"
17 #include "InputParameters.h"
18 #include "BlockRestrictable.h"
19 
20 GuaranteeConsumer::GuaranteeConsumer(MooseObject * moose_object)
21  : _gc_params(moose_object->parameters()),
22  _gc_feproblem(_gc_params.get<FEProblemBase *>("_fe_problem_base")),
23  _gc_block_restrict(dynamic_cast<BlockRestrictable *>(moose_object))
24 {
25 }
26 
27 bool
28 GuaranteeConsumer::hasGuaranteedMaterialProperty(const MaterialPropertyName & prop_name,
29  Guarantee guarantee)
30 {
31  if (!_gc_feproblem->startedInitialSetup())
32  mooseError("hasGuaranteedMaterialProperty() needs to be called in initialSetup()");
33 
34  // Reference to MaterialWarehouse for testing and retrieving block ids
35  const auto & warehouse = _gc_feproblem->getMaterialWarehouse();
36 
37  // Complete set of ids that this object is active
38  const auto & ids = (_gc_block_restrict && _gc_block_restrict->blockRestricted())
39  ? _gc_block_restrict->blockIDs()
40  : _gc_feproblem->mesh().meshSubdomains();
41 
42  // Loop over each id for this object
43  for (const auto & id : ids)
44  {
45  // If block materials exist, look if any issue the required guarantee
46  if (warehouse.hasActiveBlockObjects(id))
47  {
48  const std::vector<std::shared_ptr<Material>> & mats = warehouse.getActiveBlockObjects(id);
49  for (const auto & mat : mats)
50  {
51  const auto & mat_props = mat->getSuppliedItems();
52  if (mat_props.count(prop_name))
53  {
54  auto guarantee_mat = dynamic_cast<GuaranteeProvider *>(mat.get());
55  if (guarantee_mat && !guarantee_mat->hasGuarantee(prop_name, guarantee))
56  {
57  // we found at least one material on the set of block we operate on
58  // that does _not_ provide the requested guarantee
59  return false;
60  }
61  }
62  }
63  }
64  }
65 
66  return true;
67 }
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:16
bool hasGuaranteedMaterialProperty(const MaterialPropertyName &prop, Guarantee guarantee)