FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "engineValve.H"
00027 #include <engine/engineTime.H>
00028 #include <OpenFOAM/polyMesh.H>
00029 #include <OpenFOAM/interpolateXY.H>
00030 
00031 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00032 
00033 Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
00034 {
00035     if (theta < liftProfileStart_)
00036     {
00037         scalar adjustedTheta = theta;
00038 
00039         while (adjustedTheta < liftProfileStart_)
00040         {
00041             adjustedTheta += liftProfileEnd_ - liftProfileStart_;
00042         }
00043 
00044         return adjustedTheta;
00045     }
00046     else if (theta > liftProfileEnd_)
00047     {
00048         scalar adjustedTheta = theta;
00049 
00050         while (adjustedTheta > liftProfileEnd_)
00051         {
00052             adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
00053         }
00054 
00055         return adjustedTheta;
00056     }
00057     else
00058     {
00059         return theta;
00060     }
00061 }
00062 
00063 
00064 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00065 
00066 // Construct from components
00067 Foam::engineValve::engineValve
00068 (
00069     const word& name,
00070     const polyMesh& mesh,
00071     const autoPtr<coordinateSystem>& valveCS,
00072     const word& bottomPatchName,
00073     const word& poppetPatchName,
00074     const word& stemPatchName,
00075     const word& curtainInPortPatchName,
00076     const word& curtainInCylinderPatchName,
00077     const word& detachInCylinderPatchName,
00078     const word& detachInPortPatchName,
00079     const labelList& detachFaces,
00080     const graph& liftProfile,
00081     const scalar minLift,
00082     const scalar minTopLayer,
00083     const scalar maxTopLayer,
00084     const scalar minBottomLayer,
00085     const scalar maxBottomLayer,
00086     const scalar diameter
00087 )
00088 :
00089     name_(name),
00090     mesh_(mesh),
00091     engineDB_(refCast<const engineTime>(mesh.time())),
00092     csPtr_(valveCS),
00093     bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
00094     poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
00095     stemPatch_(stemPatchName, mesh.boundaryMesh()),
00096     curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
00097     curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
00098     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
00099     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
00100     detachFaces_(detachFaces),
00101     liftProfile_(liftProfile),
00102     liftProfileStart_(min(liftProfile_.x())),
00103     liftProfileEnd_(max(liftProfile_.x())),
00104     minLift_(minLift),
00105     minTopLayer_(minTopLayer),
00106     maxTopLayer_(maxTopLayer),
00107     minBottomLayer_(minBottomLayer),
00108     maxBottomLayer_(maxBottomLayer),
00109     diameter_(diameter)
00110 {}
00111 
00112 
00113 // Construct from dictionary
00114 Foam::engineValve::engineValve
00115 (
00116     const word& name,
00117     const polyMesh& mesh,
00118     const dictionary& dict
00119 )
00120 :
00121     name_(name),
00122     mesh_(mesh),
00123     engineDB_(refCast<const engineTime>(mesh_.time())),
00124     csPtr_
00125     (
00126         coordinateSystem::New
00127         (
00128             "coordinateSystem",
00129             dict.subDict("coordinateSystem")
00130         )
00131     ),
00132     bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
00133     poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
00134     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
00135     curtainInPortPatch_
00136     (
00137         dict.lookup("curtainInPortPatch"),
00138         mesh.boundaryMesh()
00139     ),
00140     curtainInCylinderPatch_
00141     (
00142         dict.lookup("curtainInCylinderPatch"),
00143         mesh.boundaryMesh()
00144     ),
00145     detachInCylinderPatch_
00146     (
00147         dict.lookup("detachInCylinderPatch"),
00148         mesh.boundaryMesh()
00149     ),
00150     detachInPortPatch_
00151     (
00152         dict.lookup("detachInPortPatch"),
00153         mesh.boundaryMesh()
00154     ),
00155     detachFaces_(dict.lookup("detachFaces")),
00156     liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
00157     liftProfileStart_(min(liftProfile_.x())),
00158     liftProfileEnd_(max(liftProfile_.x())),
00159     minLift_(readScalar(dict.lookup("minLift"))),
00160     minTopLayer_(readScalar(dict.lookup("minTopLayer"))),
00161     maxTopLayer_(readScalar(dict.lookup("maxTopLayer"))),
00162     minBottomLayer_(readScalar(dict.lookup("minBottomLayer"))),
00163     maxBottomLayer_(readScalar(dict.lookup("maxBottomLayer"))),
00164     diameter_(readScalar(dict.lookup("diameter")))
00165 {}
00166 
00167 
00168 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00169 
00170 
00171 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00172 
00173 Foam::scalar Foam::engineValve::lift(const scalar theta) const
00174 {
00175     return interpolateXY
00176     (
00177         adjustCrankAngle(theta),
00178         liftProfile_.x(),
00179         liftProfile_.y()
00180     );
00181 }
00182 
00183 
00184 bool Foam::engineValve::isOpen() const
00185 {
00186     return lift(engineDB_.theta()) >= minLift_;
00187 }
00188 
00189 
00190 Foam::scalar Foam::engineValve::curLift() const
00191 {
00192     return max
00193     (
00194         lift(engineDB_.theta()),
00195         minLift_
00196     );
00197 }
00198 
00199 
00200 Foam::scalar Foam::engineValve::curVelocity() const
00201 {
00202     return
00203        -(
00204              curLift()
00205            - max
00206              (
00207                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
00208                  minLift_
00209              )
00210         )/(engineDB_.deltaT().value() + VSMALL);
00211 }
00212 
00213 
00214 Foam::labelList Foam::engineValve::movingPatchIDs() const
00215 {
00216     labelList mpIDs(2);
00217     label nMpIDs = 0;
00218 
00219     if (bottomPatch_.active())
00220     {
00221         mpIDs[nMpIDs] = bottomPatch_.index();
00222         nMpIDs++;
00223     }
00224 
00225     if (poppetPatch_.active())
00226     {
00227         mpIDs[nMpIDs] = poppetPatch_.index();
00228         nMpIDs++;
00229     }
00230 
00231     mpIDs.setSize(nMpIDs);
00232 
00233     return mpIDs;
00234 }
00235 
00236 
00237 void Foam::engineValve::writeDict(Ostream& os) const
00238 {
00239     os  << nl << name() << nl << token::BEGIN_BLOCK;
00240 
00241     cs().writeDict(os);
00242 
00243     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
00244         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
00245         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
00246         << "curtainInPortPatch " << curtainInPortPatch_.name()
00247         << token::END_STATEMENT << nl
00248         << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
00249         << token::END_STATEMENT << nl
00250         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
00251         << token::END_STATEMENT << nl
00252         << "detachInPortPatch " << detachInPortPatch_.name()
00253         << token::END_STATEMENT << nl
00254         << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
00255         << "liftProfile " << nl << token::BEGIN_BLOCK
00256         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
00257         << "minLift " << minLift_ << token::END_STATEMENT << nl
00258         << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
00259         << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
00260         << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
00261         << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
00262         << "diameter " << diameter_ << token::END_STATEMENT << nl
00263         << token::END_BLOCK << endl;
00264 }
00265 
00266 
00267 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines