Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / layerSmooth / addPistonFacesPointZonesLayerSmooth.H
blob807b0fbb770c71b991c391f56538b11bb4379ab1
2     // Add the piston zone
3     if (piston().patchID().active() && offSet() > SMALL)
4     {
6         // Piston position
8         label pistonPatchID = piston().patchID().index();
10         scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();
12         Info << "zPist = " << zPist << endl;
14         scalar zPistV = zPist + offSet();
16         Info << "zPistV = " << zPistV << endl;
18         labelList zone1(faceCentres().size());
19         boolList flipZone1(faceCentres().size(), false);
20         label nZoneFaces1 = 0;
22         bool foundAtLeastOne = false;
23         scalar zHigher = GREAT;
24         scalar zLower = GREAT;
25         scalar dh = GREAT;
26         scalar dl = GREAT;
28         forAll (faceCentres(), faceI)
29         {
30             scalar zc = faceCentres()[faceI].z();
31             vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
32             scalar dd = n & vector(0,0,1);
34             if (mag(dd) > 0.1)
35             {
36                 if (zPistV - zc > 0 && zPistV - zc < dl)
37                 {
38                     zLower = zc;
39                     dl = zPistV - zc;
40                 }
42                 if (zc - zPistV > 0 && zc - zPistV < dh)
43                 {
44                     zHigher = zc;
45                     dh = zc - zHigher;
46                 }
48                 if
49                 (
50                     zc > zPistV - delta()
51                     && zc < zPistV + delta()
52                 )
53                 {
54                     foundAtLeastOne = true;
55                     if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
56                     {
57                         flipZone1[nZoneFaces1] = true;
58                     }
60                     zone1[nZoneFaces1] = faceI;
61                     nZoneFaces1++;
62                 }
63             }
64         }
66         Info << "Gambit mesh, found " << nZoneFaces1 << " faces for layer addition removal" << endl;
67         Info << "Piston patch size = " << boundaryMesh()[piston().patchID().index()].size() << endl;
69         // if no cut was found use the layer above
70         if (!foundAtLeastOne)
71         {
73             Info << "NOT FOUND AT LEAST ONE" << endl;
74             Info << "zHigher = " << zHigher << endl;
76             zPistV = zHigher;
78             forAll (faceCentres(), faceI)
79             {
80                 scalar zc = faceCentres()[faceI].z();
81                 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
82                 scalar dd = n & vector(0,0,1);
83                 if (mag(dd) > 0.1)
84                 {
86                     if
87                     (
88                         zc > zPistV - delta()
89                         && zc < zPistV + delta()
90                     )
91                     {
92                         if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
93                         {
94                             flipZone1[nZoneFaces1] = true;
95                         }
97                         zone1[nZoneFaces1] = faceI;
98                         nZoneFaces1++;
99                     }
100                 }
101             }
103         }
105         zone1.setSize(nZoneFaces1);
106         flipZone1.setSize(nZoneFaces1);
108 //        fz[nFaceZones]=
109         fz.append
110         (
111             new faceZone
112             (
113                 "pistonLayerFaces",
114                 zone1,
115                 flipZone1,
116                 nFaceZones,
117                 faceZones()
118             )
119         );
121         nFaceZones++;
124         // Construct point zones
127         // Points which don't move (= cylinder head)
128         dynamicLabelList headPoints(nPoints() / 10);
130         // Points below the piston which moves with the piston displacement
131         dynamicLabelList pistonPoints(nPoints() / 10);
133         label nHeadPoints = 0;
135         forAll (points(), pointI)
136         {
137             scalar zCoord = points()[pointI].z();
139             if (zCoord > deckHeight() - delta())
140             {
141                 headPoints.append(pointI);
142                 nHeadPoints++;
143                 //Info<< "HeadPoint:" << pointI << " coord:" << points[pointI]
144                 //   << endl;
145             }
146             else if (zCoord < zPistV + delta())
147             {
148                 pistonPoints.append(pointI);
149                 //Info<< "PistonPoint:" << pointI << " coord:" << points[pointI]
150                 //    << endl;
151             }
152         }
154         Info << "Number of head points = " << nHeadPoints << endl;
157 //        pz[nPointZones] =
158         pz.append
159         (
160             new pointZone
161             (
162                 "headPoints",
163                 headPoints.shrink(),
164                 nPointZones,
165                 pointZones()
166             )
167         );
169         nPointZones++;
171 //        pz[nPointZones] =
172         pz.append
173         (
174             new pointZone
175             (
176                 "pistonPoints",
177                 pistonPoints.shrink(),
178                 nPointZones,
179                 pointZones()
180             )
181         );
183         nPointZones++;
185     }
186     else if(piston().patchID().active() && offSet() <= SMALL)
187     {
188         label pistonPatchID = piston().patchID().index();
190         const polyPatch& pistonPatch =
191             boundaryMesh()[piston().patchID().index()];
193         labelList pistonPatchLabels(pistonPatch.size(), pistonPatch.start());
195         forAll (pistonPatchLabels, i)
196         {
197             pistonPatchLabels[i] += i;
198         }
200 //        fz[nFaceZones] =
201         fz.append
202         (
203             new faceZone
204             (
205                 "pistonLayerFaces",
206                 pistonPatchLabels,
207                 boolList(pistonPatchLabels.size(), true),
208                 nFaceZones,
209                 faceZones()
210             )
211         );
212         nFaceZones++;
213         // Construct point zones
215         scalar zPistV = max(boundary()[pistonPatchID].patch().localPoints()).z();
217         // Points which don't move (= cylinder head)
218         dynamicLabelList headPoints(nPoints() / 10);
220         // Points below the piston which moves with the piston displacement
221         dynamicLabelList pistonPoints(nPoints() / 10);
223         label nHeadPoints = 0;
225         forAll (points(), pointI)
226         {
227             scalar zCoord = points()[pointI].z();
229             if (zCoord > deckHeight() - delta())
230             {
231                 headPoints.append(pointI);
232                 nHeadPoints++;
233                 //Info<< "HeadPoint:" << pointI << " coord:" << points[pointI]
234                 //   << endl;
235             }
236             else if (zCoord < zPistV + delta())
237             {
238                 pistonPoints.append(pointI);
239                 //Info<< "PistonPoint:" << pointI << " coord:" << points[pointI]
240                 //    << endl;
241             }
242         }
244         Info << "Number of head points = " << nHeadPoints << endl;
247 //        pz[nPointZones] =
248         pz.append
249         (
250             new pointZone
251             (
252                 "headPoints",
253                 headPoints.shrink(),
254                 nPointZones,
255                 pointZones()
256             )
257         );
259         nPointZones++;
261 //        pz[nPointZones] =
262         pz.append
263         (
264             new pointZone
265             (
266                 "pistonPoints",
267                 pistonPoints.shrink(),
268                 nPointZones,
269                 pointZones()
270             )
271         );
273         nPointZones++;
275     }
280     // Add the piston zone
281     if (piston().patchID().active() && offSet() > SMALL)
282     {
284         // Piston position
286         label pistonPatchID = piston().patchID().index();
288         scalar zPist = max(boundary()[pistonPatchID].patch().localPoints()).z();
290         Info << "zPist = " << zPist << endl;
292         scalar zPistV = zPist + offSet();
294         Info << "zPistV = " << zPistV << endl;
296         labelList zone1(faceCentres().size());
297         boolList flipZone1(faceCentres().size(), false);
298         label nZoneFaces1 = 0;
300         bool foundAtLeastOne = false;
301         scalar zHigher = GREAT;
302         scalar zLower = GREAT;
303         scalar dh = GREAT;
304         scalar dl = GREAT;
306         forAll (faceCentres(), faceI)
307         {
308             scalar zc = faceCentres()[faceI].z();
309             vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
310             scalar dd = n & vector(0,0,1);
312             if (mag(dd) > 0.1)
313             {
314                 if (zPistV - zc > 0 && zPistV - zc < dl)
315                 {
316                     zLower = zc;
317                     dl = zPistV - zc;
318                 }
320                 if (zc - zPistV > 0 && zc - zPistV < dh)
321                 {
322                     zHigher = zc;
323                     dh = zc - zHigher;
324                 }
326                 if
327                 (
328                     zc > zPistV - delta()
329                     && zc < zPistV + delta()
330                 )
331                 {
332                     foundAtLeastOne = true;
333                     if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
334                     {
335                         flipZone1[nZoneFaces1] = true;
336                     }
338                     zone1[nZoneFaces1] = faceI;
339                     nZoneFaces1++;
340                 }
341             }
342         }
344         Info << "Gambit mesh, found " << nZoneFaces1 << " faces for layer addition removal" << endl;
345         Info << "Piston patch size = " << boundaryMesh()[piston().patchID().index()].size() << endl;
347         // if no cut was found use the layer above
348         if (!foundAtLeastOne)
349         {
351             Info << "NOT FOUND AT LEAST ONE" << endl;
352             Info << "zHigher = " << zHigher << endl;
354             zPistV = zHigher;
356             forAll (faceCentres(), faceI)
357             {
358                 scalar zc = faceCentres()[faceI].z();
359                 vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
360                 scalar dd = n & vector(0,0,1);
361                 if (dd > 0.1)
362                 {
364                     if
365                     (
366                         zc > zPistV - delta()
367                         && zc < zPistV + delta()
368                     )
369                     {
370                         if ((faceAreas()[faceI] & vector(0,0,1)) < 0)
371                         {
372                             flipZone1[nZoneFaces1] = true;
373                         }
375                         zone1[nZoneFaces1] = faceI;
376                         nZoneFaces1++;
377                     }
378                 }
379             }
381         }
383         Info << "zone1.setSize()" << endl;
385         zone1.setSize(nZoneFaces1);
386         flipZone1.setSize(nZoneFaces1);
388         Info << "flip.setSize()" << endl;
390         fz.append
391         (
392             new faceZone
393             (
394                 "pistonLayerFaces",
395                 zone1,
396                 flipZone1,
397                 nFaceZones,
398                 faceZones()
399             )
400         );
402         Info << "fz[nFaceZones]" << endl;
404         nFaceZones++;
407         // Construct point zones
410         // Points below the piston which moves with the piston displacement
411         dynamicLabelList pistonPoints(nPoints() / 10);
413         forAll (points(), pointI)
414         {
415             scalar zCoord = points()[pointI].z();
417             if (zCoord < zPistV + delta())
418             {
419                 pistonPoints.append(pointI);
420                 //Info<< "PistonPoint:" << pointI << " coord:" << points[pointI]
421                 //    << endl;
422             }
423         }
426         pz.append
427         (
428             new pointZone
429             (
430                 "pistonPoints",
431                 pistonPoints.shrink(),
432                 nPointZones,
433                 pointZones()
434             )
435         );
436         nPointZones++;
438     }
439     else
440     {
441         FatalErrorIn("void layerSmooth::addLayerSmoothMeshModifiers()")
442             << "the mesh is invalid, because the piston patch does not exist or"
443             << "or the offset value is equal to zero"
444             << abort(FatalError);
445     }
447     Info << "Added face zones for piston" << endl;