initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / engine / engineMesh / fvMotionSolverEngineMesh / fvMotionSolverEngineMesh.C
blob7ad1872833fa690cbb67c2bc1770f22ee16ac1f4
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "fvMotionSolverEngineMesh.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvcMeshPhi.H"
30 #include "surfaceInterpolate.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(fvMotionSolverEngineMesh, 0);
41 addToRunTimeSelectionTable(engineMesh, fvMotionSolverEngineMesh, IOobject);
43 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
45 fvMotionSolverEngineMesh::fvMotionSolverEngineMesh(const IOobject& io)
47     engineMesh(io),
48     pistonLayers_("pistonLayers", dimLength, 0.0),
49     motionSolver_(*this, engineDB_.engineDict().lookup("motionSolver"))
51     if (engineDB_.engineDict().found("pistonLayers"))
52     {
53         engineDB_.engineDict().lookup("pistonLayers") >> pistonLayers_;
54     }
58 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
60 fvMotionSolverEngineMesh::~fvMotionSolverEngineMesh()
64 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
66 void fvMotionSolverEngineMesh::move()
68     scalar deltaZ = engineDB_.pistonDisplacement().value();
69     Info<< "deltaZ = " << deltaZ << endl;
71     // Position of the top of the static mesh layers above the piston
72     scalar pistonPlusLayers = pistonPosition_.value() + pistonLayers_.value();
74     motionSolver_.cellMotionU().boundaryField()[pistonIndex_] == deltaZ;
76     {
77         scalarField linerPoints =
78             motionSolver_.cellMotionU()
79            .boundaryField()[linerIndex_].patch().Cf().component(vector::Z);
81         motionSolver_.cellMotionU().boundaryField()[linerIndex_] ==
82             deltaZ*pos(deckHeight_.value() - linerPoints)
83             *(deckHeight_.value() - linerPoints)
84             /(deckHeight_.value() - pistonPlusLayers);
85     }
87     motionSolver_.solve();
89     if (engineDB_.foundObject<surfaceScalarField>("phi"))
90     {
91         surfaceScalarField& phi = 
92             const_cast<surfaceScalarField&>
93             (engineDB_.lookupObject<surfaceScalarField>("phi"));
95         const volScalarField& rho =
96             engineDB_.lookupObject<volScalarField>("rho");
98         const volVectorField& U = 
99             engineDB_.lookupObject<volVectorField>("U");
101         bool absolutePhi = false;
102         if (moving())
103         {
104             phi += fvc::interpolate(rho)*fvc::meshPhi(rho, U);
105             absolutePhi = true;
106         }
108         movePoints(motionSolver_.curPoints());
110         if (absolutePhi)
111         {
112             phi -= fvc::interpolate(rho)*fvc::meshPhi(rho, U);
113         }
114     }
115     else
116     {
117         movePoints(motionSolver_.curPoints());
118     }
121     pistonPosition_.value() += deltaZ;
122     scalar pistonSpeed = deltaZ/engineDB_.deltaT().value();
124     Info<< "clearance: " << deckHeight_.value() - pistonPosition_.value() << nl
125         << "Piston speed = " << pistonSpeed << " m/s" << endl;
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 } // End namespace Foam
133 // ************************************************************************* //