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 -------------------------------------------------------------------------------
11 License
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"
31 #include "mathematicalConstants.H"
32 
33 using namespace Foam::constant::mathematical;
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace solidBodyMotionFunctions
40 {
41  defineTypeNameAndDebug(SDA, 0);
42  addToRunTimeSelectionTable(solidBodyMotionFunction, SDA, dictionary);
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 Foam::solidBodyMotionFunctions::SDA::SDA
50 (
51  const dictionary& SBMFCoeffs,
52  const Time& runTime
53 )
54 :
55  solidBodyMotionFunction(SBMFCoeffs, runTime),
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 {
101  solidBodyMotionFunction::read(SBMFCoeffs);
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 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
runTime
engineTime & runTime
Definition: createEngineTime.H:13
mathematicalConstants.H
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::septernion
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:66
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
SDA.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::exp
dimensionedScalar exp(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:261
Foam::solidBodyMotionFunctions::SDA::transformation
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Definition: SDA.C:64
Foam::quaternion
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:56
R
#define R(A, B, C, D, E, F, K, M)
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::solidBodyMotionFunction
Base class for defining solid-body motions.
Definition: solidBodyMotionFunction.H:63
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::constant::mathematical::twoPi
constexpr scalar twoPi(2 *M_PI)
Foam::quaternion::XYZ
Definition: quaternion.H:108
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::log
dimensionedScalar log(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:262
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
Foam::solidBodyMotionFunction::read
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
Definition: solidBodyMotionFunction.C:60
Foam::constant::mathematical::piByTwo
constexpr scalar piByTwo(0.5 *M_PI)
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::constant::mathematical
Mathematical constants.
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::Vector< scalar >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::solidBodyMotionFunctions::SDA::read
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: SDA.C:99