Initial commit of NavalHydro package from Wikki to the ShipHydroSIG
[ShipHydroSIG.git] / src / vofDynamicMesh / lnInclude / graphSolidMotion.C
blob42489897e920e16600eefdd3e5b138447e90e8e8
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 "graphSolidMotion.H"
31 #include "addToRunTimeSelectionTable.H"
32 #include "volFields.H"
33 #include "mathematicalConstants.H"
34 #include "axisCoordinateRotation.H"
35 #include "interpolateXY.H"
36 #include "IFstream.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 namespace Foam
42     defineTypeNameAndDebug(graphSolidMotion, 0);
43     addToRunTimeSelectionTable(dynamicFvMesh, graphSolidMotion, IOobject);
47 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
49 Foam::vector Foam::graphSolidMotion::centre() const
51     const scalar t = time().value();
53     return motionCentre_
54       + vector
55         (
56             interpolateXY(t, x_.x(), x_.y()),
57             interpolateXY(t, y_.x(), y_.y()),
58             interpolateXY(t, z_.x(), z_.y())
59         );
63 Foam::vector Foam::graphSolidMotion::rotation() const
65     const scalar t = time().value();
67     scalar xAngle = interpolateXY(t, xRot_.x(), xRot_.y());
68     scalar yAngle = interpolateXY(t, yRot_.x(), yRot_.y());
69     scalar zAngle = interpolateXY(t, zRot_.x(), zRot_.y());
71     if (inDegrees_)
72     {
73         xAngle *= mathematicalConstant::pi/180.0;
74         yAngle *= mathematicalConstant::pi/180.0;
75         zAngle *= mathematicalConstant::pi/180.0;
76     }
78     return vector(xAngle, yAngle, zAngle);
82 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
84 Foam::graphSolidMotion::graphSolidMotion(const IOobject& io)
86     dynamicFvMesh(io),
87     dict_
88     (
89         IOdictionary
90         (
91             IOobject
92             (
93                 "dynamicMeshDict",
94                 io.time().constant(),
95                 *this,
96                 IOobject::MUST_READ,
97                 IOobject::NO_WRITE
98             )
99         ).subDict(typeName + "Coeffs")
100     ),
101     refPoints_
102     (
103         IOobject
104         (
105             "points",
106             time().constant(),
107             polyMesh::meshSubDir,
108             *this,
109             IOobject::MUST_READ,
110             IOobject::NO_WRITE
111         )
112     ),
113     motionCentre_(dict_.lookup("motionCentre")),
114     x_
115     (
116         "t",
117         "x-translation",
118         "x",
119         IFstream(time().path()/time().caseConstant()/word(dict_.lookup("x")))()
120     ),
121     y_
122     (
123         "t",
124         "y-translation",
125         "y",
126         IFstream(time().path()/time().caseConstant()/word(dict_.lookup("y")))()
127     ),
128     z_
129     (
130         "t",
131         "z-translation",
132         "z",
133         IFstream(time().path()/time().caseConstant()/word(dict_.lookup("z")))()
134     ),
135     xRot_
136     (
137         "t",
138         "x-rotation",
139         "x",
140         IFstream(time().path()/time().caseConstant()/word(dict_.lookup("xRot")))()
141     ),
142     yRot_
143     (
144         "t",
145         "y-rotation",
146         "yRot",
147         IFstream(time().path()/time().caseConstant()/word(dict_.lookup("yRot")))()
148     ),
149     zRot_
150     (
151         "t",
152         "z-rotation",
153         "zRot",
154         IFstream(time().path()/time().caseConstant()/word(dict_.lookup("zRot")))()
155     ),
156     inDegrees_(dict_.lookup("inDegrees"))
158     refPoints_.rename("refPoints");
162 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
164 Foam::graphSolidMotion::~graphSolidMotion()
168 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
170 bool Foam::graphSolidMotion::update()
172     Info << "Updating point position" << endl;
174     vector c = centre();
175     vector r = rotation();
176     tensor R = axisCoordinateRotation(r.x(), r.y(), r.z(), false);
178     fvMesh::movePoints((R & (refPoints_ - motionCentre_)) + c);      
180     // Mesh motion only - return false
181     return false;
185 // ************************************************************************* //