fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / engineTopoChangerMesh / simpleTwoStroke / simpleTwoStrokeInitialize.C
blob5aeb0ee6ac23383a579f808e7eb1b17fe8103d7b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "simpleTwoStroke.H"
29 #include "slidingInterface.H"
30 #include "layerAdditionRemoval.H"
31 #include "surfaceFields.H"
32 #include "regionSplit.H"
34 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
36 void Foam::simpleTwoStroke::checkAndCalculate()
38     
39     label pistonIndex = -1;
40     bool foundPiston = false;
42     label linerIndex = -1;
43     bool foundLiner = false;
45     label cylinderHeadIndex = -1;
46     bool foundCylinderHead = false;
47     
48     
49     forAll(boundary(), i)
50     {
51         Info << boundary()[i].name() << endl;
52         if (boundary()[i].name() == "piston")
53         {
54             pistonIndex = i;
55             foundPiston = true;
56         }
57         else if (boundary()[i].name() == "liner")
58         {
59             linerIndex = i;
60             foundLiner = true;
61         }
62         else if (boundary()[i].name() == "cylinderHead")
63         {
64             cylinderHeadIndex = i;
65             foundCylinderHead = true;
66         }
67     }
68     
69     reduce(foundPiston, orOp<bool>());
70     reduce(foundLiner, orOp<bool>());
71     reduce(foundCylinderHead, orOp<bool>());
73     if (!foundPiston)
74     {
75         FatalErrorIn("Foam::simpleTwoStroke::checkAndCalculate()")
76             << " : cannot find piston patch"
77             << abort(FatalError);
78     }
80     if (!foundLiner)
81     { 
82         FatalErrorIn("Foam::simpleTwoStroke::checkAndCalculate()")
83             << " : cannot find liner patch"
84             << abort(FatalError);
85     }
87     if (!foundCylinderHead)
88     { 
89         FatalErrorIn("Foam::simpleTwoStroke::checkAndCalculate()")
90             << " : cannot find cylinderHead patch"
91             << exit(FatalError);
92     }
94     {
95         if (linerIndex != -1)
96         {
97             pistonPosition() =
98                 max(boundary()[pistonIndex].patch().localPoints()).z();
99         }
100         reduce(pistonPosition(), minOp<scalar>());
102         if (cylinderHeadIndex != -1)
103         {
104             deckHeight() = min
105             (
106                 boundary()[cylinderHeadIndex].patch().localPoints()
107             ).z();
108         }
109         reduce(deckHeight(), minOp<scalar>());
111         Info<< "deckHeight: " << deckHeight() << nl
112             << "piston position: " << pistonPosition() << endl;
113     }
114         
118 void Foam::simpleTwoStroke::setVirtualPistonPosition()
121     label pistonFaceIndex = faceZones().findZoneID("pistonLayerFaces");
122          
123     bool foundPistonFace = (pistonFaceIndex != -1);
124     
125     Info << "piston face index = " << pistonFaceIndex << endl; 
126     
127     if(!foundPistonFace)
128     {
129         FatalErrorIn("Foam::simpleTwoStroke::setVirtualPistonPosition()")
130             << " : cannot find the pistonLayerFaces"
131             << exit(FatalError);
132     
133     }
134         
135     const labelList& pistonFaces = faceZones()[pistonFaceIndex];
136     forAll(pistonFaces, i)
137     {
138         const face& f = faces()[pistonFaces[i]];
139         
140         // should loop over facepoints...
141         forAll(f, j)
142         {
143             virtualPistonPosition() = max(virtualPistonPosition(), points()[f[j]].z());
144         }
145     }
146     
147     reduce(virtualPistonPosition(), maxOp<scalar>());