LCOV - code coverage report
Current view: top level - src/auxkernels - RadialDisplacementSphereAux.C (source / functions) Hit Total Coverage
Test: idaholab/moose tensor_mechanics: d6b47a Lines: 34 43 79.1 %
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 "RadialDisplacementSphereAux.h"
      11             : #include "MooseMesh.h"
      12             : 
      13             : registerMooseObject("TensorMechanicsApp", RadialDisplacementSphereAux);
      14             : 
      15             : InputParameters
      16          19 : RadialDisplacementSphereAux::validParams()
      17             : {
      18          19 :   InputParameters params = AuxKernel::validParams();
      19          19 :   params.addClassDescription(
      20             :       "Compute the radial component of the displacement vector for spherical models.");
      21          38 :   params.addRequiredCoupledVar(
      22             :       "displacements",
      23             :       "The displacements appropriate for the simulation geometry and coordinate system");
      24          38 :   params.addParam<RealVectorValue>("origin",
      25             :                                    "Sphere origin for 3D Cartesian and 2D axisymmetric models");
      26          19 :   params.set<bool>("use_displaced_mesh") = false;
      27             : 
      28          19 :   return params;
      29           0 : }
      30             : 
      31          10 : RadialDisplacementSphereAux::RadialDisplacementSphereAux(const InputParameters & parameters)
      32             :   : AuxKernel(parameters),
      33          10 :     _ndisp(coupledComponents("displacements")),
      34          30 :     _disp_vals(coupledValues("displacements"))
      35             : {
      36          10 :   const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
      37             :   const auto & sbd_begin = *subdomains.begin();
      38          20 :   for (const auto & sbd : subdomains)
      39             :   {
      40          10 :     if (sbd == sbd_begin)
      41          10 :       _coord_system = _subproblem.getCoordSystem(sbd);
      42           0 :     else if (_subproblem.getCoordSystem(sbd) != _coord_system)
      43           0 :       mooseError(
      44             :           "RadialDisplacementSphereAux requires that all subdomains have the same coordinate type");
      45             :   }
      46             : 
      47          10 :   if (_ndisp != _mesh.dimension())
      48           0 :     mooseError("The number of displacement variables supplied must match the mesh dimension.");
      49             : 
      50          10 :   if ((_coord_system == Moose::COORD_XYZ) || (_coord_system == Moose::COORD_RZ))
      51             :   {
      52          12 :     if (isParamValid("origin"))
      53          12 :       _origin = getParam<RealVectorValue>("origin");
      54             :     else
      55           0 :       mooseError(
      56             :           "Must specify 'origin' for models with Cartesian or axisymmetric coordinate systems.");
      57             :   }
      58           8 :   else if (isParamValid("origin"))
      59           1 :     mooseError("The 'origin' parameter is only valid for models with Cartesian or axisymmetric "
      60             :                "coordinate systems.");
      61             : 
      62           9 :   if (_coord_system == Moose::COORD_XYZ && _ndisp != 3)
      63           0 :     mooseError("Cannot compute radial displacement for models with 1D or 2D Cartesian system");
      64             : 
      65           9 :   if (_coord_system == Moose::COORD_RZ && _ndisp != 2)
      66           0 :     mooseError(
      67             :         "Can only compute radial displacement for axisymmetric systems if the dimensionality is 2");
      68             : 
      69           9 :   if (!isNodal())
      70           0 :     mooseError("Must run on a nodal variable");
      71           9 : }
      72             : 
      73             : Real
      74      116152 : RadialDisplacementSphereAux::computeValue()
      75             : {
      76             :   Real rad_disp = 0.0;
      77             : 
      78      116152 :   if ((_coord_system == Moose::COORD_XYZ && _ndisp == 3) ||
      79             :       (_coord_system == Moose::COORD_RZ && _ndisp == 2))
      80             :   {
      81      115872 :     Point current_point(*_current_node);
      82             :     RealVectorValue rad_vec(current_point - _origin);
      83      115872 :     Real rad = rad_vec.norm();
      84             :     const RealVectorValue disp_vec(
      85      115872 :         (*_disp_vals[0])[_qp], (*_disp_vals[1])[_qp], (_ndisp == 3 ? (*_disp_vals[2])[_qp] : 0.0));
      86      115872 :     if (rad > 0.0)
      87             :     {
      88             :       rad_vec /= rad;
      89             :       rad_disp = rad_vec * disp_vec;
      90             :     }
      91             :     else
      92         320 :       rad_disp = disp_vec.norm();
      93             :   }
      94         280 :   else if (_coord_system == Moose::COORD_RSPHERICAL)
      95         280 :     rad_disp = (*_disp_vals[0])[_qp];
      96             :   else
      97           0 :     mooseError("Unsupported coordinate system");
      98             : 
      99      116152 :   return rad_disp;
     100             : }

Generated by: LCOV version 1.14