Formatting
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / layerSmooth / addAttachDetachFacesLayerSmooth.H
blobdd2beaabab1e49d2daedb738cad82ac45ec98d04
1     const polyPatch& cylinderHead =
2         boundaryMesh()[boundaryMesh().findPatchID("cylinderHead")];
4     labelList cylinderHeadFaces(cylinderHead.size());
5     forAll(cylinderHeadFaces, i)
6     {
7         cylinderHeadFaces[i] = cylinderHead.start() + i;
8     }
10     forAll(valves(), valveI)
11     {
12         (
13             valves_[valveI].detachInCylinderPatchID().active()
14          && valves_[valveI].detachInPortPatchID().active()
15         )
16         {
17             Info<< "Adding detach boundary for valve "
18                 << valveI + 1 << endl;
20             const vectorField& areas = Sf().internalField();
22             DynamicList<label> df;
24             {
25                 label ndf = 0;
26                 DynamicList<label> headList;
27                 label nHead = 0;
29                 const polyPatch& detachPatch =
30                 boundaryMesh()[valves()[valveI].poppetPatchID().index()];
32                 pointField detachPoints(detachPatch.faceCentres());
33                 detachPoints += valves()[valveI].cs().axis()*valves()[valveI].detachDistance();
35                 forAll(faceCentres(), faceI)
36                 {
37                     if
38                     (
39                         min(mag(detachPoints - faceCentres()[faceI])) < valves()[valveI].detachTol()
40                     )
41                     {
43                         bool isHead = isACylinderHeadFace(cylinderHeadFaces, faceI);
45                         if(isHead)
46                         {
47                             headList.append(faceI);
48                             nHead++;
49                         }
50                         else
51                         {
52                             df.append(faceI);
53                             ndf++;
54                         }
55                     }
56                 }
59                 Info<< "Found " << ndf << " internal faces and "
60                     << nHead << " head faces for the valve n. "
61                     << valveI + 1 <<  endl ;
63                 df.setSize(ndf);
64             }
66             boolList flip(df.size(), false);
68             const vector& valveAxis = valves()[valveI].cs().axis();
70             forAll (df, dfI)
71             {
72                 if (isInternalFace(df[dfI]))
73                 {
74                     if ((areas[df[dfI]] &  valveAxis) > 0)
75                     {
76                         flip[dfI] = true;
77                     }
78                 }
79                 else
80                 {
81                     FatalErrorIn
82                     (
83                         "void engineTopoFvMesh::addZonesAndModifiers()"
84                     )   << "found boundary face in valve detach definition "
85                         << "for valve " << valveI + 1
86                         << ".  This is not allowed.  Detach faces: "
87                         << df << " nInternalFaces: " << nInternalFaces()
88                         << abort(FatalError);
89                 }
90             }
92             // Add detach face zone
93             fz.append
94             (
95                 new faceZone
96                 (
97                     "detachFaceZoneV" + Foam::name(valveI + 1),
98                     df,
99                     flip,
100                     nFaceZones,
101                     faceZones()
102                 )
103             );
104             nFaceZones++;
105         }
109     forAll(valves(), valveI)
110     {
111         if
112         (
113             valves_[valveI].detachInCylinderPatchID().active()
114          && valves_[valveI].detachInPortPatchID().active()
115         )
116         {
117             Info<< "Adding detach boundary for valve "
118                 << valveI + 1 << endl;
120             const vectorField& areas = Sf().internalField();
122             DynamicList<label> df;
124             {
125                 label headFaces = 0;
126                 label ndf = 0;
127                 DynamicList<label> headList;
128                 label nHead = 0;
130                 const polyPatch& detachPatch =
131                 boundaryMesh()[valves()[valveI].poppetPatchID().index()];
133                 forAll(detachPatch.faceCentres(), detachFaceI)
134                 {
135 //                    scalar xFacePatch = detachPatch.faceCentres()[detachFaceI].x();
136 //                    scalar yFacePatch = detachPatch.faceCentres()[detachFaceI].y();
137 //                    scalar zFacePatch = detachPatch.faceCentres()[detachFaceI].z();
139                     point pFacePatch = valves()[valveI].cs().toLocal(detachPatch.faceCentres()[detachFaceI]);
141                     scalar xFacePatch = pFacePatch.x();
142                     scalar yFacePatch = pFacePatch.y();
143                     scalar zFacePatch = pFacePatch.z();
145                     forAll(faceCentres(),faceI)
146                     {
148                         vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
151                         scalar dd = n & valves()[valveI].cs().axis();
153 //                        if (mag(dd) > 0.1)
154                         {
156                             point pFaceMesh = valves()[valveI].cs().toLocal(faceCentres()[faceI]);
158                             scalar xFaceMesh = pFaceMesh.x();
159                             scalar yFaceMesh = pFaceMesh.y();
160                             scalar zFaceMesh = pFaceMesh.z();
162 //                            Info <<  "mag(xFaceMesh-xFacePatch) = " << mag(xFaceMesh-xFacePatch) << endl;
165                             if
166                             (
167                                 mag(xFaceMesh-xFacePatch) < valvePlaneTol_ &&
168                                 mag(yFaceMesh-yFacePatch) < valvePlaneTol_ &&
169                                 mag(zFaceMesh-zFacePatch) <
170                                 valves()[valveI].detachDistance() + valves()[valveI].detachTol() &&
171                                 mag(zFaceMesh-zFacePatch) >
172                                 valves()[valveI].detachDistance() - valves()[valveI].detachTol()
173 //                                && (zFaceMesh-zFacePatch) >  SMALL
174                             )
175                             {
176                                 bool isHead = isACylinderHeadFace(cylinderHeadFaces, faceI);
178                                 if(isHead)
179                                 {
180                                     headList.append(faceI);
181                                     nHead++;
182                                 }
183                                 else
184                                 {
185                                     df.append(faceI);
186                                     ndf++;
187                                 }
188                             }
190                         }
192                     }
194                 }
196                 Info << "Found " << ndf << " internal faces and "
197                 << nHead << " head faces for the valve n. " << valveI + 1 <<  endl ;
199                 df.setSize(ndf);
201             }
203             boolList flip(df.size(), false);
205             const vector& valveAxis = valves()[valveI].cs().axis();
207             forAll (df, dfI)
208             {
209                 if (isInternalFace(df[dfI]))
210                 {
211                     if ((areas[df[dfI]] &  valveAxis) > 0)
212                     {
213                         flip[dfI] = true;
214                     }
215                 }
216                 else
217                 {
218                     FatalErrorIn
219                     (
220                         "void engineTopoFvMesh::addZonesAndModifiers()"
221                     )   << "found boundary face in valve detach definition "
222                         << "for valve " << valveI + 1
223                         << ".  This is not allowed.  Detach faces: "
224                         << df << " nInternalFaces: " << nInternalFaces()
225                         << abort(FatalError);
226                 }
227             }
229             // Add detach face zone
230             fz.append
231             (
232                 new faceZone
233                 (
234                     "detachFaceZoneV" + Foam::name(valveI + 1),
235                     df,
236                     flip,
237                     nFaceZones,
238                     faceZones()
239                 )
240             );
241             nFaceZones++;
242         }
243         else
244         {
245             Info << "No valve attach/detach for valve " << valveI + 1 << endl;
246         }
249     }
251     Info << "Added attach/detach faces zones for valves" << endl;