Line data Source code
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 : #include "RankTwoTensorFromComponentProperties.h" 11 : 12 : registerMooseObject("MooseApp", RankTwoTensorFromComponentProperties); 13 : 14 : InputParameters 15 3112 : RankTwoTensorFromComponentProperties::validParams() 16 : { 17 3112 : InputParameters params = Material::validParams(); 18 6224 : params.addClassDescription( 19 : "Assembles a RankTwoTensor from scalar material properties or constants"); 20 12448 : params.addParam<MaterialPropertyName>("tensor_name", "Name of output tensor"); 21 9336 : params.addRequiredParam<std::vector<std::string>>( 22 : "tensor_values", "9 tensor components (row-major) as material property names or constants"); 23 3112 : return params; 24 0 : } 25 : 26 39 : RankTwoTensorFromComponentProperties::RankTwoTensorFromComponentProperties( 27 39 : const InputParameters & parameters) 28 : : Material(parameters), 29 117 : _prop(declareProperty<RankTwoTensor>(getParam<MaterialPropertyName>("tensor_name"))) 30 : { 31 78 : const auto & vals = getParam<std::vector<std::string>>("tensor_values"); 32 39 : if (vals.size() != 9) 33 0 : paramError("tensor_values", "Must provide exactly 9 values"); 34 : 35 39 : _mat_props.resize(9, nullptr); 36 39 : _const_vals.resize(9); 37 39 : _is_const.resize(9); 38 : 39 390 : for (unsigned int i = 0; i < 9; ++i) 40 : { 41 : Real val; 42 351 : if (MooseUtils::parsesToReal(vals[i], &val)) 43 : { 44 273 : _const_vals[i] = val; 45 273 : _is_const[i] = true; 46 : } 47 : else 48 : { 49 78 : _mat_props[i] = &getMaterialProperty<Real>(vals[i]); 50 78 : _is_const[i] = false; 51 : } 52 : } 53 39 : } 54 : 55 : void 56 2304 : RankTwoTensorFromComponentProperties::computeQpProperties() 57 : { 58 2304 : unsigned int k = 0; 59 9216 : for (const auto i : make_range(3)) 60 27648 : for (const auto j : make_range(3)) 61 : { 62 20736 : _prop[_qp](i, j) = _is_const[k] ? _const_vals[k] : (*_mat_props[k])[_qp]; 63 20736 : k++; 64 : } 65 2304 : }