fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / pistonSliding / addAttachDetachFacesPistonSliding.H
blobd1aa8944374d222eaaef3bc6e14aac65abb51491
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 = detachPatch.faceCentres()[detachFaceI].x();
37                     scalar yFacePatch = detachPatch.faceCentres()[detachFaceI].y();
38                     scalar zFacePatch = detachPatch.faceCentres()[detachFaceI].z();
40                     forAll(faceCentres(),faceI)
41                     {
42                         vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
44                         scalar dd = n & vector(0,0,1);
46                         if (mag(dd) > 0.1)
47                         {
48                             scalar xFaceMesh = faceCentres()[faceI].x();
49                             scalar yFaceMesh = faceCentres()[faceI].y();
50                             scalar zFaceMesh = faceCentres()[faceI].z();
52                             if
53                             (
54                                 mag(xFaceMesh-xFacePatch) < valves()[valveI].detachTol() &&
55                                 mag(yFaceMesh-yFacePatch) < valves()[valveI].detachTol() &&
56                                 mag(zFaceMesh-zFacePatch) <
57                                 valves()[valveI].detachDistance() + valves()[valveI].detachTol() &&
58                                 mag(zFaceMesh-zFacePatch) >
59                                 valves()[valveI].detachDistance() - valves()[valveI].detachTol()  &&
60                                 (zFaceMesh-zFacePatch) >  SMALL
61                             )
62                             {
63                                 bool isHead = isACylinderHeadFace(cylinderHeadFaces, faceI);
65                                 if(isHead)
66                                 {
67                                     headList.append(faceI);
68                                     nHead++;
69                                 }
70                                 else
71                                 {
72                                     df.append(faceI);
73                                     ndf++;
74                                 }
75                             }
76                         }
77                     }
78                 }
80                 Info << "Found " << ndf << " internal faces and "
81                 << nHead << " head faces for the valve n. "
82                 << valveI + 1 <<  endl;
84                 df.setSize(ndf);
85             }
87             boolList flip(df.size(), false);
89             const vector& pistonAxis = piston().cs().axis();
91             forAll (df, dfI)
92             {
93                 if (isInternalFace(df[dfI]))
94                 {
95                     if ((areas[df[dfI]] & pistonAxis) > 0)
96                     {
97                         flip[dfI] = true;
98                     }
99                 }
100                 else
101                 {
102                     FatalErrorIn
103                     (
104                         "void engineTopoFvMesh::addZonesAndModifiers()"
105                     )   << "found boundary face in valve detach definition "
106                         << "for valve " << valveI + 1
107                         << ".  This is not allowed.  Detach faces: "
108                         << df << " nInternalFaces: " << nInternalFaces()
109                         << abort(FatalError);
110                 }
111             }
113             // Add detach face zone
114             fz[nFaceZones] =
115                 new faceZone
116                 (
117                     "detachFaceZoneV" + Foam::name(valveI + 1),
118                     df,
119                     flip,
120                     nFaceZones,
121                     faceZones()
122                 );
123             nFaceZones++;
124         }
125         else
126         {
127             Info << "No valve attach/detach for valve " << valveI + 1 << endl;
128         }
129     }