www.mooseframework.org
Material.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 // MOOSE includes
11 #include "Material.h"
12 
15 {
16 
19  MooseEnum const_option("NONE=0 ELEMENT=1 SUBDOMAIN=2", "none");
20  params.addParam<MooseEnum>(
21  "constant_on",
22  const_option,
23  "When ELEMENT, MOOSE will only call computeQpProperties() for the 0th "
24  "quadrature point, and then copy that value to the other qps."
25  "When SUBDOMAIN, MOOSE will only call computeQpProperties() for the 0th "
26  "quadrature point, and then copy that value to the other qps. Evaluations on element qps "
27  "will be skipped");
28  params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
29  return params;
30 }
31 
33  : MaterialBase(parameters),
34  Coupleable(this, false),
35  MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
36  _bnd(_material_data_type != Moose::BLOCK_MATERIAL_DATA),
37  _neighbor(_material_data_type == Moose::NEIGHBOR_MATERIAL_DATA),
38  _q_point(_bnd ? (_neighbor ? _assembly.qPointsFaceNeighbor() : _assembly.qPointsFace())
39  : _assembly.qPoints()),
40  _qrule(_bnd ? (_neighbor ? _assembly.qRuleNeighbor() : _assembly.qRuleFace())
41  : _assembly.qRule()),
42  _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
43  _current_elem(_neighbor ? _assembly.neighbor() : _assembly.elem()),
44  _current_subdomain_id(_neighbor ? _assembly.currentNeighborSubdomainID()
45  : _assembly.currentSubdomainID()),
46  _current_side(_neighbor ? _assembly.neighborSide() : _assembly.side()),
47  _constant_option(computeConstantOption()),
48  _ghostable(true)
49 {
50  // 1. Fill in the MooseVariable dependencies
51  // 2. For ghost calculations we need to check and see whether this has any finite element
52  // variables. If it does, then this material doesn't support ghost calculations
53  // 3. For the purpose of ghost calculations, we will error if this material couples in both finite
54  // element and finite volume variables.
55  const std::vector<MooseVariableFieldBase *> & coupled_vars = getCoupledMooseVars();
56  bool has_fe_vars = false;
57  bool has_fv_vars = false;
58  for (auto * const var : coupled_vars)
59  {
61  if (var->isFV())
62  has_fv_vars = true;
63  else
64  {
65  has_fe_vars = true;
66  _ghostable = false;
67  }
68  }
69 
70  // Note that this check will not catch a case in which a finite volume consumer needs a
71  // non-variable-based property ghosted, but that non-variable-based property is computed within a
72  // material that has finite element coupling (but not finite volume coupling)
73  if (has_fe_vars && has_fv_vars)
74  mooseError(
75  "Your material ",
76  this->name(),
77  " couples in both FE and FV vars. To support ghost calculations which some FV "
78  "consumers may need, multiphysics simulations should define separate materials for "
79  "coupling in finite element and finite volume variables because we do not have a user "
80  "friendly way of running DerivedMaterial::computeQpProperties and saying 'compute this "
81  "property because it doesn't depend on finite element variables' or 'don't compute this "
82  "property because it *does* depend on finite element variables'");
83 }
84 
85 void
87 {
89  {
90  auto nqp = _fe_problem.getMaxQps();
91 
93  for (const auto & prop_id : _supplied_prop_ids)
94  props[prop_id].resize(nqp);
95 
96  // consider all properties are active
97  _active_prop_ids.clear();
98  for (const auto & id : _supplied_prop_ids)
99  _active_prop_ids.insert(id);
100 
101  _qp = 0;
103 
104  for (const auto & prop_id : _supplied_prop_ids)
105  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
106  props[prop_id].qpCopy(qp, props[prop_id], 0);
107  }
108 }
109 
110 void
112 {
114  return;
115 
116  // Reference to *all* the MaterialProperties in the MaterialData object, not
117  // just the ones for this Material.
119 
120  // If this Material ist set to be constant over elements, we take the
121  // value computed for _qp == 0 and use it at all the quadrature points
122  // in the element.
124  {
125  // Compute MaterialProperty values at the first qp.
126  _qp = 0;
128 
129  // Now copy the values computed at qp 0 to all the other qps.
130  for (const auto & prop_id : _supplied_prop_ids)
131  {
132  auto nqp = _qrule->n_points();
133  for (decltype(nqp) qp = 1; qp < nqp; ++qp)
134  props[prop_id].qpCopy(qp, props[prop_id], 0);
135  }
136  }
137  else
138  for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
140 }
141 
144 {
145  auto co = getParam<MooseEnum>("constant_on").getEnum<ConstantTypeEnum>();
146 
147  // If the material is operating on a boundary we'll have to _at least_ run it
148  // once per element, as there is no boundarySetup, and boundaries are worked
149  // on as they are encountered on the elements while looping elements.
150  if (_bnd && co == ConstantTypeEnum::SUBDOMAIN)
152 
153  return co;
154 }
155 
156 MaterialBase &
157 Material::getMaterialByName(const std::string & name, bool no_warn, bool no_dep)
158 {
160  mooseError("To ensure dependency resolution, discrete materials must be retrieved during "
161  "initial setup. This is a code problem.");
162 
164 
165  if (!no_dep)
166  {
167  // Insert the materials requested by the discrete material into the host material who
168  // retrieves this discrete material
169  const auto & discrete_requested = discrete_mat.getRequestedItems();
170  _requested_props.insert(discrete_requested.begin(), discrete_requested.end());
171  }
172 
173  return discrete_mat;
174 }
175 
176 void
178 {
179  for (auto & proxy : _optional_property_proxies)
180  proxy->resolve(*this);
181 }
182 
183 void
184 Material::checkMaterialProperty(const std::string & name, const unsigned int state)
185 {
186  // Avoid performing duplicate checks for triple block/face/neighbor materials
187  if (boundaryRestricted() || !_bnd)
189 }
FEProblemBase & _mi_feproblem
Reference to the FEProblemBase class.
virtual void checkMaterialProperty(const std::string &name, const unsigned int state)
A helper method for checking material properties This method was required to avoid a compiler problem...
FEProblemBase & _fe_problem
Definition: MaterialBase.h:314
const QBase *const & _qrule
Definition: Material.h:233
ConstantTypeEnum computeConstantOption()
Definition: Material.C:143
virtual void computeQpProperties()
Users must override this method.
Definition: MaterialBase.C:213
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
virtual const MaterialData & materialData() const override
Definition: Material.h:224
static InputParameters validParams()
Definition: MaterialBase.C:21
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition: Material.h:245
virtual void computeProperties() override
Performs the quadrature point loop, calling computeQpProperties.
Definition: Material.C:111
bool _ghostable
Whether this material can be computed in a ghosted context.
Definition: Material.h:254
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static InputParameters validParams()
virtual const std::set< std::string > & getRequestedItems() override
Return a set of properties accessed with getMaterialProperty.
Definition: MaterialBase.h:185
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition: Material.C:86
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:56
void resize(const std::size_t size, const WriteKey)
MaterialData & _material_data
The material data class that stores properties.
unsigned int _qp
Definition: MaterialBase.h:318
bool _bnd
Definition: Material.h:229
std::set< std::string > _requested_props
Set of properties accessed via get method.
Definition: MaterialBase.h:330
virtual void checkMaterialProperty(const std::string &name, const unsigned int state) override
A helper method for checking material properties This method was required to avoid a compiler problem...
Definition: Material.C:184
static InputParameters validParams()
Definition: Material.C:14
ConstantTypeEnum
Definition: Material.h:209
std::unordered_set< unsigned int > _active_prop_ids
The ids of the current active supplied properties.
Definition: MaterialBase.h:345
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
const MaterialProperties & props(const unsigned int state=0) const
Definition: MaterialData.h:238
std::set< unsigned int > _supplied_prop_ids
The ids of the supplied properties, i.e.
Definition: MaterialBase.h:342
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false, bool no_dep=false)
Retrieve the discrete material named "name".
Definition: Material.C:157
const std::vector< MooseVariableFieldBase * > & getCoupledMooseVars() const
Get the list of all coupled variables.
Definition: Coupleable.h:69
Interface for objects that needs coupling capabilities.
Definition: Coupleable.h:44
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
MaterialBase & getMaterialByName(const std::string &name, bool no_warn=false)
An interface for accessing Materials.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
std::vector< std::unique_ptr< OptionalMaterialPropertyProxyBase< Material > > > _optional_property_proxies
optional material properties
Definition: Material.h:258
virtual void resolveOptionalProperties() override
resolve all optional properties
Definition: Material.C:177
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:60
Material(const InputParameters &parameters)
Definition: Material.C:32
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
unsigned int getMaxQps() const
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28