FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/Time.H>
57 #include <OpenFOAM/dictionary.H>
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class engineTime Declaration
67 \*---------------------------------------------------------------------------*/
68 
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 
115  virtual ~engineTime()
116  {}
117 
118 
119  // Member Functions
120 
121  // Conversion
122 
123  //- Convert degrees to radians
124  scalar degToRad(const scalar rad) const;
125 
126  //- Convert degrees to seconds (for given engine speed in RPM)
127  scalar degToTime(const scalar theta) const;
128 
129  //- Convert seconds to degrees (for given engine speed in RPM)
130  scalar timeToDeg(const scalar t) const;
131 
132  //- Calculate the piston position from the engine geometry
133  // and given crank angle.
134  scalar pistonPosition(const scalar theta) const;
135 
136 
137  // Access
138 
139  //- Return the engine geometry dictionary
140  const dictionary& engineDict() const
141  {
142  return dict_;
143  }
144 
145  //- Return the engines current operating RPM
146  const dimensionedScalar& rpm() const
147  {
148  return rpm_;
149  }
150 
151  //- Return the engines connecting-rod length
153  {
154  return conRodLength_;
155  }
156 
157  //- Return the engines bore
158  const dimensionedScalar& bore() const
159  {
160  return bore_;
161  }
162 
163  //- Return the engines stroke
164  const dimensionedScalar& stroke() const
165  {
166  return stroke_;
167  }
168 
169  //- Return the engines clearance-gap
171  {
172  return clearance_;
173  }
174 
175 
176  //- Return current crank-angle
177  scalar theta() const;
178 
179  //- Return current crank-angle translated to a single revolution
180  // (value between -180 and 180 with 0 = top dead centre)
181  scalar thetaRevolution() const;
182 
183  //- Return crank-angle increment
184  scalar deltaTheta() const;
185 
186  //- Return current piston position
188 
189  //- Return piston displacement for current time step
191 
192  //- Return piston speed for current time step
194 
195 
196  // Member functions overriding the virtual functions in time
197 
198  //- Convert the user-time (CA deg) to real-time (s).
199  virtual scalar userTimeToTime(const scalar theta) const;
200 
201  //- Convert the real-time (s) into user-time (CA deg)
202  virtual scalar timeToUserTime(const scalar t) const;
203 
204  //- Read the control dictionary and set the write controls etc.
205  virtual void readDict();
206 
207 
208  // Edit
209 
210  //- Read the controlDict and set all the parameters
211  virtual bool read();
212 };
213 
214 
215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216 
217 } // End namespace Foam
218 
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220 
221 #endif
222 
223 // ************************ vim: set sw=4 sts=4 et: ************************ //