Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / pistonSliding / addValvePistonCellZonesPistonSliding.H
blobbad431e4f1f03da56d4e73e2e2e620426e4c19c5
1 //  Moving mask: moving cells inside the valves....
3     {
5         for(label i = 1; i <= nValves(); i++)
6         {
7             
8             
9             if(valves_[i-1].poppetPatchID().active())
10             {
11             
12                 labelList movingCells(nCells());
13                                 
14                 label nMovingCells = 0;
15         
16                 label valvePatchID = valves_[i-1].poppetPatchID().index();
17                 const polyPatch& valveTopPatch = boundaryMesh()[valvePatchID];
18                 scalar minPopZ = min(boundary()[valvePatchID].patch().localPoints()).z();
19                         
20                 forAll(cellCentres(),cellI)
21                 {
22                     const vector& v = cellCentres()[cellI];
23                         
24                     if
25                     (
26                         inValve(v, i-1)
27                         &&
28                         v.z() > minPopZ 
29                     )
30                     {
31                         movingCells[nMovingCells] = cellI;
32                         nMovingCells++;
33                     }
34             
35                 }
36                 
37                 movingCells.setSize(nMovingCells);
38                 Info << "Number of cells in the moving region poppet valve: " << nMovingCells << endl;
39                                                 
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;
57                 
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]];
74                         
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();
80                                 
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                             }
95                 
96                         }
97             
98                     }
99         
100                 }
101                 
102                 forAll(valveTopPoint, pointI)
103                 {
104                     if(valveTopPoint[pointI])
105                     {
106                         valveTopPoints.append(pointI);
107                     }
108                 }
109                                                 
110                 pz.append
111                 (
112                     new pointZone
113                     (
114                         "valveTopPointsV"+ Foam::name(i),
115                         valveTopPoints.shrink(),
116                         nPointZones,
117                         pointZones()
118                     )
119                 );
120                 
121                 nPointZones++;
123             }
124             
125             if(valves_[i-1].bottomPatchID().active())
126             {
127             
128                 labelList movingCells(nCells());
129                                 
130                 label nMovingCells = 0;
131                 
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];
140                         
141                     if
142                     (
143                         inValve(v, i-1)
144                         &&
145                         v.z() < maxPopZ + SMALL
146                     )
147                     {
148                         movingCells[nMovingCells] = cellI;
149                         nMovingCells++;
150                     }
151             
152                 }
153                 
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++;
169                 
170                 
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;
175                 
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();
196                                 
197                                 const point& p = points()[curFace[pointI]];
198                                 
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                             }
213                 
214                         }
215             
216                     }
217         
218                 }
220                 forAll(valveBottomPoint, pointI)
221                 {
222                     if(valveBottomPoint[pointI])
223                     {
224                         valveBottomPoints.append(pointI);
225                     }
226                 }
227                 
228                 // Add point zone
229                                 
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             }
245         
246         }
247         
248     }