Formatting
[foam-extend-3.2.git] / src / engine / engineTopoChangerMesh / pistonSliding / pistonSlidingInitialize.C
blobc3beb961f9ca688e707036fc50dbbe23dfe1a6af
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     verticalValvesGambit
27 \*---------------------------------------------------------------------------*/
29 #include "pistonSliding.H"
30 #include "slidingInterface.H"
31 #include "layerAdditionRemoval.H"
32 #include "surfaceFields.H"
33 #include "regionSplit.H"
35 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
37 void Foam::pistonSliding::checkAndCalculate()
40     label pistonIndex = -1;
41     bool foundPiston = false;
43     label linerIndex = -1;
44     bool foundLiner = false;
46     label cylinderHeadIndex = -1;
47     bool foundCylinderHead = false;
50     forAll(boundary(), i)
51     {
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     }
69     reduce(foundPiston, orOp<bool>());
70     reduce(foundLiner, orOp<bool>());
71     reduce(foundCylinderHead, orOp<bool>());
73     if (!foundPiston)
74     {
75         FatalErrorIn("Foam::verticalValvesGambit::checkAndCalculate()")
76             << " : cannot find piston patch"
77             << abort(FatalError);
78     }
80     if (!foundLiner)
81     {
82         FatalErrorIn("Foam::verticalValvesGambit::checkAndCalculate()")
83             << " : cannot find liner patch"
84             << abort(FatalError);
85     }
87     if (!foundCylinderHead)
88     {
89         FatalErrorIn("Foam::verticalValvesGambit::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();
109         }
110         reduce(deckHeight(), minOp<scalar>());
112         Info<< "deckHeight: " << deckHeight() << nl
113             << "piston position: " << pistonPosition() << endl;
114     }
119 void Foam::pistonSliding::setVirtualPositions()
122     {
123         virtualPistonPosition() = -GREAT;
125         label pistonFaceIndex = faceZones().findZoneID("pistonLayerFaces");
127         bool foundPistonFace = (pistonFaceIndex != -1);
129         if(!foundPistonFace)
130         {
131             FatalErrorIn("Foam::verticalValvesGambit::setVirtualPistonPosition()")
132                 << " : cannot find the pistonLayerFaces"
133                 << exit(FatalError);
135         }
137         const labelList& pistonFaces = faceZones()[pistonFaceIndex];
138         forAll(pistonFaces, i)
139         {
140             const face& f = faces()[pistonFaces[i]];
142             // should loop over facepoints...
143             forAll(f, j)
144             {
145                 virtualPistonPosition() = max(virtualPistonPosition(), points()[f[j]].z());
146             }
147         }
149         reduce(virtualPistonPosition(), maxOp<scalar>());
151     }
153     forAll(valves_, valveI)
154     {
155         if(valves_[valveI].poppetPatchID().active())
156         {
158             valveTopPosition_[valveI] = -GREAT;
160             label valveFaceIndex = faceZones().findZoneID("layeringFacesTopZoneV" + Foam::name(valveI + 1));
162             bool foundValveFace = (valveFaceIndex != -1);
164             if(!foundValveFace)
165             {
166                 FatalErrorIn("Foam::verticalValvesGambit::setVirtualPositions()")
167                     << " : cannot find the poppetValveFaces"
168                     << exit(FatalError);
169             }
171             const labelList& valvePoppetFaces = faceZones()[valveFaceIndex];
173             forAll(valvePoppetFaces, i)
174             {
175                 const face& f = faces()[valvePoppetFaces[i]];
177                 // should loop over facepoints...
178                 forAll(f, j)
179                 {
180                     valveTopPosition_[valveI] = max(valveTopPosition_[valveI], points()[f[j]].z());
181                 }
182             }
184             reduce(valveTopPosition_[valveI], maxOp<scalar>());
187         }
188         if(valves_[valveI].bottomPatchID().active())
189         {
190             valveBottomPosition_[valveI] = GREAT;
192             label valveFaceIndex = faceZones().findZoneID("layeringFacesBottomZoneV" + Foam::name(valveI + 1));
194             bool foundValveFace = (valveFaceIndex != -1);
196             if(!foundValveFace)
197             {
198                 FatalErrorIn("Foam::verticalValvesGambit::setVirtualPositions()")
199                     << " : cannot find the bottomValveFaces"
200                     << exit(FatalError);
201             }
203             const labelList& valveBottomFaces = faceZones()[valveFaceIndex];
204             forAll(valveBottomFaces, i)
205             {
206                 const face& f = faces()[valveBottomFaces[i]];
208                 // should loop over facepoints...
209                 forAll(f, j)
210                 {
211                     valveBottomPosition_[valveI] = min(valveBottomPosition_[valveI], points()[f[j]].z());
212                 }
213             }
216         }
218 /*        {
219             valvePistonPosition_[valveI] = -GREAT;
221             label valveFaceIndex = faceZones().findZoneID("pistonLayerFacesV" + Foam::name(valveI + 1));
223             const labelList& valvePistonFaces = faceZones()[valveFaceIndex];
224             forAll(valvePistonFaces, i)
225             {
226                 const face& f = faces()[valvePistonFaces[i]];
228                 // should loop over facepoints...
229                 forAll(f, j)
230                 {
231                     valvePistonPosition_[valveI] = max(valvePistonPosition_[valveI], points()[f[j]].z());
232                 }
233             }
235             reduce(valvePistonPosition_[valveI], maxOp<scalar>());
237         }
239     }