LCOV - code coverage report
Current view: top level - src/bcs - Torque.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 44 52 84.6 %
Date: 2025-07-25 05:00:39 Functions: 8 12 66.7 %
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 "Torque.h"
      11             : #include "Function.h"
      12             : 
      13             : registerMooseObject("SolidMechanicsApp", Torque);
      14             : registerMooseObject("SolidMechanicsApp", ADTorque);
      15             : 
      16             : template <bool is_ad>
      17             : InputParameters
      18         186 : TorqueTempl<is_ad>::validParams()
      19             : {
      20         186 :   InputParameters params = TorqueParent<is_ad>::validParams();
      21         186 :   params.addClassDescription(
      22             :       "Apply a moment as tractions distributed over a surface around a "
      23             :       "pivot point. This should operate on the displaced mesh for large deformations.");
      24         372 :   MooseEnum component("x=0 y=1 z=2");
      25         372 :   params.addRequiredParam<Point>(
      26             :       "origin", "Reference point defining the location for the axis the torque is applied to");
      27         372 :   params.addRequiredParam<RealVectorValue>("direction", "Torque vector");
      28         372 :   params.addParam<FunctionName>(
      29             :       "factor", "1", "Prefactor for the force (can only be time dependent)");
      30         372 :   params.addRequiredParam<PostprocessorName>(
      31             :       "polar_moment_of_inertia", "Postprocessor that computes the polar moment of inertia");
      32         372 :   params.addParam<Real>("alpha", 0.0, "alpha parameter required for HHT time integration scheme");
      33         372 :   params.addParamNamesToGroup("alpha factor", "Advanced");
      34         372 :   params.addCoupledVar("displacements", "The displacements");
      35         186 :   return params;
      36         186 : }
      37             : 
      38             : template <bool is_ad>
      39          90 : TorqueTempl<is_ad>::TorqueTempl(const InputParameters & parameters)
      40             :   : TorqueParent<is_ad>(parameters),
      41          90 :     _component(libMesh::invalid_uint),
      42          90 :     _origin(this->template getParam<Point>("origin")),
      43         180 :     _torque(this->template getParam<RealVectorValue>("direction")),
      44          90 :     _factor(this->getFunction("factor")),
      45         180 :     _alpha(this->template getParam<Real>("alpha")),
      46          90 :     _pmi(this->getPostprocessorValue("polar_moment_of_inertia")),
      47          90 :     _ndisp(this->coupledComponents("displacements")),
      48          90 :     _dvars(_ndisp),
      49          90 :     _dummy_point()
      50             : {
      51         360 :   for (unsigned int i = 0; i < _ndisp; ++i)
      52             :   {
      53         270 :     _dvars[i] = this->getVar("displacements", i)->number();
      54         270 :     if (this->_var.number() == _dvars[i])
      55          90 :       _component = i;
      56             :   }
      57             : 
      58          90 :   if (_component == libMesh::invalid_uint)
      59           0 :     this->paramError("variable",
      60             :                      "The kernel variable needs to be one of the 'displacements' variables");
      61         180 :   if (this->template getParam<bool>("use_displaced_mesh"))
      62           0 :     this->paramError("use_displaced_mesh", "This BC is only validated for small strains");
      63          90 : }
      64             : 
      65             : template <>
      66             : ADReal
      67       57600 : TorqueTempl<true>::computeQpResidual()
      68             : {
      69             :   // local lever (distance to the origin)
      70       57600 :   auto local_lever = this->_ad_q_points[_qp] - _origin;
      71             : 
      72             :   // force calculation
      73             :   auto local_force =
      74       57600 :       _factor.value(_t + _alpha * _dt, _dummy_point) * _torque.cross(local_lever) / _pmi;
      75             : 
      76      115200 :   return -local_force(_component) * _test[_i][_qp];
      77             : }
      78             : 
      79             : template <>
      80             : Real
      81    19440000 : TorqueTempl<false>::computeQpResidual()
      82             : {
      83             :   // local lever (distance to the origin)
      84    19440000 :   auto local_lever = this->_q_point[_qp] - _origin;
      85             : 
      86             :   // force calculation
      87             :   auto local_force =
      88    19440000 :       _factor.value(_t + _alpha * _dt, _dummy_point) * _torque.cross(local_lever) / _pmi;
      89             : 
      90    19440000 :   return -local_force(_component) * _test[_i][_qp];
      91             : }
      92             : 
      93             : template <>
      94             : Real
      95      875520 : TorqueTempl<false>::componentJacobian(unsigned int component)
      96             : {
      97             :   // vector phi
      98             :   RealGradient phi;
      99      875520 :   phi(component) = this->_phi[_j][_qp];
     100             : 
     101             :   // force calculation
     102      875520 :   auto d_local_force = _factor.value(_t + _alpha * _dt, _dummy_point) * _torque.cross(phi) / _pmi;
     103      875520 :   return -d_local_force(_component) * _test[_i][_qp];
     104             : }
     105             : 
     106             : template <>
     107             : Real
     108           0 : TorqueTempl<true>::componentJacobian(unsigned int)
     109             : {
     110           0 :   mooseError("This should never get called");
     111             : }
     112             : 
     113             : template <bool is_ad>
     114             : Real
     115      875520 : TorqueTempl<is_ad>::computeQpJacobian()
     116             : {
     117      875520 :   return componentJacobian(_component);
     118             : }
     119             : 
     120             : template <bool is_ad>
     121             : Real
     122           0 : TorqueTempl<is_ad>::computeQpOffDiagJacobian(unsigned int jvar)
     123             : {
     124           0 :   for (unsigned int i = 0; i < _ndisp; ++i)
     125           0 :     if (jvar == _dvars[i])
     126           0 :       return componentJacobian(i);
     127             : 
     128             :   return 0.0;
     129             : }
     130             : 
     131             : template class TorqueTempl<false>;
     132             : template class TorqueTempl<true>;

Generated by: LCOV version 1.14