initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / engine / engineTime / engineTime.H
blobf97701d2405c6084479e67f8b35b72f549777728
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::engineTime
28 Description
29     Manage time in terms of engine RPM and crank-angle.
31     When engineTime is in effect, the userTime is reported in degrees
32     crank-angle instead of in seconds. The RPM to be used is specified in
33     @c constant/engineGeometry. If only a time conversion is required,
34     the geometric engine parameters can be dropped or set to zero.
36     For example,
37     @verbatim
38         rpm             rpm  [0 0 -1 0 0]  2000;
40         conRodLength    conRodLength  [0 1 0 0 0] 0.0;
41         bore            bore          [0 1 0 0 0] 0.0;
42         stroke          stroke        [0 1 0 0 0] 0.0;
43         clearance       clearance     [0 1 0 0 0] 0.0;
44     @endverbatim
46 Note
47    The engineTime can currently only be selected at compile-time.
49 SourceFiles
50     engineTime.C
52 \*---------------------------------------------------------------------------*/
54 #ifndef engineTime_H
55 #define engineTime_H
57 #include "Time.H"
58 #include "dictionary.H"
59 #include "dimensionedScalar.H"
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 namespace Foam
66 /*---------------------------------------------------------------------------*\
67                         Class engineTime Declaration
68 \*---------------------------------------------------------------------------*/
70 class engineTime
72     public Time
74     // Private data
76         IOdictionary dict_;
78         //- RPM is required
79         dimensionedScalar rpm_;
81         //- Optional engine geometry parameters
82         dimensionedScalar conRodLength_;
83         dimensionedScalar bore_;
84         dimensionedScalar stroke_;
85         dimensionedScalar clearance_;
88     // Private Member Functions
90         //- Disallow default bitwise copy construct
91         engineTime(const engineTime&);
93         //- Disallow default bitwise assignment
94         void operator=(const engineTime&);
96         //- adjust read time values
97         void timeAdjustment();
99 public:
101     // Constructors
103         //- Construct from objectRegistry arguments
104         engineTime
105         (
106             const word& name,
107             const fileName& rootPath,
108             const fileName& caseName,
109             const fileName& systemName = "system",
110             const fileName& constantName = "constant",
111             const fileName& dictName = "engineGeometry"
112         );
114     // Destructor
116         virtual ~engineTime()
117         {}
120     // Member Functions
122         // Conversion
124             //- Convert degrees to radians
125             scalar degToRad(const scalar rad) const;
127             //- Convert degrees to seconds (for given engine speed in RPM)
128             scalar degToTime(const scalar theta) const;
130             //- Convert seconds to degrees (for given engine speed in RPM)
131             scalar timeToDeg(const scalar t) const;
133             //- Calculate the piston position from the engine geometry
134             //  and given crank angle.
135             scalar pistonPosition(const scalar theta) const;
138         // Access
140             //- Return the engine geometry dictionary
141             const dictionary& engineDict() const
142             {
143                 return dict_;
144             }
146             //- Return the engines current operating RPM
147             const dimensionedScalar& rpm() const
148             {
149                 return rpm_;
150             }
152             //- Return the engines connecting-rod length
153             const dimensionedScalar& conRodLength() const
154             {
155                 return conRodLength_;
156             }
158             //- Return the engines bore
159             const dimensionedScalar& bore() const
160             {
161                 return bore_;
162             }
164             //- Return the engines stroke
165             const dimensionedScalar& stroke() const
166             {
167                 return stroke_;
168             }
170             //- Return the engines clearance-gap
171             const dimensionedScalar& clearance() const
172             {
173                 return clearance_;
174             }
177             //- Return current crank-angle
178             scalar theta() const;
180             //- Return current crank-angle translated to a single revolution
181             //  (value between -180 and 180 with 0 = top dead centre)
182             scalar thetaRevolution() const;
184             //- Return crank-angle increment
185             scalar deltaTheta() const;
187             //- Return current piston position
188             dimensionedScalar pistonPosition() const;
190             //- Return piston displacement for current time step
191             dimensionedScalar pistonDisplacement() const;
193             //- Return piston speed for current time step
194             dimensionedScalar pistonSpeed() const;
197         // Member functions overriding the virtual functions in time
199             //- Convert the user-time (CA deg) to real-time (s).
200             virtual scalar userTimeToTime(const scalar theta) const;
202             //- Convert the real-time (s) into user-time (CA deg)
203             virtual scalar timeToUserTime(const scalar t) const;
205             //- Read the control dictionary and set the write controls etc.
206             virtual void readDict();
209         // Edit
211             //- Read the controlDict and set all the parameters
212             virtual bool read();
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 } // End namespace Foam
220 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
222 #endif
224 // ************************************************************************* //