Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / thoboisMesh / addAttachDetachFacesThoboisMesh.H
blob4aea9db691e3ad885d94a1b41f1e94d7f6895c28
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     {
16     }
18     forAll(valves(), valveI)
19     {
22         if
23         (
24             valves_[valveI].detachInCylinderPatchID().active()
25          && valves_[valveI].detachInPortPatchID().active()
26         )
27         {
31             Info<< "Adding detach boundary for valve "
32                 << valveI + 1 << endl;
34             const vectorField& areas = Sf().internalField();
36             DynamicList<label> df;
38             {
40                 label headFaces = 0;
41                 label ndf = 0;
42                 DynamicList<label> headList;
43                 label nHead = 0;
45                 const polyPatch& detachPatch =
46                 boundaryMesh()[valves()[valveI].poppetPatchID().index()];
48                 pointField detachPoints(detachPatch.faceCentres());
49                 detachPoints += valves()[valveI].cs().axis() * valves()[valveI].detachDistance();
51                 forAll(faceCentres(), faceI)
52                 {
54                     if
55                     (
56                         min(mag(detachPoints - faceCentres()[faceI])) < valves()[valveI].detachTol()
57                     )
58                     {
60                         bool isHead = isACylinderHeadFace(cylinderHeadFaces, faceI);
62                         if(isHead)
63                         {
64                             headList.append(faceI);
65                             nHead++;
66                         }
67                         else
68                         {
69                             df.append(faceI);
70                             ndf++;
71                         }
72                     }
73                 }
76                 Info << "Found " << ndf << " internal faces and "
77                 << nHead << " head faces for the valve n. " << valveI + 1 <<  endl ;
79                 df.setSize(ndf);
81             }
83             boolList flip(df.size(), false);
85             const vector& valveAxis = valves()[valveI].cs().axis();
87             forAll (df, dfI)
88             {
89                 if (isInternalFace(df[dfI]))
90                 {
91                     if ((areas[df[dfI]] &  valveAxis) > 0)
92                     {
93                         flip[dfI] = true;
94                     }
95                 }
96                 else
97                 {
98                     FatalErrorIn
99                     (
100                         "void engineTopoFvMesh::addZonesAndModifiers()"
101                     )   << "found boundary face in valve detach definition "
102                         << "for valve " << valveI + 1
103                         << ".  This is not allowed.  Detach faces: "
104                         << df << " nInternalFaces: " << nInternalFaces()
105                         << abort(FatalError);
106                 }
107             }
109             // Add detach face zone
110             fz.append
111             (
112                 new faceZone
113                 (
114                     "detachFaceZoneV" + Foam::name(valveI + 1),
115                     df,
116                     flip,
117                     nFaceZones,
118                     faceZones()
119                 )
120             );
121             nFaceZones++;
122         }
127     forAll(valves(), valveI)
128     {
131         if
132         (
133             valves_[valveI].detachInCylinderPatchID().active()
134          && valves_[valveI].detachInPortPatchID().active()
135         )
136         {
140             Info<< "Adding detach boundary for valve "
141                 << valveI + 1 << endl;
143             const vectorField& areas = Sf().internalField();
145             DynamicList<label> df;
147             {
149                 label headFaces = 0;
150                 label ndf = 0;
151                 DynamicList<label> headList;
152                 label nHead = 0;
154                 const polyPatch& detachPatch =
155                 boundaryMesh()[valves()[valveI].poppetPatchID().index()];
157                 forAll(detachPatch.faceCentres(), detachFaceI)
158                 {
159 //                    scalar xFacePatch = detachPatch.faceCentres()[detachFaceI].x();
160 //                    scalar yFacePatch = detachPatch.faceCentres()[detachFaceI].y();
161 //                    scalar zFacePatch = detachPatch.faceCentres()[detachFaceI].z();
163                     point pFacePatch = valves()[valveI].cs().toLocal(detachPatch.faceCentres()[detachFaceI]);
165                     scalar xFacePatch = pFacePatch.x();
166                     scalar yFacePatch = pFacePatch.y();
167                     scalar zFacePatch = pFacePatch.z();
169                     forAll(faceCentres(),faceI)
170                     {
172                         vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
175                         scalar dd = n & valves()[valveI].cs().axis();
177 //                        if (mag(dd) > 0.1)
178                         {
180                             point pFaceMesh = valves()[valveI].cs().toLocal(faceCentres()[faceI]);
182                             scalar xFaceMesh = pFaceMesh.x();
183                             scalar yFaceMesh = pFaceMesh.y();
184                             scalar zFaceMesh = pFaceMesh.z();
186 //                            Info <<  "mag(xFaceMesh-xFacePatch) = " << mag(xFaceMesh-xFacePatch) << endl;
189                             if
190                             (
191                                 mag(xFaceMesh-xFacePatch) < valvePlaneTol_ &&
192                                 mag(yFaceMesh-yFacePatch) < valvePlaneTol_ &&
193                                 mag(zFaceMesh-zFacePatch) <
194                                 valves()[valveI].detachDistance() + valves()[valveI].detachTol() &&
195                                 mag(zFaceMesh-zFacePatch) >
196                                 valves()[valveI].detachDistance() - valves()[valveI].detachTol()
197 //                                && (zFaceMesh-zFacePatch) >  SMALL
198                             )
199                             {
200                                 bool isHead = isACylinderHeadFace(cylinderHeadFaces, faceI);
202                                 if(isHead)
203                                 {
204                                     headList.append(faceI);
205                                     nHead++;
206                                 }
207                                 else
208                                 {
209                                     df.append(faceI);
210                                     ndf++;
211                                 }
212                             }
214                         }
216                     }
218                 }
220                 Info << "Found " << ndf << " internal faces and "
221                 << nHead << " head faces for the valve n. " << valveI + 1 <<  endl ;
223                 df.setSize(ndf);
225             }
227             boolList flip(df.size(), false);
229             const vector& valveAxis = valves()[valveI].cs().axis();
231             forAll (df, dfI)
232             {
233                 if (isInternalFace(df[dfI]))
234                 {
235                     if ((areas[df[dfI]] &  valveAxis) > 0)
236                     {
237                         flip[dfI] = true;
238                     }
239                 }
240                 else
241                 {
242                     FatalErrorIn
243                     (
244                         "void engineTopoFvMesh::addZonesAndModifiers()"
245                     )   << "found boundary face in valve detach definition "
246                         << "for valve " << valveI + 1
247                         << ".  This is not allowed.  Detach faces: "
248                         << df << " nInternalFaces: " << nInternalFaces()
249                         << abort(FatalError);
250                 }
251             }
253             // Add detach face zone
254             fz.append
255             (
256                 new faceZone
257                 (
258                     "detachFaceZoneV" + Foam::name(valveI + 1),
259                     df,
260                     flip,
261                     nFaceZones,
262                     faceZones()
263                 )
264             );
265             nFaceZones++;
266         }
267         else
268         {
269             Info << "No valve attach/detach for valve " << valveI + 1 << endl;
270         }
273     }
275     Info << "Added attach/detach faces zones for valves" << endl;