www.mooseframework.org
RadialDisplacementCylinderAux.C
Go to the documentation of this file.
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 
11 #include "MooseMesh.h"
12 
14 
17 {
19  params.addClassDescription(
20  "Compute the radial component of the displacement vector for cylindrical models.");
21  params.addRequiredCoupledVar(
22  "displacements",
23  "The displacements appropriate for the simulation geometry and coordinate system");
24  params.addParam<RealVectorValue>(
25  "origin", "Origin of cylinder axis of rotation for 2D and 3D Cartesian models");
26  params.addParam<RealVectorValue>(
27  "axis_vector", "Vector defining direction of cylindrical axis (3D Cartesian models)");
28  params.set<bool>("use_displaced_mesh") = false;
29 
30  return params;
31 }
32 
34  : AuxKernel(parameters),
35  _ndisp(coupledComponents("displacements")),
36  _disp_vals(coupledValues("displacements"))
37 {
38  const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
39  const auto & sbd_begin = *subdomains.begin();
40  for (const auto & sbd : subdomains)
41  {
42  if (sbd == sbd_begin)
44  else if (_subproblem.getCoordSystem(sbd) != _coord_system)
45  mooseError("RadialDisplacementCylinderAux requires that all subdomains have the same "
46  "coordinate type");
47  }
48 
49  if (_ndisp != _mesh.dimension())
50  mooseError("The number of displacement variables supplied must match the mesh dimension.");
51 
52  if (_coord_system == Moose::COORD_XYZ && _ndisp == 1)
53  mooseError("RadialDisplacmentCylinderAux is not applicable for 1D Cartesian models");
54 
56  mooseError("RadialDisplacementCylinderAux can only be used with Cartesian or axisymmetric "
57  "coordinate systems");
58 
59  if (isParamValid("origin"))
60  {
62  mooseError("The 'origin' parameter is only valid for Cartesian models.");
63 
64  _origin = getParam<RealVectorValue>("origin");
65  }
66  else if (_coord_system == Moose::COORD_XYZ)
67  mooseError("Must specify 'origin' for models with Cartesian coordinate systems.");
68 
69  if (isParamValid("axis_vector"))
70  {
71  if (!(_coord_system == Moose::COORD_XYZ && _ndisp == 3))
72  mooseError("The 'axis_vector' parameter is only valid for 3D Cartesian models.");
73 
74  _axis_vector = getParam<RealVectorValue>("axis_vector");
75  Real vec_len = _axis_vector.norm();
76  if (MooseUtils::absoluteFuzzyEqual(vec_len, 0.0))
77  mooseError("axis_vector must have nonzero length");
78  _axis_vector /= vec_len;
79  }
80  else if (_coord_system == Moose::COORD_XYZ && _ndisp == 3)
81  mooseError("Must specify 'axis_vector' for 3D Cartesian models");
82 
83  if (!isNodal())
84  mooseError("Must run on a nodal variable");
85 }
86 
87 Real
89 {
90  Real rad_disp = 0.0;
91  Point current_point(*_current_node);
92 
93  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  (_ndisp == 3 ? (*_disp_vals[2])[_qp] : 0.0));
101 
102  if (_ndisp == 2)
103  rad_vec = current_point - _origin;
104  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  rad_vec = current_point - p;
114  }
115 
116  Real rad = rad_vec.norm();
117  if (rad > 0.0)
118  {
119  rad_vec /= rad;
120  rad_disp = rad_vec * disp_vec;
121  }
122  else
123  rad_disp = disp_vec.norm();
124  break;
125  }
126  case Moose::COORD_RZ:
127  rad_disp = (*_disp_vals[0])[_qp];
128  break;
129  default:
130  mooseError("Unsupported coordinate system");
131  }
132 
133  return rad_disp;
134 }
registerMooseObject("SolidMechanicsApp", RadialDisplacementCylinderAux)
RadialDisplacementCylinderAux(const InputParameters &parameters)
auto norm() const -> decltype(std::norm(Real()))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const Node *const & _current_node
T & set(const std::string &name, bool quiet_mode=false)
RealVectorValue _origin
Point used to define the origin of the cylinder axis for Cartesian systems.
bool isParamValid(const std::string &name) const
const std::vector< const VariableValue * > _disp_vals
Coupled variable values of the displacement components.
virtual unsigned int dimension() const
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SubProblem & _subproblem
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
Moose::CoordinateSystemType getCoordSystem(SubdomainID sid) const
unsigned int _ndisp
Number of displacment components.
virtual Real computeValue()
Compute the value of the radial displacement.
Calculates the radial displacement for cylindrical geometries.
RealVectorValue _axis_vector
Axis direction.
Moose::CoordinateSystemType _coord_system
Type of coordinate system.
const std::set< SubdomainID > & meshSubdomains() const