1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2014 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Alessandro Tasora, Radu Serban
13 // =============================================================================
14 
15 #ifndef CHSHAFTHERMALENGINE_H
16 #define CHSHAFTHERMALENGINE_H
17 
18 #include "chrono/motion_functions/ChFunction.h"
19 #include "chrono/physics/ChShaftsTorqueBase.h"
20 
21 namespace chrono {
22 
23 /// Class for defining a thermal engine between two one-degree-of-freedom parts;
24 /// i.e., shafts that can be used to build 1D models of power trains.
25 /// The first shaft is the 'crankshaft' to whom the torque is applied, the second
26 /// is the motor block, that receives the negative torque.
27 
28 class ChApi ChShaftsThermalEngine : public ChShaftsTorqueBase {
29 
30   private:
31     std::shared_ptr<ChFunction> Tw;  ///< torque as function of angular vel.
32     double throttle;
33 
34     bool error_backward;
35 
36   public:
37     ChShaftsThermalEngine();
38     ChShaftsThermalEngine(const ChShaftsThermalEngine& other);
~ChShaftsThermalEngine()39     ~ChShaftsThermalEngine() {}
40 
41     /// "Virtual" copy constructor (covariant return type).
Clone()42     virtual ChShaftsThermalEngine* Clone() const override { return new ChShaftsThermalEngine(*this); }
43 
44     /// Set the torque curve T(w), function of angular speed between shaft1 and shaft2.
45     /// Output units: [Nm]  , input units: [rad/s]
SetTorqueCurve(std::shared_ptr<ChFunction> mf)46     void SetTorqueCurve(std::shared_ptr<ChFunction> mf) { Tw = mf; }
47     /// Get the torque curve T(w).
GetTorqueCurve()48     std::shared_ptr<ChFunction> GetTorqueCurve() { return Tw; }
49 
50     /// Set the current throttle value 's' in [0,1] range. If s=1,
51     /// the torque is exactly T=T(w), otherwise it is linearly
52     /// scaled as T=T(w)*s.
53     /// This is a simplified model of real torque modulation, but
54     /// enough for a basic model. An advanced approach would require a 2D map T(w,s)
SetThrottle(double mt)55     void SetThrottle(double mt) { throttle = mt; }
56     /// Get the current throttle value
GetThrottle()57     double GetThrottle() const { return throttle; }
58 
59     /// Tell if the engine is rotating backward.
60     /// If so, it's an erroneous situation
IsRotatingBackward()61     bool IsRotatingBackward() { return error_backward; }
62 
63     /// This is the function that actually contains the
64     /// formula for computing T=T(w,throttle)
65     virtual double ComputeTorque() override;
66 
67     /// Method to allow serialization of transient data to archives.
68     virtual void ArchiveOUT(ChArchiveOut& marchive) override;
69 
70     /// Method to allow deserialization of transient data from archives.
71     virtual void ArchiveIN(ChArchiveIn& marchive) override;
72 };
73 
74 CH_CLASS_VERSION(ChShaftsThermalEngine,0)
75 
76 }  // end namespace chrono
77 
78 #endif
79