LCOV - code coverage report
Current view: top level - src/userobjects - GlobalStrainUserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #32971 (54bef8) with base c6cf66 Lines: 43 49 87.8 %
Date: 2026-05-29 20:40:07 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          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 "GlobalStrainUserObject.h"
      11             : 
      12             : #include "libmesh/quadrature.h"
      13             : 
      14             : registerMooseObject("SolidMechanicsApp", GlobalStrainUserObject);
      15             : 
      16             : InputParameters
      17          64 : GlobalStrainUserObject::validParams()
      18             : {
      19          64 :   InputParameters params = ElementUserObject::validParams();
      20          64 :   params.addClassDescription(
      21             :       "Global Strain UserObject to provide Residual and diagonal Jacobian entry");
      22         128 :   params.addParam<std::vector<Real>>("applied_stress_tensor",
      23             :                                      "Vector of values defining the constant applied stress "
      24             :                                      "to add, in order 11, 22, 33, 23, 13, 12");
      25         128 :   params.addParam<std::string>("base_name", "Material properties base name");
      26         128 :   params.addCoupledVar("displacements", "The name of the displacement variables");
      27          64 :   params.set<ExecFlagEnum>("execute_on") = EXEC_LINEAR;
      28             : 
      29          64 :   return params;
      30           0 : }
      31             : 
      32          32 : GlobalStrainUserObject::GlobalStrainUserObject(const InputParameters & parameters)
      33             :   : ElementUserObject(parameters),
      34             :     GlobalStrainUserObjectInterface(),
      35          32 :     _base_name(isParamValid("base_name") ? getParam<std::string>("base_name") + "_" : ""),
      36          64 :     _dstress_dstrain(getMaterialProperty<RankFourTensor>(_base_name + "Jacobian_mult")),
      37          64 :     _stress(getMaterialProperty<RankTwoTensor>(_base_name + "stress")),
      38          32 :     _dim(_mesh.dimension()),
      39          64 :     _disp_var(getFieldVars("displacements")),
      40          64 :     _periodic_dir()
      41             : {
      42         120 :   for (unsigned int dir = 0; dir < _dim; ++dir)
      43             :   {
      44          88 :     _periodic_dir(dir) = _mesh.isTranslatedPeriodic(*_disp_var[0], dir);
      45             : 
      46         248 :     for (unsigned int i = 1; i < _disp_var.size(); ++i)
      47         160 :       if (_mesh.isTranslatedPeriodic(*_disp_var[i], dir) != _periodic_dir(dir))
      48           0 :         mooseError("All the displacement components in a particular direction should have same "
      49             :                    "periodicity.");
      50             :   }
      51             : 
      52          64 :   if (isParamValid("applied_stress_tensor"))
      53          48 :     _applied_stress_tensor.fillFromInputVector(
      54             :         getParam<std::vector<Real>>("applied_stress_tensor"));
      55             :   else
      56             :     _applied_stress_tensor.zero();
      57          32 : }
      58             : 
      59             : void
      60         400 : GlobalStrainUserObject::initialize()
      61             : {
      62             :   _residual.zero();
      63         400 :   _jacobian.zero();
      64         400 : }
      65             : 
      66             : void
      67        5782 : GlobalStrainUserObject::execute()
      68             : {
      69        5782 :   computeAdditionalStress();
      70             : 
      71       34694 :   for (unsigned int _qp = 0; _qp < _qrule->n_points(); _qp++)
      72             :   {
      73             :     // residual, integral of stress components
      74       28912 :     _residual += _JxW[_qp] * _coord[_qp] * (_stress[_qp] - _applied_stress_tensor);
      75             : 
      76             :     // diagonal jacobian, integral of elasticity tensor components
      77       57824 :     _jacobian += _JxW[_qp] * _coord[_qp] * _dstress_dstrain[_qp];
      78             :   }
      79        5782 : }
      80             : 
      81             : void
      82           0 : GlobalStrainUserObject::threadJoin(const UserObject & uo)
      83             : {
      84             :   const auto & pstuo = static_cast<const GlobalStrainUserObject &>(uo);
      85           0 :   _residual += pstuo._residual;
      86           0 :   _jacobian += pstuo._jacobian;
      87           0 : }
      88             : 
      89             : void
      90         400 : GlobalStrainUserObject::finalize()
      91             : {
      92         400 :   std::vector<Real> residual(9);
      93         400 :   std::vector<Real> jacobian(81);
      94             : 
      95         400 :   std::copy(&_residual(0, 0), &_residual(0, 0) + 9, residual.begin());
      96         400 :   std::copy(&_jacobian(0, 0, 0, 0), &_jacobian(0, 0, 0, 0) + 81, jacobian.begin());
      97             : 
      98             :   gatherSum(residual);
      99             :   gatherSum(jacobian);
     100             : 
     101             :   std::copy(residual.begin(), residual.end(), &_residual(0, 0));
     102             :   std::copy(jacobian.begin(), jacobian.end(), &_jacobian(0, 0, 0, 0));
     103         400 : }
     104             : 
     105             : const RankTwoTensor &
     106          32 : GlobalStrainUserObject::getResidual() const
     107             : {
     108          32 :   return _residual;
     109             : }
     110             : 
     111             : const RankFourTensor &
     112          32 : GlobalStrainUserObject::getJacobian() const
     113             : {
     114          32 :   return _jacobian;
     115             : }
     116             : 
     117             : const VectorValue<bool> &
     118         228 : GlobalStrainUserObject::getPeriodicDirections() const
     119             : {
     120         228 :   return _periodic_dir;
     121             : }

Generated by: LCOV version 1.14