https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
55void
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}
registerMooseObject("MooseApp", RankTwoTensorFromComponentProperties)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
unsigned int _qp
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
Assembles a RankTwoTensor from scalar material properties or constants.
std::vector< Real > _const_vals
Constant values in the tensor property.
MaterialProperty< RankTwoTensor > & _prop
RankTwoTensor material property.
std::vector< bool > _is_const
Keeps track of which component is a constant.
std::vector< const MaterialProperty< Real > * > _mat_props
Vector of material properties, inner ordering is tensor columns, outer is rows.
RankTwoTensorFromComponentProperties(const InputParameters &parameters)
virtual void computeQpProperties() override
Users must override this method.
bool parsesToReal(const std::string &input, Real *parsed_real)
Definition MooseUtils.C:100