fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / pistonDeform / pistonDeform.C
blob34ff6c68fd90de7ae28c22cbca4374877ff51609
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 \*---------------------------------------------------------------------------*/
27 #include "pistonDeform.H"
28 #include "engineTime.H"
29 #include "layerAdditionRemoval.H"
30 #include "pointField.H"
31 #include "mapPolyMesh.H"
32 #include "polyTopoChange.H"
33 #include "addToRunTimeSelectionTable.H"
34 #include "GeometricField.H"
35 #include "volMesh.H"
36 #include "fvPatchField.H"
37 #include "volPointInterpolation.H"
38 #include "fvcMeshPhi.H"
39 #include "fvcVolumeIntegrate.H"
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 namespace Foam
44     defineTypeNameAndDebug(pistonDeform, 0);
45     addToRunTimeSelectionTable(engineTopoChangerMesh, pistonDeform, IOobject);
49 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
52 void Foam::pistonDeform::checkAndCalculate()
54     
55     label pistonIndex = -1;
56     bool foundPiston = false;
58     label linerIndex = -1;
59     bool foundLiner = false;
61     label cylinderHeadIndex = -1;
62     bool foundCylinderHead = false;
63     
64     
65     forAll(boundary(), i)
66     {
67         Info << boundary()[i].name() << endl;
68         if (boundary()[i].name() == "piston")
69         {
70             pistonIndex = i;
71             foundPiston = true;
72         }
73         else if (boundary()[i].name() == "liner")
74         {
75             linerIndex = i;
76             foundLiner = true;
77         }
78         else if (boundary()[i].name() == "cylinderHead")
79         {
80             cylinderHeadIndex = i;
81             foundCylinderHead = true;
82         }
83     }
84     
85     reduce(foundPiston, orOp<bool>());
86     reduce(foundLiner, orOp<bool>());
87     reduce(foundCylinderHead, orOp<bool>());
89     if (!foundPiston)
90     {
91         FatalErrorIn("Foam::pistonDeform::checkAndCalculate()")
92             << " : cannot find piston patch"
93             << abort(FatalError);
94     }
96     if (!foundLiner)
97     { 
98         FatalErrorIn("Foam::pistonDeform::checkAndCalculate()")
99             << " : cannot find liner patch"
100             << abort(FatalError);
101     }
103     if (!foundCylinderHead)
104     { 
105         FatalErrorIn("Foam::pistonDeform::checkAndCalculate()")
106             << " : cannot find cylinderHead patch"
107             << exit(FatalError);
108     }
110     {
111         if (linerIndex != -1)
112         {
113             pistonPosition() =
114                 max(boundary()[pistonIndex].patch().localPoints()).z();
115         }
116         reduce(pistonPosition(), minOp<scalar>());
118         if (cylinderHeadIndex != -1)
119         {
120             deckHeight() = min
121             (
122                 boundary()[cylinderHeadIndex].patch().localPoints()
123             ).z();
124         }
125         reduce(deckHeight(), minOp<scalar>());
127         Info<< "deckHeight: " << deckHeight() << nl
128             << "piston position: " << pistonPosition() << endl;
129     }
130     
135 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
137 // Construct from components
138 Foam::pistonDeform::pistonDeform
140     const IOobject& io
143     engineTopoChangerMesh(io),
144     piston_(*this, engTime().engineDict().subDict("piston")),
145     pistonPosition_(-GREAT),
146     deckHeight_(GREAT)
148     checkAndCalculate();
152 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
154 Foam::pistonDeform::~pistonDeform()
159 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
161 bool Foam::pistonDeform::update()
163     scalar deltaZ = engTime().pistonDisplacement().value();
164     Info<< "deltaZ = " << deltaZ << endl;
165     
166     Info << "pistonPosition = " << pistonPosition_ << endl;
167     Info << "deckHeight = " << deckHeight_ << endl;
168     
170     // Position of the top of the static mesh layers above the piston
171     scalar pistonPlusLayers = pistonPosition_; //+ pistonLayers_.value();
173     pointField newPoints = points();
175     forAll (newPoints, pointi)
176     {
177         point& p = newPoints[pointi];
179         if (p.z() < pistonPlusLayers)           // In piston bowl
180         {
181             p.z() += deltaZ;
182         }
183         else if (p.z() < deckHeight_)   // In liner region
184         {
185             p.z() += 
186                 deltaZ
187                *(deckHeight_ - p.z())
188                /(deckHeight_ - pistonPlusLayers);
189         }
190     }
192     {
193         movePoints(newPoints);
194     }
196     pistonPosition_ += deltaZ;
197     scalar pistonSpeed = deltaZ/engTime().deltaT().value();
199     Info<< "clearance: " << deckHeight_ - pistonPosition_ << nl
200         << "Piston speed = " << pistonSpeed << " m/s" << endl;
203     return false;
207 void Foam::pistonDeform::setBoundaryVelocity(volVectorField& U)
209 // Does nothing, using the movingWallVelocity boundary condition for U in the piston patch...
212     
213 //    vector pistonVel = piston().cs().axis()*engTime().pistonSpeed().value();
214     
215     //mean piston velocityy
217     vector pistonVel = 0.5 * piston().cs().axis()*
218                             dimensionedScalar
219                             (
220                                 "meanPistonSpeed",
221                                 dimLength/dimTime,
222                                 2.0*engTime().stroke().value()*engTime().rpm().value()/60.0
223                             ).value();
226 //    U.boundaryField()[piston().patchID().index()] = pistonVel;
230 // ************************************************************************* //