www.mooseframework.org
RadialDisplacementSphereAux.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 spherical models.");
17  params.addRequiredCoupledVar(
18  "displacements",
19  "The displacements appropriate for the simulation geometry and coordinate system");
20  params.addParam<RealVectorValue>("origin",
21  "Sphere origin for 3D Cartesian and 2D axisymmetric models");
22  params.set<bool>("use_displaced_mesh") = false;
23 
24  return params;
25 }
26 
28  : AuxKernel(parameters), _ndisp(coupledComponents("displacements")), _disp_vals(_ndisp)
29 {
30  const std::set<SubdomainID> & subdomains = _mesh.meshSubdomains();
31  const auto & sbd_begin = *subdomains.begin();
32  for (const auto & sbd : subdomains)
33  {
34  if (sbd == sbd_begin)
35  _coord_system = _subproblem.getCoordSystem(sbd);
36  else if (_subproblem.getCoordSystem(sbd) != _coord_system)
37  mooseError(
38  "RadialDisplacementSphereAux requires that all subdomains have the same coordinate type");
39  }
40 
41  for (unsigned int i = 0; i < _ndisp; ++i)
42  _disp_vals[i] = &coupledValue("displacements", i);
43 
44  if (_ndisp != _mesh.dimension())
45  mooseError("The number of displacement variables supplied must match the mesh dimension.");
46 
47  if ((_coord_system == Moose::COORD_XYZ) || (_coord_system == Moose::COORD_RZ))
48  {
49  if (isParamValid("origin"))
50  _origin = getParam<RealVectorValue>("origin");
51  else
52  mooseError(
53  "Must specify 'origin' for models with Cartesian or axisymmetric coordinate systems.");
54  }
55  else if (isParamValid("origin"))
56  mooseError("The 'origin' parameter is only valid for models with Cartesian or axisymmetric "
57  "coordinate systems.");
58 
59  if (_coord_system == Moose::COORD_XYZ && _ndisp != 3)
60  mooseError("Cannot compute radial displacement for models with 1D or 2D Cartesian system");
61 
62  if (_coord_system == Moose::COORD_RZ && _ndisp != 2)
63  mooseError(
64  "Can only compute radial displacement for axisymmetric systems if the dimensionality is 2");
65 
66  if (!isNodal())
67  mooseError("Must run on a nodal variable");
68 }
69 
70 Real
72 {
73  Real rad_disp = 0.0;
74 
75  if ((_coord_system == Moose::COORD_XYZ && _ndisp == 3) ||
76  (_coord_system == Moose::COORD_RZ && _ndisp == 2))
77  {
78  Point current_point(*_current_node);
79  RealVectorValue rad_vec(current_point - _origin);
80  Real rad = rad_vec.norm();
81  const RealVectorValue disp_vec(
82  (*_disp_vals[0])[_qp], (*_disp_vals[1])[_qp], (_ndisp == 3 ? (*_disp_vals[2])[_qp] : 0.0));
83  if (rad > 0.0)
84  {
85  rad_vec /= rad;
86  rad_disp = rad_vec * disp_vec;
87  }
88  else
89  rad_disp = disp_vec.norm();
90  }
91  else if (_coord_system == Moose::COORD_RSPHERICAL)
92  rad_disp = (*_disp_vals[0])[_qp];
93  else
94  mooseError("Unsupported coordinate system");
95 
96  return rad_disp;
97 }
RealVectorValue _origin
Point used to define an origin for 2D axisymmetric or 3D Cartesian systems.
std::vector< const VariableValue * > _disp_vals
Coupled variable values of the displacement components.
RadialDisplacementSphereAux(const InputParameters &parameters)
unsigned int _ndisp
Number of displacment components.
virtual Real computeValue()
Compute the value of the radial displacement.
Moose::CoordinateSystemType _coord_system
Type of coordinate system.
InputParameters validParams< RadialDisplacementSphereAux >()