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 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
36 Foam::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 
69 Foam::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 
115 Foam::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  (
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 
179 Foam::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 
196 Foam::scalar Foam::engineValve::curLift() const
197 {
198  return max
199  (
200  lift(engineDB_.theta()),
201  minLift_
202  );
203 }
204 
205 
206 Foam::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  }
236 
237  mpIDs.setSize(nMpIDs);
238 
239  return mpIDs;
240 }
241 
242 
244 {
245  os << nl << name() << nl << token::BEGIN_BLOCK;
246 
247  cs().writeEntry(coordinateSystem::typeName_(), os);
248 
249  os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
250  << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
251  << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
252  << "curtainInPortPatch " << curtainInPortPatch_.name()
254  << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
256  << "detachInCylinderPatch " << detachInCylinderPatch_.name()
258  << "detachInPortPatch " << detachInPortPatch_.name()
260  << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
261  << "liftProfile " << nl << token::BEGIN_BLOCK
262  << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
263  << "minLift " << minLift_ << token::END_STATEMENT << nl
264  << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
265  << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
266  << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
267  << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
268  << "diameter " << diameter_ << token::END_STATEMENT << nl
269  << token::END_BLOCK << endl;
270 }
271 
272 
273 // ************************************************************************* //
Foam::engineValve::curVelocity
scalar curVelocity() const
Return valve velocity for current time-step.
Definition: engineValve.C:206
Foam::engineValve::curLift
scalar curLift() const
Return current lift.
Definition: engineValve.C:196
Foam::graph
Class to create, store and output qgraph files.
Definition: graph.H:61
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::OFstream::name
virtual const fileName & name() const
Read/write access to the name of the stream.
Definition: OSstream.H:107
engineValve.H
Foam::engineValve::isOpen
bool isOpen() const
Is the valve open?
Definition: engineValve.C:190
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
polyMesh.H
Foam::interpolateXY
Field< Type > interpolateXY(const scalarField &xNew, const scalarField &xOld, const Field< Type > &yOld)
Definition: interpolateXY.C:40
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:68
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:84
interpolateXY.H
Interpolates y values from one curve to another with a different x distribution.
Foam::token::END_STATEMENT
End entry [isseparator].
Definition: token.H:154
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::token::END_BLOCK
End block [isseparator].
Definition: token.H:160
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:386
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::token::BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:159
Foam::engineValve::lift
scalar lift(const scalar theta) const
Return valve lift given crank angle in degrees.
Definition: engineValve.C:179
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::engineValve::movingPatchIDs
labelList movingPatchIDs() const
Return list of active patch labels for the valve head.
Definition: engineValve.C:220
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List< label >
engineTime.H
Foam::engineValve::writeDict
void writeDict(Ostream &os) const
Write dictionary.
Definition: engineValve.C:243
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::autoPtr::clone
autoPtr< T > clone(Args &&... args) const
Copy construct by invoking clone on underlying managed object.