Initial commit of NavalHydro package from Wikki to the ShipHydroSIG
[ShipHydroSIG.git] / src / vofDynamicMesh / lnInclude / harmonicSolidMotion.C
blobb93abe35eb4858e5865823d095543447d6f8f671
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Author
26     Hrvoje Jasak, Wikki Ltd.  All rights reserved.
28 \*---------------------------------------------------------------------------*/
30 #include "harmonicSolidMotion.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "volFields.H"
33 #include "mathematicalConstants.H"
34 #include "axisCoordinateRotation.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
40     defineTypeNameAndDebug(harmonicSolidMotion, 0);
41     addToRunTimeSelectionTable(dynamicFvMesh, harmonicSolidMotion, IOobject);
45 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
47 Foam::vector Foam::harmonicSolidMotion::periodToFreq(const vector period)
49     return
50         vector
51         (
52             2.0*mathematicalConstant::pi/(period.x() + SMALL),
53             2.0*mathematicalConstant::pi/(period.y() + SMALL),
54             2.0*mathematicalConstant::pi/(period.z() + SMALL)
55         );
59 Foam::vector Foam::harmonicSolidMotion::centre() const
61     const scalar t = time().value();
63     return
64         motionCentre_
65       + cmptMultiply
66         (
67             transL_,
68             vector
69             (
70                 sin(transOmega_.x()*t + transPsi_.x()),
71                 sin(transOmega_.y()*t + transPsi_.y()),
72                 sin(transOmega_.z()*t + transPsi_.z())
73             )
74         );
78 Foam::vector Foam::harmonicSolidMotion::rotation() const
80     const scalar t = time().value();
82     return
83         cmptMultiply
84         (
85             rotL_, 
86             vector
87             (
88                 sin(rotOmega_.x()*t + rotPsi_.x()),
89                 sin(rotOmega_.y()*t + rotPsi_.y()),
90                 sin(rotOmega_.z()*t + rotPsi_.z())
91             )
92         );
96 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
98 Foam::harmonicSolidMotion::harmonicSolidMotion(const IOobject& io)
100     dynamicFvMesh(io),
101     dict_
102     (
103         IOdictionary
104         (
105             IOobject
106             (
107                 "dynamicMeshDict",
108                 io.time().constant(),
109                 *this,
110                 IOobject::MUST_READ,
111                 IOobject::NO_WRITE
112             )
113         ).subDict(typeName + "Coeffs")
114     ),
115     refPoints_
116     (
117         IOobject
118         (
119             "points",
120             time().constant(),
121             polyMesh::meshSubDir,
122             *this,
123             IOobject::MUST_READ,
124             IOobject::NO_WRITE
125         )
126     ),
127     motionCentre_(dict_.lookup("motionCentre")),
128     transL_(dict_.lookup("translationAmplitude")),
129     transOmega_(periodToFreq(dict_.lookup("translationPeriod"))),
130     transPsi_(dict_.lookup("translationPhase")),
131     rotL_(dict_.lookup("rotationAmplitude")),
132     rotOmega_(periodToFreq(dict_.lookup("rotationPeriod"))),
133     rotPsi_(dict_.lookup("rotationPhase"))
135     refPoints_.rename("refPoints");
137     Switch inDegrees(dict_.lookup("inDegrees"));
139     if (inDegrees)
140     {
141         transPsi_ *= mathematicalConstant::pi/180.0;
142         rotL_ *= mathematicalConstant::pi/180.0;
143         rotPsi_ *= mathematicalConstant::pi/180.0;
144     }
148 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
150 Foam::harmonicSolidMotion::~harmonicSolidMotion()
154 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
156 bool Foam::harmonicSolidMotion::update()
158     Info << "Updating point position" << endl;
160     vector c = centre();
161     vector r = rotation();
162     tensor R = axisCoordinateRotation(r.x(), r.y(), r.z(), false);
164     fvMesh::movePoints((R & (refPoints_ - motionCentre_)) + c);      
166     // Mesh motion only - return false
167     return false;
171 // ************************************************************************* //