21 #include "li-ion-energy-source.h"
23 #include "ns3/assert.h"
24 #include "ns3/double.h"
25 #include "ns3/trace-source-accessor.h"
26 #include "ns3/simulator.h"
34 NS_OBJECT_ENSURE_REGISTERED (LiIonEnergySource);
37 LiIonEnergySource::GetTypeId (
void)
39 static TypeId tid = TypeId (
"ns3::LiIonEnergySource")
40 .SetParent<EnergySource> ()
41 .AddConstructor<LiIonEnergySource> ()
42 .AddAttribute (
"LiIonEnergySourceInitialEnergyJ",
43 "Initial energy stored in basic energy source.",
44 DoubleValue (31752.0),
47 MakeDoubleChecker<double> ())
48 .AddAttribute (
"InitialCellVoltage",
49 "Initial (maximum) voltage of the cell (fully charged).",
53 MakeDoubleChecker<double> ())
54 .AddAttribute (
"NominalCellVoltage",
55 "Nominal voltage of the cell.",
57 MakeDoubleAccessor (&LiIonEnergySource::m_eNom),
58 MakeDoubleChecker<double> ())
59 .AddAttribute (
"ExpCellVoltage",
60 "Cell voltage at the end of the exponential zone.",
62 MakeDoubleAccessor (&LiIonEnergySource::m_eExp),
63 MakeDoubleChecker<double> ())
64 .AddAttribute (
"RatedCapacity",
65 "Rated capacity of the cell.",
67 MakeDoubleAccessor (&LiIonEnergySource::m_qRated),
68 MakeDoubleChecker<double> ())
69 .AddAttribute (
"NomCapacity",
70 "Cell capacity at the end of the nominal zone.",
72 MakeDoubleAccessor (&LiIonEnergySource::m_qNom),
73 MakeDoubleChecker<double> ())
74 .AddAttribute (
"ExpCapacity",
75 "Cell Capacity at the end of the exponential zone.",
77 MakeDoubleAccessor (&LiIonEnergySource::m_qExp),
78 MakeDoubleChecker<double> ())
79 .AddAttribute (
"InternalResistance",
80 "Internal resistance of the cell",
82 MakeDoubleAccessor (&LiIonEnergySource::m_internalResistance),
83 MakeDoubleChecker<double> ())
84 .AddAttribute (
"TypCurrent",
85 "Typical discharge current used to fit the curves",
87 MakeDoubleAccessor (&LiIonEnergySource::m_typCurrent),
88 MakeDoubleChecker<double> ())
89 .AddAttribute (
"ThresholdVoltage",
90 "Minimum threshold voltage to consider the battery depleted.",
92 MakeDoubleAccessor (&LiIonEnergySource::m_minVoltTh),
93 MakeDoubleChecker<double> ())
94 .AddAttribute (
"PeriodicEnergyUpdateInterval",
95 "Time between two consecutive periodic energy updates.",
100 .AddTraceSource (
"RemainingEnergy",
101 "Remaining energy at BasicEnergySource.",
107 LiIonEnergySource::LiIonEnergySource ()
108 : m_drainedCapacity (0.0),
109 m_lastUpdateTime (
Seconds (0.0))
114 LiIonEnergySource::~LiIonEnergySource ()
124 m_initialEnergyJ = initialEnergyJ;
126 m_remainingEnergyJ = m_initialEnergyJ;
133 return m_initialEnergyJ;
140 m_eFull = supplyVoltageV;
141 m_supplyVoltageV = supplyVoltageV;
148 return m_supplyVoltageV;
155 m_energyUpdateInterval = interval;
162 return m_energyUpdateInterval;
171 return m_remainingEnergyJ;
180 return m_remainingEnergyJ / m_initialEnergyJ;
188 m_remainingEnergyJ -= energyJ;
191 if (m_supplyVoltageV <= m_minVoltTh)
202 m_remainingEnergyJ += energyJ;
209 NS_LOG_DEBUG (
"LiIonEnergySource:Updating remaining energy at node #" <<
218 m_energyUpdateEvent.
Cancel ();
222 if (m_remainingEnergyJ <= 0)
259 NS_LOG_DEBUG (
"LiIonEnergySource:Energy depleted at node #" <<
262 m_remainingEnergyJ = 0;
274 double energyToDecreaseJ = totalCurrentA * m_supplyVoltageV * duration.
GetSeconds ();
275 m_remainingEnergyJ -= energyToDecreaseJ;
276 m_drainedCapacity += (totalCurrentA * duration.
GetSeconds () / 3600);
278 m_supplyVoltageV =
GetVoltage (totalCurrentA);
279 NS_LOG_DEBUG (
"LiIonEnergySource:Remaining energy = " << m_remainingEnergyJ);
288 double it = m_drainedCapacity;
291 double A = m_eFull - m_eExp;
292 double B = 3 / m_qExp;
295 double K = std::abs ( (m_eFull - m_eNom + A * (std::exp (-B * m_qNom) - 1)) * (m_qRated - m_qNom) / m_qNom);
298 double E0 = m_eFull + K + m_internalResistance * m_typCurrent - A;
300 double E = E0 - K * m_qRated / (m_qRated - it) + A * std::exp (-B * it);
303 double V = E - m_internalResistance * i;
#define NS_LOG_FUNCTION(parameters)
void SetEnergyUpdateInterval(Time interval)
virtual double GetEnergyFraction(void)
Ptr< Node > GetNode(void) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
virtual void UpdateEnergySource(void)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual double GetInitialEnergy(void) const
double GetVoltage(double current) const
void CalculateRemainingEnergy(void)
virtual double GetRemainingEnergy(void)
void BreakDeviceEnergyModelRefCycle(void)
double GetSeconds(void) const
void SetInitialSupplyVoltage(double supplyVoltageV)
void HandleEnergyDrainedEvent(void)
double CalculateTotalCurrent(void)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
void NotifyEnergyDrained(void)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Time GetEnergyUpdateInterval(void) const
#define NS_LOG_DEBUG(msg)
virtual double GetSupplyVoltage(void) const
virtual void DecreaseRemainingEnergy(double energyJ)
virtual void IncreaseRemainingEnergy(double energyJ)
void SetInitialEnergy(double initialEnergyJ)
static bool IsFinished(void)