https://mooseframework.inl.gov
Torque.C
Go to the documentation of this file.
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 "Torque.h"
11 #include "Function.h"
12 
13 registerMooseObject("SolidMechanicsApp", Torque);
14 registerMooseObject("SolidMechanicsApp", ADTorque);
15 
16 template <bool is_ad>
19 {
21  params.addClassDescription(
22  "Apply a moment as tractions distributed over a surface around a "
23  "pivot point. This should operate on the displaced mesh for large deformations.");
24  MooseEnum component("x=0 y=1 z=2");
25  params.addRequiredParam<Point>(
26  "origin", "Reference point defining the location for the axis the torque is applied to");
27  params.addRequiredParam<RealVectorValue>("direction", "Torque vector");
28  params.addParam<FunctionName>(
29  "factor", "1", "Prefactor for the force (can only be time dependent)");
30  params.addRequiredParam<PostprocessorName>(
31  "polar_moment_of_inertia", "Postprocessor that computes the polar moment of inertia");
32  params.addParam<Real>("alpha", 0.0, "alpha parameter required for HHT time integration scheme");
33  params.addParamNamesToGroup("alpha factor", "Advanced");
34  params.addCoupledVar("displacements", "The displacements");
35  return params;
36 }
37 
38 template <bool is_ad>
40  : TorqueParent<is_ad>(parameters),
41  _component(libMesh::invalid_uint),
42  _origin(this->template getParam<Point>("origin")),
43  _torque(this->template getParam<RealVectorValue>("direction")),
44  _factor(this->getFunction("factor")),
45  _alpha(this->template getParam<Real>("alpha")),
46  _pmi(this->getPostprocessorValue("polar_moment_of_inertia")),
47  _ndisp(this->coupledComponents("displacements")),
48  _dvars(_ndisp),
49  _dummy_point()
50 {
51  for (unsigned int i = 0; i < _ndisp; ++i)
52  {
53  _dvars[i] = this->getVar("displacements", i)->number();
54  if (this->_var.number() == _dvars[i])
55  _component = i;
56  }
57 
59  this->paramError("variable",
60  "The kernel variable needs to be one of the 'displacements' variables");
61  if (this->template getParam<bool>("use_displaced_mesh"))
62  this->paramError("use_displaced_mesh", "This BC is only validated for small strains");
63 }
64 
65 template <>
66 ADReal
68 {
69  // local lever (distance to the origin)
70  auto local_lever = this->_ad_q_points[_qp] - _origin;
71 
72  // force calculation
73  auto local_force =
74  _factor.value(_t + _alpha * _dt, _dummy_point) * _torque.cross(local_lever) / _pmi;
75 
76  return -local_force(_component) * _test[_i][_qp];
77 }
78 
79 template <>
80 Real
82 {
83  // local lever (distance to the origin)
84  auto local_lever = this->_q_point[_qp] - _origin;
85 
86  // force calculation
87  auto local_force =
88  _factor.value(_t + _alpha * _dt, _dummy_point) * _torque.cross(local_lever) / _pmi;
89 
90  return -local_force(_component) * _test[_i][_qp];
91 }
92 
93 template <>
94 Real
96 {
97  // vector phi
98  RealGradient phi;
99  phi(component) = this->_phi[_j][_qp];
100 
101  // force calculation
102  auto d_local_force = _factor.value(_t + _alpha * _dt, _dummy_point) * _torque.cross(phi) / _pmi;
103  return -d_local_force(_component) * _test[_i][_qp];
104 }
105 
106 template <>
107 Real
109 {
110  mooseError("This should never get called");
111 }
112 
113 template <bool is_ad>
114 Real
116 {
117  return componentJacobian(_component);
118 }
119 
120 template <bool is_ad>
121 Real
123 {
124  for (unsigned int i = 0; i < _ndisp; ++i)
125  if (jvar == _dvars[i])
126  return componentJacobian(i);
127 
128  return 0.0;
129 }
130 
131 template class TorqueTempl<false>;
132 template class TorqueTempl<true>;
const unsigned int invalid_uint
Real componentJacobian(unsigned int component)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void mooseError(Args &&... args)
static const std::string component
Definition: NS.h:153
std::vector< unsigned int > _dvars
coupled displacement variables
Definition: Torque.h:58
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
DualNumber< Real, DNDerivativeType, true > ADReal
void addRequiredParam(const std::string &name, const std::string &doc_string)
const unsigned int _ndisp
number of coupled displacement variables
Definition: Torque.h:56
typename std::conditional< is_ad, ADIntegratedBC, IntegratedBC >::type TorqueParent
Definition: Torque.h:19
InputParameters validParams()
unsigned int _component
coordinte axis this BC acts on
Definition: Torque.h:41
TorqueTempl(const InputParameters &parameters)
Definition: Torque.C:39
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
virtual Real computeQpJacobian()
Definition: Torque.C:115
static InputParameters validParams()
Definition: Torque.C:18
void addCoupledVar(const std::string &name, const std::string &doc_string)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual Real computeQpOffDiagJacobian(unsigned int)
Definition: Torque.C:122
void addClassDescription(const std::string &doc_string)
Apply a torque as tractions distributed over a surface.
Definition: Torque.h:25
registerMooseObject("SolidMechanicsApp", Torque)
virtual GenericReal< is_ad > computeQpResidual()
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)