fix consistancy of gradient on coupled patches
[OpenFOAM-1.6-ext.git] / src / engine / engineTime / engineTime.H
blob34fbe0feadd3d5f4e0c0423275783e9677ee2540
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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     //- Runtime type information
102     TypeName("engineTime");
104     // Constructors
106         //- Construct from objectRegistry arguments
107         engineTime
108         (
109             const word& name,
110             const fileName& rootPath,
111             const fileName& caseName,
112             const fileName& systemName = "system",
113             const fileName& constantName = "constant",
114             const fileName& dictName = "engineGeometry"
115         );
117     // Destructor
119         virtual ~engineTime()
120         {}
123     // Member Functions
125         // Conversion
127             //- Convert degrees to radians
128             scalar degToRad(const scalar rad) const;
130             //- Convert degrees to seconds (for given engine speed in RPM)
131             scalar degToTime(const scalar theta) const;
133             //- Convert seconds to degrees (for given engine speed in RPM)
134             scalar timeToDeg(const scalar t) const;
136             //- Calculate the piston position from the engine geometry
137             //  and given crank angle.
138             scalar pistonPosition(const scalar theta) const;
141         // Access
143             //- Return the engine geometry dictionary
144             const dictionary& engineDict() const
145             {
146                 return dict_;
147             }
149             //- Return the engines current operating RPM
150             const dimensionedScalar& rpm() const
151             {
152                 return rpm_;
153             }
155             //- Return the engines connecting-rod length
156             const dimensionedScalar& conRodLength() const
157             {
158                 return conRodLength_;
159             }
161             //- Return the engines bore
162             const dimensionedScalar& bore() const
163             {
164                 return bore_;
165             }
167             //- Return the engines stroke
168             const dimensionedScalar& stroke() const
169             {
170                 return stroke_;
171             }
173             //- Return the engines clearance-gap
174             const dimensionedScalar& clearance() const
175             {
176                 return clearance_;
177             }
180             //- Return current crank-angle
181             scalar theta() const;
183             //- Return current crank-angle translated to a single revolution
184             //  (value between -180 and 180 with 0 = top dead centre)
185             scalar thetaRevolution() const;
187             //- Return crank-angle increment
188             scalar deltaTheta() const;
190             //- Return current piston position
191             dimensionedScalar pistonPosition() const;
193             //- Return piston displacement for current time step
194             dimensionedScalar pistonDisplacement() const;
196             //- Return piston speed for current time step
197             dimensionedScalar pistonSpeed() const;
200         // Member functions overriding the virtual functions in time
202             //- Convert the user-time (CA deg) to real-time (s).
203             virtual scalar userTimeToTime(const scalar theta) const;
205             //- Convert the real-time (s) into user-time (CA deg)
206             virtual scalar timeToUserTime(const scalar t) const;
208             //- Read the control dictionary and set the write controls etc.
209             virtual void readDict();
212         // Edit
214             //- Read the controlDict and set all the parameters
215             virtual bool read();
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 } // End namespace Foam
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
225 #endif
227 // ************************************************************************* //