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 "GeneralizedPlaneStrainOffDiag.h" 11 : 12 : // MOOSE includes 13 : #include "Assembly.h" 14 : #include "Material.h" 15 : #include "MooseVariable.h" 16 : #include "MooseVariableScalar.h" 17 : #include "RankTwoTensor.h" 18 : #include "RankFourTensor.h" 19 : #include "UserObject.h" 20 : 21 : #include "libmesh/quadrature.h" 22 : 23 : registerMooseObject("SolidMechanicsApp", GeneralizedPlaneStrainOffDiag); 24 : 25 : InputParameters 26 562 : GeneralizedPlaneStrainOffDiag::validParams() 27 : { 28 562 : InputParameters params = Kernel::validParams(); 29 562 : params.addClassDescription("Generalized Plane Strain kernel to provide contribution of the " 30 : "out-of-plane strain to other kernels"); 31 1124 : params.addRequiredParam<std::vector<VariableName>>("displacements", 32 : "Variable for the displacements"); 33 1124 : params.addCoupledVar("temperature", "Variable for the temperature"); 34 : 35 1124 : params.addCoupledVar("scalar_out_of_plane_strain", 36 : "Scalar variable for generalized plane strain"); 37 1124 : MooseEnum outOfPlaneDirection("x y z", "z"); 38 1124 : params.addParam<MooseEnum>( 39 : "out_of_plane_direction", outOfPlaneDirection, "The direction of the out-of-plane strain."); 40 1124 : params.addParam<UserObjectName>("subblock_index_provider", 41 : "SubblockIndexProvider user object name"); 42 1124 : params.addParam<unsigned int>( 43 : "scalar_out_of_plane_strain_index", 44 : "The index number of scalar_out_of_plane_strain this kernel acts on"); 45 1124 : params.addParam<std::string>("base_name", "Material property base name"); 46 1124 : params.addParam<std::vector<MaterialPropertyName>>( 47 : "eigenstrain_names", {}, "List of eigenstrains to be applied in this strain calculation"); 48 : 49 562 : return params; 50 562 : } 51 : 52 368 : GeneralizedPlaneStrainOffDiag::GeneralizedPlaneStrainOffDiag(const InputParameters & parameters) 53 : : DerivativeMaterialInterface<Kernel>(parameters), 54 368 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 55 736 : _Jacobian_mult(getMaterialProperty<RankFourTensor>(_base_name + "Jacobian_mult")), 56 736 : _eigenstrain_names(getParam<std::vector<MaterialPropertyName>>("eigenstrain_names")), 57 368 : _deigenstrain_dT(_eigenstrain_names.size()), 58 368 : _scalar_out_of_plane_strain_var(coupledScalar("scalar_out_of_plane_strain")), 59 368 : _subblock_id_provider(isParamValid("subblock_index_provider") 60 368 : ? &getUserObject<SubblockIndexProvider>("subblock_index_provider") 61 : : nullptr), 62 368 : _scalar_var_id(isParamValid("scalar_out_of_plane_strain_index") 63 368 : ? getParam<unsigned int>("scalar_out_of_plane_strain_index") 64 : : 0), 65 464 : _temp_var(isCoupled("temperature") ? getVar("temperature", 0) : nullptr), 66 736 : _num_disp_var(getParam<std::vector<VariableName>>("displacements").size()), 67 1104 : _scalar_out_of_plane_strain_direction(getParam<MooseEnum>("out_of_plane_direction")) 68 : { 69 368 : const std::vector<VariableName> & nl_vnames(getParam<std::vector<VariableName>>("displacements")); 70 : 71 368 : if (_scalar_out_of_plane_strain_direction == 2 && _num_disp_var > 2) 72 0 : mooseError("For 1D axisymmetric or 2D cartesian simulations where the out-of-plane direction " 73 : "is z, the number of supplied displacements to GeneralizedPlaneStrainOffDiag must " 74 : "be less than three."); 75 368 : else if (_scalar_out_of_plane_strain_direction != 2 && _num_disp_var != 3) 76 0 : mooseError("For 2D cartesian simulations where the out-of-plane direction is x or y the number " 77 : "of supplied displacements must be three."); 78 : 79 1144 : for (unsigned int i = 0; i < _num_disp_var; ++i) 80 776 : _disp_var.push_back(&_subproblem.getStandardVariable(_tid, nl_vnames[i])); 81 : 82 368 : for (unsigned int i = 0; i < _deigenstrain_dT.size(); ++i) 83 0 : _deigenstrain_dT[i] = &getMaterialPropertyDerivative<RankTwoTensor>( 84 0 : _base_name + _eigenstrain_names[i], _temp_var->name()); 85 : 86 1104 : if (isParamValid("scalar_variable_index_provider") && 87 368 : !isParamValid("scalar_out_of_plane_strain_index")) 88 0 : paramError("scalar_out_of_plane_index", 89 : "scalar_out_of_plane_strain_index should be provided if more " 90 : "than one is available"); 91 736 : if (coupledComponents("temperature") > 1) 92 0 : paramError("temperature", "Only one variable my be specified in 'temperature'"); 93 368 : } 94 : 95 : void 96 1704 : GeneralizedPlaneStrainOffDiag::computeOffDiagJacobianScalar(unsigned int jvar) 97 : { 98 : const unsigned int elem_scalar_var_id = 99 1704 : _subblock_id_provider ? _subblock_id_provider->getSubblockIndex(*_current_elem) : 0; 100 : 101 1704 : if (elem_scalar_var_id == _scalar_var_id) 102 : { 103 1704 : if (_assembly.coordSystem() == Moose::COORD_RZ) 104 0 : _scalar_out_of_plane_strain_direction = 1; 105 : 106 1704 : if (_var.number() == _disp_var[0]->number()) 107 852 : computeDispOffDiagJacobianScalar(0, jvar); 108 852 : else if (_num_disp_var == 2 && _var.number() == _disp_var[1]->number()) 109 820 : computeDispOffDiagJacobianScalar(1, jvar); 110 32 : else if (_temp_var && _var.number() == _temp_var->number()) 111 0 : computeTempOffDiagJacobianScalar(jvar); 112 : } 113 1704 : } 114 : 115 : void 116 1672 : GeneralizedPlaneStrainOffDiag::computeDispOffDiagJacobianScalar(unsigned int component, 117 : unsigned int jvar) 118 : { 119 1672 : if (jvar == _scalar_out_of_plane_strain_var) 120 : { 121 1672 : prepareMatrixTag(_assembly, _var.number(), jvar); 122 1672 : MooseVariableScalar & jv = _sys.getScalarVariable(_tid, jvar); 123 : 124 : // Set appropriate components for scalar kernels, including in the cases where a planar model is 125 : // running in planes other than the x-y plane (defined by _out_of_plane_strain_direction). 126 1672 : if (_scalar_out_of_plane_strain_direction == 0) 127 16 : component += 1; 128 1656 : else if (_scalar_out_of_plane_strain_direction == 1 && component == 1) 129 : component += 1; 130 : 131 8360 : for (_i = 0; _i < _test.size(); ++_i) 132 13376 : for (_j = 0; _j < jv.order(); ++_j) 133 33440 : for (_qp = 0; _qp < _qrule->n_points(); ++_qp) 134 26752 : _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * 135 26752 : _Jacobian_mult[_qp](_scalar_out_of_plane_strain_direction, 136 : _scalar_out_of_plane_strain_direction, 137 : component, 138 26752 : component) * 139 26752 : _grad_test[_i][_qp](component); 140 1672 : accumulateTaggedLocalMatrix(); 141 1672 : _ke_copy = _local_ke; 142 : 143 1672 : prepareMatrixTag(_assembly, jvar, _var.number()); 144 1672 : _ke_copy.get_transpose(_local_ke); 145 1672 : accumulateTaggedLocalMatrix(); 146 : } 147 1672 : } 148 : 149 : void 150 0 : GeneralizedPlaneStrainOffDiag::computeTempOffDiagJacobianScalar(unsigned int jvar) 151 : { 152 0 : if (jvar == _scalar_out_of_plane_strain_var) 153 : { 154 0 : prepareMatrixTag(_assembly, _var.number(), jvar); 155 0 : MooseVariableScalar & jv = _sys.getScalarVariable(_tid, jvar); 156 0 : unsigned int n_eigenstrains = _deigenstrain_dT.size(); 157 : 158 0 : for (_i = 0; _i < _test.size(); ++_i) 159 0 : for (_j = 0; _j < jv.order(); ++_j) 160 0 : for (_qp = 0; _qp < _qrule->n_points(); ++_qp) 161 0 : for (unsigned int ies = 0; ies < n_eigenstrains; ++ies) 162 0 : _local_ke(_i, _j) += 163 0 : _JxW[_qp] * _coord[_qp] * 164 0 : (_Jacobian_mult[_qp] * (*_deigenstrain_dT[ies])[_qp])( 165 0 : _scalar_out_of_plane_strain_direction, _scalar_out_of_plane_strain_direction) * 166 0 : _test[_i][_qp]; 167 0 : accumulateTaggedLocalMatrix(); 168 : } 169 0 : }