Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / thoboisSliding / addAttachDetachFacesThoboisSliding.H
blob157028448930ff3185fcc5d246db39690c67db66
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         if
13         (
14             valves_[valveI].detachInCylinderPatchID().active()
15          && valves_[valveI].detachInPortPatchID().active()
16         )
17         {
18             Info<< "Adding detach boundary for valve "
19                 << valveI + 1 << endl;
21             const vectorField& areas = Sf().internalField();
23             DynamicList<label> df;
25             {
26                 label headFaces = 0;
27                 label ndf = 0;
28                 DynamicList<label> headList;
29                 label nHead = 0;
31                 const polyPatch& detachPatch =
32                 boundaryMesh()[valves()[valveI].poppetPatchID().index()];
34                 forAll(detachPatch.faceCentres(), detachFaceI)
35                 {
36                     scalar xFacePatch =
37                         detachPatch.faceCentres()[detachFaceI].x();
39                     scalar yFacePatch =
40                         detachPatch.faceCentres()[detachFaceI].y();
42                     scalar zFacePatch =
43                         detachPatch.faceCentres()[detachFaceI].z();
45                     forAll(faceCentres(),faceI)
46                     {
47                         vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
49                         scalar dd = n & vector(0,0,1);
51                         if (mag(dd) > 0.1)
52                         {
53                             scalar xFaceMesh = faceCentres()[faceI].x();
54                             scalar yFaceMesh = faceCentres()[faceI].y();
55                             scalar zFaceMesh = faceCentres()[faceI].z();
57                             if
58                             (
59                                 mag(xFaceMesh-xFacePatch)
60                               < valves()[valveI].detachTol()
61                              &&
62                                 mag(yFaceMesh-yFacePatch)
63                               < valves()[valveI].detachTol()
64                              &&
65                                 mag(zFaceMesh-zFacePatch)
66                               < valves()[valveI].detachDistance()
67                               + valves()[valveI].detachTol()
68                              &&
69                                 mag(zFaceMesh-zFacePatch)
70                               > valves()[valveI].detachDistance()
71                               - valves()[valveI].detachTol()
72                              &&
73                                 (zFaceMesh-zFacePatch) >  SMALL
74                             )
75                             {
76                                 bool isHead = isACylinderHeadFace
77                                 (
78                                     cylinderHeadFaces,
79                                     faceI
80                                 );
82                                 if (isHead)
83                                 {
84                                     headList.append(faceI);
85                                     nHead++;
86                                 }
87                                 else
88                                 {
89                                     df.append(faceI);
90                                     ndf++;
91                                 }
92                             }
93                         }
94                     }
95                 }
97                 Info << "Found " << ndf << " internal faces and "
98                     << nHead << " head faces for the valve n. "
99                     << valveI + 1 <<  endl ;
101                 df.setSize(ndf);
102             }
104             boolList flip(df.size(), false);
106             const vector& pistonAxis = piston().cs().axis();
108             forAll (df, dfI)
109             {
110                 if (isInternalFace(df[dfI]))
111                 {
112                     if ((areas[df[dfI]] & pistonAxis) > 0)
113                     {
114                         flip[dfI] = true;
115                     }
116                 }
117                 else
118                 {
119                     FatalErrorIn
120                     (
121                         "void engineTopoFvMesh::addZonesAndModifiers()"
122                     )   << "found boundary face in valve detach definition "
123                         << "for valve " << valveI + 1
124                         << ".  This is not allowed.  Detach faces: "
125                         << df << " nInternalFaces: " << nInternalFaces()
126                         << abort(FatalError);
127                 }
128             }
130             // Add detach face zone
131             fz[nFaceZones] =
132                 new faceZone
133                 (
134                     "detachFaceZoneV" + Foam::name(valveI + 1),
135                     df,
136                     flip,
137                     nFaceZones,
138                     faceZones()
139                 );
140             nFaceZones++;
141         }
142         else
143         {
144             Info << "No valve attach/detach for valve " << valveI + 1 << endl;
145         }
146     }