SDA.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "SDA.H"
28 #include "mathematicalConstants.H"
29 
30 using namespace Foam::constant::mathematical;
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace solidBodyMotionFunctions
37 {
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 (
48  const dictionary& SBMFCoeffs,
49  const Time& runTime
50 )
51 :
52  solidBodyMotionFunction(SBMFCoeffs, runTime),
53  CofG_(SBMFCoeffs_.lookup("CofG"))
54 {
55  read(SBMFCoeffs);
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 
62 {}
63 
64 
65 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
66 
68 {
69  scalar time = time_.value();
70 
71  scalar Tpi = Tp_ + dTp_*(time/dTi_); // Current roll period [sec]
72  scalar wr = twoPi/Tpi; // Current Freq [/sec]
73 
74  // Current Phase for roll [rad]
75  scalar r = dTp_/dTi_;
76  scalar u = Tp_ + r*time;
77  scalar phr = twoPi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
78 
79  // Current Phase for Sway [rad]
80  scalar phs = phr + pi;
81 
82  // Current Phase for Heave [rad]
83  scalar phh = phr + piByTwo;
84 
85  scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
86 
87  vector T
88  (
89  0,
90  swayA_*(sin(wr*time + phs) - sin(phs)),
91  heaveA_*(sin(wr*time + phh) - sin(phh))
92  );
93  quaternion R(quaternion::XYZ, vector(rollA*sin(wr*time + phr), 0, 0));
94  septernion TR(septernion(-CofG_ - T)*R*septernion(CofG_));
95 
96  DebugInFunction << "Time = " << time << " transformation: " << TR << endl;
97 
98  return TR;
99 }
100 
101 
103 {
104  solidBodyMotionFunction::read(SBMFCoeffs);
105 
106  SBMFCoeffs_.lookup("CofG") >> CofG_;
107  SBMFCoeffs_.lookup("lambda") >> lambda_;
108  SBMFCoeffs_.lookup("rollAmax") >> rollAmax_;
109  SBMFCoeffs_.lookup("rollAmin") >> rollAmin_;
110  SBMFCoeffs_.lookup("heaveA") >> heaveA_;
111  SBMFCoeffs_.lookup("swayA") >> swayA_;
112  SBMFCoeffs_.lookup("Q") >> Q_;
113  SBMFCoeffs_.lookup("Tp") >> Tp_;
114  SBMFCoeffs_.lookup("Tpn") >> Tpn_;
115  SBMFCoeffs_.lookup("dTi") >> dTi_;
116  SBMFCoeffs_.lookup("dTp") >> dTp_;
117 
118  // Rescale parameters according to the given scale parameter
119  if (lambda_ > 1 + small)
120  {
121  heaveA_ /= lambda_;
122  swayA_ /= lambda_;
123  Tp_ /= sqrt(lambda_);
124  Tpn_ /= sqrt(lambda_);
125  dTi_ /= sqrt(lambda_);
126  dTp_ /= sqrt(lambda_);
127  }
128 
129  return true;
130 }
131 
132 
133 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:61
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:66
Base class for defining solid-body motions.
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Ship design analysis (SDA) 3DoF motion function.
Definition: SDA.H:59
virtual ~SDA()
Destructor.
Definition: SDA.C:61
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Definition: SDA.C:67
SDA(const dictionary &SBMFCoeffs, const Time &runTime)
Construct from components.
Definition: SDA.C:47
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: SDA.C:102
#define DebugInFunction
Report an information message using Foam::Info.
mathematical constants.
const scalar piByTwo(0.5 *pi)
const scalar twoPi(2 *pi)
Namespace for OpenFOAM.
dimensionedScalar exp(const dimensionedScalar &ds)
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)