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 "TorqueReaction.h" 11 : 12 : // MOOSE includes 13 : #include "AuxiliarySystem.h" 14 : #include "MooseVariable.h" 15 : 16 : registerMooseObject("SolidMechanicsApp", TorqueReaction); 17 : 18 : InputParameters 19 36 : TorqueReaction::validParams() 20 : { 21 36 : InputParameters params = NodalPostprocessor::validParams(); 22 36 : 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 72 : params.addRequiredParam<std::vector<AuxVariableName>>("reaction_force_variables", 26 : "The reaction variables"); 27 36 : params.addParam<RealVectorValue>( 28 36 : "axis_origin", Point(), "Origin of the axis of rotation used to calculate the torque"); 29 72 : params.addRequiredParam<RealVectorValue>("direction_vector", 30 : "The direction vector of the axis " 31 : "of rotation about which the " 32 : "calculated torque is calculated"); 33 36 : params.set<bool>("use_displaced_mesh") = true; 34 36 : return params; 35 0 : } 36 : 37 18 : TorqueReaction::TorqueReaction(const InputParameters & parameters) 38 : : NodalPostprocessor(parameters), 39 18 : _aux(_fe_problem.getAuxiliarySystem()), 40 18 : _axis_origin(getParam<RealVectorValue>("axis_origin")), 41 36 : _direction_vector(getParam<RealVectorValue>("direction_vector")) 42 : { 43 : std::vector<AuxVariableName> reacts = 44 54 : getParam<std::vector<AuxVariableName>>("reaction_force_variables"); 45 18 : _nrt = reacts.size(); 46 : 47 66 : for (unsigned int i = 0; i < _nrt; ++i) 48 48 : _react.push_back(&_aux.getFieldVariable<Real>(_tid, reacts[i]).dofValues()); 49 18 : } 50 : 51 : void 52 36 : TorqueReaction::initialize() 53 : { 54 36 : _sum = 0.0; 55 36 : } 56 : 57 : void 58 304 : TorqueReaction::execute() 59 : { 60 : // Tranform the node coordinates into the coordinate system specified by the user 61 304 : 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 304 : 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 304 : if (_nrt == 3) 70 288 : _rz = (*_react[2])[_qp]; 71 : else 72 : _rz = 0.0; 73 : 74 304 : Point force((*_react[0])[_qp], (*_react[1])[_qp], _rz); 75 : 76 : // Cross the normal component of the position vector with the force 77 304 : 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 304 : (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 304 : _sum += parallel_torque_component.norm(); 86 304 : } 87 : 88 : Real 89 36 : TorqueReaction::getValue() const 90 : { 91 36 : return _sum; 92 : } 93 : 94 : void 95 36 : TorqueReaction::finalize() 96 : { 97 36 : gatherSum(_sum); 98 36 : } 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 : }