Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / verticalValves / movePistonPoints.H
blobb262abf7994e1b4dee449da661f121508ce7227a
1     {
2         
3         Info << "moving piston points" << endl;
4     
5         boolList scaleDisp(nPoints(), true);
6         label nScaled = nPoints();
8         List<bool> pistonPoint(newPoints.size(), false);
10         label pistonPtsIndex = pointZones().findZoneID("pistonPoints");
11 //        const labelList& pistonPoints = pointZones()[pistonPtsIndex];
12          
13         const scalarField& movingPointsMPiston = movingPointsMaskPiston(); 
15         labelList pistonPoints;
17         {
18             label pistonCellIndex = cellZones().findZoneID("movingCellsPiston");
20             if (pistonCellIndex < 0)
21             {
22                 FatalErrorIn("bool verticalValves::update()")
23                     << "Cannot find cell zone movingCellsPiston"
24                     << abort(FatalError);
25             }
27             const labelList& pistonCells = cellZones()[pistonCellIndex];
29             const labelListList& cp = cellPoints();
31             boolList count(newPoints.size(), false);
33             forAll (pistonCells, cellI)
34             {
35                 const labelList& curCellPoints = cp[pistonCells[cellI]];
37                 forAll (curCellPoints, i)
38                 {
39                     count[curCellPoints[i]] = true;
40                 }
41             }
43             // Count the points
44             label nCounted = 0;
45             forAll (count, pointI)
46             {
47                 if (count[pointI] == true)
48                 {
49                     nCounted++;
50                 }
51             }
53             pistonPoints.setSize(nCounted);
55             // Collect the points
56             nCounted = 0;
57             forAll (count, pointI)
58             {
59                 if (count[pointI] == true)
60                 {
61                     pistonPoints[nCounted] = pointI;
62                     nCounted++;
63                 }
64             }
66         }
68         
69            
70         {
71                         
72             // Always move piston
73             scalar pistonTopZ = -GREAT;
74             forAll(pistonPoints, i)
75             {
76                 point& p = newPoints[pistonPoints[i]];
77                 p.z() = p.z() + deltaZ*movingPointsMPiston[pistonPoints[i]];
78                 pistonTopZ = max(pistonTopZ, p.z());
79             }
81         // NN! fix. only needed for compression
82             if (deltaZ > 0.0)
83             {
84                 // check if piston-points have moved beyond the layer above
85                 forAll(newPoints, i)
86                 {
87                     if (!pistonPoint[i])
88                     {
89                         bool foundLow = false;
90                         if (virtualPistonPosition() > newPoints[i].z())
91                         {
93                             foundLow = true;
94                             
95                             newPoints[i].z() 
96                             = 
97                             (1.0 - movingPointsMPiston[i])*newPoints[i].z() 
98                             +
99                             movingPointsMPiston[i] *
100                             (
101                                 pistonTopZ 
102                             +   
103                                 (
104                                     0.9*minLayerThickness
105                                 )
106                             );
107                             
108                         }
109                     }
110                 }
111             }
112         }
113         
114         deleteDemandDrivenData(movingPointsMaskPistonPtr_);
115         
116         forAll(valves(), valveI)
117         {
119             Info << "moving valve points valve n. " << valveI << endl;
120         
121             boolList scaleDisp(nPoints(), true);
122             label nScaled = nPoints();
124             const scalarField& movingPointsMPistonValves = movingPointsMaskPistonValves(valveI); 
126             List<bool> pistonPointValve(newPoints.size(), false);
127             labelList pistonPointsV;
129             {
130                 label pistonCellVIndex = cellZones().findZoneID("movingCellsPistonV"+ Foam::name(valveI + 1));
131                 
132                 if (pistonCellVIndex < 0)
133                 {      
134                     FatalErrorIn("bool verticalValves::update()")
135                         << "movingCellsPistonV"+ Foam::name(valveI + 1)
136                         << abort(FatalError);
137                 }
139                 const labelList& pistonCellsV = cellZones()[pistonCellVIndex];
141                 const labelListList& cp = cellPoints();
143                 boolList count(newPoints.size(), false);
145                 forAll (pistonCellsV, cellI)
146                 {
147                     const labelList& curCellPoints = cp[pistonCellsV[cellI]];
149                     forAll (curCellPoints, i)
150                     {
151                         count[curCellPoints[i]] = true;
152                     }
153                 }
155                 // Count the points
156                 label nCounted = 0;
157                 forAll (count, pointI)
158                 {
159                     if (count[pointI] == true)
160                     {
161                         nCounted++;
162                     }
163                 }
165                 pistonPointsV.setSize(nCounted);
167                 // Collect the points
168                 nCounted = 0;
169                 forAll (count, pointI)
170                 {
171                     if (count[pointI] == true)
172                     {
173                         pistonPointsV[nCounted] = pointI;
174                         nCounted++;
175                     }
176                 }
177                             
178             }
181             forAll(pistonPointsV, i)
182             {
183                 label pointI = pistonPointsV[i];
184                 pistonPointValve[pointI] = true;
185                 point& p = newPoints[pointI];
186             
187                 if (p.z() < pistonPosition() - 1.0e-6)
188                 {
189                     scaleDisp[pointI] = false;
190                     nScaled--;
191                 }
192             }
193            
194             {
195                         
196                 // Always move piston
197                 scalar pistonTopZ = -GREAT;
198                 forAll(pistonPointsV, i)
199                 {
200                     point& p = newPoints[pistonPointsV[i]];
201                     
202                     p.z() = p.z() + deltaZ*movingPointsMPistonValves[pistonPointsV[i]];
203                     pistonTopZ = max(pistonTopZ, p.z());
204                 }
206         // NN! fix. only needed for compression
207                 if (deltaZ > 0.0)
208                 {
209                     // check if piston-points have moved beyond the layer above
210                     forAll(newPoints, i)
211                     {
212                         if (!pistonPointValve[i])
213                         {
214                             bool foundLow = false;
215                             if (virtualPistonPosition() > newPoints[i].z())
216                             {
218                                 foundLow = true;
219                             
220                                 newPoints[i].z() 
221                                 = 
222                                 (1.0 - movingPointsMPistonValves[i])*newPoints[i].z() 
223                                 +
224                                 movingPointsMPistonValves[i] *
225                                 (
226                                     pistonTopZ 
227                                 +      
228                                     (
229                                         0.9*minLayerThickness
230                                     )
231                                 );
232                             
233                             }
234                         }   
235                     }
236                 }
237             }
238             
239             deleteDemandDrivenData(movingPointsMaskPistonValvesPtr_);
240         }
241     
242     }