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 "GlobalStrain.h" 11 : #include "GlobalStrainUserObjectInterface.h" 12 : 13 : // MOOSE includes 14 : #include "Assembly.h" 15 : #include "MooseVariableScalar.h" 16 : #include "SystemBase.h" 17 : #include "RankTwoTensor.h" 18 : #include "RankFourTensor.h" 19 : 20 : using namespace libMesh; 21 : 22 : registerMooseObject("SolidMechanicsApp", GlobalStrain); 23 : 24 : InputParameters 25 96 : GlobalStrain::validParams() 26 : { 27 96 : InputParameters params = ScalarKernel::validParams(); 28 96 : params.addClassDescription("Scalar Kernel to solve for the global strain"); 29 192 : params.addRequiredParam<UserObjectName>("global_strain_uo", 30 : "The name of the GlobalStrainUserObject"); 31 : 32 96 : return params; 33 0 : } 34 : 35 48 : GlobalStrain::GlobalStrain(const InputParameters & parameters) 36 : : ScalarKernel(parameters), 37 48 : _pst(getUserObject<GlobalStrainUserObjectInterface>("global_strain_uo")), 38 48 : _pst_residual(_pst.getResidual()), 39 48 : _pst_jacobian(_pst.getJacobian()), 40 48 : _periodic_dir(_pst.getPeriodicDirections()), 41 48 : _components(_var.order()), 42 96 : _dim(_mesh.dimension()) 43 : { 44 48 : if ((_dim == 1 && _var.order() != FIRST) || (_dim == 2 && _var.order() != THIRD) || 45 48 : (_dim == 3 && _var.order() != SIXTH)) 46 0 : mooseError("PerdiodicStrain ScalarKernel is only compatible with scalar variables of order " 47 : "FIRST in 1D, THIRD in 2D, and SIXTH in 3D. Please change the order of the scalar" 48 : "variable according to the mesh dimension."); 49 : 50 48 : assignComponentIndices(_var.order()); 51 48 : } 52 : 53 : void 54 260 : GlobalStrain::computeResidual() 55 : { 56 260 : prepareVectorTag(_assembly, _var.number()); 57 1646 : for (_i = 0; _i < _local_re.size(); ++_i) 58 : { 59 1386 : if (_periodic_dir(_components[_i].first) || _periodic_dir(_components[_i].second)) 60 1050 : _local_re(_i) += _pst_residual(_components[_i].first, _components[_i].second); 61 : } 62 260 : accumulateTaggedLocalResidual(); 63 260 : } 64 : 65 : void 66 62 : GlobalStrain::computeJacobian() 67 : { 68 62 : prepareMatrixTag(_assembly, _var.number(), _var.number()); 69 392 : for (_i = 0; _i < _local_ke.m(); ++_i) 70 2184 : for (_j = 0; _j < _local_ke.m(); ++_j) 71 : // periodic direction check is not done for jacobian calculations to avoid zero pivot error 72 1854 : _local_ke(_i, _j) += _pst_jacobian(_components[_i].first, 73 1854 : _components[_i].second, 74 : _components[_j].first, 75 1854 : _components[_j].second); 76 62 : accumulateTaggedLocalMatrix(); 77 62 : } 78 : 79 : void 80 48 : GlobalStrain::assignComponentIndices(Order order) 81 : { 82 48 : switch (order) 83 : { 84 0 : case 1: 85 0 : _components[0].first = 0; 86 0 : _components[0].second = 0; 87 0 : break; 88 : 89 12 : case 3: 90 12 : _components[0].first = 0; 91 12 : _components[0].second = 0; 92 12 : _components[1].first = 1; 93 12 : _components[1].second = 1; 94 12 : _components[2].first = 0; 95 12 : _components[2].second = 1; 96 12 : break; 97 : 98 36 : case 6: 99 36 : _components[0].first = 0; 100 36 : _components[0].second = 0; 101 36 : _components[1].first = 1; 102 36 : _components[1].second = 1; 103 36 : _components[2].first = 2; 104 36 : _components[2].second = 2; 105 36 : _components[3].first = 1; 106 36 : _components[3].second = 2; 107 36 : _components[4].first = 0; 108 36 : _components[4].second = 2; 109 36 : _components[5].first = 0; 110 36 : _components[5].second = 1; 111 36 : break; 112 : 113 0 : default: 114 0 : mooseError("PerdiodicStrain ScalarKernel is only compatible with FIRST, THIRD, and SIXTH " 115 : "order scalar variables."); 116 : } 117 48 : }