https://mooseframework.inl.gov
GenericConstantStdVectorMaterial.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 
11 
14 
15 template <bool is_ad>
18 {
19 
21  params.addClassDescription("Declares material properties based on names and vector values "
22  "prescribed by input parameters.");
23  params.addRequiredParam<std::vector<std::string>>(
24  "prop_names", "The names of the properties this material will have");
25  params.addRequiredParam<std::vector<std::vector<Real>>>(
26  "prop_values", "The values associated with the named properties. ");
27  params.set<MooseEnum>("constant_on") = "SUBDOMAIN";
28  return params;
29 }
30 
31 template <bool is_ad>
33  const InputParameters & parameters)
34  : Material(parameters),
36  _prop_names(getParam<std::vector<std::string>>("prop_names")),
37  _prop_values(getParam<std::vector<std::vector<Real>>>("prop_values"))
38 {
39  const auto num_names = _prop_names.size();
40  const auto num_values = _prop_values.size();
41  if (num_names != num_values)
42  paramError("prop_values",
43  "Number of vector property names (" + std::to_string(num_names) +
44  ") does not match the number of vectors of property values (" +
45  std::to_string(num_values) + ")");
46 
47  _num_props = num_names;
48  _properties.resize(num_names);
49 
50  for (const auto i : make_range(_num_props))
51  _properties[i] = &declareGenericProperty<std::vector<Real>, is_ad>(_prop_names[i]);
52 }
53 
54 template <bool is_ad>
55 void
57 {
58  computeQpProperties();
59 }
60 
61 template <bool is_ad>
62 void
64 {
65  for (unsigned int i = 0; i < _num_props; i++)
66  {
67  auto & prop_out = (*_properties[i])[_qp];
68  const auto & prop_in = _prop_values[i];
69  prop_out.resize(prop_in.size());
70  for (const auto j : index_range(prop_in))
71  prop_out[j] = prop_in[j];
72  }
73 }
74 
75 template <bool is_ad>
76 std::size_t
78  const MaterialPropertyName & prop_name) const
79 {
80  for (const auto i : index_range(_prop_names))
81  if (_prop_names[i] == prop_name)
82  return _prop_values[i].size();
83  paramError("prop_names", "Property '" + prop_name + "' was not defined");
84 }
85 
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:439
const std::vector< std::string > & _prop_names
The names of the constant vector material 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...
virtual void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
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< std::vector< Real > > & _prop_values
The vector values of each vector material property.
static InputParameters validParams()
Definition: Material.C:14
std::vector< GenericMaterialProperty< std::vector< Real >, is_ad > * > _properties
A vector of pointers to the material properties.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
registerMooseObject("MooseApp", GenericConstantStdVectorMaterial)
virtual void computeQpProperties() override
Users must override this method.
Material to create constant properties with the variable-size std::vector<Real> type.
virtual std::size_t getVectorPropertySize(const MaterialPropertyName &prop_name) const override
Return the size of the variable size vector material property that the material defines.
GenericConstantStdVectorMaterialTempl(const InputParameters &parameters)
Materials compute MaterialProperties.
Definition: Material.h:34
Interface class to return the size of material properties that do not have a fixed size...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
std::size_t _num_props
The number of constant vector material properties defined.
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...
auto index_range(const T &sizable)