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 params.addParamNamesToGroup("use_displaced_mesh", "Advanced");
28 return params;
29}
30
32 : MaterialBase(parameters),
33 Coupleable(this, false),
34 MaterialPropertyInterface(this, blockIDs(), boundaryIDs()),
35 _bnd(_material_data_type != Moose::BLOCK_MATERIAL_DATA),
36 _neighbor(_material_data_type == Moose::NEIGHBOR_MATERIAL_DATA),
37 _q_point(_bnd ? (_neighbor ? _assembly.qPointsFaceNeighbor() : _assembly.qPointsFace())
38 : _assembly.qPoints()),
39 _qrule(_bnd ? (_neighbor ? _assembly.qRuleNeighbor() : _assembly.qRuleFace())
40 : _assembly.qRule()),
41 _JxW(_bnd ? _assembly.JxWFace() : _assembly.JxW()),
42 _current_elem(_neighbor ? _assembly.neighbor() : _assembly.elem()),
43 _current_subdomain_id(_neighbor ? _assembly.currentNeighborSubdomainID()
44 : _assembly.currentSubdomainID()),
45 _current_side(_neighbor ? _assembly.neighborSide() : _assembly.side()),
46 _constant_option(computeConstantOption()),
47 _ghostable(true)
48{
49 // 1. Fill in the MooseVariable dependencies
50 // 2. For ghost calculations we need to check and see whether this has any finite element
51 // variables. If it does, then this material doesn't support ghost calculations
52 // 3. For the purpose of ghost calculations, we will error if this material couples in both finite
53 // element and finite volume variables.
54 const std::vector<MooseVariableFieldBase *> & coupled_vars = getCoupledMooseVars();
55 bool has_fe_vars = false;
56 bool has_fv_vars = false;
57 for (auto * const var : coupled_vars)
58 {
60 if (var->isFV())
61 has_fv_vars = true;
62 else
63 {
64 has_fe_vars = true;
65 _ghostable = false;
66 }
67 }
68
69 // Note that this check will not catch a case in which a finite volume consumer needs a
70 // non-variable-based property ghosted, but that non-variable-based property is computed within a
71 // material that has finite element coupling (but not finite volume coupling)
72 if (has_fe_vars && has_fv_vars)
74 "Your material ",
75 this->name(),
76 " couples in both FE and FV vars. To support ghost calculations which some FV "
77 "consumers may need, multiphysics simulations should define separate materials for "
78 "coupling in finite element and finite volume variables because we do not have a user "
79 "friendly way of running DerivedMaterial::computeQpProperties and saying 'compute this "
80 "property because it doesn't depend on finite element variables' or 'don't compute this "
81 "property because it *does* depend on finite element variables'");
82}
83
84void
86{
87 if (_constant_option == ConstantTypeEnum::SUBDOMAIN)
88 {
89 auto nqp = _fe_problem.getMaxQps();
90
92 for (const auto & prop_id : _supplied_prop_ids)
93 props[prop_id].resize(nqp);
94
95 // consider all properties are active
97 for (const auto & id : _supplied_prop_ids)
98 _active_prop_ids.insert(id);
99
100 _qp = 0;
102
103 for (const auto & prop_id : _supplied_prop_ids)
104 for (decltype(nqp) qp = 1; qp < nqp; ++qp)
105 props[prop_id].qpCopy(qp, props[prop_id], 0);
106 }
107}
108
109void
111{
112 if (_constant_option == ConstantTypeEnum::SUBDOMAIN)
113 return;
114
115 // Reference to *all* the MaterialProperties in the MaterialData object, not
116 // just the ones for this Material.
118
119 // If this Material ist set to be constant over elements, we take the
120 // value computed for _qp == 0 and use it at all the quadrature points
121 // in the element.
122 if (_constant_option == ConstantTypeEnum::ELEMENT)
123 {
124 // Compute MaterialProperty values at the first qp.
125 _qp = 0;
127
128 // Now copy the values computed at qp 0 to all the other qps.
129 for (const auto & prop_id : _supplied_prop_ids)
130 {
131 auto nqp = _qrule->n_points();
132 for (decltype(nqp) qp = 1; qp < nqp; ++qp)
133 props[prop_id].qpCopy(qp, props[prop_id], 0);
134 }
135 }
136 else
137 for (_qp = 0; _qp < _qrule->n_points(); ++_qp)
139}
140
141Material::ConstantTypeEnum
143{
144 auto co = getParam<MooseEnum>("constant_on").getEnum<ConstantTypeEnum>();
145
146 // If the material is operating on a boundary we'll have to _at least_ run it
147 // once per element, as there is no boundarySetup, and boundaries are worked
148 // on as they are encountered on the elements while looping elements.
149 if (_bnd && co == ConstantTypeEnum::SUBDOMAIN)
150 co = ConstantTypeEnum::ELEMENT;
151
152 return co;
153}
154
156Material::getMaterialByName(const std::string & name, bool no_warn, bool no_dep)
157{
159 mooseError("To ensure dependency resolution, discrete materials must be retrieved during "
160 "initial setup. This is a code problem.");
161
163
164 if (!no_dep)
165 {
166 // Insert the materials requested by the discrete material into the host material who
167 // retrieves this discrete material
168 const auto & discrete_requested = discrete_mat.getRequestedItems();
169 _requested_props.insert(discrete_requested.begin(), discrete_requested.end());
170 }
171
172 return discrete_mat;
173}
174
175void
177{
178 for (auto & proxy : _optional_property_proxies)
179 proxy->resolve(*this);
180}
181
182void
183Material::checkMaterialProperty(const std::string & name, const unsigned int state)
184{
185 // Avoid performing duplicate checks for triple block/face/neighbor materials
186 if (boundaryRestricted() || !_bnd)
188}
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
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 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...
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:156
virtual void computeProperties() override
Performs the quadrature point loop, calling computeQpProperties.
Definition Material.C:110
static InputParameters validParams()
Definition Material.C:14
virtual void resolveOptionalProperties() override
resolve all optional properties
Definition Material.C:176
const ConstantTypeEnum _constant_option
Options of the constantness level of the material.
Definition Material.h:242
ConstantTypeEnum computeConstantOption()
Definition Material.C:142
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:31
virtual void subdomainSetup() override
Subdomain setup evaluating material properties when required.
Definition Material.C:85
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:183
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...