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 "layerARGambit.H"
27 #include "slidingInterface.H"
28 #include "layerAdditionRemoval.H"
29 #include "surfaceFields.H"
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 void Foam::layerARGambit::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 layerARGambit::addZonesAndModifiers() : "
45 << "Zones and modifiers already present. Skipping."
48 if (topoChanger_.size() == 0)
52 "void layerARGambit::addZonesAndModifiers()"
53 ) << "Mesh modifiers not read properly"
57 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;
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)
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)
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;
230 pistonPoints.shrink(),
238 else if(piston().patchID().active() && offSet() <= SMALL)
240 label pistonPatchID = piston().patchID().index();
242 const polyPatch& pistonPatch =
243 boundaryMesh()[piston().patchID().index()];
245 labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
247 forAll (pistonPatchLabels, i)
249 pistonPatchLabels[i] += i;
257 boolList(pistonPatchLabels.size(), true),
262 // Construct point zones
264 scalar zPistV = 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);
282 //Info<< "HeadPoint:" << pointI << " coord:" << points[pointI]
285 else if (zCoord < zPistV + delta())
287 pistonPoints.append(pointI);
288 //Info<< "PistonPoint:" << pointI << " coord:" << points[pointI]
293 Info << "Number of head points = " << nHeadPoints << endl;
311 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 // Write mesh and modifiers
351 topoChanger_.writeOpt() = IOobject::AUTO_WRITE;
352 topoChanger_.write();
355 // Calculating the virtual piston position
356 setVirtualPistonPosition();
358 Info << "virtualPistonPosition = " << virtualPistonPosition() << endl;
359 Info << "piston position = " << pistonPosition() << endl;
363 // ************************************************************************* //