SDA.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "SDA.H"
32
33using namespace Foam::constant::mathematical;
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
39namespace solidBodyMotionFunctions
40{
43}
44}
45
46
47// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48
50(
51 const dictionary& SBMFCoeffs,
52 const Time& runTime
53)
54:
56 CofG_(SBMFCoeffs_.get<vector>("CofG"))
57{
58 read(SBMFCoeffs);
59}
60
61
62// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
63
65{
66 scalar time = time_.value();
67
68 scalar Tpi = Tp_ + dTp_*(time/dTi_); // Current roll period [sec]
69 scalar wr = twoPi/Tpi; // Current Freq [/sec]
70
71 // Current Phase for roll [rad]
72 scalar r = dTp_/dTi_;
73 scalar u = Tp_ + r*time;
74 scalar phr = twoPi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
75
76 // Current Phase for Sway [rad]
77 scalar phs = phr + pi;
78
79 // Current Phase for Heave [rad]
80 scalar phh = phr + piByTwo;
81
82 scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
83
84 vector T
85 (
86 0,
87 swayA_*(sin(wr*time + phs) - sin(phs)),
88 heaveA_*(sin(wr*time + phh) - sin(phh))
89 );
90 quaternion R(quaternion::XYZ, vector(rollA*sin(wr*time + phr), 0, 0));
91 septernion TR(septernion(-CofG_ - T)*R*septernion(CofG_));
92
93 DebugInFunction << "Time = " << time << " transformation: " << TR << endl;
94
95 return TR;
96}
97
98
100{
102
103 SBMFCoeffs_.readEntry("CofG", CofG_);
104 SBMFCoeffs_.readEntry("lamda", lamda_);
105 SBMFCoeffs_.readEntry("rollAmax", rollAmax_);
106 SBMFCoeffs_.readEntry("rollAmin", rollAmin_);
107 SBMFCoeffs_.readEntry("heaveA", heaveA_);
108 SBMFCoeffs_.readEntry("swayA", swayA_);
109 SBMFCoeffs_.readEntry("Q", Q_);
110 SBMFCoeffs_.readEntry("Tp", Tp_);
111 SBMFCoeffs_.readEntry("Tpn", Tpn_);
112 SBMFCoeffs_.readEntry("dTi", dTi_);
113 SBMFCoeffs_.readEntry("dTp", dTp_);
114
115 // Rescale parameters according to the given scale parameter
116 if (lamda_ > 1 + SMALL)
117 {
118 heaveA_ /= lamda_;
119 swayA_ /= lamda_;
120 Tp_ /= sqrt(lamda_);
121 Tpn_ /= sqrt(lamda_);
122 dTi_ /= sqrt(lamda_);
123 dTp_ /= sqrt(lamda_);
124 }
125
126 return true;
127}
128
129
130// ************************************************************************* //
#define R(A, B, C, D, E, F, K, M)
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
virtual bool read()
Re-read model coefficients if they have changed.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:58
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:67
Base class for defining solid-body motions.
Ship design analysis (SDA) 3DoF motion function.
Definition: SDA.H:62
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Definition: SDA.C:64
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: SDA.C:99
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const volScalarField & T
engineTime & runTime
#define DebugInFunction
Report an information message using Foam::Info.
Mathematical constants.
constexpr scalar pi(M_PI)
constexpr scalar piByTwo(0.5 *M_PI)
constexpr scalar twoPi(2 *M_PI)
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
dimensionedScalar exp(const dimensionedScalar &ds)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Vector< scalar > vector
Definition: vector.H:61