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