1 /*---------------------------------------------------------------------------*\
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 -------------------------------------------------------------------------------
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/>.
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.
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;
46 The engineTime can currently only be selected at compile-time.
51 \*---------------------------------------------------------------------------*/
56 #include "objectRegistry.H"
58 #include "dictionary.H"
59 #include "dimensionedScalar.H"
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 /*---------------------------------------------------------------------------*\
67 Class engineTime Declaration
68 \*---------------------------------------------------------------------------*/
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();
101 //- Runtime type information
102 TypeName("engineTime");
106 //- Construct from objectRegistry arguments
110 const fileName& rootPath,
111 const fileName& caseName,
112 const fileName& systemName = "system",
113 const fileName& constantName = "constant",
114 const fileName& dictName = "engineGeometry"
119 virtual ~engineTime()
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;
143 //- Return the engine geometry dictionary
144 const dictionary& engineDict() const
149 //- Return the engines current operating RPM
150 const dimensionedScalar& rpm() const
155 //- Return the engines connecting-rod length
156 const dimensionedScalar& conRodLength() const
158 return conRodLength_;
161 //- Return the engines bore
162 const dimensionedScalar& bore() const
167 //- Return the engines stroke
168 const dimensionedScalar& stroke() const
173 //- Return the engines clearance-gap
174 const dimensionedScalar& clearance() const
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();
214 //- Read the controlDict and set all the parameters
219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
221 } // End namespace Foam
223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 // ************************************************************************* //