LCOV - code coverage report
Current view: top level - src/auxkernels - RotationAngle.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: f45d79 Lines: 26 30 86.7 %
Date: 2025-07-25 05:00:39 Functions: 3 3 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 "RotationAngle.h"
      11             : 
      12             : registerMooseObject("SolidMechanicsApp", RotationAngle);
      13             : 
      14             : InputParameters
      15          62 : RotationAngle::validParams()
      16             : {
      17          62 :   InputParameters params = AuxKernel::validParams();
      18         124 :   params.addRequiredParam<Point>("origin", "Axis origin");
      19         124 :   params.addRequiredParam<RealVectorValue>("direction", "Axis direction");
      20          62 :   params.addClassDescription("Compute the field of angular rotations of points around an axis "
      21             :                              "defined by an origin point and a direction vector");
      22         124 :   params.addRequiredCoupledVar("displacements", "The displacements");
      23          62 :   params.set<bool>("use_displaced_mesh") = false;
      24          62 :   return params;
      25           0 : }
      26             : 
      27          30 : RotationAngle::RotationAngle(const InputParameters & parameters)
      28             :   : AuxKernel(parameters),
      29          30 :     _origin(getParam<Point>("origin")),
      30          60 :     _direction(getParam<RealVectorValue>("direction")),
      31          60 :     _disp(coupledValues("displacements"))
      32             : {
      33             :   // normalize direction
      34          30 :   _direction /= _direction.norm();
      35             : 
      36             :   // sanity checks
      37          60 :   if (getParam<bool>("use_displaced_mesh"))
      38           0 :     paramError("use_displaced_mesh", "This AuxKernel must be run on the undisplaced mesh");
      39          30 :   if (!isNodal())
      40           0 :     paramError("variable", "This AuxKernel must operate on a nodal variable");
      41          30 :   if (_disp.size() > LIBMESH_DIM)
      42           0 :     paramError("displacements",
      43             :                "Too many displacement variables were specified. The max is LIBMESH_DIM, which is ",
      44             :                LIBMESH_DIM);
      45          30 : }
      46             : 
      47             : Real
      48     2441520 : RotationAngle::computeValue()
      49             : {
      50             :   // displacement vector
      51             :   RealVectorValue delta;
      52     9766080 :   for (unsigned int i = 0; i < _disp.size(); ++i)
      53     7324560 :     delta(i) = (*_disp[i])[_qp];
      54             : 
      55             :   // undisplaced and displaced locations relative to the origin.
      56     2441520 :   RealVectorValue dr1 = *_current_node - _origin;
      57             :   RealVectorValue dr2 = dr1 + delta;
      58             : 
      59             :   // subtract out of plane projections
      60     2441520 :   dr1 -= _direction * (_direction * dr1);
      61     2441520 :   dr2 -= _direction * (_direction * dr2);
      62             : 
      63             :   // product of the lengths
      64     2441520 :   auto norms = std::sqrt(dr1.norm_sq() * dr2.norm_sq());
      65             : 
      66             :   // angle between dr1 and dr2
      67     2441520 :   if (norms > libMesh::TOLERANCE)
      68     3189810 :     return std::acos((dr1 * dr2) / norms) * ((dr1.cross(dr2) * _direction) > 0 ? 1.0 : -1.0);
      69             :   else
      70             :     return 0.0;
      71             : }

Generated by: LCOV version 1.14