LCOV - code coverage report
Current view: top level - src/auxkernels - RadialDisplacementCylinderAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose solid_mechanics: #31405 (292dce) with base fef103 Lines: 47 59 79.7 %
Date: 2025-09-04 07:57:23 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          46 : RadialDisplacementCylinderAux::validParams()
      17             : {
      18          46 :   InputParameters params = AuxKernel::validParams();
      19          46 :   params.addClassDescription(
      20             :       "Compute the radial component of the displacement vector for cylindrical models.");
      21          92 :   params.addRequiredCoupledVar(
      22             :       "displacements",
      23             :       "The displacements appropriate for the simulation geometry and coordinate system");
      24          92 :   params.addParam<RealVectorValue>(
      25             :       "origin", "Origin of cylinder axis of rotation for 2D and 3D Cartesian models");
      26          92 :   params.addParam<RealVectorValue>(
      27             :       "axis_vector", "Vector defining direction of cylindrical axis (3D Cartesian models)");
      28          46 :   params.set<bool>("use_displaced_mesh") = false;
      29             : 
      30          46 :   return params;
      31           0 : }
      32             : 
      33          25 : RadialDisplacementCylinderAux::RadialDisplacementCylinderAux(const InputParameters & parameters)
      34             :   : AuxKernel(parameters),
      35          25 :     _ndisp(coupledComponents("displacements")),
      36          75 :     _disp_vals(coupledValues("displacements"))
      37             : {
      38          25 :   const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
      39             :   const auto & sbd_begin = *subdomains.begin();
      40          50 :   for (const auto & sbd : subdomains)
      41             :   {
      42          25 :     if (sbd == sbd_begin)
      43          25 :       _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          25 :   if (_ndisp != _mesh.dimension())
      50           0 :     mooseError("The number of displacement variables supplied must match the mesh dimension.");
      51             : 
      52          25 :   if (_coord_system == Moose::COORD_XYZ && _ndisp == 1)
      53           0 :     mooseError("RadialDisplacmentCylinderAux is not applicable for 1D Cartesian models");
      54             : 
      55          25 :   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          50 :   if (isParamValid("origin"))
      60             :   {
      61          16 :     if (_coord_system != Moose::COORD_XYZ)
      62           0 :       mooseError("The 'origin' parameter is only valid for Cartesian models.");
      63             : 
      64          32 :     _origin = getParam<RealVectorValue>("origin");
      65             :   }
      66           9 :   else if (_coord_system == Moose::COORD_XYZ)
      67           0 :     mooseError("Must specify 'origin' for models with Cartesian coordinate systems.");
      68             : 
      69          50 :   if (isParamValid("axis_vector"))
      70             :   {
      71          11 :     if (!(_coord_system == Moose::COORD_XYZ && _ndisp == 3))
      72           2 :       mooseError("The 'axis_vector' parameter is only valid for 3D Cartesian models.");
      73             : 
      74          18 :     _axis_vector = getParam<RealVectorValue>("axis_vector");
      75           9 :     Real vec_len = _axis_vector.norm();
      76           9 :     if (MooseUtils::absoluteFuzzyEqual(vec_len, 0.0))
      77           2 :       mooseError("axis_vector must have nonzero length");
      78             :     _axis_vector /= vec_len;
      79             :   }
      80          14 :   else if (_coord_system == Moose::COORD_XYZ && _ndisp == 3)
      81           0 :     mooseError("Must specify 'axis_vector' for 3D Cartesian models");
      82             : 
      83          21 :   if (!isNodal())
      84           0 :     mooseError("Must run on a nodal variable");
      85          21 : }
      86             : 
      87             : Real
      88      496250 : RadialDisplacementCylinderAux::computeValue()
      89             : {
      90             :   Real rad_disp = 0.0;
      91      496250 :   Point current_point(*_current_node);
      92             : 
      93      496250 :   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      487350 :                                      (_ndisp == 3 ? (*_disp_vals[2])[_qp] : 0.0));
     101             : 
     102      487350 :       if (_ndisp == 2)
     103       36450 :         rad_vec = current_point - _origin;
     104      450900 :       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      450900 :         rad_vec = current_point - p;
     114             :       }
     115             : 
     116      487350 :       Real rad = rad_vec.norm();
     117      487350 :       if (rad > 0.0)
     118             :       {
     119             :         rad_vec /= rad;
     120             :         rad_disp = rad_vec * disp_vec;
     121             :       }
     122             :       else
     123        6498 :         rad_disp = disp_vec.norm();
     124             :       break;
     125             :     }
     126        8900 :     case Moose::COORD_RZ:
     127        8900 :       rad_disp = (*_disp_vals[0])[_qp];
     128        8900 :       break;
     129           0 :     default:
     130           0 :       mooseError("Unsupported coordinate system");
     131             :   }
     132             : 
     133      496250 :   return rad_disp;
     134             : }

Generated by: LCOV version 1.14