LCOV - code coverage report
Current view: top level - src/auxkernels - RadialDisplacementCylinderAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #32971 (54bef8) with base c6cf66 Lines: 47 59 79.7 %
Date: 2026-05-29 20:40:07 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 "RadialDisplacementCylinderAux.h"
      11             : #include "MooseMesh.h"
      12             : 
      13             : registerMooseObject("SolidMechanicsApp", RadialDisplacementCylinderAux);
      14             : 
      15             : InputParameters
      16          26 : RadialDisplacementCylinderAux::validParams()
      17             : {
      18          26 :   InputParameters params = AuxKernel::validParams();
      19          26 :   params.addClassDescription(
      20             :       "Compute the radial component of the displacement vector for cylindrical models.");
      21          52 :   params.addRequiredCoupledVar(
      22             :       "displacements",
      23             :       "The displacements appropriate for the simulation geometry and coordinate system");
      24          52 :   params.addParam<RealVectorValue>(
      25             :       "origin", "Origin of cylinder axis of rotation for 2D and 3D Cartesian models");
      26          52 :   params.addParam<RealVectorValue>(
      27             :       "axis_vector", "Vector defining direction of cylindrical axis (3D Cartesian models)");
      28          26 :   params.set<bool>("use_displaced_mesh") = false;
      29             : 
      30          26 :   return params;
      31           0 : }
      32             : 
      33          14 : RadialDisplacementCylinderAux::RadialDisplacementCylinderAux(const InputParameters & parameters)
      34             :   : AuxKernel(parameters),
      35          14 :     _ndisp(coupledComponents("displacements")),
      36          42 :     _disp_vals(coupledValues("displacements"))
      37             : {
      38          14 :   const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
      39             :   const auto & sbd_begin = *subdomains.begin();
      40          28 :   for (const auto & sbd : subdomains)
      41             :   {
      42          14 :     if (sbd == sbd_begin)
      43          14 :       _coord_system = _subproblem.getCoordSystem(sbd);
      44           0 :     else if (_subproblem.getCoordSystem(sbd) != _coord_system)
      45           0 :       mooseError("RadialDisplacementCylinderAux requires that all subdomains have the same "
      46             :                  "coordinate type");
      47             :   }
      48             : 
      49          14 :   if (_ndisp != _mesh.dimension())
      50           0 :     mooseError("The number of displacement variables supplied must match the mesh dimension.");
      51             : 
      52          14 :   if (_coord_system == Moose::COORD_XYZ && _ndisp == 1)
      53           0 :     mooseError("RadialDisplacmentCylinderAux is not applicable for 1D Cartesian models");
      54             : 
      55          14 :   else if (!(_coord_system == Moose::COORD_XYZ || _coord_system == Moose::COORD_RZ))
      56           0 :     mooseError("RadialDisplacementCylinderAux can only be used with Cartesian or axisymmetric "
      57             :                "coordinate systems");
      58             : 
      59          28 :   if (isParamValid("origin"))
      60             :   {
      61           9 :     if (_coord_system != Moose::COORD_XYZ)
      62           0 :       mooseError("The 'origin' parameter is only valid for Cartesian models.");
      63             : 
      64          18 :     _origin = getParam<RealVectorValue>("origin");
      65             :   }
      66           5 :   else if (_coord_system == Moose::COORD_XYZ)
      67           0 :     mooseError("Must specify 'origin' for models with Cartesian coordinate systems.");
      68             : 
      69          28 :   if (isParamValid("axis_vector"))
      70             :   {
      71           6 :     if (!(_coord_system == Moose::COORD_XYZ && _ndisp == 3))
      72           1 :       mooseError("The 'axis_vector' parameter is only valid for 3D Cartesian models.");
      73             : 
      74          10 :     _axis_vector = getParam<RealVectorValue>("axis_vector");
      75           5 :     Real vec_len = _axis_vector.norm();
      76           5 :     if (MooseUtils::absoluteFuzzyEqual(vec_len, 0.0))
      77           1 :       mooseError("axis_vector must have nonzero length");
      78             :     _axis_vector /= vec_len;
      79             :   }
      80           8 :   else if (_coord_system == Moose::COORD_XYZ && _ndisp == 3)
      81           0 :     mooseError("Must specify 'axis_vector' for 3D Cartesian models");
      82             : 
      83          12 :   if (!isNodal())
      84           0 :     mooseError("Must run on a nodal variable");
      85          12 : }
      86             : 
      87             : Real
      88      334025 : RadialDisplacementCylinderAux::computeValue()
      89             : {
      90             :   Real rad_disp = 0.0;
      91      334025 :   Point current_point(*_current_node);
      92             : 
      93      334025 :   switch (_coord_system)
      94             :   {
      95             :     case Moose::COORD_XYZ:
      96             :     {
      97             :       RealVectorValue rad_vec;
      98             :       const RealVectorValue disp_vec((*_disp_vals[0])[_qp],
      99             :                                      (*_disp_vals[1])[_qp],
     100      328350 :                                      (_ndisp == 3 ? (*_disp_vals[2])[_qp] : 0.0));
     101             : 
     102      328350 :       if (_ndisp == 2)
     103       23250 :         rad_vec = current_point - _origin;
     104      305100 :       else if (_ndisp == 3)
     105             :       {
     106             :         // t is the distance along the axis from point 1 to 2 to the point nearest to the current
     107             :         // point.
     108             :         const RealVectorValue p1pc(current_point - _origin);
     109             :         const Real t = p1pc * _axis_vector;
     110             : 
     111             :         // The nearest point on the cylindrical axis to current_point is p.
     112             :         const RealVectorValue p(_origin + t * _axis_vector);
     113      305100 :         rad_vec = current_point - p;
     114             :       }
     115             : 
     116      328350 :       Real rad = rad_vec.norm();
     117      328350 :       if (rad > 0.0)
     118             :       {
     119             :         rad_vec /= rad;
     120             :         rad_disp = rad_vec * disp_vec;
     121             :       }
     122             :       else
     123        4378 :         rad_disp = disp_vec.norm();
     124             :       break;
     125             :     }
     126        5675 :     case Moose::COORD_RZ:
     127        5675 :       rad_disp = (*_disp_vals[0])[_qp];
     128        5675 :       break;
     129           0 :     default:
     130           0 :       mooseError("Unsupported coordinate system");
     131             :   }
     132             : 
     133      334025 :   return rad_disp;
     134             : }

Generated by: LCOV version 1.14