Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / engineValveSliding / addAttachDetachFacesEngineValveSliding.H
blob0c90b9771cf6445af7fd0e3a8558c0792f91c066
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();
38                     scalar yFacePatch =
39                         detachPatch.faceCentres()[detachFaceI].y();
40                     scalar zFacePatch =
41                         detachPatch.faceCentres()[detachFaceI].z();
43                     forAll(faceCentres(),faceI)
44                     {
45                         vector n = faceAreas()[faceI]/mag(faceAreas()[faceI]);
47                         scalar dd = n & vector(0,0,1);
49                         if (mag(dd) > 0.1)
50                         {
51                             scalar xFaceMesh = faceCentres()[faceI].x();
52                             scalar yFaceMesh = faceCentres()[faceI].y();
53                             scalar zFaceMesh = faceCentres()[faceI].z();
55                             if
56                             (
57                                 mag(xFaceMesh-xFacePatch)
58                               < valves()[valveI].detachTol()
59                              &&
60                                 mag(yFaceMesh-yFacePatch)
61                               < valves()[valveI].detachTol()
62                              &&
63                                 mag(zFaceMesh-zFacePatch)
64                               <
65                                 valves()[valveI].detachDistance()
66                               + valves()[valveI].detachTol()
67                              &&
68                                 mag(zFaceMesh-zFacePatch)
69                               >
70                                 valves()[valveI].detachDistance()
71                               - valves()[valveI].detachTol()
72                              &&
73                                 (zFaceMesh-zFacePatch)
74                               > SMALL
75                             )
76                             {
77                                 bool isHead = isACylinderHeadFace
78                                 (
79                                     cylinderHeadFaces,
80                                     faceI
81                                 );
83                                 if (isHead)
84                                 {
85                                     headList.append(faceI);
86                                     nHead++;
87                                 }
88                                 else
89                                 {
90                                     df.append(faceI);
91                                     ndf++;
92                                 }
93                             }
94                         }
95                     }
96                 }
98                 Info << "Found " << ndf << " internal faces and "
99                     << nHead << " head faces for the valve n. "
100                     << valveI + 1 <<  endl ;
102                 df.setSize(ndf);
103             }
105             boolList flip(df.size(), false);
107             const vector& pistonAxis = piston().cs().axis();
109             forAll (df, dfI)
110             {
111                 if (isInternalFace(df[dfI]))
112                 {
113                     if ((areas[df[dfI]] & pistonAxis) > 0)
114                     {
115                         flip[dfI] = true;
116                     }
117                 }
118                 else
119                 {
120                     FatalErrorIn
121                     (
122                         "void engineTopoFvMesh::addZonesAndModifiers()"
123                     )   << "found boundary face in valve detach definition "
124                         << "for valve " << valveI + 1
125                         << ".  This is not allowed.  Detach faces: "
126                         << df << " nInternalFaces: " << nInternalFaces()
127                         << abort(FatalError);
128                 }
129             }
131             // Add detach face zone
132             fz[nFaceZones] =
133                 new faceZone
134                 (
135                     "detachFaceZoneV" + Foam::name(valveI + 1),
136                     df,
137                     flip,
138                     nFaceZones,
139                     faceZones()
140                 );
141             nFaceZones++;
142         }
143         else
144         {
145             Info << "No valve attach/detach for valve " << valveI + 1 << endl;
146         }
147     }