Forward compatibility: flex
[foam-extend-3.2.git] / src / engine / engineValve / engineValve.C
blob3b0147d076fe802456b9c8ec7a86f6a2d6359fa1
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 \*---------------------------------------------------------------------------*/
26 #include "engineValve.H"
27 #include "engineTime.H"
28 #include "polyMesh.H"
29 #include "interpolateXY.H"
30 #include "IFstream.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_
158     (
159         "theta",
160         "lift",
161         name_,
162         IFstream
163         (
164             mesh.time().path()/mesh.time().constant()/
165             word(dict.lookup("liftProfileFile"))
166         )()
167     ),
168     liftProfileStart_(min(liftProfile_.x())),
169     liftProfileEnd_(max(liftProfile_.x())),
170     minLift_(readScalar(dict.lookup("minLift"))),
171     minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
172     maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
173     minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
174     maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
175     diameter_(readScalar(dict.lookup("diameter")))
179 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
182 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
184 Foam::scalar Foam::engineValve::lift(const scalar theta) const
186     return interpolateXY
187     (
188         adjustCrankAngle(theta),
189         liftProfile_.x(),
190         liftProfile_.y()
191     );
195 bool Foam::engineValve::isOpen() const
197     return lift(engineDB_.theta()) >= minLift_;
201 Foam::scalar Foam::engineValve::curLift() const
203     return max
204     (
205         lift(engineDB_.theta()),
206         minLift_
207     );
211 Foam::scalar Foam::engineValve::curVelocity() const
213     return
214        -(
215              curLift()
216            - max
217              (
218                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
219                  minLift_
220              )
221         )/(engineDB_.deltaT().value() + VSMALL);
225 Foam::labelList Foam::engineValve::movingPatchIDs() const
227     labelList mpIDs(2);
228     label nMpIDs = 0;
230     if (bottomPatch_.active())
231     {
232         mpIDs[nMpIDs] = bottomPatch_.index();
233         nMpIDs++;
234     }
236     if (poppetPatch_.active())
237     {
238         mpIDs[nMpIDs] = poppetPatch_.index();
239         nMpIDs++;
240     }
242     mpIDs.setSize(nMpIDs);
244     return mpIDs;
248 void Foam::engineValve::writeDict(Ostream& os) const
250     os  << nl << name() << nl << token::BEGIN_BLOCK;
252     cs().writeDict(os);
254     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
255         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
256         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
257         << "curtainInPortPatch " << curtainInPortPatch_.name()
258         << token::END_STATEMENT << nl
259         << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
260         << token::END_STATEMENT << nl
261         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
262         << token::END_STATEMENT << nl
263         << "detachInPortPatch " << detachInPortPatch_.name()
264         << token::END_STATEMENT << nl
265         << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
266         << "liftProfile " << nl << token::BEGIN_BLOCK
267         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
268         << "minLift " << minLift_ << token::END_STATEMENT << nl
269         << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
270         << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
271         << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
272         << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
273         << "diameter " << diameter_ << token::END_STATEMENT << nl
274         << token::END_BLOCK << endl;
278 // ************************************************************************* //