www.mooseframework.org
RadialDisplacementCylinderAux.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 #include "MooseMesh.h"
9 
10 template <>
11 InputParameters
13 {
14  InputParameters params = validParams<AuxKernel>();
15  params.addClassDescription(
16  "Compute the radial component of the displacement vector for cylindrical models.");
17  params.addRequiredCoupledVar(
18  "displacements",
19  "The displacements appropriate for the simulation geometry and coordinate system");
20  params.addParam<RealVectorValue>(
21  "origin", "Origin of cylinder axis of rotation for 2D and 3D Cartesian models");
22  params.addParam<RealVectorValue>(
23  "axis_vector", "Vector defining direction of cylindrical axis (3D Cartesian models)");
24  params.set<bool>("use_displaced_mesh") = false;
25 
26  return params;
27 }
28 
30  : AuxKernel(parameters), _ndisp(coupledComponents("displacements")), _disp_vals(_ndisp)
31 {
32  const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
33  const auto & sbd_begin = *subdomains.begin();
34  for (const auto & sbd : subdomains)
35  {
36  if (sbd == sbd_begin)
37  _coord_system = _subproblem.getCoordSystem(sbd);
38  else if (_subproblem.getCoordSystem(sbd) != _coord_system)
39  mooseError("RadialDisplacementCylinderAux requires that all subdomains have the same "
40  "coordinate type");
41  }
42 
43  for (unsigned int i = 0; i < _ndisp; ++i)
44  _disp_vals[i] = &coupledValue("displacements", i);
45 
46  if (_ndisp != _mesh.dimension())
47  mooseError("The number of displacement variables supplied must match the mesh dimension.");
48 
49  if (_coord_system == Moose::COORD_XYZ && _ndisp == 1)
50  mooseError("RadialDisplacmentCylinderAux is not applicable for 1D Cartesian models");
51 
52  else if (!(_coord_system == Moose::COORD_XYZ || _coord_system == Moose::COORD_RZ))
53  mooseError("RadialDisplacementCylinderAux can only be used with Cartesian or axisymmetric "
54  "coordinate systems");
55 
56  if (isParamValid("origin"))
57  {
58  if (_coord_system != Moose::COORD_XYZ)
59  mooseError("The 'origin' parameter is only valid for Cartesian models.");
60 
61  _origin = getParam<RealVectorValue>("origin");
62  }
63  else if (_coord_system == Moose::COORD_XYZ)
64  mooseError("Must specify 'origin' for models with Cartesian coordinate systems.");
65 
66  if (isParamValid("axis_vector"))
67  {
68  if (!(_coord_system == Moose::COORD_XYZ && _ndisp == 3))
69  mooseError("The 'axis_vector' parameter is only valid for 3D Cartesian models.");
70 
71  _axis_vector = getParam<RealVectorValue>("axis_vector");
72  Real vec_len = _axis_vector.norm();
73  if (MooseUtils::absoluteFuzzyEqual(vec_len, 0.0))
74  mooseError("axis_vector must have nonzero length");
75  _axis_vector /= vec_len;
76  }
77  else if (_coord_system == Moose::COORD_XYZ && _ndisp == 3)
78  mooseError("Must specify 'axis_vector' for 3D Cartesian models");
79 
80  if (!isNodal())
81  mooseError("Must run on a nodal variable");
82 }
83 
84 Real
86 {
87  Real rad_disp = 0.0;
88  Point current_point(*_current_node);
89 
90  switch (_coord_system)
91  {
92  case Moose::COORD_XYZ:
93  {
94  RealVectorValue rad_vec;
95  const RealVectorValue disp_vec((*_disp_vals[0])[_qp],
96  (*_disp_vals[1])[_qp],
97  (_ndisp == 3 ? (*_disp_vals[2])[_qp] : 0.0));
98 
99  if (_ndisp == 2)
100  rad_vec = current_point - _origin;
101  else if (_ndisp == 3)
102  {
103  // t is the distance along the axis from point 1 to 2 to the point nearest to the current
104  // point.
105  const RealVectorValue p1pc(current_point - _origin);
106  const Real t = p1pc * _axis_vector;
107 
108  // The nearest point on the cylindrical axis to current_point is p.
109  const RealVectorValue p(_origin + t * _axis_vector);
110  rad_vec = current_point - p;
111  }
112 
113  Real rad = rad_vec.norm();
114  if (rad > 0.0)
115  {
116  rad_vec /= rad;
117  rad_disp = rad_vec * disp_vec;
118  }
119  else
120  rad_disp = disp_vec.norm();
121  break;
122  }
123  case Moose::COORD_RZ:
124  rad_disp = (*_disp_vals[0])[_qp];
125  break;
126  default:
127  mooseError("Unsupported coordinate system");
128  }
129 
130  return rad_disp;
131 }
RadialDisplacementCylinderAux(const InputParameters &parameters)
RealVectorValue _origin
Point used to define the origin of the cylinder axis for Cartesian systems.
InputParameters validParams< RadialDisplacementCylinderAux >()
std::vector< const VariableValue * > _disp_vals
Coupled variable values of the displacement components.
unsigned int _ndisp
Number of displacment components.
virtual Real computeValue()
Compute the value of the radial displacement.
RealVectorValue _axis_vector
Axis direction.
Moose::CoordinateSystemType _coord_system
Type of coordinate system.