Clean up
[ShipHydroSIG.git] / src / vofDynamicMesh / lnInclude / excentreRotationFvMesh.C
blobe3643c553ea8ab3ca04fa2500960176a41f64bd4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2005 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
27 #include "excentreRotationFvMesh.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "volFields.H"
30 #include "mathematicalConstants.H"
31 #include "Time.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
37     defineTypeNameAndDebug(excentreRotationFvMesh, 0);
38     addToRunTimeSelectionTable(dynamicFvMesh, excentreRotationFvMesh, IOobject);
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 Foam::excentreRotationFvMesh::excentreRotationFvMesh(const IOobject& io)
46     dynamicFvMesh(io),
47     dynamicMeshCoeffs_
48     (
49         IOdictionary
50         (
51             IOobject
52             (
53                 "dynamicMeshDict",
54                 io.time().constant(),
55                 *this,
56                 IOobject::MUST_READ,
57                 IOobject::NO_WRITE
58             )
59         ).subDict(typeName + "Coeffs")
60     ),
61     rpm_
62     (
63         readScalar(dynamicMeshCoeffs_.lookup("rpm"))
64     ),
65     excentre_
66     (
67         readScalar(dynamicMeshCoeffs_.lookup("excentre"))
68     ),
69     rotAxis_
70     (
71        readScalar(dynamicMeshCoeffs_.lookup("rotAxis"))
72     ),
73     time0_
74     (
75         readScalar(dynamicMeshCoeffs_.lookup("time0"))
76     ),
77     time1_
78     (
79         readScalar(dynamicMeshCoeffs_.lookup("time1"))
80     )
84 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
86 Foam::excentreRotationFvMesh::~excentreRotationFvMesh()
90 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
92 bool Foam::excentreRotationFvMesh::update()
94     scalar omega = 0.0;
95       
96     scalar localTime = time().value();
98     scalar deltaT1 = time1_ - time0_ ;
99       
100     if (localTime >= 0.0 && localTime < time0_)
101     {
102         omega = 0.0;
103     }
104     else if (localTime < time1_)
105     {
106         scalar tempTime = localTime - time0_;
108         omega = rpm_ * 
109             (
110                 3.0*sqr(tempTime)/deltaT1/deltaT1
111               - 2.0*pow3(tempTime)/pow3(deltaT1)
112             );
113     }
114     else if (localTime > time1_)
115     {
116         omega = rpm_;           
117     }
119     Info << "Eccentricity = " << excentre_ << endl;
120     Info << "  Local Time = " << localTime << endl;
121     Info << "         rpm = " << omega << nl << endl;
123     scalar theta = (omega*360.0*time().value()/60.0)*
124         mathematicalConstant::pi/180.0;
126     scalar deltaTheta = (omega*360.0*time().deltaT().value()/60.0)*
127         mathematicalConstant::pi/180.0;
128       
129     const pointField& motionPoints = allPoints();
131     pointField newPoints(motionPoints.size(), vector::zero);
133     if (rotAxis_ == 1)
134     {
135         newPoints.replace
136         (
137             vector::X,
138             motionPoints.component(vector::X)
139           + excentre_*(cos(theta) - cos(theta + deltaTheta)) 
140         ); 
141       
142         newPoints.replace
143         (
144             vector::Y,
145             motionPoints.component(vector::Y)
146         );
148         newPoints.replace
149         (
150             vector::Z,
151             motionPoints.component(vector::Z)
152           + excentre_*(-sin(theta) + sin(theta + deltaTheta)) 
153         );
154     }
155     else if (rotAxis_ == 2)
156     {
157         newPoints.replace
158         (
159             vector::X,
160             motionPoints.component(vector::X)
161           + excentre_*(cos(theta) - cos(theta + deltaTheta))
162         );
164         newPoints.replace
165         (
166             vector::Y,
167             motionPoints.component(vector::Y)
168           + excentre_*(-sin(theta) + sin(theta + deltaTheta))
169         );
171         newPoints.replace
172         (
173             vector::Z,
174             motionPoints.component(vector::Z) 
175         );
176     }
177     else if (rotAxis_ == 3)
178     {
179         newPoints.replace
180         (
181             vector::X,
182             motionPoints.component(vector::X) 
183         );
185         newPoints.replace
186         (
187             vector::Y,
188             motionPoints.component(vector::Y)
189           + excentre_*(cos(theta) - cos(theta + deltaTheta))
190         );
192         newPoints.replace
193         (
194             vector::Z,
195             motionPoints.component(vector::Z)
196           + excentre_*(-sin(theta) + sin(theta + deltaTheta))
197         );
198     }
200     fvMesh::movePoints(newPoints);      
202     // Mesh motion only - return false
203     return false;
207 // ************************************************************************* //