rigidBodySolver.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "rigidBodySolver.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 namespace RBD
33 {
34 
35  defineTypeNameAndDebug(rigidBodySolver, 0);
36  defineRunTimeSelectionTable(rigidBodySolver, dictionary);
37 }
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 :
45  model_(body)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
50 
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 
58 {
59  if (model_.unitQuaternions())
60  {
61  forAll (model_.joints(), i)
62  {
63  const label qi = model_.joints()[i].qIndex();
64 
65  if (model_.joints()[i].unitQuaternion())
66  {
67  // Calculate the change in the unit quaternion
68  vector dv((q().block<vector>(qi) - q0().block<vector>(qi)));
69  scalar magDv = mag(dv);
70 
71  if (magDv > small)
72  {
73  // Calculate the unit quaternion corresponding to the change
74  quaternion dQuat(dv/magDv, cos(magDv), true);
75 
76  // Transform the previous time unit quaternion
77  quaternion quat
78  (
79  normalize(model_.joints()[i].unitQuaternion(q0())*dQuat)
80  );
81 
82  // Update the joint unit quaternion
83  model_.joints()[i].unitQuaternion(quat, q());
84  }
85  }
86  }
87  }
88 }
89 
90 
91 // ************************************************************************* //
rigidBodyMotion & model_
The rigid-body model.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
quaternion normalize(const quaternion &q)
Return the normalized (unit) quaternion of the given quaternion.
Definition: quaternionI.H:609
scalarField & q()
Return the current joint position and orientation.
const scalarField & q0() const
Return the current joint position and orientation.
Six degree of freedom motion for a rigid body.
dimensionedScalar cos(const dimensionedScalar &ds)
const PtrList< joint > & joints() const
Return the list of joints in the model.
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:60
bool unitQuaternions() const
Return true if any of the joints using quaternions.
defineTypeNameAndDebug(cuboid, 0)
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:63
rigidBodySolver(rigidBodyMotion &body)
defineRunTimeSelectionTable(rigidBody, dictionary)
virtual ~rigidBodySolver()
Destructor.
dimensioned< scalar > mag(const dimensioned< Type > &)
void correctQuaternionJoints()
Correct the quaternion joints based on the current change in q.
Namespace for OpenFOAM.