Merge commit 'd3b269b7c6ffa0cd68845adfecdfb849316dba71' into nextRelease
[foam-extend-3.2.git] / src / engine / dieselEngineValve / dieselEngineValve.C
blob05825b6d5766d99b0eceeba4b7370b1399d21874
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     |
5     \\  /    A nd           | For copyright notice see file Copyright
6      \\/     M anipulation  |
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 "dieselEngineValve.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::dieselEngineValve::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::dieselEngineValve::dieselEngineValve
70     const word& name,
71     const polyMesh& mesh,
72     const autoPtr<coordinateSystem>& valveCS,
73     const word& bottomPatchName,
74     const word& poppetPatchName,
75     const word& sidePatchName,
76     const word& stemPatchName,
77     const word& downInPortPatchName,
78     const word& downInCylinderPatchName,
79     const word& upInPortPatchName,
80     const word& upInCylinderPatchName,
81     const word& detachInCylinderPatchName,
82     const word& detachInPortPatchName,
83     const labelList& detachFaces,
84     const scalar& detachTol,
85     const graph& liftProfile,
86     const scalar minLift,
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     sidePatch_(sidePatchName, mesh.boundaryMesh()),
97     stemPatch_(stemPatchName, mesh.boundaryMesh()),
98     downInPortPatch_(downInPortPatchName, mesh.boundaryMesh()),
99     downInCylinderPatch_(downInCylinderPatchName, mesh.boundaryMesh()),
100     upInPortPatch_(upInPortPatchName, mesh.boundaryMesh()),
101     upInCylinderPatch_(upInCylinderPatchName, mesh.boundaryMesh()),
102     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
103     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
104     detachFaces_(detachFaces),
105     detachTol_(detachTol),
106     liftProfile_(liftProfile),
107     liftProfileStart_(min(liftProfile_.x())),
108     liftProfileEnd_(max(liftProfile_.x())),
109     minLift_(minLift),
110     diameter_(diameter)
114 // Construct from dictionary
115 Foam::dieselEngineValve::dieselEngineValve
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     sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
136     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
137     downInPortPatch_
138     (
139         dict.lookup("downInPortPatch"),
140         mesh.boundaryMesh()
141     ),
142     downInCylinderPatch_
143     (
144         dict.lookup("downInCylinderPatch"),
145         mesh.boundaryMesh()
146     ),
147     upInPortPatch_
148     (
149         dict.lookup("upInPortPatch"),
150         mesh.boundaryMesh()
151     ),
152     upInCylinderPatch_
153     (
154         dict.lookup("upInCylinderPatch"),
155         mesh.boundaryMesh()
156     ),
157     detachInCylinderPatch_
158     (
159         dict.lookup("detachInCylinderPatch"),
160         mesh.boundaryMesh()
161     ),
162     detachInPortPatch_
163     (
164         dict.lookup("detachInPortPatch"),
165         mesh.boundaryMesh()
166     ),
167     detachFaces_(dict.lookup("detachFaces")),
168     detachTol_(readScalar(dict.lookup("detachTol"))),
169     liftProfile_
170     (
171         "theta",
172         "lift",
173         name_,
174         IFstream
175         (
176             mesh.time().path()/mesh.time().constant()/
177             word(dict.lookup("liftProfileFile"))
178         )()
179     ),
180     liftProfileStart_(min(liftProfile_.x())),
181     liftProfileEnd_(max(liftProfile_.x())),
182     minLift_(readScalar(dict.lookup("minLift"))),
183     diameter_(readScalar(dict.lookup("diameter")))
187 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
190 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
192 Foam::scalar Foam::dieselEngineValve::lift(const scalar theta) const
194     return interpolateXY
195     (
196         adjustCrankAngle(theta),
197         liftProfile_.x(),
198         liftProfile_.y()
199     );
203 bool Foam::dieselEngineValve::isOpen() const
205     return lift(engineDB_.theta()) >= minLift_;
209 Foam::scalar Foam::dieselEngineValve::curLift() const
211     return max
212     (
213         lift(engineDB_.theta()),
214         minLift_
215     );
219 Foam::scalar Foam::dieselEngineValve::curVelocity() const
221     return
222        -(
223              curLift()
224            - max
225              (
226                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
227                  minLift_
228              )
229         )/(engineDB_.deltaT().value() + VSMALL);
233 Foam::labelList Foam::dieselEngineValve::movingPatchIDs() const
235     labelList mpIDs(2);
236     label nMpIDs = 0;
238     if (bottomPatch_.active())
239     {
240         mpIDs[nMpIDs] = bottomPatch_.index();
241         nMpIDs++;
242     }
244     if (poppetPatch_.active())
245     {
246         mpIDs[nMpIDs] = poppetPatch_.index();
247         nMpIDs++;
248     }
250     mpIDs.setSize(nMpIDs);
252     return mpIDs;
256 void Foam::dieselEngineValve::writeDict(Ostream& os) const
258     os  << nl << name() << nl << token::BEGIN_BLOCK;
260     cs().writeDict(os);
262     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
263         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
264         << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
265         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
266         << "downInPortPatch " << downInPortPatch_.name()
267         << token::END_STATEMENT << nl
268         << "downInCylinderPatch " << downInCylinderPatch_.name()
269         << token::END_STATEMENT << nl
270         << "upInPortPatch " << upInPortPatch_.name()
271         << token::END_STATEMENT << nl
272         << "upInCylinderPatch " << upInCylinderPatch_.name()
273         << token::END_STATEMENT << nl
274         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
275         << token::END_STATEMENT << nl
276         << "detachInPortPatch " << detachInPortPatch_.name()
277         << token::END_STATEMENT << nl
278         << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
279         << "liftProfile " << nl << token::BEGIN_BLOCK
280         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
281         << "minLift " << minLift_ << token::END_STATEMENT << nl
282         << "diameter " << diameter_ << token::END_STATEMENT << nl
283         << token::END_BLOCK << endl;
287 // ************************************************************************* //