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-2026 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 word& name,
49  const dictionary& SBMFCoeffs,
50  const Time& runTime
51 )
52 :
53  solidBodyMotionFunction(name, SBMFCoeffs, runTime),
54  CofG_(SBMFCoeffs_.lookup("CofG"))
55 {
56  read(SBMFCoeffs);
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
61 
63 {}
64 
65 
66 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
67 
69 {
70  scalar time = time_.value();
71 
72  scalar Tpi = Tp_ + dTp_*(time/dTi_); // Current roll period [sec]
73  scalar wr = twoPi/Tpi; // Current Freq [/sec]
74 
75  // Current Phase for roll [rad]
76  scalar r = dTp_/dTi_;
77  scalar u = Tp_ + r*time;
78  scalar phr = twoPi*((Tp_/u - 1) + log(mag(u)) - log(Tp_))/r;
79 
80  // Current Phase for Sway [rad]
81  scalar phs = phr + pi;
82 
83  // Current Phase for Heave [rad]
84  scalar phh = phr + piByTwo;
85 
86  scalar rollA = max(rollAmax_*exp(-sqr(Tpi - Tpn_)/(2*Q_)), rollAmin_);
87 
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(quaternion::XYZ, vector(rollA*sin(wr*time + phr), 0, 0));
95  septernion TR(septernion(-CofG_ - T)*R*septernion(CofG_));
96 
97  DebugInFunction << "Time = " << time << " transformation: " << TR << endl;
98 
99  return TR;
100 }
101 
102 
104 {
105  solidBodyMotionFunction::read(SBMFCoeffs);
106 
107  SBMFCoeffs_.lookup("CofG") >> CofG_;
108  SBMFCoeffs_.lookup("lambda") >> lambda_;
109  SBMFCoeffs_.lookup("rollAmax") >> rollAmax_;
110  SBMFCoeffs_.lookup("rollAmin") >> rollAmin_;
111  SBMFCoeffs_.lookup("heaveA") >> heaveA_;
112  SBMFCoeffs_.lookup("swayA") >> swayA_;
113  SBMFCoeffs_.lookup("Q") >> Q_;
114  SBMFCoeffs_.lookup("Tp") >> Tp_;
115  SBMFCoeffs_.lookup("Tpn") >> Tpn_;
116  SBMFCoeffs_.lookup("dTi") >> dTi_;
117  SBMFCoeffs_.lookup("dTp") >> dTp_;
118 
119  // Rescale parameters according to the given scale parameter
120  if (lambda_ > 1 + small)
121  {
122  heaveA_ /= lambda_;
123  swayA_ /= lambda_;
124  Tp_ /= sqrt(lambda_);
125  Tpn_ /= sqrt(lambda_);
126  dTi_ /= sqrt(lambda_);
127  dTp_ /= sqrt(lambda_);
128  }
129 
130  return true;
131 }
132 
133 
134 // ************************************************************************* //
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 keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
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 &dict)=0
Update properties from given dictionary.
Ship design analysis (SDA) 3DoF motion function.
Definition: SDA.H:59
virtual ~SDA()
Destructor.
Definition: SDA.C:62
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Definition: SDA.C:68
SDA(const word &name, 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:103
A class for handling words, derived from string.
Definition: word.H:63
#define DebugInFunction
Report an information message using Foam::Info.
mathematical constants.
const scalar piByTwo(0.5 *pi)
const scalar twoPi(2 *pi)
const dimensionSet time
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
dimensionedScalar exp(const dimensionedScalar &ds)
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)