LCOV - code coverage report
Current view: top level - src/kernels - MomentBalancing.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 44 47 93.6 %
Date: 2025-07-25 05:00:39 Functions: 5 5 100.0 %
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 "MomentBalancing.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "ElasticityTensorTools.h"
      14             : #include "Material.h"
      15             : #include "MooseVariable.h"
      16             : #include "PermutationTensor.h"
      17             : #include "RankFourTensor.h"
      18             : #include "RankTwoTensor.h"
      19             : 
      20             : registerMooseObject("SolidMechanicsApp", MomentBalancing);
      21             : 
      22             : InputParameters
      23        1182 : MomentBalancing::validParams()
      24             : {
      25        1182 :   InputParameters params = Kernel::validParams();
      26        1182 :   params.addClassDescription("Balance of momentum for three-dimensional Cosserat media, notably in "
      27             :                              "a Cosserat layered elasticity model.");
      28        2364 :   params.addRequiredRangeCheckedParam<unsigned int>(
      29             :       "component",
      30             :       "component<3",
      31             :       "An integer corresponding to the direction the variable this "
      32             :       "kernel acts in. (0 for x, 1 for y, 2 for z)");
      33        2364 :   params.addParam<std::string>(
      34             :       "appended_property_name", "", "Name appended to material properties to make them unique");
      35        2364 :   params.addRequiredCoupledVar("Cosserat_rotations", "The 3 Cosserat rotation variables");
      36        2364 :   params.addRequiredCoupledVar("displacements", "The 3 displacement variables");
      37        1182 :   params.set<bool>("use_displaced_mesh") = false;
      38             : 
      39        1182 :   return params;
      40           0 : }
      41             : 
      42         590 : MomentBalancing::MomentBalancing(const InputParameters & parameters)
      43             :   : Kernel(parameters),
      44        1180 :     _stress(getMaterialProperty<RankTwoTensor>("stress" +
      45             :                                                getParam<std::string>("appended_property_name"))),
      46         590 :     _Jacobian_mult(getMaterialProperty<RankFourTensor>(
      47        1180 :         "Jacobian_mult" + getParam<std::string>("appended_property_name"))),
      48        1180 :     _component(getParam<unsigned int>("component")),
      49         590 :     _nrots(coupledComponents("Cosserat_rotations")),
      50         590 :     _wc_var(_nrots),
      51         590 :     _ndisp(coupledComponents("displacements")),
      52        1180 :     _disp_var(_ndisp)
      53             : {
      54         590 :   if (_nrots != 3)
      55           0 :     mooseError("MomentBalancing: This Kernel is only defined for 3-dimensional simulations so 3 "
      56             :                "Cosserat rotation variables are needed");
      57        2360 :   for (unsigned i = 0; i < _nrots; ++i)
      58        1770 :     _wc_var[i] = coupled("Cosserat_rotations", i);
      59             : 
      60         590 :   if (_ndisp != 3)
      61           0 :     mooseError("MomentBalancing: This Kernel is only defined for 3-dimensional simulations so 3 "
      62             :                "displacement variables are needed");
      63        2360 :   for (unsigned i = 0; i < _ndisp; ++i)
      64        1770 :     _disp_var[i] = coupled("displacements", i);
      65             : 
      66             :   // Following check is necessary to ensure the correct Jacobian is calculated
      67         590 :   if (_wc_var[_component] != _var.number())
      68           2 :     mooseError("MomentBalancing: The variable for this Kernel must be equal to the Cosserat "
      69             :                "rotation variable defined by the \"component\" and the \"Cosserat_rotations\" "
      70             :                "parameters");
      71         588 : }
      72             : 
      73             : Real
      74     1670656 : MomentBalancing::computeQpResidual()
      75             : {
      76             :   Real the_sum = 0.0;
      77     6682624 :   for (const auto j : make_range(Moose::dim))
      78    20047872 :     for (const auto k : make_range(Moose::dim))
      79    15035904 :       the_sum += PermutationTensor::eps(_component, j, k) * _stress[_qp](j, k);
      80     1670656 :   return _test[_i][_qp] * the_sum;
      81             : }
      82             : 
      83             : Real
      84     5238784 : MomentBalancing::computeQpJacobian()
      85             : {
      86     5238784 :   return ElasticityTensorTools::momentJacobianWC(
      87     5238784 :       _Jacobian_mult[_qp], _component, _component, _test[_i][_qp], _phi[_j][_qp]);
      88             : }
      89             : 
      90             : Real
      91    17534976 : MomentBalancing::computeQpOffDiagJacobian(unsigned int jvar)
      92             : {
      93             :   // What does 2D look like here?
      94    45895680 :   for (unsigned v = 0; v < _ndisp; ++v)
      95    41680896 :     if (jvar == _disp_var[v])
      96    13320192 :       return ElasticityTensorTools::momentJacobian(
      97    13320192 :           _Jacobian_mult[_qp], _component, v, _test[_i][_qp], _grad_phi[_j][_qp]);
      98             : 
      99             :   // What does 2D look like here?
     100     7858176 :   for (unsigned v = 0; v < _nrots; ++v)
     101     7858176 :     if (jvar == _wc_var[v])
     102     4214784 :       return ElasticityTensorTools::momentJacobianWC(
     103     4214784 :           _Jacobian_mult[_qp], _component, v, _test[_i][_qp], _phi[_j][_qp]);
     104             : 
     105             :   return 0.0;
     106             : }

Generated by: LCOV version 1.14