Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / verticalValves / addPistonFacesPointZones.H
blob82005bd606d33298b94e453b5917e0f5033b0c4f
1     // Add the piston zone
2     if (piston().patchID().active())
3     {
5         // Piston position
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)
25         {
26             zonePiston[zoneI].setSize(faceCentres().size());
27             flipZonePiston[zoneI].setSize(faceCentres().size());
28             flipZonePiston[zoneI] = false;
29         }
31         forAll (faceCentres(), faceI)
32         {
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)
41             {
43                 if(inValve(faceCentres()[faceI], valveI))
44                 {
45                     foundInValve = true;
47                     scalar zPistV = zPistonValvesOffset[valveI];
49                     if (mag(dd) > 0.1)
50                     {
51                         if (zPistV - zc > 0 && zPistV - zc < dl[valveI])
52                         {
53                             zLower[valveI] = zc;
54                             dl[valveI] = zPistV - zc;
55                         }
57                         if (zc - zPistV > 0 && zc - zPistV < dh[valveI])
58                         {
59                             zHigher[valveI] = zc;
60                             dh[valveI] = zc - zHigher[valveI];
61                         }
63                         if
64                         (
65                             zc > zPistV - delta()
66                             && zc < zPistV + delta()
67                         )
68                         {
70                             foundOneFace[valveI] = true;
72                             if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
73                             {
74                                 flipZonePiston[valveI][nZoneFacesPiston[valveI]] = true;
75                             }
77                             zonePiston[valveI][nZoneFacesPiston[valveI]] = faceI;
78                             nZoneFacesPiston[valveI]++;
80                         }
81                     }
82                 }
83             }
85             if(!foundInValve)
86             {
87                 label valveSize = valves().size();
89                 scalar zPistV = zPistonValvesOffset[valveSize];
91                 if (mag(dd) > 0.1)
92                 {
93                     if (zPistV - zc > 0 && zPistV - zc < dl[valveSize])
94                     {
95                         zLower[valveSize] = zc;
96                         dl[valveSize] = zPistV - zc;
97                     }
99                     if (zc - zPistV > 0 && zc - zPistV < dh[valveSize])
100                     {
101                         zHigher[valveSize] = zc;
102                         dh[valveSize] = zc - zHigher[valveSize];
103                     }
105                     if
106                     (
107                         zc > zPistV - delta()
108                         && zc < zPistV + delta()
109                     )
110                     {
112                         foundOneFace[valveSize] = true;
114                         if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
115                         {
116                             flipZonePiston[valveSize][nZoneFacesPiston[valveSize]] = true;
117                         }
119                         zonePiston[valveSize][nZoneFacesPiston[valveSize]] = faceI;
120                         nZoneFacesPiston[valveSize]++;
122                     }
123                 }
124             }
125         }
128         // if no cut was found use the layer above
130         forAll(valves(), valveI)
131         {
133             if (!foundOneFace[valveI])
134             {
135                 zPistonValvesOffset[valveI] = zHigher[valveI];
136             }
137         }
139         if(!foundOneFace[valves().size()])
140         {
141             zPistonValvesOffset[valves().size()] = zHigher[valves().size()];
142         }
144         forAll (faceCentres(), faceI)
145         {
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)
155             {
157                 if(!foundOneFace[valveI])
158                 {
160                     scalar zPistV = zPistonValvesOffset[valveI];
163                     if(inValve(faceCentres()[faceI], valveI))
164                     {
165                         foundInValve = true;
167                         if (mag(dd) > 0.1)
168                         {
170                             if
171                             (
172                                 zc > zPistV - delta()
173                                 && zc < zPistV + delta()
174                             )
175                             {
177                                 if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
178                                 {
179                                     flipZonePiston[valveI][nZoneFacesPiston[valveI]] = true;
180                                 }
182                                 zonePiston[valveI][nZoneFacesPiston[valveI]] = faceI;
183                                 nZoneFacesPiston[valveI]++;
184                             }
185                         }
186                     }
188                 }
189             }
191             if(!foundInValve && !foundOneFace[valves().size()])
192             {
193                 label valveSize = valves().size();
194                 scalar zPistV = zPistonValvesOffset[valveSize];
196                 if (mag(dd) > 0.1)
197                 {
199                     if
200                     (
201                         zc > zPistV - delta()
202                         && zc < zPistV + delta()
203                     )
204                     {
205                         if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
206                         {
207                             flipZonePiston[valveSize][nZoneFacesPiston[valveSize]] = true;
208                         }
210                         zonePiston[valveSize][nZoneFacesPiston[valveSize]] = faceI;
211                         nZoneFacesPiston[valveSize]++;
212                     }
213                 }
214             }
215         }
217         forAll(valves(), valveI)
218         {
219             zonePiston[valveI].setSize(nZoneFacesPiston[valveI]);
220             flipZonePiston[valveI].setSize(nZoneFacesPiston[valveI]);
222             fz.append
223             (
224                 new faceZone
225                 (
226                     "pistonLayerFacesV" + Foam::name(valveI + 1),
227                     zonePiston[valveI],
228                     flipZonePiston[valveI],
229                     nFaceZones,
230                     faceZones()
231                 )
232             );
234             nFaceZones++;
235         }
237         {
238             label valveSize = valves().size();
239             zonePiston[valveSize].setSize(nZoneFacesPiston[valveSize]);
240             flipZonePiston[valveSize].setSize(nZoneFacesPiston[valveSize]);
242             fz.append
243             (
244                 new faceZone
245                 (
246                     "pistonLayerFaces",
247                     zonePiston[valveSize],
248                     flipZonePiston[valveSize],
249                     nFaceZones,
250                     faceZones()
251                 )
252             );
254             nFaceZones++;
256         }
258         forAll(valves(), valveI)
259         {
261             labelList movingCells(nCells());
263             label nMovingCells = 0;
265             forAll(cellCentres(),cellI)
266             {
267                 const vector& v = cellCentres()[cellI];
269                 if
270                 (
271                     inValve(v, valveI)
272                     &&
273                     v.z() < zPistonValvesOffset[valveI]
274                 )
275                 {
276                     movingCells[nMovingCells] = cellI;
277                     nMovingCells++;
278                 }
280             }
282             movingCells.setSize(nMovingCells);
283             Info << "Number of cells in the moving region poppet valve: " << nMovingCells << endl;
285             cz.append
286             (
287                 new cellZone
288                 (
289                     "movingCellsPistonV"+ Foam::name(valveI + 1),
290                     movingCells,
291                     nCellZones,
292                     cellZones()
293                 )
294             );
296             nCellZones++;
298         }
301         {
302             label valveSize = valves().size();
303             labelList movingCells(nCells());
305             label nMovingCells = 0;
307             forAll(cellCentres(),cellI)
308             {
309                 const vector& v = cellCentres()[cellI];
311                 bool fallInValve = false;
312                 forAll(valves(), valveI)
313                 {
314                     if(inValve(v, valveI))
315                     {
316                         fallInValve = true;
317                     }
318                 }
320                 if
321                 (
322                     !fallInValve
323                     &&
324                     v.z() < zPistonValvesOffset[valveSize]
325                 )
326                 {
327                     movingCells[nMovingCells] = cellI;
328                     nMovingCells++;
329                 }
331             }
333             movingCells.setSize(nMovingCells);
334             Info << "Number of cells in the moving region poppet valve: " << nMovingCells << endl;
336             cz.append
337             (
338                 new cellZone
339                 (
340                     "movingCellsPiston",
341                     movingCells,
342                     nCellZones,
343                     cellZones()
344                 )
345             );
347             nCellZones++;
349         }
351     }