fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / engine / thoboisSlidingValve / thoboisSlidingValve.C
blobca1ffd45b62ccf203c5ce7eb430f168cb0e01c42
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 \*---------------------------------------------------------------------------*/
27 #include "thoboisSlidingValve.H"
28 #include "engineTime.H"
29 #include "polyMesh.H"
30 #include "interpolateXY.H"
31 #include "IFstream.H"
33 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
35 Foam::scalar Foam::thoboisSlidingValve::adjustCrankAngle(const scalar theta) const
37     if (theta < liftProfileStart_)
38     {
39         scalar adjustedTheta = theta;
41         while (adjustedTheta < liftProfileStart_)
42         {
43             adjustedTheta += liftProfileEnd_ - liftProfileStart_;
44         }
46         return adjustedTheta;
47     }
48     else if (theta > liftProfileEnd_)
49     {
50         scalar adjustedTheta = theta;
52         while (adjustedTheta > liftProfileEnd_)
53         {
54             adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
55         }
57         return adjustedTheta;
58     }
59     else
60     {
61         return theta;
62     }
66 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
68 // Construct from components
69 Foam::thoboisSlidingValve::thoboisSlidingValve
71     const word& name,
72     const polyMesh& mesh,
73     const autoPtr<coordinateSystem>& valveCS,
74     const word& bottomPatchName,
75     const word& poppetPatchName,
76     const word& sidePatchName,
77     const word& stemPatchName,
78     const word& curtainInPortPatchName,
79     const word& curtainInCylinderPatchName,
80     const word& detachInCylinderPatchName,
81     const word& detachInPortPatchName,
82     const labelList& detachFaces,
83     const graph& liftProfile,
84     const scalar minLift,
85     const scalar diameter,
86     const scalar deformationLift,
87     const word& layeringFacesTopName,
88     const word& layeringFacesBottomName,
89     const word& movingCellsTopName,
90     const word& movingCellsBottomName,
91     const word& movingPointsTopName,
92     const word& movingPointsBottomName,
93     const scalar minTopLayer,
94     const scalar maxTopLayer,
95     const scalar minBottomLayer,
96     const scalar maxBottomLayer,
97     const word& staticPointsName,
98     const word& movingPointsName,
99     const word& staticCellsName,
100     const word& movingCellsName
103     name_(name),
104     mesh_(mesh),
105     engineDB_(refCast<const engineTime>(mesh.time())),
106     csPtr_(valveCS),
107     bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
108     poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
109     sidePatch_(sidePatchName, mesh.boundaryMesh()),
110     stemPatch_(stemPatchName, mesh.boundaryMesh()),
111     curtainInCylinderPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
112     curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
113     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
114     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
115     detachFaces_(detachFaces),
116     liftProfile_(liftProfile),
117     liftProfileStart_(min(liftProfile_.x())),
118     liftProfileEnd_(max(liftProfile_.x())),
119     minLift_(minLift),
120     diameter_(diameter),
121     deformationLift_(deformationLift),
122     layeringFacesTopName_(layeringFacesTopName),
123     layeringFacesBottomName_(layeringFacesBottomName),
124     movingCellsTopName_(movingCellsTopName),
125     movingCellsBottomName_(movingCellsBottomName),
126     movingPointsTopName_(movingPointsTopName),
127     movingPointsBottomName_(movingPointsBottomName),
128     minTopLayer_(minTopLayer),
129     maxTopLayer_(maxTopLayer),
130     minBottomLayer_(minBottomLayer),
131     maxBottomLayer_(maxBottomLayer),
132     staticPointsName_(staticPointsName),
133     movingPointsName_(movingPointsName),
134     staticCellsName_(staticCellsName),
135     movingCellsName_(movingCellsName)
139 // Construct from dictionary
140 Foam::thoboisSlidingValve::thoboisSlidingValve
142     const word& name,
143     const polyMesh& mesh,
144     const dictionary& dict
147     name_(name),
148     mesh_(mesh),
149     engineDB_(refCast<const engineTime>(mesh_.time())),
150     csPtr_
151     (
152         coordinateSystem::New
153         (
154             "coordinateSystem",
155             dict.subDict("coordinateSystem")
156         )
157     ),
158     bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
159     poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
160     sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
161     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
162     curtainInCylinderPatch_
163     (
164         dict.lookup("curtainInCylinderPatch"),
165         mesh.boundaryMesh()
166     ),
167     curtainInPortPatch_
168     (
169         dict.lookup("curtainInPortPatch"),
170         mesh.boundaryMesh()
171     ),
172     detachInCylinderPatch_
173     (
174         dict.lookup("detachInCylinderPatch"),
175         mesh.boundaryMesh()
176     ),
177     detachInPortPatch_
178     (
179         dict.lookup("detachInPortPatch"),
180         mesh.boundaryMesh()
181     ),
182     detachFaces_(dict.lookup("detachFaces")),
183      liftProfile_
184     (
185         "theta",
186         "lift",
187         name_,
188         IFstream
189         (
190             mesh.time().path()/mesh.time().constant()/
191             word(dict.lookup("liftProfileFile"))
192         )()
193     ),
194     liftProfileStart_(min(liftProfile_.x())),
195     liftProfileEnd_(max(liftProfile_.x())),
196     minLift_(readScalar(dict.lookup("minLift"))),
197     diameter_(readScalar(dict.lookup("diameter"))),
198     deformationLift_(readScalar(dict.lookup("deformationLift"))),    
199     layeringFacesTopName_(dict.lookup("layeringFacesTop")),
200     layeringFacesBottomName_(dict.lookup("layeringFacesBottom")),
201     movingCellsTopName_(dict.lookup("movingCellsTop")),
202     movingCellsBottomName_(dict.lookup("movingCellsBottom")),
203     movingPointsTopName_(dict.lookup("movingPointsTop")),
204     movingPointsBottomName_(dict.lookup("movingPointsBottom")),
205     minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
206     maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
207     minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
208     maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
209     staticPointsName_(dict.lookup("staticPoints")),
210     movingPointsName_(dict.lookup("movingPoints")),
211     staticCellsName_(dict.lookup("staticCells")),
212     movingCellsName_(dict.lookup("movingCells"))
216 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
218 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
220 Foam::scalar Foam::thoboisSlidingValve::lift(const scalar theta) const
222     return interpolateXY
223     (
224         adjustCrankAngle(theta),
225         liftProfile_.x(),
226         liftProfile_.y()
227     );
231 bool Foam::thoboisSlidingValve::isOpen() const
233     return lift(engineDB_.theta()) >= minLift_;
237 Foam::scalar Foam::thoboisSlidingValve::curLift() const
239     return max
240     (
241         lift(engineDB_.theta()),
242         minLift_
243     );
247 Foam::scalar Foam::thoboisSlidingValve::curVelocity() const
249     return
250        -(
251              curLift()
252            - max
253              (
254                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
255                  minLift_
256              )
257         )/(engineDB_.deltaT().value() + VSMALL);
261 Foam::labelList Foam::thoboisSlidingValve::movingPatchIDs() const
263     labelList mpIDs(2);
264     label nMpIDs = 0;
266     if (bottomPatch_.active())
267     {
268         mpIDs[nMpIDs] = bottomPatch_.index();
269         nMpIDs++;
270     }
272     if (poppetPatch_.active())
273     {
274         mpIDs[nMpIDs] = poppetPatch_.index();
275         nMpIDs++;
276     }
278     mpIDs.setSize(nMpIDs);
280     return mpIDs;
284 void Foam::thoboisSlidingValve::writeDict(Ostream& os) const
286     os  << nl << name() << nl << token::BEGIN_BLOCK;
288     cs().writeDict(os);
290     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
291         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
292         << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
293         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
294         << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
295         << token::END_STATEMENT << nl
296         << "curtainInPortPatch " << curtainInPortPatch_.name()
297         << token::END_STATEMENT << nl
298 //        << "detachInCylinderPatch " << detachInCylinderPatch_.name()
299 //        << token::END_STATEMENT << nl
300         << "liftProfile " << nl << token::BEGIN_BLOCK
301         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
302         << "minLift " << minLift_ << token::END_STATEMENT << nl
303         << "diameter " << diameter_ << token::END_STATEMENT << nl
304          << token::END_BLOCK << endl;
308 // ************************************************************************* //