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 "noEngineMesh.H"
28 #include "slidingInterface.H"
29 #include "layerAdditionRemoval.H"
30 #include "surfaceFields.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::noEngineMesh::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 noEngineMesh::addZonesAndModifiers() : "
46 << "Zones and modifiers already present. Skipping."
49 if (topoChanger_.size() == 0)
53 "void noEngineMesh::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)
84 label pistonPatchID = piston().patchID().index();
86 scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();
88 scalar zPistV = zPist + offSet();
90 labelList zone1(faceCentres().size());
91 boolList flipZone1(faceCentres().size(), false);
92 label nZoneFaces1 = 0;
94 bool foundAtLeastOne = false;
95 scalar zHigher = GREAT;
96 scalar zLower = GREAT;
100 forAll (faceCentres(), faceI)
102 scalar zc = faceCentres()[faceI].z();
103 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
104 scalar dd = n & vector(0,0,1);
108 if (zPistV - zc > 0 && zPistV - zc < dl)
114 if (zc - zPistV > 0 && zc - zPistV < dh)
122 zc > zPistV - delta()
123 && zc < zPistV + delta()
126 foundAtLeastOne = true;
127 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
129 flipZone1[nZoneFaces1] = true;
132 zone1[nZoneFaces1] = faceI;
138 // if no cut was found use the layer above
139 if (!foundAtLeastOne)
143 forAll (faceCentres(), faceI)
145 scalar zc = faceCentres()[faceI].z();
146 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
147 scalar dd = n & vector(0,0,1);
153 zc > zPistV - delta()
154 && zc < zPistV + delta()
157 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
159 flipZone1[nZoneFaces1] = true;
162 zone1[nZoneFaces1] = faceI;
170 zone1.setSize(nZoneFaces1);
171 flipZone1.setSize(nZoneFaces1);
186 // Construct point zones
189 // Points which don't move (= cylinder head)
190 DynamicList<label> headPoints(nPoints() / 10);
192 // Points below the piston which moves with the piston displacement
193 DynamicList<label> pistonPoints(nPoints() / 10);
195 label nHeadPoints = 0;
197 forAll (points(), pointI)
199 scalar zCoord = points()[pointI].z();
201 if (zCoord > deckHeight() - delta())
203 headPoints.append(pointI);
206 else if (zCoord < zPistV + delta())
208 pistonPoints.append(pointI);
212 Info << "Number of head points = " << nHeadPoints << endl;
229 pistonPoints.shrink(),
237 else if (piston().patchID().active() && offSet() <= SMALL)
239 label pistonPatchID = piston().patchID().index();
241 const polyPatch& pistonPatch =
242 boundaryMesh()[piston().patchID().index()];
244 labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
246 forAll (pistonPatchLabels, i)
248 pistonPatchLabels[i] += i;
256 boolList(pistonPatchLabels.size(), true),
261 // Construct point zones
264 max(boundary()[pistonPatchID].patch().localPoints()).z();
266 // Points which don't move (= cylinder head)
267 DynamicList<label> headPoints(nPoints() / 10);
269 // Points below the piston which moves with the piston displacement
270 DynamicList<label> pistonPoints(nPoints() / 10);
272 label nHeadPoints = 0;
274 forAll (points(), pointI)
276 scalar zCoord = points()[pointI].z();
278 if (zCoord > deckHeight() - delta())
280 headPoints.append(pointI);
283 else if (zCoord < zPistV + delta())
285 pistonPoints.append(pointI);
289 Info << "Number of head points = " << nHeadPoints << endl;
306 pistonPoints.shrink(),
314 Info<< "Adding " << nPointZones << " point and "
315 << nFaceZones << " face zones" << endl;
317 pz.setSize(nPointZones);
318 fz.setSize(nFaceZones);
319 addZones(pz, fz, cz);
321 List<polyMeshModifier*> tm(1);
324 // Add piston layer addition
325 Info << "Adding Layer Addition/Removal Mesh Modifier" << endl;
327 if (piston().patchID().active())
329 topoChanger_.setSize(1);
333 new layerAdditionRemoval
345 // Write mesh and modifiers
346 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
347 topoChanger_.write();
350 // Calculating the virtual piston position
351 setVirtualPistonPosition();
353 Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
354 Info << "piston position = " << pistonPosition() << endl;
358 // ************************************************************************* //