1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | 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 "simpleTwoStroke.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "surfaceFields.H"
30 #include "regionSplit.H"
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34 void Foam::simpleTwoStroke::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<< "Time = " << engTime().theta() << endl;
46 Info<< "void simpleTwoStroke::addZonesAndModifiers() : "
47 << "Zones and modifiers already present. Skipping."
50 if (topoChanger_.size() == 0)
54 "void simpleTwoStroke::addZonesAndModifiers()"
55 ) << "Mesh modifiers not read properly"
59 setVirtualPistonPosition();
67 Info << "checkAndCalculate()" << endl;
70 Info<< "Time = " << engTime().theta() << endl
71 << "Adding zones to the engine mesh" << endl;
74 //fz = 4: virtual piston, outSidePort, insidePort, cutFaceZone
75 //pz = 2: piston points, cutPointZone
78 List<pointZone*> pz(3);
79 List<faceZone*> fz(4);
80 List<cellZone*> cz(1);
82 label nPointZones = 0;
86 // Add the piston zone
87 if (piston().patchID().active())
92 Info << "Adding face zone for piston layer addition/removal" << endl;
94 label pistonPatchID = piston().patchID().index();
97 max(boundary()[pistonPatchID].patch().localPoints()).z();
99 scalar zPistV = zPist + offSet();
101 labelList zone1(faceCentres().size());
102 boolList flipZone1(faceCentres().size(), false);
103 label nZoneFaces1 = 0;
105 bool foundAtLeastOne = false;
106 scalar zHigher = GREAT;
110 forAll (faceCentres(), faceI)
112 // The points have to be in the cylinder and not in the ports....
114 scalar zc = faceCentres()[faceI].z();
116 scalar xc = faceCentres()[faceI].x();
117 scalar yc = faceCentres()[faceI].y();
119 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
120 scalar dd = n & vector(0,0,1);
122 if(sqrt(sqr(xc)+sqr(yc)) < 0.5 * engTime().bore().value())
126 if (zPistV - zc > 0 && zPistV - zc < dl)
131 if (zc - zPistV > 0 && zc - zPistV < dh)
139 zc > zPistV - delta()
140 && zc < zPistV + delta()
143 foundAtLeastOne = true;
144 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
146 flipZone1[nZoneFaces1] = true;
149 zone1[nZoneFaces1] = faceI;
156 // if no cut was found use the layer above
157 if (!foundAtLeastOne)
161 forAll (faceCentres(), faceI)
163 scalar zc = faceCentres()[faceI].z();
165 scalar xc = faceCentres()[faceI].x();
166 scalar yc = faceCentres()[faceI].y();
168 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
169 scalar dd = n & vector(0,0,1);
171 if(sqrt(sqr(xc)+sqr(yc)) < 0.5 * engTime().bore().value())
178 zc > zPistV - delta()
179 && zc < zPistV + delta()
182 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
184 flipZone1[nZoneFaces1] = true;
187 zone1[nZoneFaces1] = faceI;
196 zone1.setSize(nZoneFaces1);
197 flipZone1.setSize(nZoneFaces1);
211 // Points which don't move (= cylinder head)
212 DynamicList<label> headPoints(nPoints() / 10);
214 label nHeadPoints = 0;
215 forAll (points(), pointI)
217 scalar zCoord = points()[pointI].z();
219 if (zCoord > deckHeight() - delta())
221 headPoints.append(pointI);
226 Info << "Number of head points = " << nHeadPoints << endl;
240 // Sliding interface for scavenging ports
242 if (foundScavPorts())
246 const polyPatch& innerScav =
247 boundaryMesh()[boundaryMesh().findPatchID(scavInCylPatchName_)];
249 labelList isf(innerScav.size());
253 isf[i] = innerScav.start() + i;
256 fz[nFaceZones] = new faceZone
258 scavInCylPatchName_ + "Zone",
260 boolList(innerScav.size(), false),
269 const polyPatch& outerScav =
270 boundaryMesh()[boundaryMesh().findPatchID(scavInPortPatchName_)];
272 labelList osf(outerScav.size());
276 osf[i] = outerScav.start() + i;
279 fz[nFaceZones] = new faceZone
281 scavInPortPatchName_ + "Zone",
283 boolList(outerScav.size(), false),
290 fz[nFaceZones] = new faceZone
301 pz[nPointZones] = new pointZone
314 labelList movingCells(nCells());
315 label nMovingCells = 0;
317 scalar pistonX = piston().cs().origin().x();
318 scalar pistonY = piston().cs().origin().y();
320 forAll(cellCentres(),cellI)
322 const vector& v = cellCentres()[cellI];
326 sqrt(sqr(v.x()-pistonX)+sqr(v.y()-pistonY))
327 < 0.5*engTime().bore().value()
330 movingCells[nMovingCells] = cellI;
335 movingCells.setSize(nMovingCells);
336 Info<< "Number of cells in the moving region: "
337 << nMovingCells << endl;
339 cz[nCellZones] = new cellZone
351 Info<< "Adding " << nPointZones << " point, "
352 << nFaceZones << " face zones and "
353 << nCellZones << " cell zones" << endl;
355 pz.setSize(nPointZones);
356 fz.setSize(nFaceZones);
357 cz.setSize(nCellZones);
358 addZones(pz, fz, cz);
360 List<polyMeshModifier*> tm(2);
363 // Add piston layer addition
364 if (piston().patchID().active())
367 topoChanger_.setSize(topoChanger_.size() + 1);
372 new layerAdditionRemoval
388 topoChanger_.setSize(topoChanger_.size() + 1);
398 scavInCylPatchName_ + "Zone",
399 scavInPortPatchName_ + "Zone",
403 scavInPortPatchName_,
404 slidingInterface::INTEGRAL,
405 // slidingInterface::PARTIAL,
406 true, // Attach-detach action
407 intersection::VISIBLE // Projection algorithm
413 Info << "Adding " << nMods << " topology modifiers" << endl;
415 // Calculating the virtual piston position
417 setVirtualPistonPosition();
419 topoChanger_.setSize(nMods);
421 // Write mesh modifiers
422 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
423 topoChanger_.write();
426 Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
427 Info << "piston position = " << pistonPosition() << endl;
431 // ************************************************************************* //