www.mooseframework.org
GenericConstantMaterial.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 
11 
14 
15 template <bool is_ad>
18 {
20  params.addClassDescription(
21  "Declares material properties based on names and values prescribed by input parameters.");
22  params.addRequiredParam<std::vector<std::string>>(
23  "prop_names", "The names of the properties this material will have");
24  params.addRequiredParam<std::vector<Real>>("prop_values",
25  "The values associated with the named properties");
26  params.set<MooseEnum>("constant_on") = "SUBDOMAIN";
27  params.declareControllable("prop_values");
28  return params;
29 }
30 
31 template <bool is_ad>
33  const InputParameters & parameters)
34  : Material(parameters),
35  _prop_names(getParam<std::vector<std::string>>("prop_names")),
36  _prop_values(getParam<std::vector<Real>>("prop_values"))
37 {
38  unsigned int num_names = _prop_names.size();
39  unsigned int num_values = _prop_values.size();
40 
41  if (num_names != num_values)
42  mooseError(
43  "Number of prop_names must match the number of prop_values for a GenericConstantMaterial!");
44 
45  _num_props = num_names;
46 
47  _properties.resize(num_names);
48 
49  for (unsigned int i = 0; i < _num_props; i++)
50  _properties[i] = &declareGenericProperty<Real, is_ad>(_prop_names[i]);
51 }
52 
53 template <bool is_ad>
54 void
56 {
57  computeQpProperties();
58 }
59 
60 template <bool is_ad>
61 void
63 {
64  for (unsigned int i = 0; i < _num_props; i++)
65  (*_properties[i])[_qp] = _prop_values[i];
66 }
67 
std::vector< GenericMaterialProperty< Real, is_ad > * > _properties
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
GenericConstantMaterialTempl(const InputParameters &parameters)
registerMooseObject("MooseApp", GenericConstantMaterial)
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
const std::vector< Real > & _prop_values
static InputParameters validParams()
Definition: Material.C:14
virtual void computeQpProperties() override
Users must override this method.
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 std::vector< std::string > & _prop_names
static InputParameters validParams()
Materials compute MaterialProperties.
Definition: Material.h:34
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This material automatically declares as material properties whatever is passed to it through the para...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
void declareControllable(const std::string &name, std::set< ExecFlagType > execute_flags={})
Declare the given parameters as controllable.