adding scalarIOList
[OpenFOAM-1.5.x.git] / src / engine / engineValve / engineValve.C
blob3da42c0aff9b99569c4597ee72bdd5a3b594d901
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
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 "engineValve.H"
28 #include "engineTime.H"
29 #include "polyMesh.H"
30 #include "interpolateXY.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
36     if (theta < liftProfileStart_)
37     {
38         scalar adjustedTheta = theta;
40         while (adjustedTheta < liftProfileStart_)
41         {
42             adjustedTheta += liftProfileEnd_ - liftProfileStart_;
43         }
45         return adjustedTheta;
46     }
47     else if (theta > liftProfileEnd_)
48     {
49         scalar adjustedTheta = theta;
51         while (adjustedTheta > liftProfileEnd_)
52         {
53             adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
54         }
56         return adjustedTheta;
57     }
58     else
59     {
60         return theta;
61     }
65 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
67 // Construct from components
68 Foam::engineValve::engineValve
70     const word& name,
71     const polyMesh& mesh,
72     const autoPtr<coordinateSystem>& valveCS,
73     const word& bottomPatchName,
74     const word& poppetPatchName,
75     const word& stemPatchName,
76     const word& curtainInPortPatchName,
77     const word& curtainInCylinderPatchName,
78     const word& detachInCylinderPatchName,
79     const word& detachInPortPatchName,
80     const labelList& detachFaces,
81     const graph& liftProfile,
82     const scalar minLift,
83     const scalar minTopLayer,
84     const scalar maxTopLayer,
85     const scalar minBottomLayer,
86     const scalar maxBottomLayer,
87     const scalar diameter
90     name_(name),
91     mesh_(mesh),
92     engineDB_(refCast<const engineTime>(mesh.time())),
93     csPtr_(valveCS),
94     bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
95     poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
96     stemPatch_(stemPatchName, mesh.boundaryMesh()),
97     curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
98     curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
99     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
100     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
101     detachFaces_(detachFaces),
102     liftProfile_(liftProfile),
103     liftProfileStart_(min(liftProfile_.x())),
104     liftProfileEnd_(max(liftProfile_.x())),
105     minLift_(minLift),
106     minTopLayer_(minTopLayer),
107     maxTopLayer_(maxTopLayer),
108     minBottomLayer_(minBottomLayer),
109     maxBottomLayer_(maxBottomLayer),
110     diameter_(diameter)
114 // Construct from dictionary
115 Foam::engineValve::engineValve
117     const word& name,
118     const polyMesh& mesh,
119     const dictionary& dict
122     name_(name),
123     mesh_(mesh),
124     engineDB_(refCast<const engineTime>(mesh_.time())),
125     csPtr_
126     (
127         coordinateSystem::New
128         (
129             "coordinateSystem",
130             dict.subDict("coordinateSystem")
131         )
132     ),
133     bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
134     poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
135     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
136     curtainInPortPatch_
137     (
138         dict.lookup("curtainInPortPatch"),
139         mesh.boundaryMesh()
140     ),
141     curtainInCylinderPatch_
142     (
143         dict.lookup("curtainInCylinderPatch"),
144         mesh.boundaryMesh()
145     ),
146     detachInCylinderPatch_
147     (
148         dict.lookup("detachInCylinderPatch"),
149         mesh.boundaryMesh()
150     ),
151     detachInPortPatch_
152     (
153         dict.lookup("detachInPortPatch"),
154         mesh.boundaryMesh()
155     ),
156     detachFaces_(dict.lookup("detachFaces")),
157     liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
158     liftProfileStart_(min(liftProfile_.x())),
159     liftProfileEnd_(max(liftProfile_.x())),
160     minLift_(readScalar(dict.lookup("minLift"))),
161     minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
162     maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
163     minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
164     maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
165     diameter_(readScalar(dict.lookup("diameter")))
169 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
172 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
174 Foam::scalar Foam::engineValve::lift(const scalar theta) const
176     return interpolateXY
177     (
178         adjustCrankAngle(theta),
179         liftProfile_.x(),
180         liftProfile_.y()
181     );
185 bool Foam::engineValve::isOpen() const
187     return lift(engineDB_.theta()) >= minLift_;
191 Foam::scalar Foam::engineValve::curLift() const
193     return max
194     (
195         lift(engineDB_.theta()),
196         minLift_
197     );
201 Foam::scalar Foam::engineValve::curVelocity() const
203     return
204        -(
205              curLift()
206            - max
207              (
208                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
209                  minLift_
210              )
211         )/(engineDB_.deltaT().value() + VSMALL);
215 Foam::labelList Foam::engineValve::movingPatchIDs() const
217     labelList mpIDs(2);
218     label nMpIDs = 0;
220     if (bottomPatch_.active())
221     {
222         mpIDs[nMpIDs] = bottomPatch_.index();
223         nMpIDs++;
224     }
226     if (poppetPatch_.active())
227     {
228         mpIDs[nMpIDs] = poppetPatch_.index();
229         nMpIDs++;
230     }
232     mpIDs.setSize(nMpIDs);
234     return mpIDs;
238 void Foam::engineValve::writeDict(Ostream& os) const
240     os  << nl << name() << nl << token::BEGIN_BLOCK;
242     cs().writeDict(os);
244     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
245         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
246         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
247         << "curtainInPortPatch " << curtainInPortPatch_.name()
248         << token::END_STATEMENT << nl
249         << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
250         << token::END_STATEMENT << nl
251         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
252         << token::END_STATEMENT << nl
253         << "detachInPortPatch " << detachInPortPatch_.name()
254         << token::END_STATEMENT << nl
255         << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
256         << "liftProfile " << nl << token::BEGIN_BLOCK
257         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
258         << "minLift " << minLift_ << token::END_STATEMENT << nl
259         << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
260         << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
261         << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
262         << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
263         << "diameter " << diameter_ << token::END_STATEMENT << nl
264         << token::END_BLOCK << endl;
268 // ************************************************************************* //