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 "layerARGambit.H"
28 #include "slidingInterface.H"
29 #include "layerAdditionRemoval.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::layerARGambit::addZonesAndModifiers()
36 // Add the zones and mesh modifiers to operate piston motion
40 pointZones().size() > 0
41 || faceZones().size() > 0
42 || cellZones().size() > 0
45 Info<< "void layerARGambit::addZonesAndModifiers() : "
46 << "Zones and modifiers already present. Skipping."
49 if (topoChanger_.size() == 0)
53 "void layerARGambit::addZonesAndModifiers()"
54 ) << "Mesh modifiers not read properly"
58 setVirtualPistonPosition();
67 Info<< "Time = " << engTime().theta() << endl
68 << "Adding zones to the engine mesh" << endl;
70 //fz = 1: faces where layer are added/removed
71 //pz = 2: points below the virtual piston faces and head points
73 List<pointZone*> pz(2);
74 List<faceZone*> fz(1);
75 List<cellZone*> cz(0);
77 label nPointZones = 0;
80 // Add the piston zone
81 if (piston().patchID().active() && offSet() > SMALL)
86 label pistonPatchID = piston().patchID().index();
88 scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();
90 scalar zPistV = zPist + offSet();
92 labelList zone1(faceCentres().size());
93 boolList flipZone1(faceCentres().size(), false);
94 label nZoneFaces1 = 0;
96 bool foundAtLeastOne = false;
97 scalar zHigher = GREAT;
98 scalar zLower = GREAT;
102 forAll (faceCentres(), faceI)
104 scalar zc = faceCentres()[faceI].z();
105 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
106 scalar dd = n & vector(0,0,1);
110 if (zPistV - zc > 0 && zPistV - zc < dl)
116 if (zc - zPistV > 0 && zc - zPistV < dh)
124 zc > zPistV - delta()
125 && zc < zPistV + delta()
128 foundAtLeastOne = true;
129 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
131 flipZone1[nZoneFaces1] = true;
134 zone1[nZoneFaces1] = faceI;
140 // if no cut was found use the layer above
141 if (!foundAtLeastOne)
146 forAll (faceCentres(), faceI)
148 scalar zc = faceCentres()[faceI].z();
149 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
150 scalar dd = n & vector(0,0,1);
156 zc > zPistV - delta()
157 && zc < zPistV + delta()
160 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
162 flipZone1[nZoneFaces1] = true;
165 zone1[nZoneFaces1] = faceI;
173 zone1.setSize(nZoneFaces1);
174 flipZone1.setSize(nZoneFaces1);
189 // Construct point zones
192 // Points which don't move (= cylinder head)
193 DynamicList<label> headPoints(nPoints() / 10);
195 // Points below the piston which moves with the piston displacement
196 DynamicList<label> pistonPoints(nPoints() / 10);
198 label nHeadPoints = 0;
200 forAll (points(), pointI)
202 scalar zCoord = points()[pointI].z();
204 if (zCoord > deckHeight() - delta())
206 headPoints.append(pointI);
209 else if (zCoord < zPistV + delta())
211 pistonPoints.append(pointI);
215 Info << "Number of head points = " << nHeadPoints << endl;
233 pistonPoints.shrink(),
241 else if(piston().patchID().active() && offSet() <= SMALL)
243 label pistonPatchID = piston().patchID().index();
245 const polyPatch& pistonPatch =
246 boundaryMesh()[piston().patchID().index()];
248 labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
250 forAll (pistonPatchLabels, i)
252 pistonPatchLabels[i] += i;
260 boolList(pistonPatchLabels.size(), true),
265 // Construct point zones
267 scalar zPistV = max(boundary()[pistonPatchID].patch().localPoints()).z();
269 // Points which don't move (= cylinder head)
270 DynamicList<label> headPoints(nPoints() / 10);
272 // Points below the piston which moves with the piston displacement
273 DynamicList<label> pistonPoints(nPoints() / 10);
275 label nHeadPoints = 0;
277 forAll (points(), pointI)
279 scalar zCoord = points()[pointI].z();
281 if (zCoord > deckHeight() - delta())
283 headPoints.append(pointI);
285 //Info<< "HeadPoint:" << pointI << " coord:" << points[pointI]
288 else if (zCoord < zPistV + delta())
290 pistonPoints.append(pointI);
291 //Info<< "PistonPoint:" << pointI << " coord:" << points[pointI]
296 Info << "Number of head points = " << nHeadPoints << endl;
314 pistonPoints.shrink(),
322 Info<< "Adding " << nPointZones << " point and "
323 << nFaceZones << " face zones" << endl;
325 pz.setSize(nPointZones);
326 fz.setSize(nFaceZones);
327 addZones(pz, fz, cz);
329 List<polyMeshModifier*> tm(1);
332 // Add piston layer addition
333 Info << "Adding Layer Addition/Removal Mesh Modifier" << endl;
335 if (piston().patchID().active())
337 topoChanger_.setSize(1);
341 new layerAdditionRemoval
353 // Write mesh and modifiers
354 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
355 topoChanger_.write();
358 // Calculating the virtual piston position
359 setVirtualPistonPosition();
361 Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
362 Info << "piston position = " << pistonPosition() << endl;
366 // ************************************************************************* //