Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / thoboisSliding / addValvePistonCellZonesThoboisSliding.H
blobffbe5097b840da56ebaa300847e55b07ed1c486e
1 //  Moving mask: moving cells inside the valves....
3     {
5         for(label i = 1; i <= nValves(); i++)
6         {
9             if(valves_[i-1].poppetPatchID().active())
10             {
12                 labelList movingCells(nCells());
14                 label nMovingCells = 0;
16                 label valvePatchID = valves_[i-1].poppetPatchID().index();
17                 const polyPatch& valveTopPatch = boundaryMesh()[valvePatchID];
18                 scalar minPopZ = min(boundary()[valvePatchID].patch().localPoints()).z();
20                 forAll(cellCentres(),cellI)
21                 {
22                     const vector& v = cellCentres()[cellI];
24                     if
25                     (
26                         inValve(v, i-1)
27                         &&
28                         v.z() > minPopZ
29                     )
30                     {
31                         movingCells[nMovingCells] = cellI;
32                         nMovingCells++;
33                     }
35                 }
37                 movingCells.setSize(nMovingCells);
38                 Info << "Number of cells in the moving region poppet valve: " << nMovingCells << endl;
40                 cz.append
41                 (
42                     new cellZone
43                     (
44                         "movingCellsTopV"+ Foam::name(i),
45                         movingCells,
46                         nCellZones,
47                         cellZones()
48                     )
49                 );
51                 nCellZones++;
53                 // valve top points (move all with valve displacement)
54                 DynamicList<label> valveTopPoints(nPoints() / 10);
55                 List<bool> valveTopPoint(nPoints(), false);
56                 bool foundOne = false;
58                 const cellList& c = cells();
59                 const faceList& f = allFaces();
61                 forAll (movingCells, cellI)
62                 {
63                     const cell& curCell = c[movingCells[cellI]];
65                     forAll (curCell, faceI)
66                     {
67                         // Mark all the points as moving
68                         const face& curFace = f[curCell[faceI]];
70                         forAll (curFace, pointI)
71                         {
73                             const point& p = points()[curFace[pointI]];
75                             forAll(valveTopPatch.localPoints(), j)
76                             {
77                                 scalar xFacePatch = valveTopPatch.localPoints()[j].x();
78                                 scalar yFacePatch = valveTopPatch.localPoints()[j].y();
79                                 scalar zFacePatch = valveTopPatch.localPoints()[j].z();
81                                 if
82                                 (
83                                     mag(p.x() - xFacePatch) < poppetValveTol_
84                                     &&
85                                     mag(p.y() - yFacePatch) < poppetValveTol_
86                                     &&
87                                     mag(p.z() - zFacePatch) < valves_[i-1].topLayerOffset() +
88                                     valves_[i-1].topLayerTol()
89                                 )
90                                 {
91                                     foundOne = true;
92                                     valveTopPoint[curFace[pointI]] = true;
93                                 }
94                             }
96                         }
98                     }
100                 }
102                 forAll(valveTopPoint, pointI)
103                 {
104                     if(valveTopPoint[pointI])
105                     {
106                         valveTopPoints.append(pointI);
107                     }
108                 }
110                 pz.append
111                 (
112                     new pointZone
113                     (
114                         "valveTopPointsV"+ Foam::name(i),
115                         valveTopPoints.shrink(),
116                         nPointZones,
117                         pointZones()
118                     )
119                 );
121                 nPointZones++;
123             }
125             if(valves_[i-1].bottomPatchID().active())
126             {
128                 labelList movingCells(nCells());
130                 label nMovingCells = 0;
132                 label valvePatchID = valves_[i-1].bottomPatchID().index();
133                 const polyPatch& valveBottomPatch = boundaryMesh()[valvePatchID];
134                 scalar maxPopZ = max(boundary()[valvePatchID].patch().localPoints()).z();
137                 forAll(cellCentres(),cellI)
138                 {
139                     const vector& v = cellCentres()[cellI];
141                     if
142                     (
143                         inValve(v, i-1)
144                         &&
145                         v.z() < maxPopZ + SMALL
146                     )
147                     {
148                         movingCells[nMovingCells] = cellI;
149                         nMovingCells++;
150                     }
152                 }
154                 movingCells.setSize(nMovingCells);
155                 Info << "Number of cells in the moving region bottom valve: " << nMovingCells << endl;
157                 cz.append
158                 (
159                     new cellZone
160                     (
161                         "movingCellsBotV"+ Foam::name(i),
162                         movingCells,
163                         nCellZones,
164                         cellZones()
165                     )
166                 );
168                 nCellZones++;
171                 // valve bottom points (move all with valve displacement)
172                 DynamicList<label> valveBottomPoints(nPoints() / 10);
173                 List<bool> valveBottomPoint(nPoints(), false);
174                 bool foundOne = false;
177                 const cellList& c = cells();
178                 const faceList& f = allFaces();
180                 forAll (movingCells, cellI)
181                 {
182                     const cell& curCell = c[movingCells[cellI]];
184                     forAll (curCell, faceI)
185                     {
186                         // Mark all the points as moving
187                         const face& curFace = f[curCell[faceI]];
189                         forAll (curFace, pointI)
190                         {
191                             forAll(valveBottomPatch.localPoints(), j)
192                             {
193                                 scalar xFacePatch = valveBottomPatch.localPoints()[j].x();
194                                 scalar yFacePatch = valveBottomPatch.localPoints()[j].y();
195                                 scalar zFacePatch = valveBottomPatch.localPoints()[j].z();
197                                 const point& p = points()[curFace[pointI]];
199                                 if
200                                 (
201                                     mag(p.x() - xFacePatch) < bottomValveTol_
202                                     &&
203                                     mag(p.y() - yFacePatch) < bottomValveTol_
204                                     &&
205                                     mag(p.z() - zFacePatch) < valves_[i-1].bottomLayerOffset() +
206                                     valves_[i-1].bottomLayerTol()
207                                 )
208                                 {
209                                     foundOne = true;
210                                     valveBottomPoint[curFace[pointI]] = true;
211                                 }
212                             }
214                         }
216                     }
218                 }
220                 forAll(valveBottomPoint, pointI)
221                 {
222                     if(valveBottomPoint[pointI])
223                     {
224                         valveBottomPoints.append(pointI);
225                     }
226                 }
228                 // Add point zone
230                 pz.append
231                 (
232                     new pointZone
233                     (
234                         "valveBottomPointsV"+ Foam::name(i),
235                         valveBottomPoints.shrink(),
236                         nPointZones,
237                         pointZones()
238                     )
239                 );
241                 nPointZones++;
243             }
246         }
248     }