OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

engineValve.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "engineValve.H"
00028 #include "engineTime.H"
00029 #include "polyMesh.H"
00030 #include "interpolateXY.H"
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
00035 {
00036     if (theta < liftProfileStart_)
00037     {
00038         scalar adjustedTheta = theta;
00039 
00040         while (adjustedTheta < liftProfileStart_)
00041         {
00042             adjustedTheta += liftProfileEnd_ - liftProfileStart_;
00043         }
00044 
00045         return adjustedTheta;
00046     }
00047     else if (theta > liftProfileEnd_)
00048     {
00049         scalar adjustedTheta = theta;
00050 
00051         while (adjustedTheta > liftProfileEnd_)
00052         {
00053             adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
00054         }
00055 
00056         return adjustedTheta;
00057     }
00058     else
00059     {
00060         return theta;
00061     }
00062 }
00063 
00064 
00065 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00066 
00067 // Construct from components
00068 Foam::engineValve::engineValve
00069 (
00070     const word& name,
00071     const polyMesh& mesh,
00072     const autoPtr<coordinateSystem>& valveCS,
00073     const word& bottomPatchName,
00074     const word& poppetPatchName,
00075     const word& stemPatchName,
00076     const word& curtainInPortPatchName,
00077     const word& curtainInCylinderPatchName,
00078     const word& detachInCylinderPatchName,
00079     const word& detachInPortPatchName,
00080     const labelList& detachFaces,
00081     const graph& liftProfile,
00082     const scalar minLift,
00083     const scalar minTopLayer,
00084     const scalar maxTopLayer,
00085     const scalar minBottomLayer,
00086     const scalar maxBottomLayer,
00087     const scalar diameter
00088 )
00089 :
00090     name_(name),
00091     mesh_(mesh),
00092     engineDB_(refCast<const engineTime>(mesh.time())),
00093     csPtr_(valveCS),
00094     bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
00095     poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
00096     stemPatch_(stemPatchName, mesh.boundaryMesh()),
00097     curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
00098     curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
00099     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
00100     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
00101     detachFaces_(detachFaces),
00102     liftProfile_(liftProfile),
00103     liftProfileStart_(min(liftProfile_.x())),
00104     liftProfileEnd_(max(liftProfile_.x())),
00105     minLift_(minLift),
00106     minTopLayer_(minTopLayer),
00107     maxTopLayer_(maxTopLayer),
00108     minBottomLayer_(minBottomLayer),
00109     maxBottomLayer_(maxBottomLayer),
00110     diameter_(diameter)
00111 {}
00112 
00113 
00114 // Construct from dictionary
00115 Foam::engineValve::engineValve
00116 (
00117     const word& name,
00118     const polyMesh& mesh,
00119     const dictionary& dict
00120 )
00121 :
00122     name_(name),
00123     mesh_(mesh),
00124     engineDB_(refCast<const engineTime>(mesh_.time())),
00125     csPtr_
00126     (
00127         coordinateSystem::New
00128         (
00129             "coordinateSystem",
00130             dict.subDict("coordinateSystem")
00131         )
00132     ),
00133     bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
00134     poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
00135     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
00136     curtainInPortPatch_
00137     (
00138         dict.lookup("curtainInPortPatch"),
00139         mesh.boundaryMesh()
00140     ),
00141     curtainInCylinderPatch_
00142     (
00143         dict.lookup("curtainInCylinderPatch"),
00144         mesh.boundaryMesh()
00145     ),
00146     detachInCylinderPatch_
00147     (
00148         dict.lookup("detachInCylinderPatch"),
00149         mesh.boundaryMesh()
00150     ),
00151     detachInPortPatch_
00152     (
00153         dict.lookup("detachInPortPatch"),
00154         mesh.boundaryMesh()
00155     ),
00156     detachFaces_(dict.lookup("detachFaces")),
00157     liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
00158     liftProfileStart_(min(liftProfile_.x())),
00159     liftProfileEnd_(max(liftProfile_.x())),
00160     minLift_(readScalar(dict.lookup("minLift"))),
00161     minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
00162     maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
00163     minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
00164     maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
00165     diameter_(readScalar(dict.lookup("diameter")))
00166 {}
00167 
00168 
00169 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00170 
00171 
00172 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00173 
00174 Foam::scalar Foam::engineValve::lift(const scalar theta) const
00175 {
00176     return interpolateXY
00177     (
00178         adjustCrankAngle(theta),
00179         liftProfile_.x(),
00180         liftProfile_.y()
00181     );
00182 }
00183 
00184 
00185 bool Foam::engineValve::isOpen() const
00186 {
00187     return lift(engineDB_.theta()) >= minLift_;
00188 }
00189 
00190 
00191 Foam::scalar Foam::engineValve::curLift() const
00192 {
00193     return max
00194     (
00195         lift(engineDB_.theta()),
00196         minLift_
00197     );
00198 }
00199 
00200 
00201 Foam::scalar Foam::engineValve::curVelocity() const
00202 {
00203     return
00204        -(
00205              curLift()
00206            - max
00207              (
00208                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
00209                  minLift_
00210              )
00211         )/(engineDB_.deltaT().value() + VSMALL);
00212 }
00213 
00214 
00215 Foam::labelList Foam::engineValve::movingPatchIDs() const
00216 {
00217     labelList mpIDs(2);
00218     label nMpIDs = 0;
00219 
00220     if (bottomPatch_.active())
00221     {
00222         mpIDs[nMpIDs] = bottomPatch_.index();
00223         nMpIDs++;
00224     }
00225 
00226     if (poppetPatch_.active())
00227     {
00228         mpIDs[nMpIDs] = poppetPatch_.index();
00229         nMpIDs++;
00230     }
00231 
00232     mpIDs.setSize(nMpIDs);
00233 
00234     return mpIDs;
00235 }
00236 
00237 
00238 void Foam::engineValve::writeDict(Ostream& os) const
00239 {
00240     os  << nl << name() << nl << token::BEGIN_BLOCK;
00241 
00242     cs().writeDict(os);
00243 
00244     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
00245         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
00246         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
00247         << "curtainInPortPatch " << curtainInPortPatch_.name()
00248         << token::END_STATEMENT << nl
00249         << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
00250         << token::END_STATEMENT << nl
00251         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
00252         << token::END_STATEMENT << nl
00253         << "detachInPortPatch " << detachInPortPatch_.name()
00254         << token::END_STATEMENT << nl
00255         << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
00256         << "liftProfile " << nl << token::BEGIN_BLOCK
00257         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
00258         << "minLift " << minLift_ << token::END_STATEMENT << nl
00259         << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
00260         << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
00261         << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
00262         << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
00263         << "diameter " << diameter_ << token::END_STATEMENT << nl
00264         << token::END_BLOCK << endl;
00265 }
00266 
00267 
00268 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd