2 if (piston().patchID().active())
7 Info << "Adding face zone for piston layer addition/removal" << endl;
9 label pistonPatchID = piston().patchID().index();
11 scalarField zPistonValves(valves().size() + 1,max(boundary()[pistonPatchID].patch().localPoints()).z());
13 scalarField zPistonValvesOffset = zPistonValves + offSet();
15 labelListList zonePiston(valves().size()+1);
16 boolListList flipZonePiston(valves().size() + 1);
17 labelList nZoneFacesPiston(valves().size() + 1, 0);
18 boolList foundOneFace(valves().size() + 1, false);
19 scalarList zHigher(valves().size() + 1, GREAT);
20 scalarList zLower(valves().size() + 1, GREAT);
21 scalarList dh(valves().size() + 1, GREAT);
22 scalarList dl(valves().size() + 1, GREAT);
24 forAll(zonePiston, zoneI)
26 zonePiston[zoneI].setSize(faceCentres().size());
27 flipZonePiston[zoneI].setSize(faceCentres().size());
28 flipZonePiston[zoneI] = false;
31 forAll (faceCentres(), faceI)
33 bool foundInValve = false;
35 scalar zc = faceCentres()[faceI].z();
37 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
38 scalar dd = n & vector(0,0,1);
40 forAll(valves(), valveI)
43 if(inValve(faceCentres()[faceI], valveI))
47 scalar zPistV = zPistonValvesOffset[valveI];
51 if (zPistV - zc > 0 && zPistV - zc < dl[valveI])
54 dl[valveI] = zPistV - zc;
57 if (zc - zPistV > 0 && zc - zPistV < dh[valveI])
60 dh[valveI] = zc - zHigher[valveI];
66 && zc < zPistV + delta()
70 foundOneFace[valveI] = true;
72 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
74 flipZonePiston[valveI][nZoneFacesPiston[valveI]] = true;
77 zonePiston[valveI][nZoneFacesPiston[valveI]] = faceI;
78 nZoneFacesPiston[valveI]++;
87 label valveSize = valves().size();
89 scalar zPistV = zPistonValvesOffset[valveSize];
93 if (zPistV - zc > 0 && zPistV - zc < dl[valveSize])
95 zLower[valveSize] = zc;
96 dl[valveSize] = zPistV - zc;
99 if (zc - zPistV > 0 && zc - zPistV < dh[valveSize])
101 zHigher[valveSize] = zc;
102 dh[valveSize] = zc - zHigher[valveSize];
107 zc > zPistV - delta()
108 && zc < zPistV + delta()
112 foundOneFace[valveSize] = true;
114 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
116 flipZonePiston[valveSize][nZoneFacesPiston[valveSize]] = true;
119 zonePiston[valveSize][nZoneFacesPiston[valveSize]] = faceI;
120 nZoneFacesPiston[valveSize]++;
128 // if no cut was found use the layer above
130 forAll(valves(), valveI)
133 if (!foundOneFace[valveI])
135 zPistonValvesOffset[valveI] = zHigher[valveI];
139 if(!foundOneFace[valves().size()])
141 zPistonValvesOffset[valves().size()] = zHigher[valves().size()];
144 forAll (faceCentres(), faceI)
147 bool foundInValve = false;
149 scalar zc = faceCentres()[faceI].z();
151 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
152 scalar dd = n & vector(0,0,1);
154 forAll(valves(), valveI)
157 if(!foundOneFace[valveI])
160 scalar zPistV = zPistonValvesOffset[valveI];
163 if(inValve(faceCentres()[faceI], valveI))
172 zc > zPistV - delta()
173 && zc < zPistV + delta()
177 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
179 flipZonePiston[valveI][nZoneFacesPiston[valveI]] = true;
182 zonePiston[valveI][nZoneFacesPiston[valveI]] = faceI;
183 nZoneFacesPiston[valveI]++;
191 if(!foundInValve && !foundOneFace[valves().size()])
193 label valveSize = valves().size();
194 scalar zPistV = zPistonValvesOffset[valveSize];
201 zc > zPistV - delta()
202 && zc < zPistV + delta()
205 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
207 flipZonePiston[valveSize][nZoneFacesPiston[valveSize]] = true;
210 zonePiston[valveSize][nZoneFacesPiston[valveSize]] = faceI;
211 nZoneFacesPiston[valveSize]++;
217 forAll(valves(), valveI)
219 zonePiston[valveI].setSize(nZoneFacesPiston[valveI]);
220 flipZonePiston[valveI].setSize(nZoneFacesPiston[valveI]);
226 "pistonLayerFacesV" + Foam::name(valveI + 1),
228 flipZonePiston[valveI],
238 label valveSize = valves().size();
239 zonePiston[valveSize].setSize(nZoneFacesPiston[valveSize]);
240 flipZonePiston[valveSize].setSize(nZoneFacesPiston[valveSize]);
247 zonePiston[valveSize],
248 flipZonePiston[valveSize],
258 forAll(valves(), valveI)
261 labelList movingCells(nCells());
263 label nMovingCells = 0;
265 forAll(cellCentres(),cellI)
267 const vector& v = cellCentres()[cellI];
273 v.z() < zPistonValvesOffset[valveI]
276 movingCells[nMovingCells] = cellI;
282 movingCells.setSize(nMovingCells);
283 Info << "Number of cells in the moving region poppet valve: " << nMovingCells << endl;
289 "movingCellsPistonV"+ Foam::name(valveI + 1),
298 // valve top points (move all with valve displacement)
299 DynamicList<label> valvePistonPoints(nPoints() / 10);
300 List<bool> valvePistonPoint(nPoints(), false);
301 bool foundOne = false;
303 const cellList& c = cells();
304 const faceList& f = allFaces();
306 forAll (movingCells, cellI)
308 const cell& curCell = c[movingCells[cellI]];
310 forAll (curCell, faceI)
312 // Mark all the points as moving
313 const face& curFace = f[curCell[faceI]];
315 forAll (curFace, pointI)
318 valvePistonPoint[curFace[pointI]] = true;
325 forAll(valvePistonPoint, pointI)
327 if(valvePistonPoint[pointI])
329 valvePistonPoints.append(pointI);
337 "valvePistonPointsV"+ Foam::name(valveI + 1),
338 valvePistonPoints.shrink(),
351 label valveSize = valves().size();
352 labelList movingCells(nCells());
354 label nMovingCells = 0;
356 forAll(cellCentres(),cellI)
358 const vector& v = cellCentres()[cellI];
360 bool fallInValve = false;
361 forAll(valves(), valveI)
363 if(inValve(v, valveI))
373 v.z() < zPistonValvesOffset[valveSize]
376 movingCells[nMovingCells] = cellI;
382 movingCells.setSize(nMovingCells);
383 Info << "Number of cells in the moving region poppet valve: " << nMovingCells << endl;
398 // valve top points (move all with valve displacement)
399 DynamicList<label> pistonPoints(nPoints() / 10);
400 List<bool> pistonPoint(nPoints(), false);
401 bool foundOne = false;
403 const cellList& c = cells();
404 const faceList& f = allFaces();
406 forAll (movingCells, cellI)
408 const cell& curCell = c[movingCells[cellI]];
410 forAll (curCell, faceI)
412 // Mark all the points as moving
413 const face& curFace = f[curCell[faceI]];
415 forAll (curFace, pointI)
418 pistonPoint[curFace[pointI]] = true;
425 forAll(pistonPoint, pointI)
427 if(pistonPoint[pointI])
429 pistonPoints.append(pointI);
438 pistonPoints.shrink(),