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);
38  defineRunTimeSelectionTable(rigidBodySolver, dictionary);
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  normalize(model_.joints()[i].unitQuaternion(q0())*dQuat)
82  );
83 
84  // Update the joint unit quaternion
85  model_.joints()[i].unitQuaternion(quat, q());
86  }
87  }
88  }
89  }
90 }
91 
92 
93 // ************************************************************************* //
rigidBodySolver.H
Foam::block
Creates a single block of cells from point coordinates, numbers of cells in each direction and an exp...
Definition: block.H:58
Foam::RBD::rigidBodyMotion
Six degree of freedom motion for a rigid body.
Definition: rigidBodyMotion.H:73
Foam::RBD::rigidBodySolver::rigidBodySolver
rigidBodySolver(rigidBodyMotion &body)
Definition: rigidBodySolver.C:45
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
Foam::RBD::rigidBodySolver::correctQuaternionJoints
void correctQuaternionJoints()
Correct the quaternion joints based on the current change in q.
Definition: rigidBodySolver.C:59
Foam::RBD::defineTypeNameAndDebug
defineTypeNameAndDebug(cuboid, 0)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Vector< scalar >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::RBD::defineRunTimeSelectionTable
defineRunTimeSelectionTable(rigidBody, dictionary)
Foam::normalize
quaternion normalize(const quaternion &q)
Return the normalized (unit) quaternion of the given quaternion.
Definition: quaternionI.H:661
Foam::RBD::rigidBodySolver::~rigidBodySolver
virtual ~rigidBodySolver()
Destructor.
Definition: rigidBodySolver.C:53
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265