Solid body motion bug fixes. Author: Hrvoje Jasak. Merge: Hrvoje Jasak.
[foam-extend-3.2.git] / src / engine / thoboisValve / thoboisValve.C
blobcd7195ad0a78269d0b26c6d4ba76627f4c6823d9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
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 "thoboisValve.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::thoboisValve::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::thoboisValve::thoboisValve
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& detachInCylinderPatchName,
78     const word& detachInPortPatchName,
79     const word& detachFacesName,
80     const graph& liftProfile,
81     const scalar minLift,
82     const scalar diameter,
83     const word& staticPointsName,
84     const word& movingPointsName,
85     const word& movingInternalPointsName,
86     const word& staticCellsName,
87     const word& movingCellsName
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     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
99     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
100     detachFacesName_(detachFacesName),
101     liftProfile_(liftProfile),
102     liftProfileStart_(min(liftProfile_.x())),
103     liftProfileEnd_(max(liftProfile_.x())),
104     minLift_(minLift),
105     diameter_(diameter),
106     staticPointsName_(staticPointsName),
107     movingPointsName_(movingPointsName),
108     movingInternalPointsName_(movingInternalPointsName),
109     staticCellsName_(staticCellsName),
110     movingCellsName_(movingCellsName)
114 // Construct from dictionary
115 Foam::thoboisValve::thoboisValve
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     detachInCylinderPatch_
138     (
139         dict.lookup("detachInCylinderPatch"),
140         mesh.boundaryMesh()
141     ),
142     detachInPortPatch_
143     (
144         dict.lookup("detachInPortPatch"),
145         mesh.boundaryMesh()
146     ),
147     detachFacesName_(dict.lookup("detachFaces")),
148     liftProfile_
149     (
150         "theta",
151         "lift",
152         name_,
153         IFstream
154         (
155             mesh.time().path()/mesh.time().constant()/
156             word(dict.lookup("liftProfileFile"))
157         )()
158     ),
159     liftProfileStart_(min(liftProfile_.x())),
160     liftProfileEnd_(max(liftProfile_.x())),
161     minLift_(readScalar(dict.lookup("minLift"))),
162     diameter_(readScalar(dict.lookup("diameter"))),
163     staticPointsName_(dict.lookup("staticPoints")),
164     movingPointsName_(dict.lookup("movingPoints")),
165     movingInternalPointsName_(dict.lookup("movingInternalPoints")),
166     staticCellsName_(dict.lookup("staticCells")),
167     movingCellsName_(dict.lookup("movingCells"))
171 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
174 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
176 Foam::scalar Foam::thoboisValve::lift(const scalar theta) const
178     return interpolateXY
179     (
180         adjustCrankAngle(theta),
181         liftProfile_.x(),
182         liftProfile_.y()
183     );
187 bool Foam::thoboisValve::isOpen() const
189     return lift(engineDB_.theta()) >= minLift_;
193 Foam::scalar Foam::thoboisValve::curLift() const
195     return max
196     (
197         lift(engineDB_.theta()),
198         minLift_
199     );
203 Foam::scalar Foam::thoboisValve::curVelocity() const
205     return
206        -(
207              curLift()
208            - max
209              (
210                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
211                  minLift_
212              )
213         )/(engineDB_.deltaT().value() + VSMALL);
217 Foam::labelList Foam::thoboisValve::movingPatchIDs() const
219     labelList mpIDs(2);
220     label nMpIDs = 0;
222     if (bottomPatch_.active())
223     {
224         mpIDs[nMpIDs] = bottomPatch_.index();
225         nMpIDs++;
226     }
228     if (poppetPatch_.active())
229     {
230         mpIDs[nMpIDs] = poppetPatch_.index();
231         nMpIDs++;
232     }
234     mpIDs.setSize(nMpIDs);
236     return mpIDs;
240 void Foam::thoboisValve::writeDict(Ostream& os) const
242     os  << nl << name() << nl << token::BEGIN_BLOCK;
244     cs().writeDict(os);
246     os  << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
247         << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
248         << "sidePatch " << sidePatch_.name() << token::END_STATEMENT << nl
249         << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
250         << "detachInCylinderPatch " << detachInCylinderPatch_.name()
251         << token::END_STATEMENT << nl
252         << "detachInPortPatch " << detachInPortPatch_.name()
253         << token::END_STATEMENT << nl
254         << "detachFaces " << detachFacesName_ << token::END_STATEMENT << nl
255         << "liftProfile " << nl << token::BEGIN_BLOCK
256         << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
257         << "minLift " << minLift_ << token::END_STATEMENT << nl
258         << "diameter " << diameter_ << token::END_STATEMENT << nl
259         << "staticCells " << staticCellsName_ << token::END_STATEMENT << nl
260         << "movingCells " << movingCellsName_ << token::END_STATEMENT << nl
261         << "staticPoints " << staticPointsName_ << token::END_STATEMENT << nl
262         << "movingPoints " << movingPointsName_ << token::END_STATEMENT << nl
263         << token::END_BLOCK << endl;
267 // ************************************************************************* //