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