A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
energy-source.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
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 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
18 *
19 * Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
20 * University of Rochester, Rochester, NY, USA.
21 *
22 * Modifications made by: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
23 */
24
25#ifndef ENERGY_SOURCE_H
26#define ENERGY_SOURCE_H
27
28#include "device-energy-model-container.h" // #include "device-energy-model.h"
29#include "energy-harvester.h"
30
31#include "ns3/node.h"
32#include "ns3/object.h"
33#include "ns3/ptr.h"
34#include "ns3/type-id.h"
35
36namespace ns3
37{
38namespace energy
39{
40
41class EnergyHarvester;
42
43/**
44 * \defgroup energy Energy Models
45 */
46
47/**
48 * \ingroup energy
49 * \ingroup tests
50 * \defgroup energy-tests Energy module tests
51 */
52
53/**
54 * \ingroup energy
55 *
56 * \brief Energy source base class.
57 *
58 * This is the base class for energy sources. Energy sources keep track of
59 * remaining energy. Device energy models will be updating the remaining energy
60 * in the energy source. The energy source itself does not update the remaining
61 * energy. Energy source also keeps a list of device energy models installed on
62 * the same node. When the remaining energy level reaches 0, the energy source
63 * will notify all device energy models stored in the list.
64 *
65 * EnergySource provides 2 types of interfaces for DeviceEnergyModels to update
66 * the remaining energy stored in EnergySource:
67 * -Direct energy update interface (Joules):
68 * DecreaseRemainingEnergy
69 * IncreaseRemainingEnergy
70 * -Indirect energy update interface (Current):
71 * UpdateEnergySource
72 * Direct energy update interface will decrease/increase energy from the source
73 * directly (in Joules). Direct energy update interface is typically used by
74 * simple DeviceEnergyModel which knows only average power consumption for each
75 * of its state.
76 * Indirect energy update interface uses the total current cumulated from all
77 * DeviceEnergyModel to calculate energy to decrease from the source. Indirect
78 * energy update interface is typically used by DeviceEnergyModel who knows its
79 * current draw for each of its states. Nonlinear EnergySource also uses this
80 * interface.
81 *
82 * Unit of energy is chosen as Joules since energy models typically calculate
83 * energy as (time in seconds * power in Watts). If the energy source stores
84 * energy in different units (eg. kWh), a simple converter function should
85 * suffice.
86 */
87class EnergySource : public Object
88{
89 public:
90 /**
91 * \brief Get the type ID.
92 * \return The object TypeId.
93 */
94 static TypeId GetTypeId();
96 ~EnergySource() override;
97
98 /**
99 * \returns Supply voltage of the energy source.
100 *
101 * Set method is to be defined in child class only if necessary. For sources
102 * with a fixed supply voltage, set method is not needed.
103 */
104 virtual double GetSupplyVoltage() const = 0;
105
106 /**
107 * \returns Initial energy (capacity) of the energy source.
108 *
109 * Set method is to be defined in child class only if necessary. For sources
110 * with a fixed initial energy (energy capacity), set method is not needed.
111 */
112 virtual double GetInitialEnergy() const = 0;
113
114 /**
115 * \returns Remaining energy at the energy source.
116 */
117 virtual double GetRemainingEnergy() = 0;
118
119 /**
120 * \return Energy fraction = remaining energy / initial energy [0, 1]
121 *
122 * This function returns the percentage of energy left in the energy source.
123 */
124 virtual double GetEnergyFraction() = 0;
125
126 /**
127 * This function goes through the list of DeviceEnergyModels to obtain total
128 * current draw at the energy source and updates remaining energy. Called by
129 * DeviceEnergyModels to inform EnergySource of a state change.
130 */
131 virtual void UpdateEnergySource() = 0;
132
133 /**
134 * \brief Sets pointer to node containing this EnergySource.
135 *
136 * \param node Pointer to node containing this EnergySource.
137 */
138 void SetNode(Ptr<Node> node);
139
140 /**
141 * \returns Pointer to node containing this EnergySource.
142 *
143 * When a subclass needs to get access to the underlying node base class to
144 * print the nodeId for example, it can invoke this method.
145 */
146 Ptr<Node> GetNode() const;
147
148 /**
149 * \param deviceEnergyModelPtr Pointer to device energy model.
150 *
151 * This function appends a device energy model to the end of a list of
152 * DeviceEnergyModelInfo structs.
153 */
154 void AppendDeviceEnergyModel(Ptr<DeviceEnergyModel> deviceEnergyModelPtr);
155
156 /**
157 * \param tid TypeId of the DeviceEnergyModel we are searching for.
158 * \returns List of pointers to DeviceEnergyModel objects installed on node.
159 */
161
162 /**
163 * \param name name of the DeviceEnergyModel we are searching for.
164 * \returns List of pointers to DeviceEnergyModel objects installed on node.
165 */
167
168 /**
169 * Calls Start () method of the device energy models. Device energy models are
170 * not aggregated to the node, therefore we need to manually start them here.
171 * Called by EnergySourceContainer, which is aggregated to the node.
172 */
174
175 /**
176 * Calls Dispose () method of the device energy models. Device energy models
177 * are not aggregated to the node, therefore we need to manually start them
178 * here. Called by EnergySourceContainer, which is aggregated to the node.
179 */
180 void DisposeDeviceModels();
181
182 /**
183 * \param energyHarvesterPtr Pointer to energy harvester.
184 *
185 * This function connect an energy harvester to the energy source. After the
186 * execution of this method, the pointer to the energy harvester is appended
187 * to the end of a vector of EnergyHarvester pointer.
188 * Note that the order in which different energy harvester are added to the
189 * energy source does not impact the simulation results.
190 */
191 void ConnectEnergyHarvester(Ptr<EnergyHarvester> energyHarvesterPtr);
192
193 private:
194 /**
195 * All child's implementation must call BreakDeviceEnergyModelRefCycle to
196 * ensure reference cycles to DeviceEnergyModel objects are broken.
197 *
198 * Defined in ns3::Object
199 */
200 void DoDispose() override;
201
202 private:
203 /**
204 * List of device energy models installed on the same node.
205 */
207
208 /**
209 * Pointer to node containing this EnergySource. Used by helper class to make
210 * sure device models are installed onto the corresponding node.
211 */
213
214 /**
215 * Vector of EnergyHarvester pointer connected to the same energy source.
216 * This vector is used by the CalculateTotalCurrent method to determine the
217 * total power provided by the energy harvesters connected to the energy source.
218 */
219 std::vector<Ptr<EnergyHarvester>> m_harvesters;
220
221 protected:
222 /**
223 * \returns Total current draw from all DeviceEnergyModels.
224 */
225 double CalculateTotalCurrent();
226
227 /**
228 * This function notifies all DeviceEnergyModel of energy depletion event. It
229 * is called by the child EnergySource class when energy depletion happens.
230 */
231 void NotifyEnergyDrained();
232
233 /**
234 * This function notifies all DeviceEnergyModel of energy recharged event. It
235 * is called by the child EnergySource class when energy source is recharged.
236 */
238
239 /**
240 * This function notifies all DeviceEnergyModel of energy changed event. It
241 * is called by the child EnergySource class when energy source is changed.
242 */
243 void NotifyEnergyChanged();
244
245 /**
246 * This function is called to break reference cycle between EnergySource and
247 * DeviceEnergyModel. Child of the EnergySource base class must call this
248 * function in their implementation of DoDispose to make sure the reference
249 * cycle is broken.
250 *
251 * Normally this work will be completed by the DoDispose function. However it
252 * will be overridden in the child class. Hence we introduced this function.
253 */
255};
256
257} // namespace energy
258} // namespace ns3
259
260#endif /* ENERGY_SOURCE_H */
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a unique identifier for an interface.
Definition: type-id.h:59
Holds a vector of ns3::DeviceEnergyModel pointers.
Energy source base class.
Definition: energy-source.h:88
void BreakDeviceEnergyModelRefCycle()
This function is called to break reference cycle between EnergySource and DeviceEnergyModel.
void NotifyEnergyDrained()
This function notifies all DeviceEnergyModel of energy depletion event.
DeviceEnergyModelContainer FindDeviceEnergyModels(TypeId tid)
virtual double GetEnergyFraction()=0
void ConnectEnergyHarvester(Ptr< EnergyHarvester > energyHarvesterPtr)
void InitializeDeviceModels()
Calls Start () method of the device energy models.
void NotifyEnergyRecharged()
This function notifies all DeviceEnergyModel of energy recharged event.
std::vector< Ptr< EnergyHarvester > > m_harvesters
Vector of EnergyHarvester pointer connected to the same energy source.
DeviceEnergyModelContainer m_models
List of device energy models installed on the same node.
virtual double GetRemainingEnergy()=0
static TypeId GetTypeId()
Get the type ID.
void DoDispose() override
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
Ptr< Node > m_node
Pointer to node containing this EnergySource.
virtual void UpdateEnergySource()=0
This function goes through the list of DeviceEnergyModels to obtain total current draw at the energy ...
void SetNode(Ptr< Node > node)
Sets pointer to node containing this EnergySource.
void NotifyEnergyChanged()
This function notifies all DeviceEnergyModel of energy changed event.
void AppendDeviceEnergyModel(Ptr< DeviceEnergyModel > deviceEnergyModelPtr)
virtual double GetSupplyVoltage() const =0
void DisposeDeviceModels()
Calls Dispose () method of the device energy models.
Ptr< Node > GetNode() const
virtual double GetInitialEnergy() const =0
Every class exported by the ns3 library is enclosed in the ns3 namespace.