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
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
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 (
127 coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_())
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
189
191{
192 return lift(engineDB_.theta()) >= minLift_;
193}
194
195
196Foam::scalar Foam::engineValve::curLift() const
197{
198 return max
199 (
200 lift(engineDB_.theta()),
201 minLift_
202 );
203}
204
205
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 }
236
237 mpIDs.setSize(nMpIDs);
238
239 return mpIDs;
240}
241
242
244{
245 os << nl << name() << nl << token::BEGIN_BLOCK;
246
247 if (csysPtr_)
248 {
249 csysPtr_->writeEntry(os);
250 }
251
252 os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
253 << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
254 << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
255 << "curtainInPortPatch " << curtainInPortPatch_.name()
257 << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
259 << "detachInCylinderPatch " << detachInCylinderPatch_.name()
261 << "detachInPortPatch " << detachInPortPatch_.name()
263 << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
264 << "liftProfile " << nl << token::BEGIN_BLOCK
265 << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
266 << "minLift " << minLift_ << token::END_STATEMENT << nl
267 << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
268 << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
269 << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
270 << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
271 << "diameter " << diameter_ << token::END_STATEMENT << nl
273}
274
275
276// ************************************************************************* //
void setSize(const label n)
Alias for resize()
Definition: List.H:218
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:107
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:63
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:126
An abstract class for the time description of the piston motion.
Definition: engineTime.H:57
Foam::engineValve.
Definition: engineValve.H:58
bool isOpen() const
Is the valve open?
Definition: engineValve.C:190
scalar lift(const scalar theta) const
Return valve lift given crank angle in degrees.
Definition: engineValve.C:179
labelList movingPatchIDs() const
Return list of active patch labels for the valve head.
Definition: engineValve.C:220
scalar curLift() const
Return current lift.
Definition: engineValve.C:196
scalar curVelocity() const
Return valve velocity for current time-step.
Definition: engineValve.C:206
Foam::dictionary writeDict() const
Write to dictionary.
Class to create, store and output qgraph files.
Definition: graph.H:62
A class for handling keywords in dictionaries.
Definition: keyType.H:71
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Lookup type of boundary radiation properties.
Definition: lookup.H:66
@ BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:159
@ END_BLOCK
End block [isseparator].
Definition: token.H:160
@ END_STATEMENT
End entry [isseparator].
Definition: token.H:154
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
Interpolates y values from one curve to another with a different x distribution.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:131
Field< Type > interpolateXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
Definition: interpolateXY.C:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict