1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "noEngineMesh.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "surfaceFields.H"
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 void Foam::noEngineMesh::addZonesAndModifiers()
35 // Add the zones and mesh modifiers to operate piston motion
39 pointZones().size() > 0
40 || faceZones().size() > 0
41 || cellZones().size() > 0
44 Info<< "void noEngineMesh::addZonesAndModifiers() : "
45 << "Zones and modifiers already present. Skipping."
48 if (topoChanger_.size() == 0)
52 "void noEngineMesh::addZonesAndModifiers()"
53 ) << "Mesh modifiers not read properly"
57 setVirtualPistonPosition();
65 Info<< "Time = " << engTime().theta() << endl
66 << "Adding zones to the engine mesh" << endl;
68 //fz = 1: faces where layer are added/removed
69 //pz = 2: points below the virtual piston faces and head points
71 List<pointZone*> pz(2);
72 List<faceZone*> fz(1);
73 List<cellZone*> cz(0);
75 label nPointZones = 0;
78 // Add the piston zone
79 if (piston().patchID().active() && offSet() > SMALL)
83 label pistonPatchID = piston().patchID().index();
85 scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();
87 scalar zPistV = zPist + offSet();
89 labelList zone1(faceCentres().size());
90 boolList flipZone1(faceCentres().size(), false);
91 label nZoneFaces1 = 0;
93 bool foundAtLeastOne = false;
94 scalar zHigher = GREAT;
95 scalar zLower = GREAT;
99 forAll (faceCentres(), faceI)
101 scalar zc = faceCentres()[faceI].z();
102 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
103 scalar dd = n & vector(0,0,1);
107 if (zPistV - zc > 0 && zPistV - zc < dl)
113 if (zc - zPistV > 0 && zc - zPistV < dh)
121 zc > zPistV - delta()
122 && zc < zPistV + delta()
125 foundAtLeastOne = true;
126 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
128 flipZone1[nZoneFaces1] = true;
131 zone1[nZoneFaces1] = faceI;
137 // if no cut was found use the layer above
138 if (!foundAtLeastOne)
142 forAll (faceCentres(), faceI)
144 scalar zc = faceCentres()[faceI].z();
145 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
146 scalar dd = n & vector(0,0,1);
152 zc > zPistV - delta()
153 && zc < zPistV + delta()
156 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
158 flipZone1[nZoneFaces1] = true;
161 zone1[nZoneFaces1] = faceI;
169 zone1.setSize(nZoneFaces1);
170 flipZone1.setSize(nZoneFaces1);
185 // Construct point zones
188 // Points which don't move (= cylinder head)
189 dynamicLabelList headPoints(nPoints() / 10);
191 // Points below the piston which moves with the piston displacement
192 dynamicLabelList pistonPoints(nPoints() / 10);
194 label nHeadPoints = 0;
196 forAll (points(), pointI)
198 scalar zCoord = points()[pointI].z();
200 if (zCoord > deckHeight() - delta())
202 headPoints.append(pointI);
205 else if (zCoord < zPistV + delta())
207 pistonPoints.append(pointI);
211 Info << "Number of head points = " << nHeadPoints << endl;
228 pistonPoints.shrink(),
236 else if (piston().patchID().active() && offSet() <= SMALL)
238 label pistonPatchID = piston().patchID().index();
240 const polyPatch& pistonPatch =
241 boundaryMesh()[piston().patchID().index()];
243 labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
245 forAll (pistonPatchLabels, i)
247 pistonPatchLabels[i] += i;
255 boolList(pistonPatchLabels.size(), true),
260 // Construct point zones
263 max(boundary()[pistonPatchID].patch().localPoints()).z();
265 // Points which don't move (= cylinder head)
266 dynamicLabelList headPoints(nPoints() / 10);
268 // Points below the piston which moves with the piston displacement
269 dynamicLabelList pistonPoints(nPoints() / 10);
271 label nHeadPoints = 0;
273 forAll (points(), pointI)
275 scalar zCoord = points()[pointI].z();
277 if (zCoord > deckHeight() - delta())
279 headPoints.append(pointI);
282 else if (zCoord < zPistV + delta())
284 pistonPoints.append(pointI);
288 Info << "Number of head points = " << nHeadPoints << endl;
305 pistonPoints.shrink(),
313 Info<< "Adding " << nPointZones << " point and "
314 << nFaceZones << " face zones" << endl;
316 pz.setSize(nPointZones);
317 fz.setSize(nFaceZones);
318 addZones(pz, fz, cz);
320 List<polyMeshModifier*> tm(1);
323 // Add piston layer addition
324 Info << "Adding Layer Addition/Removal Mesh Modifier" << endl;
326 if (piston().patchID().active())
328 topoChanger_.setSize(1);
332 new layerAdditionRemoval
344 // Write mesh and modifiers
345 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
346 topoChanger_.write();
349 // Calculating the virtual piston position
350 setVirtualPistonPosition();
352 Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
353 Info << "piston position = " << pistonPosition() << endl;
357 // ************************************************************************* //