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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "engineValve.H"
29 #include "engineTime.H"
30 #include "polyMesh.H"
31 #include "interpolateXY.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 Foam::scalar Foam::engineValve::adjustCrankAngle(const scalar theta) const
36 {
37  if (theta < liftProfileStart_)
38  {
39  scalar adjustedTheta = theta;
40 
41  while (adjustedTheta < liftProfileStart_)
42  {
43  adjustedTheta += liftProfileEnd_ - liftProfileStart_;
44  }
45 
46  return adjustedTheta;
47  }
48  else if (theta > liftProfileEnd_)
49  {
50  scalar adjustedTheta = theta;
51 
52  while (adjustedTheta > liftProfileEnd_)
53  {
54  adjustedTheta -= liftProfileEnd_ - liftProfileStart_;
55  }
56 
57  return adjustedTheta;
58  }
59  else
60  {
61  return theta;
62  }
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
68 Foam::engineValve::engineValve
69 (
70  const word& name,
71  const polyMesh& mesh,
72  const autoPtr<coordinateSystem>& valveCS,
73  const word& bottomPatchName,
74  const word& poppetPatchName,
75  const word& stemPatchName,
76  const word& curtainInPortPatchName,
77  const word& curtainInCylinderPatchName,
78  const word& detachInCylinderPatchName,
79  const word& detachInPortPatchName,
80  const labelList& detachFaces,
81  const graph& liftProfile,
82  const scalar minLift,
83  const scalar minTopLayer,
84  const scalar maxTopLayer,
85  const scalar minBottomLayer,
86  const scalar maxBottomLayer,
87  const scalar diameter
88 )
89 :
90  name_(name),
91  mesh_(mesh),
92  engineDB_(refCast<const engineTime>(mesh.time())),
93  csysPtr_(valveCS.clone()),
94  bottomPatch_(bottomPatchName, mesh.boundaryMesh()),
95  poppetPatch_(poppetPatchName, mesh.boundaryMesh()),
96  stemPatch_(stemPatchName, mesh.boundaryMesh()),
97  curtainInPortPatch_(curtainInPortPatchName, mesh.boundaryMesh()),
98  curtainInCylinderPatch_(curtainInCylinderPatchName, mesh.boundaryMesh()),
99  detachInCylinderPatch_(detachInCylinderPatchName, mesh.boundaryMesh()),
100  detachInPortPatch_(detachInPortPatchName, mesh.boundaryMesh()),
101  detachFaces_(detachFaces),
102  liftProfile_(liftProfile),
103  liftProfileStart_(min(liftProfile_.x())),
104  liftProfileEnd_(max(liftProfile_.x())),
105  minLift_(minLift),
106  minTopLayer_(minTopLayer),
107  maxTopLayer_(maxTopLayer),
108  minBottomLayer_(minBottomLayer),
109  maxBottomLayer_(maxBottomLayer),
110  diameter_(diameter)
111 {}
112 
113 
114 Foam::engineValve::engineValve
115 (
116  const word& name,
117  const polyMesh& mesh,
118  const dictionary& dict
119 )
120 :
121  name_(name),
122  mesh_(mesh),
123  engineDB_(refCast<const engineTime>(mesh_.time())),
124  csysPtr_
125  (
126  coordinateSystem::New(mesh_, dict, coordinateSystem::typeName_())
127  ),
128  bottomPatch_(dict.lookup("bottomPatch"), mesh.boundaryMesh()),
129  poppetPatch_(dict.lookup("poppetPatch"), mesh.boundaryMesh()),
130  stemPatch_(dict.lookup("stemPatch"), mesh.boundaryMesh()),
131  curtainInPortPatch_
132  (
133  dict.lookup("curtainInPortPatch"),
135  ),
136  curtainInCylinderPatch_
137  (
138  dict.lookup("curtainInCylinderPatch"),
140  ),
141  detachInCylinderPatch_
142  (
143  dict.lookup("detachInCylinderPatch"),
145  ),
146  detachInPortPatch_
147  (
148  dict.lookup("detachInPortPatch"),
150  ),
151  detachFaces_(dict.lookup("detachFaces")),
152  liftProfile_("theta", "lift", name_, dict.lookup("liftProfile")),
153  liftProfileStart_(min(liftProfile_.x())),
154  liftProfileEnd_(max(liftProfile_.x())),
155  minLift_(dict.get<scalar>("minLift")),
156  minTopLayer_(dict.get<scalar>("minTopLayer")),
157  maxTopLayer_(dict.get<scalar>("maxTopLayer")),
158  minBottomLayer_(dict.get<scalar>("minBottomLayer")),
159  maxBottomLayer_(dict.get<scalar>("maxBottomLayer")),
160  diameter_(dict.get<scalar>("diameter"))
161 {}
162 
163 
164 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
165 
166 Foam::scalar Foam::engineValve::lift(const scalar theta) const
167 {
168  return interpolateXY
169  (
170  adjustCrankAngle(theta),
171  liftProfile_.x(),
172  liftProfile_.y()
173  );
174 }
175 
176 
178 {
179  return lift(engineDB_.theta()) >= minLift_;
180 }
181 
182 
183 Foam::scalar Foam::engineValve::curLift() const
184 {
185  return max
186  (
187  lift(engineDB_.theta()),
188  minLift_
189  );
190 }
191 
192 
193 Foam::scalar Foam::engineValve::curVelocity() const
194 {
195  return
196  -(
197  curLift()
198  - max
199  (
200  lift(engineDB_.theta() - engineDB_.deltaTheta()),
201  minLift_
202  )
203  )/(engineDB_.deltaTValue() + VSMALL);
204 }
205 
206 
208 {
209  labelList mpIDs(2);
210  label nMpIDs = 0;
211 
212  if (bottomPatch_.active())
213  {
214  mpIDs[nMpIDs] = bottomPatch_.index();
215  nMpIDs++;
216  }
217 
218  if (poppetPatch_.active())
219  {
220  mpIDs[nMpIDs] = poppetPatch_.index();
221  nMpIDs++;
222  }
223 
224  mpIDs.setSize(nMpIDs);
225 
226  return mpIDs;
227 }
228 
229 
231 {
232  os << nl << name() << nl << token::BEGIN_BLOCK;
233 
234  cs().writeEntry(coordinateSystem::typeName_(), os);
235 
236  os << "bottomPatch " << bottomPatch_.name() << token::END_STATEMENT << nl
237  << "poppetPatch " << poppetPatch_.name() << token::END_STATEMENT << nl
238  << "stemPatch " << stemPatch_.name() << token::END_STATEMENT << nl
239  << "curtainInPortPatch " << curtainInPortPatch_.name()
241  << "curtainInCylinderPatch " << curtainInCylinderPatch_.name()
243  << "detachInCylinderPatch " << detachInCylinderPatch_.name()
245  << "detachInPortPatch " << detachInPortPatch_.name()
247  << "detachFaces " << detachFaces_ << token::END_STATEMENT << nl
248  << "liftProfile " << nl << token::BEGIN_BLOCK
249  << liftProfile_ << token::END_BLOCK << token::END_STATEMENT << nl
250  << "minLift " << minLift_ << token::END_STATEMENT << nl
251  << "minTopLayer " << minTopLayer_ << token::END_STATEMENT << nl
252  << "maxTopLayer " << maxTopLayer_ << token::END_STATEMENT << nl
253  << "minBottomLayer " << minBottomLayer_ << token::END_STATEMENT << nl
254  << "maxBottomLayer " << maxBottomLayer_ << token::END_STATEMENT << nl
255  << "diameter " << diameter_ << token::END_STATEMENT << nl
256  << token::END_BLOCK << endl;
257 }
258 
259 
260 // ************************************************************************* //
Foam::engineValve::curVelocity
scalar curVelocity() const
Return valve velocity for current time-step.
Definition: engineValve.C:193
Foam::engineValve::curLift
scalar curLift() const
Return current lift.
Definition: engineValve.C:183
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:62
engineValve.H
Foam::engineValve::isOpen
bool isOpen() const
Is the valve open?
Definition: engineValve.C:177
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:435
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
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::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::coordinateSystem::New
static autoPtr< coordinateSystem > New(word modelType, const objectRegistry &obr, const dictionary &dict)
Definition: coordinateSystemNew.C:82
interpolateXY.H
Interpolates y values from one curve to another with a different x distribution.
Foam::IOstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: IOstream.C:39
Foam::token::END_STATEMENT
End entry [isseparator].
Definition: token.H:116
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:122
Foam::dictionary::lookup
ITstream & lookup(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:419
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:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::token::BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:121
Foam::engineValve::lift
scalar lift(const scalar theta) const
Return valve lift given crank angle in degrees.
Definition: engineValve.C:166
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:207
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::List< label >
engineTime.H
Foam::engineValve::writeDict
void writeDict(Ostream &os) const
Write dictionary.
Definition: engineValve.C:230
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::autoPtr::clone
autoPtr< T > clone(Args &&... args) const
Construct copy by invoking clone on underlying managed object.