1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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"
36 #include "fvPatchField.H"
37 #include "volPointInterpolation.H"
38 #include "fvcMeshPhi.H"
39 #include "fvcVolumeIntegrate.H"
40 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
44 defineTypeNameAndDebug(pistonDeform, 0);
45 addToRunTimeSelectionTable(engineTopoChangerMesh, pistonDeform, IOobject);
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
52 void Foam::pistonDeform::checkAndCalculate()
55 label pistonIndex = -1;
56 bool foundPiston = false;
58 label linerIndex = -1;
59 bool foundLiner = false;
61 label cylinderHeadIndex = -1;
62 bool foundCylinderHead = false;
67 Info << boundary()[i].name() << endl;
68 if (boundary()[i].name() == "piston")
73 else if (boundary()[i].name() == "liner")
78 else if (boundary()[i].name() == "cylinderHead")
80 cylinderHeadIndex = i;
81 foundCylinderHead = true;
85 reduce(foundPiston, orOp<bool>());
86 reduce(foundLiner, orOp<bool>());
87 reduce(foundCylinderHead, orOp<bool>());
91 FatalErrorIn("Foam::pistonDeform::checkAndCalculate()")
92 << " : cannot find piston patch"
98 FatalErrorIn("Foam::pistonDeform::checkAndCalculate()")
99 << " : cannot find liner patch"
100 << abort(FatalError);
103 if (!foundCylinderHead)
105 FatalErrorIn("Foam::pistonDeform::checkAndCalculate()")
106 << " : cannot find cylinderHead patch"
111 if (linerIndex != -1)
114 max(boundary()[pistonIndex].patch().localPoints()).z();
116 reduce(pistonPosition(), minOp<scalar>());
118 if (cylinderHeadIndex != -1)
122 boundary()[cylinderHeadIndex].patch().localPoints()
125 reduce(deckHeight(), minOp<scalar>());
127 Info<< "deckHeight: " << deckHeight() << nl
128 << "piston position: " << pistonPosition() << endl;
135 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
137 // Construct from components
138 Foam::pistonDeform::pistonDeform
143 engineTopoChangerMesh(io),
144 piston_(*this, engTime().engineDict().subDict("piston")),
145 pistonPosition_(-GREAT),
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;
166 Info << "pistonPosition = " << pistonPosition_ << endl;
167 Info << "deckHeight = " << deckHeight_ << endl;
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)
177 point& p = newPoints[pointi];
179 if (p.z() < pistonPlusLayers) // In piston bowl
183 else if (p.z() < deckHeight_) // In liner region
187 *(deckHeight_ - p.z())
188 /(deckHeight_ - pistonPlusLayers);
193 movePoints(newPoints);
196 pistonPosition_ += deltaZ;
197 scalar pistonSpeed = deltaZ/engTime().deltaT().value();
199 Info<< "clearance: " << deckHeight_ - pistonPosition_ << nl
200 << "Piston speed = " << pistonSpeed << " m/s" << endl;
207 void Foam::pistonDeform::setBoundaryVelocity(volVectorField& U)
209 // Does nothing, using the movingWallVelocity boundary condition for U in the piston patch...
213 // vector pistonVel = piston().cs().axis()*engTime().pistonSpeed().value();
215 //mean piston velocityy
217 vector pistonVel = 0.5 * piston().cs().axis()*
222 2.0*engTime().stroke().value()*engTime().rpm().value()/60.0
226 // U.boundaryField()[piston().patchID().index()] = pistonVel;
230 // ************************************************************************* //