Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / verticalValves / addAttachDetachFaces.H
blob090c07f0169d050338d5a101055fdd6965b7d280
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     {
14         if
15         (
16             valves_[valveI].detachInCylinderPatchID().active()
17          && valves_[valveI].detachInPortPatchID().active()
18         )
19         {
23             Info<< "Adding detach boundary for valve "
24                 << valveI + 1 << endl;
26             const vectorField& areas = Sf().internalField();
28             DynamicList<label> df;
30             {
31                 label ndf = 0;
32                 DynamicList<label> headList;
33                 label nHead = 0;
35                 const polyPatch& detachPatch =
36                 boundaryMesh()[valves()[valveI].poppetPatchID().index()];
38                 forAll(detachPatch.faceCentres(), detachFaceI)
39                 {
40                     scalar xFacePatch = detachPatch.faceCentres()[detachFaceI].x();
41                     scalar yFacePatch = detachPatch.faceCentres()[detachFaceI].y();
42                     scalar zFacePatch = detachPatch.faceCentres()[detachFaceI].z();
44                     forAll(faceCentres(),faceI)
45                     {
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) < valves()[valveI].detachTol() &&
60                                 mag(yFaceMesh-yFacePatch) < valves()[valveI].detachTol() &&
61                                 mag(zFaceMesh-zFacePatch) <
62                                 valves()[valveI].detachDistance() + valves()[valveI].detachTol() &&
63                                 mag(zFaceMesh-zFacePatch) >
64                                 valves()[valveI].detachDistance() - valves()[valveI].detachTol()  &&
65                                 (zFaceMesh-zFacePatch) >  SMALL
66                             )
67                             {
68                                 bool isHead = isACylinderHeadFace(cylinderHeadFaces, faceI);
70                                 if(isHead)
71                                 {
72                                     headList.append(faceI);
73                                     nHead++;
74                                 }
75                                 else
76                                 {
77                                     df.append(faceI);
78                                     ndf++;
79                                 }
80                             }
82                         }
84                     }
86                 }
88                 Info << "Found " << ndf << " internal faces and "
89                 << nHead << " head faces for the valve n. " << valveI + 1 <<  endl ;
91                 df.setSize(ndf);
93             }
95             boolList flip(df.size(), false);
97             const vector& pistonAxis = piston().cs().axis();
99             forAll (df, dfI)
100             {
101                 if (isInternalFace(df[dfI]))
102                 {
103                     if ((areas[df[dfI]] & pistonAxis) > 0)
104                     {
105                         flip[dfI] = true;
106                     }
107                 }
108                 else
109                 {
110                     FatalErrorIn
111                     (
112                         "void engineTopoFvMesh::addZonesAndModifiers()"
113                     )   << "found boundary face in valve detach definition "
114                         << "for valve " << valveI + 1
115                         << ".  This is not allowed.  Detach faces: "
116                         << df << " nInternalFaces: " << nInternalFaces()
117                         << abort(FatalError);
118                 }
119             }
121             // Add detach face zone
122             fz[nFaceZones] =
123                 new faceZone
124                 (
125                     "detachFaceZoneV" + Foam::name(valveI + 1),
126                     df,
127                     flip,
128                     nFaceZones,
129                     faceZones()
130                 );
131             nFaceZones++;
132         }
133         else
134         {
135             Info << "No valve attach/detach for valve " << valveI + 1 << endl;
136         }
137     }