1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Dubravko Matijasevic, FSB Zagreb. All rights reserved.
30 Update by Hrvoje Jasak
32 \*---------------------------------------------------------------------------*/
34 #include "finiteRotation.H"
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
38 Foam::vector Foam::finiteRotation::rotVector(const tensor& rotT)
40 vector ur = - *( inv(I + rotT) & (I - rotT) );
42 // Scaling to a unit vector. HJ, problems with round-off
44 return ur/(mag(ur) + SMALL);
48 Foam::scalar Foam::finiteRotation::rotAngle(const tensor& rotT)
50 // Alternative formulation: Daniel Schmode, 15/Feb/2009
51 scalar x = rotT.zy() - rotT.yz();
52 scalar y = rotT.xz() - rotT.zx();
53 scalar z = rotT.yx() - rotT.xy();
55 scalar r = hypot(x, hypot(y, z));
58 return atan2(r, t - 1);
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 Foam::finiteRotation::finiteRotation(const HamiltonRodriguezRot& rot)
68 rotIncrementTensor_(tensor::zero)
72 Foam::finiteRotation::finiteRotation
78 eInitial_(HamiltonRodriguezRot(r, angle)),
79 rotTensor_(eInitial_.R()),
80 rotIncrementTensor_(tensor::zero)
84 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
86 Foam::finiteRotation::~finiteRotation()
90 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92 void Foam::finiteRotation::updateRotation(const HamiltonRodriguezRot& rot)
94 tensor rotR = rot.R();
96 rotIncrementTensor_ = (rotR & (rotTensor_.T()));
101 const Foam::HamiltonRodriguezRot& Foam::finiteRotation::eInitial() const
107 Foam::HamiltonRodriguezRot Foam::finiteRotation::eCurrent() const
109 return HamiltonRodriguezRot(rotVector(), rotAngle());
113 const Foam::tensor& Foam::finiteRotation::rotTensor() const
119 Foam::vector Foam::finiteRotation::rotVector() const
121 return rotVector(rotTensor_);
125 Foam::scalar Foam::finiteRotation::rotAngle() const
127 return rotAngle(rotTensor_);
131 const Foam::tensor& Foam::finiteRotation::rotIncrementTensor() const
133 return rotIncrementTensor_;
137 Foam::vector Foam::finiteRotation::rotIncrementVector() const
139 return rotVector(rotIncrementTensor_);
143 Foam::scalar Foam::finiteRotation::rotIncrementAngle() const
145 return rotAngle(rotIncrementTensor_);
149 Foam::vector Foam::finiteRotation::omegaAverage(const scalar deltaT) const
151 return (rotIncrementAngle()/deltaT)*rotIncrementVector();
155 Foam::tensor Foam::finiteRotation::rotTensorAverage() const
161 rotIncrementVector(),
162 0.5*rotIncrementAngle()
169 Foam::vector Foam::finiteRotation::rotVectorAverage() const
171 return rotVector(rotTensorAverage());
175 Foam::vector Foam::finiteRotation::omegaAverageAbsolute
180 return (rotTensorAverage().T() & omegaAverage(deltaT));
184 // ************************************************************************* //