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