Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / engine / engineTime / engineTime.H
blobdde37b39365bff4e532f72521002ec4fb488d8e6
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::engineTime
27 Description
28     Manage time in terms of engine RPM and crank-angle.
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.
35     For example,
36     @verbatim
37         rpm             rpm  [0 0 -1 0 0]  2000;
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
45 Note
46    The engineTime can currently only be selected at compile-time.
48 SourceFiles
49     engineTime.C
51 \*---------------------------------------------------------------------------*/
53 #ifndef engineTime_H
54 #define engineTime_H
56 #include "objectRegistry.H"
57 #include "foamTime.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 // ************************************************************************* //