A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
li-ion-energy-source.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Andrea Sacco
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Andrea Sacco <andrea.sacco85@gmail.com>
18 */
19
20#ifndef LI_ION_ENERGY_SOURCE_H
21#define LI_ION_ENERGY_SOURCE_H
22
23#include "energy-source.h"
24
25#include "ns3/deprecated.h"
26#include "ns3/event-id.h"
27#include "ns3/nstime.h"
28#include "ns3/traced-value.h"
29
30namespace ns3
31{
32namespace energy
33{
34
35/**
36 * \ingroup energy
37 * \brief Model a generic Lithium Ion Battery basing on [1][2].
38 *
39 * \deprecated The LiIonEnergySource was deprecated in ns-3.40 in favor of GenericBatteryModel, and
40 * will be removed in a future release.
41 *
42 * The model can be fitted to any type of Li-Ion Battery, simply changing the
43 * model parameters.
44 * The default values are fitted for the Panasonic CGR18650DA Li-Ion Battery [3].
45 *
46 * The energy is drained as defined from the EnergySource interface but, this class
47 * consider the non-linear behaviour of Li-Ion cell. Each time energy is drained from
48 * the cell, the class evaluates the discharge curve to get the actual cell's voltage,
49 * accordingly to State of Charge (SOC) and current's drain.
50 *
51 * If the actual voltage of the cell goes below the minimum threshold voltage, the
52 * cell is considered depleted and the energy drained event fired up.
53 *
54 *
55 * The model requires several parameters to approximates the discharge curves:
56 * - InitialCellVoltage, maximum voltage of the fully charged cell
57 * - NominalCellVoltage, nominal cell's voltage, is used to determine the end of the
58 * nominal zone.
59 * - ExpCellVoltage, cell's voltage at the end of the exponential zone
60 * - RatedCapacity, rated capacity of the cell, in Ah
61 * - NomCapacity, cell's capacity at the end of the nominal zone, in Ah
62 * - ExpCapacity, cell's capacity at the end of the exponential zone, in Ah
63 * - InternalResistance, internal resistance of the cell, in Ohms
64 * - TypCurrent, typical discharge current value, used during the fitting process, in Ah
65 * - ThresholdVoltage, minimum threshold voltage below which the cell is considered
66 * depleted
67 *
68 * For a complete reference of the energy source model and model's fitting please refer
69 * to <a href="http://www.nsnam.org/wiki/GSOC2010UANFramework">UAN Framework</a>
70 * page and <a href="http://www.nsnam.org/wiki/Li-Ion_model_fitting">Li-Ion model
71 * fitting</a> page.
72 *
73 * References:
74 * [1] C. M. Shepherd, "Design of Primary and Secondary Cells - Part 3. Battery discharge equation,"
75 * U.S. Naval Research Laboratory, 1963 [2] Tremblay, O.; Dessaint, L.-A.; Dekkiche, A.-I., "A
76 * Generic Battery Model for the Dynamic Simulation of Hybrid Electric Vehicles," Ecole de
77 * Technologie Superieure, Universite du Quebec, 2007 [3]
78 * http://www.panasonic.com/industrial/includes/pdf/Panasonic_LiIon_CGR18650DA.pdf
79 *
80 */
82{
83 public:
84 /**
85 * \brief Get the type ID.
86 * \return The object TypeId.
87 */
88 static TypeId GetTypeId();
90 ~LiIonEnergySource() override;
91
92 /**
93 * \return Initial energy stored in energy source, in Joules.
94 *
95 * Implements GetInitialEnergy.
96 */
97 double GetInitialEnergy() const override;
98
99 /**
100 * \param initialEnergyJ Initial energy, in Joules
101 *
102 * Implements SetInitialEnergy. Note that initial energy is assumed to be set
103 * before simulation starts and is set only once per simulation.
104 */
105 void SetInitialEnergy(double initialEnergyJ);
106
107 /**
108 * \returns Supply voltage at the energy source.
109 *
110 * Implements GetSupplyVoltage.
111 */
112 double GetSupplyVoltage() const override;
113
114 /**
115 * \param supplyVoltageV Initial Supply voltage at the energy source, in Volts.
116 *
117 * Sets the initial supply voltage of the energy source.
118 * To be called only once.
119 */
120 void SetInitialSupplyVoltage(double supplyVoltageV);
121
122 /**
123 * \return Remaining energy in energy source, in Joules
124 *
125 * Implements GetRemainingEnergy.
126 */
127 double GetRemainingEnergy() override;
128
129 /**
130 * \returns Energy fraction.
131 *
132 * Implements GetEnergyFraction.
133 */
134 double GetEnergyFraction() override;
135
136 /**
137 * \param energyJ Amount of energy (in Joules) to decrease from energy source.
138 *
139 * Implements DecreaseRemainingEnergy.
140 */
141 NS_DEPRECATED_3_40("Use GenericBatteryModel instead")
142 virtual void DecreaseRemainingEnergy(double energyJ);
143
144 /**
145 * \param energyJ Amount of energy (in Joules) to increase from energy source.
146 *
147 * Implements IncreaseRemainingEnergy.
148 */
149 NS_DEPRECATED_3_40("Use GenericBatteryModel instead")
150 virtual void IncreaseRemainingEnergy(double energyJ);
151
152 /**
153 * Implements UpdateEnergySource.
154 */
155 void UpdateEnergySource() override;
156
157 /**
158 * \param interval Energy update interval.
159 *
160 * This function sets the interval between each energy update.
161 */
162 void SetEnergyUpdateInterval(Time interval);
163
164 /**
165 * \returns The interval between each energy update.
166 */
168
169 private:
170 void DoInitialize() override;
171 void DoDispose() override;
172
173 /**
174 * Handles the remaining energy going to zero event. This function notifies
175 * all the energy models aggregated to the node about the energy being
176 * depleted. Each energy model is then responsible for its own handler.
177 */
179
180 /**
181 * Calculates remaining energy. This function uses the total current from all
182 * device models to calculate the amount of energy to decrease. The energy to
183 * decrease is given by:
184 * energy to decrease = total current * supply voltage * time duration
185 * This function subtracts the calculated energy to decrease from remaining
186 * energy.
187 */
189
190 /**
191 * Get the cell voltage in function of the discharge current.
192 * It consider different discharge curves for different discharge currents
193 * and the remaining energy of the cell.
194 *
195 * \param current the actual discharge current value.
196 * \return the cell voltage
197 */
198 double GetVoltage(double current) const;
199
200 private:
201 double m_initialEnergyJ; //!< initial energy, in Joules
202 TracedValue<double> m_remainingEnergyJ; //!< remaining energy, in Joules
203 double m_drainedCapacity; //!< capacity drained from the cell, in Ah
204 double m_supplyVoltageV; //!< actual voltage of the cell
205 double m_lowBatteryTh; //!< low battery threshold, as a fraction of the initial energy
206 EventId m_energyUpdateEvent; //!< energy update event
207 Time m_lastUpdateTime; //!< last update time
208 Time m_energyUpdateInterval; //!< energy update interval
209 double m_eFull; //!< initial voltage of the cell, in Volts
210 double m_eNom; //!< nominal voltage of the cell, in Volts
211 double m_eExp; //!< cell voltage at the end of the exponential zone, in Volts
212 double m_internalResistance; //!< internal resistance of the cell, in Ohms
213 double m_qRated; //!< rated capacity of the cell, in Ah
214 double m_qNom; //!< cell capacity at the end of the nominal zone, in Ah
215 double m_qExp; //!< capacity value at the end of the exponential zone, in Ah
216 double m_typCurrent; //!< typical discharge current used to fit the curves
217 double m_minVoltTh; //!< minimum threshold voltage to consider the battery depleted
218};
219
220} // namespace energy
221} // namespace ns3
222
223#endif /* LI_ION_ENERGY_SOURCE_H */
An identifier for simulation events.
Definition: event-id.h:56
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
Energy source base class.
Definition: energy-source.h:88
Model a generic Lithium Ion Battery basing on [1][2].
void UpdateEnergySource() override
Implements UpdateEnergySource.
void SetInitialEnergy(double initialEnergyJ)
double m_minVoltTh
minimum threshold voltage to consider the battery depleted
double m_qNom
cell capacity at the end of the nominal zone, in Ah
EventId m_energyUpdateEvent
energy update event
double m_eNom
nominal voltage of the cell, in Volts
double m_qExp
capacity value at the end of the exponential zone, in Ah
double m_drainedCapacity
capacity drained from the cell, in Ah
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
void DoInitialize() override
Initialize() implementation.
virtual void IncreaseRemainingEnergy(double energyJ)
void SetEnergyUpdateInterval(Time interval)
double GetInitialEnergy() const override
void SetInitialSupplyVoltage(double supplyVoltageV)
virtual void DecreaseRemainingEnergy(double energyJ)
double GetVoltage(double current) const
Get the cell voltage in function of the discharge current.
double m_internalResistance
internal resistance of the cell, in Ohms
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
Time m_energyUpdateInterval
energy update interval
double m_typCurrent
typical discharge current used to fit the curves
void DoDispose() override
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
double m_supplyVoltageV
actual voltage of the cell
double GetSupplyVoltage() const override
static TypeId GetTypeId()
Get the type ID.
void CalculateRemainingEnergy()
Calculates remaining energy.
double m_qRated
rated capacity of the cell, in Ah
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
double m_eFull
initial voltage of the cell, in Volts
double m_eExp
cell voltage at the end of the exponential zone, in Volts
double m_initialEnergyJ
initial energy, in Joules
#define NS_DEPRECATED_3_40(msg)
Tag for things deprecated in version ns-3.40.
Definition: deprecated.h:116
Every class exported by the ns3 library is enclosed in the ns3 namespace.