LCOV - code coverage report
Current view: top level - src/postprocessors - TorqueReaction.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 36 40 90.0 %
Date: 2024-02-27 11:53:14 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          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 "TorqueReaction.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "AuxiliarySystem.h"
      14             : #include "MooseVariable.h"
      15             : 
      16             : registerMooseObject("TensorMechanicsApp", TorqueReaction);
      17             : 
      18             : InputParameters
      19          18 : TorqueReaction::validParams()
      20             : {
      21          18 :   InputParameters params = NodalPostprocessor::validParams();
      22          18 :   params.addClassDescription("TorqueReaction calculates the torque in 2D and 3D"
      23             :                              "about a user-specified axis of rotation centered"
      24             :                              "at a user-specified origin.");
      25          36 :   params.addRequiredParam<std::vector<AuxVariableName>>("reaction_force_variables",
      26             :                                                         "The reaction variables");
      27          18 :   params.addParam<RealVectorValue>(
      28          18 :       "axis_origin", Point(), "Origin of the axis of rotation used to calculate the torque");
      29          36 :   params.addRequiredParam<RealVectorValue>("direction_vector",
      30             :                                            "The direction vector of the axis "
      31             :                                            "of rotation about which the "
      32             :                                            "calculated torque is calculated");
      33          18 :   params.set<bool>("use_displaced_mesh") = true;
      34          18 :   return params;
      35           0 : }
      36             : 
      37           9 : TorqueReaction::TorqueReaction(const InputParameters & parameters)
      38             :   : NodalPostprocessor(parameters),
      39           9 :     _aux(_fe_problem.getAuxiliarySystem()),
      40           9 :     _axis_origin(getParam<RealVectorValue>("axis_origin")),
      41          18 :     _direction_vector(getParam<RealVectorValue>("direction_vector"))
      42             : {
      43             :   std::vector<AuxVariableName> reacts =
      44          27 :       getParam<std::vector<AuxVariableName>>("reaction_force_variables");
      45           9 :   _nrt = reacts.size();
      46             : 
      47          33 :   for (unsigned int i = 0; i < _nrt; ++i)
      48          24 :     _react.push_back(&_aux.getFieldVariable<Real>(_tid, reacts[i]).dofValues());
      49           9 : }
      50             : 
      51             : void
      52          18 : TorqueReaction::initialize()
      53             : {
      54          18 :   _sum = 0.0;
      55          18 : }
      56             : 
      57             : void
      58         152 : TorqueReaction::execute()
      59             : {
      60             :   // Tranform the node coordinates into the coordinate system specified by the user
      61         152 :   Point position = (*_current_node) - _axis_origin;
      62             : 
      63             :   // Determine the component of the vector in the direction of the rotation direction vector
      64             :   Point normal_position_component =
      65         152 :       position - (position * _direction_vector) / _direction_vector.norm_sq() * _direction_vector;
      66             : 
      67             :   // Define the force vector from the reaction force/ residuals from the stress divergence kernel
      68             :   Real _rz;
      69         152 :   if (_nrt == 3)
      70         144 :     _rz = (*_react[2])[_qp];
      71             :   else
      72             :     _rz = 0.0;
      73             : 
      74         152 :   Point force((*_react[0])[_qp], (*_react[1])[_qp], _rz);
      75             : 
      76             :   // Cross the normal component of the position vector with the force
      77         152 :   RealVectorValue torque = normal_position_component.cross(force);
      78             : 
      79             :   // Find the component of the torque vector acting along the given axis of rotation direction
      80             :   // vector
      81             :   RealVectorValue parallel_torque_component =
      82         152 :       (torque * _direction_vector) / _direction_vector.norm_sq() * _direction_vector;
      83             : 
      84             :   // Add the magnitude of the parallel torque component to the sum of the acting torques
      85         152 :   _sum += parallel_torque_component.norm();
      86         152 : }
      87             : 
      88             : Real
      89          18 : TorqueReaction::getValue() const
      90             : {
      91          18 :   return _sum;
      92             : }
      93             : 
      94             : void
      95          18 : TorqueReaction::finalize()
      96             : {
      97          18 :   gatherSum(_sum);
      98          18 : }
      99             : 
     100             : void
     101           0 : TorqueReaction::threadJoin(const UserObject & y)
     102             : {
     103             :   const auto & pps = static_cast<const TorqueReaction &>(y);
     104           0 :   _sum += pps._sum;
     105           0 : }

Generated by: LCOV version 1.14