https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
15template <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
31template <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
54template <bool is_ad>
55void
60
61template <bool is_ad>
62void
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
75template <bool is_ad>
76std::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
registerMooseObject("MooseApp", GenericConstantStdVectorMaterial)
Material to create constant properties with the variable-size std::vector<Real> type.
const std::vector< std::string > & _prop_names
The names of the constant vector material properties.
const std::vector< std::vector< Real > > & _prop_values
The vector values of each vector material property.
virtual void computeQpProperties() override
Users must override this method.
std::size_t _num_props
The number of constant vector material properties defined.
virtual void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
std::vector< GenericMaterialProperty< std::vector< Real >, is_ad > * > _properties
A vector of pointers to the material properties.
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)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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...
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
auto & declareGenericProperty(const std::string &prop_name)
Materials compute MaterialProperties.
Definition Material.h:36
static InputParameters validParams()
Definition Material.C:14
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:457
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Interface class to return the size of material properties that do not have a fixed size.