engineTime.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::engineTime
26 
27 Description
28  Manage time in terms of engine RPM and crank-angle.
29 
30  When engineTime is in effect, the userTime is reported in degrees
31  crank-angle instead of in seconds. The RPM to be used is specified in
32  \c constant/engineGeometry. If only a time conversion is required,
33  the geometric engine parameters can be dropped or set to zero.
34 
35  For example,
36  \verbatim
37  rpm rpm [0 0 -1 0 0] 2000;
38 
39  conRodLength conRodLength [0 1 0 0 0] 0.0;
40  bore bore [0 1 0 0 0] 0.0;
41  stroke stroke [0 1 0 0 0] 0.0;
42  clearance clearance [0 1 0 0 0] 0.0;
43  \endverbatim
44 
45 Note
46  The engineTime can currently only be selected at compile-time.
47 
48 SourceFiles
49  engineTime.C
50 
51 \*---------------------------------------------------------------------------*/
52 
53 #ifndef engineTime_H
54 #define engineTime_H
55 
56 #include "Time.H"
57 #include "dictionary.H"
58 #include "dimensionedScalar.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class engineTime Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class engineTime
70 :
71  public Time
72 {
73  // Private data
74 
75  IOdictionary dict_;
76 
77  //- RPM is required
78  dimensionedScalar rpm_;
79 
80  //- Optional engine geometry parameters
81  dimensionedScalar conRodLength_;
82  dimensionedScalar bore_;
83  dimensionedScalar stroke_;
84  dimensionedScalar clearance_;
85 
86 
87  // Private Member Functions
88 
89  //- Disallow default bitwise copy construct
90  engineTime(const engineTime&);
91 
92  //- Disallow default bitwise assignment
93  void operator=(const engineTime&);
94 
95  //- Adjust read time values
96  void timeAdjustment();
97 
98 public:
99 
100  // Constructors
101 
102  //- Construct from objectRegistry arguments
103  engineTime
104  (
105  const word& name,
106  const fileName& rootPath,
107  const fileName& caseName,
108  const fileName& systemName = "system",
109  const fileName& constantName = "constant",
110  const fileName& dictName = "engineGeometry"
111  );
112 
113  //- Destructor
114  virtual ~engineTime()
115  {}
116 
117 
118  // Member Functions
119 
120  // Conversion
121 
122  //- Convert degrees to seconds (for given engine speed in RPM)
123  scalar degToTime(const scalar theta) const;
124 
125  //- Convert seconds to degrees (for given engine speed in RPM)
126  scalar timeToDeg(const scalar t) const;
127 
128  //- Calculate the piston position from the engine geometry
129  // and given crank angle.
130  scalar pistonPosition(const scalar theta) const;
131 
132 
133  // Access
134 
135  //- Return the engine geometry dictionary
136  const IOdictionary& engineDict() const
137  {
138  return dict_;
139  }
140 
141  //- Return the engines current operating RPM
142  const dimensionedScalar& rpm() const
143  {
144  return rpm_;
145  }
146 
147  //- Return the engines connecting-rod length
148  const dimensionedScalar& conRodLength() const
149  {
150  return conRodLength_;
151  }
152 
153  //- Return the engines bore
154  const dimensionedScalar& bore() const
155  {
156  return bore_;
157  }
158 
159  //- Return the engines stroke
160  const dimensionedScalar& stroke() const
161  {
162  return stroke_;
163  }
164 
165  //- Return the engines clearance-gap
166  const dimensionedScalar& clearance() const
167  {
168  return clearance_;
169  }
170 
171 
172  //- Return current crank-angle
173  scalar theta() const;
174 
175  //- Return current crank-angle translated to a single revolution
176  // (value between -180 and 180 with 0 = top dead centre)
177  scalar thetaRevolution() const;
178 
179  //- Return crank-angle increment
180  scalar deltaTheta() const;
181 
182  //- Return current piston position
184 
185  //- Return piston displacement for current time step
187 
188  //- Return piston speed for current time step
190 
191 
192  // Member functions overriding the virtual functions in time
193 
194  //- Convert the user-time (CA deg) to real-time (s).
195  virtual scalar userTimeToTime(const scalar theta) const;
196 
197  //- Convert the real-time (s) into user-time (CA deg)
198  virtual scalar timeToUserTime(const scalar t) const;
199 
200  //- Read the control dictionary and set the write controls etc.
201  virtual void readDict();
202 
203 
204  // Edit
205 
206  //- Read the controlDict and set all the parameters
207  virtual bool read();
208 };
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 } // End namespace Foam
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 #endif
218 
219 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:69
dimensionedScalar pistonDisplacement() const
Return piston displacement for current time step.
Definition: engineTime.C:201
const dimensionedScalar & conRodLength() const
Return the engines connecting-rod length.
Definition: engineTime.H:147
const dimensionedScalar & stroke() const
Return the engines stroke.
Definition: engineTime.H:159
const IOdictionary & engineDict() const
Return the engine geometry dictionary.
Definition: engineTime.H:135
scalar degToTime(const scalar theta) const
Convert degrees to seconds (for given engine speed in RPM)
Definition: engineTime.C:125
const dimensionedScalar & rpm() const
Return the engines current operating RPM.
Definition: engineTime.H:141
virtual bool read()
Read the controlDict and set all the parameters.
Definition: engineTime.C:111
virtual void readDict()
Read the control dictionary and set the write controls etc.
Definition: engineTime.C:103
scalar timeToDeg(const scalar t) const
Convert seconds to degrees (for given engine speed in RPM)
Definition: engineTime.C:132
Manage time in terms of engine RPM and crank-angle.
Definition: engineTime.H:68
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
dimensionedScalar pistonPosition() const
Return current piston position.
Definition: engineTime.C:190
const fileName & rootPath() const
Return root path.
Definition: Time.H:257
const word & name() const
Return const reference to name.
dimensionedScalar pistonSpeed() const
Return piston speed for current time step.
Definition: engineTime.C:212
virtual ~engineTime()
Destructor.
Definition: engineTime.H:113
const dimensionedScalar & bore() const
Return the engines bore.
Definition: engineTime.H:153
A class for handling words, derived from string.
Definition: word.H:59
virtual scalar timeToUserTime(const scalar t) const
Convert the real-time (s) into user-time (CA deg)
Definition: engineTime.C:229
const dimensionedScalar & clearance() const
Return the engines clearance-gap.
Definition: engineTime.H:165
scalar thetaRevolution() const
Return current crank-angle translated to a single revolution.
Definition: engineTime.C:147
scalar theta() const
Return current crank-angle.
Definition: engineTime.C:139
word dictName("noiseDict")
virtual scalar userTimeToTime(const scalar theta) const
Convert the user-time (CA deg) to real-time (s).
Definition: engineTime.C:223
scalar deltaTheta() const
Return crank-angle increment.
Definition: engineTime.C:165
Namespace for OpenFOAM.
const fileName & caseName() const
Return case name.
Definition: Time.H:263