initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicFvMesh / solidBodyMotionFvMesh / solidBodyMotionFunctions / SDA / SDA.C
blobd2f0c467d2d797110f96fc70e7076c0eb1e5f7c9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "SDA.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "mathematicalConstants.H"
31 using namespace Foam::mathematicalConstant;
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 namespace Foam
37 namespace solidBodyMotionFunctions
39     defineTypeNameAndDebug(SDA, 0);
40     addToRunTimeSelectionTable(solidBodyMotionFunction, SDA, dictionary);
45 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
47 Foam::solidBodyMotionFunctions::SDA::SDA
49     const dictionary& SBMFCoeffs,
50     const Time& runTime
53     solidBodyMotionFunction(SBMFCoeffs, runTime),
54     CofG_(SBMFCoeffs_.lookup("CofG"))
56     read(SBMFCoeffs);
60 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
62 Foam::solidBodyMotionFunctions::SDA::~SDA()
66 // * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * * //
68 Foam::septernion Foam::solidBodyMotionFunctions::SDA::transformation() const
70     scalar time = time_.value();
72     scalar Tpi = Tp_ + dTp_*(time/dTi_);   // Current roll period [sec]
73     scalar wr = 2*pi/Tpi; // Current Freq [/sec]
75     // Current Phase for roll [rad]
76     scalar r = dTp_/dTi_;
77     scalar u = Tp_ + r*time;
78     scalar phr = 2*pi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
80     // Current Phase for Sway [rad]
81     scalar phs = phr + pi;
83     // Current Phase for Heave [rad]
84     scalar phh = phr + pi/2;
86     scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
88     vector T
89     (
90         0,
91         swayA_*(sin(wr*time + phs) - sin(phs)),
92         heaveA_*(sin(wr*time + phh) - sin(phh))
93     );
94     quaternion R(rollA*sin(wr*time + phr), 0, 0);
95     septernion TR(septernion(CofG_ + T)*R*septernion(-CofG_));
97     Info<< "solidBodyMotionFunctions::SDA::transformation(): "
98         << "Time = " << time << " transformation: " << TR << endl;
100     return TR;
104 bool Foam::solidBodyMotionFunctions::SDA::read(const dictionary& SBMFCoeffs)
106     solidBodyMotionFunction::read(SBMFCoeffs);
108     SBMFCoeffs_.lookup("CofG") >> CofG_;
109     SBMFCoeffs_.lookup("lamda") >> lamda_;
110     SBMFCoeffs_.lookup("rollAmax") >> rollAmax_;
111     SBMFCoeffs_.lookup("rollAmin") >> rollAmin_;
112     SBMFCoeffs_.lookup("heaveA") >> heaveA_;
113     SBMFCoeffs_.lookup("swayA") >> swayA_;
114     SBMFCoeffs_.lookup("Q") >> Q_;
115     SBMFCoeffs_.lookup("Tp") >> Tp_;
116     SBMFCoeffs_.lookup("Tpn") >> Tpn_;
117     SBMFCoeffs_.lookup("dTi") >> dTi_;
118     SBMFCoeffs_.lookup("dTp") >> dTp_;
120     // Rescale parameters according to the given scale parameter
121     if (lamda_ > 1 + SMALL)
122     {
123         heaveA_ /= lamda_;
124         swayA_ /= lamda_;
125         Tp_ /= sqrt(lamda_);
126         Tpn_ /= sqrt(lamda_);
127         dTi_ /= sqrt(lamda_);
128         dTp_ /= sqrt(lamda_);
129     }
131     return true;
135 // ************************************************************************* //