https://mooseframework.inl.gov
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 
22 template <typename T, bool is_ad>
24 {
25 public:
27 
28  IndexableProperty(T * host,
29  const std::string & property_param = "property",
30  const std::string & component_param = "component");
31 
33  GenericReal<is_ad> operator[](int qp) const;
34 
36  void check() const;
37 
38 protected:
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 
64 template <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 
79 template <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 
106 template <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 
126 template <typename T, bool is_ad>
127 void
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 
150 template <typename T, bool is_ad>
151 void
152 IndexableProperty<T, is_ad>::checkComponents(unsigned int components) const
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 }
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
Moose::GenericType< Real, is_ad > GenericReal
Definition: MooseTypes.h:648
const std::string & _component_param
name of the input parameter containing the component index
void checkComponents(unsigned int components) const
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...
InputParameters validParams()
RankThreeTensor is designed to handle any N-dimensional third order tensor, r.
const GenericOptionalMaterialProperty< RankTwoTensor, is_ad > & _property_rank_two_tensor
const std::vector< unsigned int > _component
Index of the selected scalar component of the material property.
const std::string & _property_param
name of the input parameter containing the material property name
const GenericOptionalMaterialProperty< RankThreeTensor, is_ad > & _property_rank_three_tensor
IndexableProperty is a helper (proxy) object to obtain a scalar component from a material property...
const GenericOptionalMaterialProperty< std::vector< Real >, is_ad > & _property_std_vector
T * _host
pointer to the host object
static InputParameters validParams()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const GenericOptionalMaterialProperty< Real, is_ad > & _property_real
only one of those pointers will be non-null and pointing to the selected property ...
const std::string & _property_name
name of the coupled material property (for error reporting)
IndexableProperty(T *host, const std::string &property_param="property", const std::string &component_param="component")
const GenericOptionalMaterialProperty< RealVectorValue, is_ad > & _property_real_vector_value
void check() const
integrity check
void ErrorVector unsigned int
const GenericOptionalMaterialProperty< RankFourTensor, is_ad > & _property_rank_four_tensor