https://mooseframework.inl.gov
Loading...
Searching...
No Matches
IndexableProperty.h
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#pragma once
11
12#include "MooseTypes.h"
13#include <vector>
14
22template <typename T, bool is_ad>
24{
25public:
27
29 const std::string & property_param = "property",
30 const std::string & component_param = "component");
31
34
36 void check() const;
37
38protected:
39 void checkComponents(unsigned int components) const;
40
42 T * _host;
43
45 const std::string & _property_param;
47 const std::string & _property_name;
49 const std::string & _component_param;
50
52 const std::vector<unsigned int> _component;
53
62};
63
64template <typename T, bool is_ad>
67{
68 auto params = T::validParams();
69 params.template addRequiredParam<MaterialPropertyName>("property",
70 "The name of the material property");
71 params.template addParam<std::vector<unsigned int>>(
72 "component",
73 {},
74 "Index vector of the scalar component to extract from "
75 "the material property (empty for scalar properties)");
76 return params;
77}
78
79template <typename T, bool is_ad>
81 const std::string & property_param,
82 const std::string & component_param)
83 : _host(host),
84 _property_param(property_param),
85 _property_name(_host->template getParam<MaterialPropertyName>(_property_param)),
86 _component_param(component_param),
87 _component(host->template getParam<std::vector<unsigned int>>(_component_param)),
88 _property_real(
89 _host->template getGenericOptionalMaterialProperty<Real, is_ad>(_property_param)),
90 _property_std_vector(
91 _host->template getGenericOptionalMaterialProperty<std::vector<Real>, is_ad>(
92 _property_param)),
93 _property_real_vector_value(
94 _host->template getGenericOptionalMaterialProperty<RealVectorValue, is_ad>(
95 _property_param)),
96 _property_rank_two_tensor(
97 _host->template getGenericOptionalMaterialProperty<RankTwoTensor, is_ad>(_property_param)),
98 _property_rank_three_tensor(
99 _host->template getGenericOptionalMaterialProperty<RankThreeTensor, is_ad>(
100 _property_param)),
101 _property_rank_four_tensor(
102 _host->template getGenericOptionalMaterialProperty<RankFourTensor, is_ad>(_property_param))
103{
104}
105
106template <typename T, bool is_ad>
109{
110 if (_property_real)
111 return _property_real[qp];
112 if (_property_std_vector)
113 return _property_std_vector[qp][_component[0]];
114 if (_property_real_vector_value)
115 return _property_real_vector_value[qp](_component[0]);
116 if (_property_rank_two_tensor)
117 return _property_rank_two_tensor[qp](_component[0], _component[1]);
118 if (_property_rank_three_tensor)
119 return _property_rank_three_tensor[qp](_component[0], _component[1], _component[2]);
120 if (_property_rank_four_tensor)
121 return _property_rank_four_tensor[qp](
122 _component[0], _component[1], _component[2], _component[3]);
123 _host->mooseError("internal error in IndexableProperty");
124}
125
126template <typename T, bool is_ad>
127void
129{
130 if (_property_real)
131 checkComponents(0);
132 else if (_property_std_vector)
133 checkComponents(1);
134 else if (_property_real_vector_value)
135 checkComponents(1);
136 else if (_property_rank_two_tensor)
137 checkComponents(2);
138 else if (_property_rank_three_tensor)
139 checkComponents(3);
140 else if (_property_rank_four_tensor)
141 checkComponents(4);
142 else
143 _host->mooseError("The ",
144 is_ad ? "AD" : "non-AD",
145 " material property '",
146 _property_name,
147 "' does not exist");
148}
149
150template <typename T, bool is_ad>
151void
153{
154 if (_component.size() != components)
155 _host->mooseError("Material property '",
156 _property_name,
157 "' is ",
158 components,
159 "-dimensional, but an index vector of size ",
160 _component.size(),
161 " was supplied to select a component. It looks like you were expecting the "
162 "material property to have a different type.");
163}
Moose::GenericType< Real, is_ad > GenericReal
Definition MooseTypes.h:698
void ErrorVector unsigned int
Wrapper around a material property pointer.
IndexableProperty is a helper (proxy) object to obtain a scalar component from a material property.
void checkComponents(unsigned int components) const
const GenericOptionalMaterialProperty< std::vector< Real >, is_ad > & _property_std_vector
const GenericOptionalMaterialProperty< RankFourTensor, is_ad > & _property_rank_four_tensor
const std::string & _component_param
name of the input parameter containing the component index
const std::vector< unsigned int > _component
Index of the selected scalar component of the material property.
void check() const
integrity check
const std::string & _property_param
name of the input parameter containing the material property name
const GenericOptionalMaterialProperty< RealVectorValue, is_ad > & _property_real_vector_value
T * _host
pointer to the host object
static InputParameters validParams()
const std::string & _property_name
name of the coupled material property (for error reporting)
const GenericOptionalMaterialProperty< RankTwoTensor, is_ad > & _property_rank_two_tensor
const GenericOptionalMaterialProperty< RankThreeTensor, is_ad > & _property_rank_three_tensor
IndexableProperty(T *host, const std::string &property_param="property", const std::string &component_param="component")
const GenericOptionalMaterialProperty< Real, is_ad > & _property_real
only one of those pointers will be non-null and pointing to the selected property
GenericReal< is_ad > operator[](int qp) const
get the selected component value for the given quadrature point
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.