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 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dimensionedScalar log(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
dimensionedSymmTensor sqr(const dimensionedVector &dv)
engineTime & runTime
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Septernion class used to perform translations and rotations in 3D space.
Definition: septernion.H:62
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
dimensionedScalar exp(const dimensionedScalar &ds)
Base class for defining solid-body motions.
constexpr scalar twoPi(2 *M_PI)
Mathematical constants.
#define DebugInFunction
Report an information message using Foam::Info.
virtual bool read(const dictionary &SBMFCoeffs)
Update properties from given dictionary.
Definition: SDA.C:92
virtual bool read(const dictionary &SBMFCoeffs)=0
Update properties from given dictionary.
constexpr scalar pi(M_PI)
Quaternion class used to perform rotations in 3D space.
Definition: quaternion.H:53
Vector< scalar > vector
Definition: vector.H:57
constexpr scalar piByTwo(0.5 *M_PI)
dimensionedScalar sin(const dimensionedScalar &ds)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineTypeNameAndDebug(combustionModel, 0)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define R(A, B, C, D, E, F, K, M)
virtual septernion transformation() const
Return the solid-body motion transformation septernion.
Definition: SDA.C:57
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)