Loading...
Searching...
No Matches
engineValve.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2013 OpenFOAM Foundation
9 Copyright (C) 2020-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "engineValve.H"
30#include "engineTime.H"
31#include "polyMesh.H"
32#include "interpolateXY.H"
33
34// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35
36Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
37{
38 if (theta < liftProfileStart_)
39 {
40 scalar adjustedTheta = theta;
41
42 while (adjustedTheta < liftProfileStart_)
43 {
44 adjustedTheta += liftProfileEnd_ - liftProfileStart_;
45 }
46
47 return adjustedTheta;
48 }
49 else if (theta > liftProfileEnd_)
50 {
51 scalar adjustedTheta = theta;
52
53 while (adjustedTheta > liftProfileEnd_)
54 {
55 adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
56 }
57
58 return adjustedTheta;
59 }
60 else
61 {
62 return theta;
63 }
64}
65
66
67// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68
69Foam::engineValve::engineValve
70(
71 const word& name,
72 const polyMesh& mesh,
73 const autoPtr<coordinateSystem>& valveCS,
74 const word& bottomPatchName,
75 const word& poppetPatchName,
76 const word& stemPatchName,
77 const word& curtainInPortPatchName,
78 const word& curtainInCylinderPatchName,
79 const word& detachInCylinderPatchName,
80 const word& detachInPortPatchName,
81 const labelList& detachFaces,
82 const graph& liftProfile,
83 const scalar minLift,
84 const scalar minTopLayer,
85 const scalar maxTopLayer,
86 const scalar minBottomLayer,
87 const scalar maxBottomLayer,
88 const scalar diameter
89)
90:
91 name_(name),
92 mesh_(mesh),
93 engineDB_(refCast<const engineTime>(mesh.time())),
94 csysPtr_(valveCS.clone()),
95 bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
96 poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
97 stemPatch_(stemPatchName, mesh.boundaryMesh()),
98 curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
99 curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
100 detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
101 detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
102 detachFaces_(detachFaces),
103 liftProfile_(liftProfile),
104 liftProfileStart_(min(liftProfile_.x())),
105 liftProfileEnd_(max(liftProfile_.x())),
106 minLift_(minLift),
107 minTopLayer_(minTopLayer),
108 maxTopLayer_(maxTopLayer),
109 minBottomLayer_(minBottomLayer),
110 maxBottomLayer_(maxBottomLayer),
111 diameter_(diameter)
112{}
113
114
115Foam::engineValve::engineValve
116(
117 const word& name,
118 const polyMesh& mesh,
119 const dictionary& dict
120)
121:
122 name_(name),
123 mesh_(mesh),
124 engineDB_(refCast<const engineTime>(mesh_.time())),
125 csysPtr_
126 (
128 ),
129 bottomPatch_
130 (
131 dict.get<keyType>("bottomPatch"),
133 ),
134 poppetPatch_
135 (
136 dict.get<keyType>("poppetPatch"),
138 ),
139 stemPatch_
140 (
141 dict.get<keyType>("stemPatch"),
143 ),
144 curtainInPortPatch_
145 (
146 dict.get<keyType>("curtainInPortPatch"),
148 ),
149 curtainInCylinderPatch_
150 (
151 dict.get<keyType>("curtainInCylinderPatch"),
153 ),
154 detachInCylinderPatch_
155 (
156 dict.get<keyType>("detachInCylinderPatch"),
158 ),
159 detachInPortPatch_
160 (
161 dict.get<keyType>("detachInPortPatch"),
163 ),
164 detachFaces_(dict.get<labelList>("detachFaces")),
165 liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
166 liftProfileStart_(min(liftProfile_.x())),
167 liftProfileEnd_(max(liftProfile_.x())),
168 minLift_(dict.get<scalar>("minLift")),
169 minTopLayer_(dict.get<scalar>("minTopLayer")),
170 maxTopLayer_(dict.get<scalar>("maxTopLayer")),
171 minBottomLayer_(dict.get<scalar>("minBottomLayer")),
172 maxBottomLayer_(dict.get<scalar>("maxBottomLayer")),
173 diameter_(dict.get<scalar>("diameter"))
174{}
175
176
177// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
178
179Foam::scalar Foam::engineValve::lift(const scalar theta) const
180{
181 return interpolateXY
182 (
183 adjustCrankAngle(theta),
184 liftProfile_.x(),
185 liftProfile_.y()
186 );
187}
188
190bool Foam::engineValve::isOpen() const
191{
192 return lift(engineDB_.theta()) >= minLift_;
193}
194
195
196Foam::scalar Foam::engineValve::curLift() const
197{
198 return max
200 lift(engineDB_.theta()),
201 minLift_
202 );
203}
204
205
206Foam::scalar Foam::engineValve::curVelocity() const
207{
208 return
209 -(
210 curLift()
211 - max
212 (
213 lift(engineDB_.theta() - engineDB_.deltaTheta()),
214 minLift_
215 )
216 )/(engineDB_.deltaTValue() + VSMALL);
217}
218
219
221{
222 labelList mpIDs(2);
223 label nMpIDs = 0;
224
225 if (bottomPatch_.active())
226 {
227 mpIDs[nMpIDs] = bottomPatch_.index();
228 nMpIDs++;
229 }
230
231 if (poppetPatch_.active())
232 {
233 mpIDs[nMpIDs] = poppetPatch_.index();
234 nMpIDs++;
235 }
237 mpIDs.setSize(nMpIDs);
238
239 return mpIDs;
240}
241
242
244{
245 os << nl;
246 os.beginBlock(name());
247
248 if (csysPtr_)
249 {
250 csysPtr_->writeEntry(os);
251 }
252
253 os.writeEntry("bottomPatch", bottomPatch_.name());
254 os.writeEntry("poppetPatch", poppetPatch_.name());
255 os.writeEntry("stemPatch", stemPatch_.name());
256 os.writeEntry("curtainInPortPatch", curtainInPortPatch_.name());
257 os.writeEntry("curtainInCylinderPatch", curtainInCylinderPatch_.name());
258 os.writeEntry("detachInCylinderPatch", detachInCylinderPatch_.name());
259 os.writeEntry("detachInPortPatch", detachInPortPatch_.name());
260 os.writeEntry("detachFaces", detachFaces_);
261
262 os << "liftProfile" << nl << token::BEGIN_LIST
263 << liftProfile_ << token::END_LIST;
264 os.endEntry();
265
266 os.writeEntry("minLift", minLift_);
267 os.writeEntry("minTopLayer", minTopLayer_);
268 os.writeEntry("maxTopLayer", maxTopLayer_);
269 os.writeEntry("minBottomLayer", minBottomLayer_);
270 os.writeEntry("maxBottomLayer", maxBottomLayer_);
271 os.writeEntry("diameter", diameter_);
272
273 os.endBlock();
274}
275
276
277// ************************************************************************* //
void setSize(label n)
Alias for resize().
Definition List.H:536
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Base class for coordinate system specification, the default coordinate system type is cartesian .
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
An abstract class for the time description of the piston motion.
Definition engineTime.H:53
bool isOpen() const
Is the valve open?
scalar maxTopLayer() const
scalar minBottomLayer() const
scalar maxBottomLayer() const
scalar lift(const scalar theta) const
Return valve lift given crank angle in degrees.
scalar diameter() const
Return valve diameter.
const word & name() const
Return name.
labelList movingPatchIDs() const
Return list of active patch labels for the valve head.
scalar curLift() const
Return current lift.
const graph & liftProfile() const
Return lift profile.
scalar minTopLayer() const
const labelList & detachFaces() const
Return face labels of detach curtain.
scalar curVelocity() const
Return valve velocity for current time-step.
void writeDict(Ostream &os) const
Write dictionary.
Class to create, store and output qgraph files.
Definition graph.H:56
A class for handling keywords in dictionaries.
Definition keyType.H:69
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Lookup type of boundary radiation properties.
Definition lookup.H:60
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
auto & name
Interpolates y values from one curve to another with a different x distribution.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
List< label > labelList
A List of labels.
Definition List.H:62
Field< Type > interpolateXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict