Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / engine / accordionValve / accordionValve.C
blob8dd1795b421018296a273ec278fe3b0b652265a5
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 "accordionValve.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::accordionValve::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::accordionValve::accordionValve
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& staticCellsName,
84     const word& movingCellsName
87     name_(name),
88     mesh_(mesh),
89     engineDB_(refCast<const engineTime>(mesh.time())),
90     csPtr_(valveCS),
91     bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
92     poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
93     sidePatch_(sidePatchName, mesh.boundaryMesh()),
94     stemPatch_(stemPatchName, mesh.boundaryMesh()),
95     detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
96     detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
97     detachFacesName_(detachFacesName),
98     liftProfile_(liftProfile),
99     liftProfileStart_(min(liftProfile_.x())),
100     liftProfileEnd_(max(liftProfile_.x())),
101     minLift_(minLift),
102     diameter_(diameter),
103     staticCellsName_(staticCellsName),
104     movingCellsName_(movingCellsName)
108 // Construct from dictionary
109 Foam::accordionValve::accordionValve
111     const word& name,
112     const polyMesh& mesh,
113     const dictionary& dict
116     name_(name),
117     mesh_(mesh),
118     engineDB_(refCast<const engineTime>(mesh_.time())),
119     csPtr_
120     (
121         coordinateSystem::New
122         (
123             "coordinateSystem",
124             dict.subDict("coordinateSystem")
125         )
126     ),
127     bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
128     poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
129     sidePatch_(dict.lookup("sidePatch"), mesh.boundaryMesh()),
130     stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
131     detachInCylinderPatch_
132     (
133         dict.lookup("detachInCylinderPatch"),
134         mesh.boundaryMesh()
135     ),
136     detachInPortPatch_
137     (
138         dict.lookup("detachInPortPatch"),
139         mesh.boundaryMesh()
140     ),
141     detachFacesName_(dict.lookup("detachFaces")),
142     liftProfile_
143     (
144         "theta",
145         "lift",
146         name_,
147         IFstream
148         (
149             mesh.time().path()/mesh.time().caseConstant()/
150             word(dict.lookup("liftProfileFile"))
151         )()
152     ),
153     liftProfileStart_(min(liftProfile_.x())),
154     liftProfileEnd_(max(liftProfile_.x())),
155     minLift_(readScalar(dict.lookup("minLift"))),
156     diameter_(readScalar(dict.lookup("diameter"))),
157     staticCellsName_(dict.lookup("staticCells")),
158     movingCellsName_(dict.lookup("movingCells"))
162 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
165 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
167 Foam::scalar Foam::accordionValve::lift(const scalar theta) const
170     label curCycle = theta/720.0;
171     scalar curTheta = theta - curCycle * 720.0;
173     return interpolateXY
174     (
175         curTheta,
176         liftProfile_.x(),
177         liftProfile_.y()
178     );
182 bool Foam::accordionValve::isOpen() const
184     return lift(engineDB_.theta()) >= minLift_;
188 Foam::scalar Foam::accordionValve::curLift() const
190     return max
191     (
192         lift(engineDB_.theta()),
193         minLift_
194     );
198 Foam::scalar Foam::accordionValve::curVelocity() const
200     return
201        -(
202              curLift()
203            - max
204              (
205                  lift(engineDB_.theta() - engineDB_.deltaTheta()),
206                  minLift_
207              )
208         )/(engineDB_.deltaT().value() + VSMALL);
211 Foam::labelList Foam::accordionValve::movingPatchIDs() const
213     labelList mpIDs(3);
214     label nMpIDs = 0;
216     if (bottomPatch_.active())
217     {
218         mpIDs[nMpIDs] = bottomPatch_.index();
219         nMpIDs++;
220     }
222     if (poppetPatch_.active())
223     {
224         mpIDs[nMpIDs] = poppetPatch_.index();
225         nMpIDs++;
226     }
228     if (sidePatch_.active())
229     {
230         mpIDs[nMpIDs] = sidePatch_.index();
231         nMpIDs++;
232     }
234     mpIDs.setSize(nMpIDs);
236     return mpIDs;
240 void Foam::accordionValve::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         << token::END_BLOCK << endl;
264 // ************************************************************************* //