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

Generated by: LCOV version 1.14