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