Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://www.mooseframework.org 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 "GeneralizedPlaneStrainUserObject.h" 11 : #include "RankTwoTensor.h" 12 : #include "RankFourTensor.h" 13 : #include "Function.h" 14 : #include "Assembly.h" 15 : #include "UserObjectInterface.h" 16 : 17 : #include "libmesh/quadrature.h" 18 : 19 : registerMooseObject("TensorMechanicsApp", GeneralizedPlaneStrainUserObject); 20 : 21 : InputParameters 22 182 : GeneralizedPlaneStrainUserObject::validParams() 23 : { 24 182 : InputParameters params = ElementUserObject::validParams(); 25 182 : params.addClassDescription( 26 : "Generalized plane strain UserObject to provide residual and diagonal Jacobian entries."); 27 364 : params.addParam<UserObjectName>("subblock_index_provider", 28 : "SubblockIndexProvider user object name"); 29 364 : params.addParam<FunctionName>("out_of_plane_pressure_function", 30 : "Function used to prescribe pressure (applied toward the body) in " 31 : "the out-of-plane direction"); 32 364 : params.addDeprecatedParam<FunctionName>( 33 : "out_of_plane_pressure", 34 : "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction " 35 : "(y for 1D Axisymmetric or z for 2D Cartesian problems)", 36 : "This has been replaced by 'out_of_plane_pressure_function'"); 37 364 : params.addParam<MaterialPropertyName>("out_of_plane_pressure_material", 38 : "0", 39 : "Material used to prescribe pressure (applied toward the " 40 : "body) in the out-of-plane direction"); 41 364 : MooseEnum outOfPlaneDirection("x y z", "z"); 42 364 : params.addParam<MooseEnum>( 43 : "out_of_plane_direction", outOfPlaneDirection, "The direction of the out-of-plane strain."); 44 364 : params.addDeprecatedParam<Real>( 45 : "factor", 46 : "Scale factor applied to prescribed out-of-plane pressure (both material and function)", 47 : "This has been replaced by 'pressure_factor'"); 48 364 : params.addParam<Real>( 49 : "pressure_factor", 50 : "Scale factor applied to prescribed out-of-plane pressure (both material and function)"); 51 364 : params.addParam<std::string>("base_name", "Material properties base name"); 52 728 : params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_NONLINEAR}; 53 : 54 182 : return params; 55 364 : } 56 : 57 91 : GeneralizedPlaneStrainUserObject::GeneralizedPlaneStrainUserObject( 58 91 : const InputParameters & parameters) 59 : : ElementUserObject(parameters), 60 91 : _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""), 61 182 : _Jacobian_mult(getMaterialProperty<RankFourTensor>(_base_name + "Jacobian_mult")), 62 182 : _stress(getMaterialProperty<RankTwoTensor>(_base_name + "stress")), 63 91 : _subblock_id_provider(nullptr), 64 91 : _out_of_plane_pressure_function(parameters.isParamSetByUser("out_of_plane_pressure_function") 65 182 : ? &getFunction("out_of_plane_pressure_function") 66 176 : : parameters.isParamSetByUser("out_of_plane_pressure") 67 91 : ? &getFunction("out_of_plane_pressure") 68 : : nullptr), 69 182 : _out_of_plane_pressure_material(getMaterialProperty<Real>("out_of_plane_pressure_material")), 70 182 : _pressure_factor(parameters.isParamSetByUser("pressure_factor") 71 188 : ? getParam<Real>("pressure_factor") 72 176 : : parameters.isParamSetByUser("factor") ? getParam<Real>("factor") 73 91 : : 1.0) 74 : { 75 182 : if (parameters.isParamSetByUser("out_of_plane_pressure_function") && 76 97 : parameters.isParamSetByUser("out_of_plane_pressure")) 77 0 : mooseError("Cannot specify both 'out_of_plane_pressure_function' and 'out_of_plane_pressure'"); 78 97 : if (parameters.isParamSetByUser("pressure_factor") && parameters.isParamSetByUser("factor")) 79 0 : mooseError("Cannot specify both 'pressure_factor' and 'factor'"); 80 91 : } 81 : 82 : void 83 6925 : GeneralizedPlaneStrainUserObject::initialize() 84 : { 85 13850 : if (isParamValid("subblock_index_provider")) 86 0 : _subblock_id_provider = &getUserObject<SubblockIndexProvider>("subblock_index_provider"); 87 6925 : if (_assembly.coordSystem() == Moose::COORD_XYZ) 88 13370 : _scalar_out_of_plane_strain_direction = getParam<MooseEnum>("out_of_plane_direction"); 89 240 : else if (_assembly.coordSystem() == Moose::COORD_RZ) 90 240 : _scalar_out_of_plane_strain_direction = 1; 91 : else 92 0 : mooseError("Unsupported coordinate system for generalized plane strain formulation"); 93 : 94 6925 : unsigned int max_size = _subblock_id_provider ? _subblock_id_provider->getMaxSubblockIndex() : 1; 95 6925 : _residual.assign(max_size, 0.0); 96 6925 : _reference_residual.assign(max_size, 0.0); 97 6925 : _jacobian.assign(max_size, 0.0); 98 6925 : } 99 : 100 : void 101 17078 : GeneralizedPlaneStrainUserObject::execute() 102 : { 103 : const unsigned int subblock_id = 104 17078 : _subblock_id_provider ? _subblock_id_provider->getSubblockIndex(*_current_elem) : 0; 105 : 106 81118 : for (unsigned int _qp = 0; _qp < _qrule->n_points(); _qp++) 107 : { 108 : const Real out_of_plane_pressure = 109 64040 : ((_out_of_plane_pressure_function 110 64040 : ? _out_of_plane_pressure_function->value(_t, _q_point[_qp]) 111 64040 : : 0.0) + 112 64040 : _out_of_plane_pressure_material[_qp]) * 113 64040 : _pressure_factor; 114 : 115 : // residual, integral of stress_zz for COORD_XYZ 116 64040 : _residual[subblock_id] += _JxW[_qp] * _coord[_qp] * 117 64040 : (_stress[_qp](_scalar_out_of_plane_strain_direction, 118 64040 : _scalar_out_of_plane_strain_direction) + 119 : out_of_plane_pressure); 120 : 121 64040 : _reference_residual[subblock_id] += std::abs( 122 64040 : _JxW[_qp] * _coord[_qp] * 123 64040 : _stress[_qp](_scalar_out_of_plane_strain_direction, _scalar_out_of_plane_strain_direction)); 124 : 125 : // diagonal jacobian, integral of C(2, 2, 2, 2) for COORD_XYZ 126 64040 : _jacobian[subblock_id] += _JxW[_qp] * _coord[_qp] * 127 64040 : _Jacobian_mult[_qp](_scalar_out_of_plane_strain_direction, 128 : _scalar_out_of_plane_strain_direction, 129 : _scalar_out_of_plane_strain_direction, 130 : _scalar_out_of_plane_strain_direction); 131 : } 132 17078 : } 133 : 134 : void 135 0 : GeneralizedPlaneStrainUserObject::threadJoin(const UserObject & uo) 136 : { 137 : const auto & gpsuo = static_cast<const GeneralizedPlaneStrainUserObject &>(uo); 138 0 : for (unsigned int i = 0; i < _residual.size(); ++i) 139 : { 140 0 : _residual[i] += gpsuo._residual[i]; 141 0 : _reference_residual[i] += gpsuo._reference_residual[i]; 142 0 : _jacobian[i] += gpsuo._jacobian[i]; 143 : } 144 0 : } 145 : 146 : void 147 6925 : GeneralizedPlaneStrainUserObject::finalize() 148 : { 149 6925 : gatherSum(_residual); 150 6925 : gatherSum(_reference_residual); 151 6925 : gatherSum(_jacobian); 152 6925 : } 153 : 154 : Real 155 4058 : GeneralizedPlaneStrainUserObject::returnResidual(unsigned int scalar_var_id) const 156 : { 157 4058 : if (_residual.size() <= scalar_var_id) 158 0 : mooseError("Index out of bounds!"); 159 : 160 4058 : return _residual[scalar_var_id]; 161 : } 162 : 163 : Real 164 48 : GeneralizedPlaneStrainUserObject::returnReferenceResidual(unsigned int scalar_var_id) const 165 : { 166 : // At startup, the GeneralizedPlaneStrainReferenceResidual class can ask for this value 167 : // before it has been computed. Return 0.0 in this case. The only way size will stay 168 : // zero is if initialize is never called. 169 48 : if (_reference_residual.size() == 0) 170 : return 0.0; 171 : 172 48 : if (_residual.size() <= scalar_var_id) 173 0 : mooseError("Index out of bounds!"); 174 : 175 48 : return _reference_residual[scalar_var_id]; 176 : } 177 : 178 : Real 179 486 : GeneralizedPlaneStrainUserObject::returnJacobian(unsigned int scalar_var_id) const 180 : { 181 486 : if (_jacobian.size() <= scalar_var_id) 182 0 : mooseError("Index out of bounds!"); 183 : 184 486 : return _jacobian[scalar_var_id]; 185 : }