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 \*---------------------------------------------------------------------------*/
28 #include "slidingInterface.H"
29 #include "layerAdditionRemoval.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::layerAR::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 layerAR::addZonesAndModifiers() : "
46 << "Zones and modifiers already present. Skipping."
49 if (topoChanger_.size() == 0)
53 "void layerAR::addZonesAndModifiers()"
54 ) << "Mesh modifiers not read properly"
58 setVirtualPistonPosition();
66 Info<< "Time = " << engTime().theta() << endl
67 << "Adding zones to the engine mesh" << endl;
69 //fz = 1: faces where layer are added/removed
70 //pz = 2: points below the virtual piston faces and head points
72 List<pointZone*> pz(2);
73 List<faceZone*> fz(1);
74 List<cellZone*> cz(0);
76 label nPointZones = 0;
79 // Add the piston zone
80 if (piston().patchID().active() && offSet() > SMALL)
85 label pistonPatchID = piston().patchID().index();
87 scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();
89 scalar zPistV = zPist + offSet();
91 labelList zone1(faceCentres().size());
92 boolList flipZone1(faceCentres().size(), false);
93 label nZoneFaces1 = 0;
95 bool foundAtLeastOne = false;
96 scalar zHigher = GREAT;
97 scalar zLower = GREAT;
101 forAll (faceCentres(), faceI)
103 scalar zc = faceCentres()[faceI].z();
104 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
105 scalar dd = n & vector(0,0,1);
109 if (zPistV - zc > 0 && zPistV - zc < dl)
115 if (zc - zPistV > 0 && zc - zPistV < dh)
123 zc > zPistV - delta()
124 && zc < zPistV + delta()
127 foundAtLeastOne = true;
128 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
130 flipZone1[nZoneFaces1] = true;
133 zone1[nZoneFaces1] = faceI;
139 // if no cut was found use the layer above
140 if (!foundAtLeastOne)
145 forAll (faceCentres(), faceI)
147 scalar zc = faceCentres()[faceI].z();
148 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
149 scalar dd = n & vector(0,0,1);
155 zc > zPistV - delta()
156 && zc < zPistV + delta()
159 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
161 flipZone1[nZoneFaces1] = true;
164 zone1[nZoneFaces1] = faceI;
172 zone1.setSize(nZoneFaces1);
173 flipZone1.setSize(nZoneFaces1);
188 // Construct point zones
191 // Points which don't move (= cylinder head)
192 DynamicList<label> headPoints(nPoints() / 10);
194 // Points below the piston which moves with the piston displacement
195 DynamicList<label> pistonPoints(nPoints() / 10);
197 label nHeadPoints = 0;
199 forAll (points(), pointI)
201 scalar zCoord = points()[pointI].z();
203 if (zCoord > deckHeight() - delta())
205 headPoints.append(pointI);
208 else if (zCoord < zPistV + delta())
210 pistonPoints.append(pointI);
214 Info << "Number of head points = " << nHeadPoints << endl;
232 pistonPoints.shrink(),
240 else if(piston().patchID().active() && offSet() <= SMALL)
242 label pistonPatchID = piston().patchID().index();
244 const polyPatch& pistonPatch =
245 boundaryMesh()[piston().patchID().index()];
247 labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
249 forAll (pistonPatchLabels, i)
251 pistonPatchLabels[i] += i;
259 boolList(pistonPatchLabels.size(), true),
264 // Construct point zones
266 scalar zPistV = max(boundary()[pistonPatchID].patch().localPoints()).z();
268 // Points which don't move (= cylinder head)
269 DynamicList<label> headPoints(nPoints() / 10);
271 // Points below the piston which moves with the piston displacement
272 DynamicList<label> pistonPoints(nPoints() / 10);
274 label nHeadPoints = 0;
276 forAll (points(), pointI)
278 scalar zCoord = points()[pointI].z();
280 if (zCoord > deckHeight() - delta())
282 headPoints.append(pointI);
285 else if (zCoord < zPistV + delta())
287 pistonPoints.append(pointI);
291 Info << "Number of head points = " << nHeadPoints << endl;
309 pistonPoints.shrink(),
319 Info<< "Adding " << nPointZones << " point and "
320 << nFaceZones << " face zones" << endl;
322 pz.setSize(nPointZones);
323 fz.setSize(nFaceZones);
324 addZones(pz, fz, cz);
326 List<polyMeshModifier*> tm(1);
329 // Add piston layer addition
330 Info << "Adding Layer Addition/Removal Mesh Modifier" << endl;
332 if (piston().patchID().active())
334 topoChanger_.setSize(1);
338 new layerAdditionRemoval
350 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
351 topoChanger_.write();
354 // Calculating the virtual piston position
355 setVirtualPistonPosition();
357 Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
358 Info << "piston position = " << pistonPosition() << endl;
362 // ************************************************************************* //