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
25 \*---------------------------------------------------------------------------*/
28 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 using namespace Foam::mathematicalConstant;
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace solidBodyMotionFunctions
39 defineTypeNameAndDebug(SDA, 0);
40 addToRunTimeSelectionTable(solidBodyMotionFunction, SDA, dictionary);
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 Foam::solidBodyMotionFunctions::SDA::calcTransformation(const scalar t) const
50 scalar Tpi = Tp_ + dTp_*(t/dTi_); // Current roll period [sec]
51 scalar wr = 2*pi/Tpi; // Current freq [/sec]
53 // Current phase for roll [rad]
56 scalar phr = 2*pi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
58 // Current phase for Sway [rad]
59 scalar phs = phr + pi;
61 // Current phase for Heave [rad]
62 scalar phh = phr + pi/2;
64 scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
69 swayA_*(sin(wr*t + phs) - sin(phs)),
70 heaveA_*(sin(wr*t + phh) - sin(phh))
72 quaternion R(rollA*sin(wr*t + phr), 0, 0);
73 septernion TR(septernion(CofG_ + T)*R*septernion(-CofG_));
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 Foam::solidBodyMotionFunctions::SDA::SDA
82 const dictionary& SBMFCoeffs,
86 solidBodyMotionFunction(SBMFCoeffs, runTime),
87 CofG_(SBMFCoeffs_.lookup("CofG"))
93 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
95 Foam::solidBodyMotionFunctions::SDA::~SDA()
99 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
101 Foam::septernion Foam::solidBodyMotionFunctions::SDA::transformation() const
103 scalar t = time_.value();
105 septernion TR = calcTransformation(t);
107 Info<< "solidBodyMotionFunctions::SDA::transformation(): "
108 << "Time = " << t << " transformation: " << TR << endl;
114 Foam::septernion Foam::solidBodyMotionFunctions::SDA::velocity() const
116 // Velocity is calculated as a difference
117 scalar t = time_.value();
118 scalar dt = time_.deltaT().value();
120 return (calcTransformation(t + dt) - calcTransformation(t))/dt;
124 bool Foam::solidBodyMotionFunctions::SDA::read(const dictionary& SBMFCoeffs)
126 solidBodyMotionFunction::read(SBMFCoeffs);
128 SBMFCoeffs_.lookup("CofG") >> CofG_;
129 SBMFCoeffs_.lookup("lamda") >> lamda_;
130 SBMFCoeffs_.lookup("rollAmax") >> rollAmax_;
131 SBMFCoeffs_.lookup("rollAmin") >> rollAmin_;
132 SBMFCoeffs_.lookup("heaveA") >> heaveA_;
133 SBMFCoeffs_.lookup("swayA") >> swayA_;
134 SBMFCoeffs_.lookup("Q") >> Q_;
135 SBMFCoeffs_.lookup("Tp") >> Tp_;
136 SBMFCoeffs_.lookup("Tpn") >> Tpn_;
137 SBMFCoeffs_.lookup("dTi") >> dTi_;
138 SBMFCoeffs_.lookup("dTp") >> dTp_;
140 // Rescale parameters according to the given scale parameter
141 if (lamda_ > 1 + SMALL)
146 Tpn_ /= sqrt(lamda_);
147 dTi_ /= sqrt(lamda_);
148 dTp_ /= sqrt(lamda_);
155 // ************************************************************************* //