Fix tutorials: typo in tutorials/viscoelastic/viscoelasticFluidFoam/S-MDCPP/constant...
[OpenFOAM-1.6-ext.git] / src / engine / dieselEngineValve / dieselEngineValve.C
blob03182711cbd48809383607027ef3225385ac79ae
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 "dieselEngineValve.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::dieselEngineValve::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::dieselEngineValve::dieselEngineValve
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& downInPortPatchName,
79     const word& downInCylinderPatchName,
80     const word& upInPortPatchName,
81     const word& upInCylinderPatchName,
82     const word& detachInCylinderPatchName,
83     const word& detachInPortPatchName,
84     const labelList& detachFaces,
85     const scalar& detachTol,
86     const graph& liftProfile,
87     const scalar minLift,
88     const scalar diameter
91     name_(name),
92     mesh_(mesh),
93     engineDB_(refCast<const engineTime>(mesh.time())),
94     csPtr_(valveCS),
95     bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
96     poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
97     sidePatch_(sidePatchName, mesh.boundaryMesh()),
98     stemPatch_(stemPatchName, mesh.boundaryMesh()),
99     downInPortPatch_(downInPortPatchName, mesh.boundaryMesh()),
100     downInCylinderPatch_(downInCylinderPatchName, mesh.boundaryMesh()),
101     upInPortPatch_(upInPortPatchName, mesh.boundaryMesh()),
102     upInCylinderPatch_(upInCylinderPatchName, mesh.boundaryMesh()),
103     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
104     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
105     detachFaces_(detachFaces),
106     detachTol_(detachTol),
107     liftProfile_(liftProfile),
108     liftProfileStart_(min(liftProfile_.x())),
109     liftProfileEnd_(max(liftProfile_.x())),
110     minLift_(minLift),
111     diameter_(diameter)
115 // Construct from dictionary
116 Foam::dieselEngineValve::dieselEngineValve
118     const word& name,
119     const polyMesh& mesh,
120     const dictionary& dict
123     name_(name),
124     mesh_(mesh),
125     engineDB_(refCast<const engineTime>(mesh_.time())),
126     csPtr_
127     (
128         coordinateSystem::New
129         (
130             "coordinateSystem",
131             dict.subDict("coordinateSystem")
132         )
133     ),
134     bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
135     poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
136     sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
137     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
138     downInPortPatch_
139     (
140         dict.lookup("downInPortPatch"),
141         mesh.boundaryMesh()
142     ),
143     downInCylinderPatch_
144     (
145         dict.lookup("downInCylinderPatch"),
146         mesh.boundaryMesh()
147     ),
148     upInPortPatch_
149     (
150         dict.lookup("upInPortPatch"),
151         mesh.boundaryMesh()
152     ),
153     upInCylinderPatch_
154     (
155         dict.lookup("upInCylinderPatch"),
156         mesh.boundaryMesh()
157     ),
158     detachInCylinderPatch_
159     (
160         dict.lookup("detachInCylinderPatch"),
161         mesh.boundaryMesh()
162     ),
163     detachInPortPatch_
164     (
165         dict.lookup("detachInPortPatch"),
166         mesh.boundaryMesh()
167     ),
168     detachFaces_(dict.lookup("detachFaces")),
169     detachTol_(readScalar(dict.lookup("detachTol"))),
170     liftProfile_
171     (
172         "theta",
173         "lift",
174         name_,
175         IFstream
176         (
177             mesh.time().path()/mesh.time().constant()/
178             word(dict.lookup("liftProfileFile"))
179         )()
180     ),
181     liftProfileStart_(min(liftProfile_.x())),
182     liftProfileEnd_(max(liftProfile_.x())),
183     minLift_(readScalar(dict.lookup("minLift"))),
184     diameter_(readScalar(dict.lookup("diameter")))
188 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
191 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
193 Foam::scalar Foam::dieselEngineValve::lift(const scalar theta) const
195     return interpolateXY
196     (
197         adjustCrankAngle(theta),
198         liftProfile_.x(),
199         liftProfile_.y()
200     );
204 bool Foam::dieselEngineValve::isOpen() const
206     return lift(engineDB_.theta()) >= minLift_;
210 Foam::scalar Foam::dieselEngineValve::curLift() const
212     return max
213     (
214         lift(engineDB_.theta()),
215         minLift_
216     );
220 Foam::scalar Foam::dieselEngineValve::curVelocity() const
222     return
223        -(
224              curLift()
225            - max
226              (
227                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
228                  minLift_
229              )
230         )/(engineDB_.deltaT().value() + VSMALL);
234 Foam::labelList Foam::dieselEngineValve::movingPatchIDs() const
236     labelList mpIDs(2);
237     label nMpIDs = 0;
239     if (bottomPatch_.active())
240     {
241         mpIDs[nMpIDs] = bottomPatch_.index();
242         nMpIDs++;
243     }
245     if (poppetPatch_.active())
246     {
247         mpIDs[nMpIDs] = poppetPatch_.index();
248         nMpIDs++;
249     }
251     mpIDs.setSize(nMpIDs);
253     return mpIDs;
257 void Foam::dieselEngineValve::writeDict(Ostream& os) const
259     os  << nl << name() << nl << token::BEGIN_BLOCK;
261     cs().writeDict(os);
263     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
264         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
265         << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
266         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
267         << "downInPortPatch " << downInPortPatch_.name()
268         << token::END_STATEMENT << nl
269         << "downInCylinderPatch " << downInCylinderPatch_.name()
270         << token::END_STATEMENT << nl
271         << "upInPortPatch " << upInPortPatch_.name()
272         << token::END_STATEMENT << nl
273         << "upInCylinderPatch " << upInCylinderPatch_.name()
274         << token::END_STATEMENT << nl
275         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
276         << token::END_STATEMENT << nl
277         << "detachInPortPatch " << detachInPortPatch_.name()
278         << token::END_STATEMENT << nl
279         << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
280         << "liftProfile " << nl << token::BEGIN_BLOCK
281         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
282         << "minLift " << minLift_ << token::END_STATEMENT << nl
283         << "diameter " << diameter_ << token::END_STATEMENT << nl
284         << token::END_BLOCK << endl;
288 // ************************************************************************* //