https://mooseframework.inl.gov
RankTwoTensorFromComponentProperties.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 
13 
16 {
18  params.addClassDescription(
19  "Assembles a RankTwoTensor from scalar material properties or constants");
20  params.addParam<MaterialPropertyName>("tensor_name", "Name of output tensor");
21  params.addRequiredParam<std::vector<std::string>>(
22  "tensor_values", "9 tensor components (row-major) as material property names or constants");
23  return params;
24 }
25 
27  const InputParameters & parameters)
28  : Material(parameters),
29  _prop(declareProperty<RankTwoTensor>(getParam<MaterialPropertyName>("tensor_name")))
30 {
31  const auto & vals = getParam<std::vector<std::string>>("tensor_values");
32  if (vals.size() != 9)
33  paramError("tensor_values", "Must provide exactly 9 values");
34 
35  _mat_props.resize(9, nullptr);
36  _const_vals.resize(9);
37  _is_const.resize(9);
38 
39  for (unsigned int i = 0; i < 9; ++i)
40  {
41  Real val;
42  if (MooseUtils::parsesToReal(vals[i], &val))
43  {
44  _const_vals[i] = val;
45  _is_const[i] = true;
46  }
47  else
48  {
49  _mat_props[i] = &getMaterialProperty<Real>(vals[i]);
50  _is_const[i] = false;
51  }
52  }
53 }
54 
55 void
57 {
58  unsigned int k = 0;
59  for (const auto i : make_range(3))
60  for (const auto j : make_range(3))
61  {
62  _prop[_qp](i, j) = _is_const[k] ? _const_vals[k] : (*_mat_props[k])[_qp];
63  k++;
64  }
65 }
RankTwoTensorFromComponentProperties(const InputParameters &parameters)
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:467
MaterialProperty< RankTwoTensor > & _prop
RankTwoTensor material property.
std::vector< const MaterialProperty< Real > * > _mat_props
Vector of material properties, inner ordering is tensor columns, outer is rows.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void computeQpProperties() override
Users must override this method.
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...
unsigned int _qp
Definition: MaterialBase.h:336
registerMooseObject("MooseApp", RankTwoTensorFromComponentProperties)
static InputParameters validParams()
Definition: Material.C:14
Materials compute MaterialProperties.
Definition: Material.h:35
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
Assembles a RankTwoTensor from scalar material properties or constants.
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
bool parsesToReal(const std::string &input, Real *parsed_real)
Definition: MooseUtils.C:89
std::vector< Real > _const_vals
Constant values in the tensor property.
std::vector< bool > _is_const
Keeps track of which component is a constant.