engineTime.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2021-2026 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "engineTime.H"
27 #include "units.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace userTimes
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
45 :
47  omega_(dict(controlDict))
48 {
50  (
51  unitName(),
52  unitSet(dimTime, 0, 0, userTimeToTime(1))
53  );
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58 
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 (
67  const scalar theta
68 ) const
69 {
70  return theta/radToDeg(omega_.value());
71 }
72 
73 
74 Foam::scalar Foam::userTimes::engine::timeToUserTime(const scalar t) const
75 {
76  return t*radToDeg(omega_.value());
77 }
78 
79 
81 {
82  return "CAD";
83 }
84 
85 
87 {
88  return Foam::units::lookup(unitName());
89 }
90 
91 
93 {
94  omega_ = omega(dict(controlDict));
95  units::add(unitName(), unitSet(dimTime, 0, 0, userTimeToTime(1)));
96  return true;
97 }
98 
99 
100 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
Definition: unitSet.H:68
A userTime based on engine crank-angle degrees.
Definition: engineTime.H:54
virtual scalar timeToUserTime(const scalar t) const
Return the time t in crank-angle.
Definition: engineTime.C:74
virtual word unitName() const
Return engine-time unit name (CAD)
Definition: engineTime.C:80
virtual scalar userTimeToTime(const scalar theta) const
Return the theta crank-angle is s.
Definition: engineTime.C:66
virtual ~engine()
Destructor.
Definition: engineTime.C:59
virtual bool read(const dictionary &controlDict)
Read the controlDict and set all the parameters.
Definition: engineTime.C:92
virtual const unitSet & units() const
Return the engine-time unit conversion.
Definition: engineTime.C:86
engine(const dictionary &controlDict)
Construct from controlDict.
Definition: engineTime.C:44
A class for handling words, derived from string.
Definition: word.H:63
const scalar omega
void add(const word &name, const unitSet &unit)
Add a unit conversion.
Definition: units.C:331
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
addToRunTimeSelectionTable(userTime, engine, dictionary)
defineTypeNameAndDebug(engine, 0)
Namespace for OpenFOAM.
scalar radToDeg(const scalar rad)
Convert radians to degrees.
Definition: units.C:370
const dimensionSet & dimTime
Definition: dimensions.C:142
runTime controlDict().lookup("adjustTimeStep") >> adjustTimeStep
dictionary dict
Useful unit conversions.