fix consistancy of gradient on coupled patches
[OpenFOAM-1.6-ext.git] / src / engine / thoboisValve / thoboisValve.C
blobdae0917bedda7baefa3b4e61d1f3646e4ddbe320
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 "thoboisValve.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::thoboisValve::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::thoboisValve::thoboisValve
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& detachInCylinderPatchName,
79     const word& detachInPortPatchName,
80     const word& detachFacesName,
81     const graph& liftProfile,
82     const scalar minLift,
83     const scalar diameter,
84     const word& staticPointsName,
85     const word& movingPointsName,
86     const word& movingInternalPointsName,
87     const word& staticCellsName,
88     const word& movingCellsName
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     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
100     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
101     detachFacesName_(detachFacesName),
102     liftProfile_(liftProfile),
103     liftProfileStart_(min(liftProfile_.x())),
104     liftProfileEnd_(max(liftProfile_.x())),
105     minLift_(minLift),
106     diameter_(diameter),
107     staticPointsName_(staticPointsName),
108     movingPointsName_(movingPointsName),
109     movingInternalPointsName_(movingInternalPointsName),
110     staticCellsName_(staticCellsName),
111     movingCellsName_(movingCellsName)
115 // Construct from dictionary
116 Foam::thoboisValve::thoboisValve
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     detachInCylinderPatch_
139     (
140         dict.lookup("detachInCylinderPatch"),
141         mesh.boundaryMesh()
142     ),
143     detachInPortPatch_
144     (
145         dict.lookup("detachInPortPatch"),
146         mesh.boundaryMesh()
147     ),
148     detachFacesName_(dict.lookup("detachFaces")),
149     liftProfile_
150     (
151         "theta",
152         "lift",
153         name_,
154         IFstream
155         (
156             mesh.time().path()/mesh.time().constant()/
157             word(dict.lookup("liftProfileFile"))
158         )()
159     ),
160     liftProfileStart_(min(liftProfile_.x())),
161     liftProfileEnd_(max(liftProfile_.x())),
162     minLift_(readScalar(dict.lookup("minLift"))),
163     diameter_(readScalar(dict.lookup("diameter"))),
164     staticPointsName_(dict.lookup("staticPoints")),
165     movingPointsName_(dict.lookup("movingPoints")),
166     movingInternalPointsName_(dict.lookup("movingInternalPoints")),
167     staticCellsName_(dict.lookup("staticCells")),
168     movingCellsName_(dict.lookup("movingCells"))
172 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
175 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
177 Foam::scalar Foam::thoboisValve::lift(const scalar theta) const
179     return interpolateXY
180     (
181         adjustCrankAngle(theta),
182         liftProfile_.x(),
183         liftProfile_.y()
184     );
188 bool Foam::thoboisValve::isOpen() const
190     return lift(engineDB_.theta()) >= minLift_;
194 Foam::scalar Foam::thoboisValve::curLift() const
196     return max
197     (
198         lift(engineDB_.theta()),
199         minLift_
200     );
204 Foam::scalar Foam::thoboisValve::curVelocity() const
206     return
207        -(
208              curLift()
209            - max
210              (
211                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
212                  minLift_
213              )
214         )/(engineDB_.deltaT().value() + VSMALL);
218 Foam::labelList Foam::thoboisValve::movingPatchIDs() const
220     labelList mpIDs(2);
221     label nMpIDs = 0;
223     if (bottomPatch_.active())
224     {
225         mpIDs[nMpIDs] = bottomPatch_.index();
226         nMpIDs++;
227     }
229     if (poppetPatch_.active())
230     {
231         mpIDs[nMpIDs] = poppetPatch_.index();
232         nMpIDs++;
233     }
235     mpIDs.setSize(nMpIDs);
237     return mpIDs;
241 void Foam::thoboisValve::writeDict(Ostream& os) const
243     os  << nl << name() << nl << token::BEGIN_BLOCK;
245     cs().writeDict(os);
247     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
248         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
249         << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
250         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
251         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
252         << token::END_STATEMENT << nl
253         << "detachInPortPatch " << detachInPortPatch_.name()
254         << token::END_STATEMENT << nl
255         << "detachFaces " << detachFacesName_ << 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         << "diameter " << diameter_ << token::END_STATEMENT << nl
260         << "staticCells " << staticCellsName_ << token::END_STATEMENT << nl
261         << "movingCells " << movingCellsName_ << token::END_STATEMENT << nl
262         << "staticPoints " << staticPointsName_ << token::END_STATEMENT << nl
263         << "movingPoints " << movingPointsName_ << token::END_STATEMENT << nl
264         << token::END_BLOCK << endl;
268 // ************************************************************************* //