Energy harvester model
This commit is contained in:
337
examples/energy/energy-model-with-harvesting-example.cc
Normal file
337
examples/energy/energy-model-with-harvesting-example.cc
Normal file
@@ -0,0 +1,337 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This example extends the energy model example by connecting a basic energy
|
||||
* harvester to the nodes.
|
||||
*
|
||||
* The example considers a simple communication link between a source and a
|
||||
* destination node, where the source node sends a packet to the destination
|
||||
* every 1 second. Each node is powered by a BasiEnergySource, which is recharged
|
||||
* by a BasicEnergyHarvester, and the WiFi radio consumes energy for the transmission/
|
||||
* reception of the packets.
|
||||
*
|
||||
* For the receiver node, the example prints the energy consumption of the WiFi radio,
|
||||
* the power harvested by the energy harvester and the residual energy in the
|
||||
* energy source.
|
||||
*
|
||||
* The nodes initial energy is set to 1.0 J, the transmission and reception entail a
|
||||
* current consumption of 0.0174 A and 0.0197 A, respectively (default values in
|
||||
* WifiRadioEnergyModel). The energy harvester provides an amount of power that varies
|
||||
* according to a random variable uniformly distributed in [0 0.1] W, and is updated
|
||||
* every 1 s. The energy source voltage is 3 V (default value in BasicEnergySource) and
|
||||
* the residual energy level is updated every 1 second (default value).
|
||||
*
|
||||
* The simulation start at time 0 and it is hard stopped at time 10 seconds. Given the
|
||||
* packet size and the distance between the nodes, each transmission lasts 0.0023s.
|
||||
* As a result, the destination node receives 10 messages.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ns3/core-module.h"
|
||||
#include "ns3/network-module.h"
|
||||
#include "ns3/mobility-module.h"
|
||||
#include "ns3/config-store-module.h"
|
||||
#include "ns3/wifi-module.h"
|
||||
#include "ns3/energy-module.h"
|
||||
#include "ns3/internet-module.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("EnergyWithHarvestingExample");
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
static inline std::string
|
||||
PrintReceivedPacket (Address& from)
|
||||
{
|
||||
InetSocketAddress iaddr = InetSocketAddress::ConvertFrom (from);
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "--\nReceived one packet! Socket: " << iaddr.GetIpv4 ()
|
||||
<< " port: " << iaddr.GetPort ()
|
||||
<< " at time = " << Simulator::Now ().GetSeconds ()
|
||||
<< "\n--";
|
||||
|
||||
return oss.str ();
|
||||
}
|
||||
|
||||
/**
|
||||
* \param socket Pointer to socket.
|
||||
*
|
||||
* Packet receiving sink.
|
||||
*/
|
||||
void
|
||||
ReceivePacket (Ptr<Socket> socket)
|
||||
{
|
||||
Ptr<Packet> packet;
|
||||
Address from;
|
||||
while ((packet = socket->RecvFrom (from)))
|
||||
{
|
||||
if (packet->GetSize () > 0)
|
||||
{
|
||||
NS_LOG_UNCOND (PrintReceivedPacket (from));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* \param socket Pointer to socket.
|
||||
* \param pktSize Packet size.
|
||||
* \param n Pointer to node.
|
||||
* \param pktCount Number of packets to generate.
|
||||
* \param pktInterval Packet sending interval.
|
||||
*
|
||||
* Traffic generator.
|
||||
*/
|
||||
static void
|
||||
GenerateTraffic (Ptr<Socket> socket, uint32_t pktSize, Ptr<Node> n,
|
||||
uint32_t pktCount, Time pktInterval)
|
||||
{
|
||||
if (pktCount > 0)
|
||||
{
|
||||
socket->Send (Create<Packet> (pktSize));
|
||||
Simulator::Schedule (pktInterval, &GenerateTraffic, socket, pktSize, n,
|
||||
pktCount - 1, pktInterval);
|
||||
}
|
||||
else
|
||||
{
|
||||
socket->Close ();
|
||||
}
|
||||
}
|
||||
|
||||
/// Trace function for remaining energy at node.
|
||||
void
|
||||
RemainingEnergy (double oldValue, double remainingEnergy)
|
||||
{
|
||||
std::cout << Simulator::Now ().GetSeconds ()
|
||||
<< "s Current remaining energy = " << remainingEnergy << "J" << std::endl;
|
||||
}
|
||||
|
||||
/// Trace function for total energy consumption at node.
|
||||
void
|
||||
TotalEnergy (double oldValue, double totalEnergy)
|
||||
{
|
||||
std::cout << Simulator::Now ().GetSeconds ()
|
||||
<< "s Total energy consumed by radio = " << totalEnergy << "J" << std::endl;
|
||||
}
|
||||
|
||||
/// Trace function for the power harvested by the energy harvester.
|
||||
void
|
||||
HarvestedPower (double oldValue, double harvestedPower)
|
||||
{
|
||||
std::cout << Simulator::Now ().GetSeconds ()
|
||||
<< "s Current harvested power = " << harvestedPower << " W" << std::endl;
|
||||
}
|
||||
|
||||
/// Trace function for the total energy harvested by the node.
|
||||
void
|
||||
TotalEnergyHarvested (double oldValue, double TotalEnergyHarvested)
|
||||
{
|
||||
std::cout << Simulator::Now ().GetSeconds ()
|
||||
<< "s Total energy harvested by harvester = "
|
||||
<< TotalEnergyHarvested << " J" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
/*
|
||||
LogComponentEnable ("EnergySource", LOG_LEVEL_DEBUG);
|
||||
LogComponentEnable ("BasicEnergySource", LOG_LEVEL_DEBUG);
|
||||
LogComponentEnable ("DeviceEnergyModel", LOG_LEVEL_DEBUG);
|
||||
LogComponentEnable ("WifiRadioEnergyModel", LOG_LEVEL_DEBUG);
|
||||
LogComponentEnable ("EnergyHarvester", LOG_LEVEL_DEBUG);
|
||||
LogComponentEnable ("BasicEnergyHarvester", LOG_LEVEL_DEBUG);
|
||||
*/
|
||||
|
||||
std::string phyMode ("DsssRate1Mbps");
|
||||
double Prss = -80; // dBm
|
||||
uint32_t PpacketSize = 200; // bytes
|
||||
bool verbose = false;
|
||||
|
||||
// simulation parameters
|
||||
uint32_t numPackets = 10000; // number of packets to send
|
||||
double interval = 1; // seconds
|
||||
double startTime = 0.0; // seconds
|
||||
double distanceToRx = 100.0; // meters
|
||||
/*
|
||||
* This is a magic number used to set the transmit power, based on other
|
||||
* configuration.
|
||||
*/
|
||||
double offset = 81;
|
||||
|
||||
// Energy Harvester variables
|
||||
double harvestingUpdateInterval = 1; // seconds
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.AddValue ("phyMode", "Wifi Phy mode", phyMode);
|
||||
cmd.AddValue ("Prss", "Intended primary RSS (dBm)", Prss);
|
||||
cmd.AddValue ("PpacketSize", "size of application packet sent", PpacketSize);
|
||||
cmd.AddValue ("numPackets", "Total number of packets to send", numPackets);
|
||||
cmd.AddValue ("startTime", "Simulation start time", startTime);
|
||||
cmd.AddValue ("distanceToRx", "X-Axis distance between nodes", distanceToRx);
|
||||
cmd.AddValue ("verbose", "Turn on all device log components", verbose);
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
// Convert to time object
|
||||
Time interPacketInterval = Seconds (interval);
|
||||
|
||||
// disable fragmentation for frames below 2200 bytes
|
||||
Config::SetDefault ("ns3::WifiRemoteStationManager::FragmentationThreshold",
|
||||
StringValue ("2200"));
|
||||
// turn off RTS/CTS for frames below 2200 bytes
|
||||
Config::SetDefault ("ns3::WifiRemoteStationManager::RtsCtsThreshold",
|
||||
StringValue ("2200"));
|
||||
// Fix non-unicast data rate to be the same as that of unicast
|
||||
Config::SetDefault ("ns3::WifiRemoteStationManager::NonUnicastMode",
|
||||
StringValue (phyMode));
|
||||
|
||||
NodeContainer c;
|
||||
c.Create (2); // create 2 nodes
|
||||
NodeContainer networkNodes;
|
||||
networkNodes.Add (c.Get (0));
|
||||
networkNodes.Add (c.Get (1));
|
||||
|
||||
// The below set of helpers will help us to put together the wifi NICs we want
|
||||
WifiHelper wifi;
|
||||
if (verbose)
|
||||
{
|
||||
wifi.EnableLogComponents ();
|
||||
}
|
||||
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
|
||||
|
||||
/** Wifi PHY **/
|
||||
/***************************************************************************/
|
||||
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
||||
wifiPhy.Set ("RxGain", DoubleValue (-10));
|
||||
wifiPhy.Set ("TxGain", DoubleValue (offset + Prss));
|
||||
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (0.0));
|
||||
/***************************************************************************/
|
||||
|
||||
/** wifi channel **/
|
||||
YansWifiChannelHelper wifiChannel;
|
||||
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
|
||||
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
|
||||
// create wifi channel
|
||||
Ptr<YansWifiChannel> wifiChannelPtr = wifiChannel.Create ();
|
||||
wifiPhy.SetChannel (wifiChannelPtr);
|
||||
|
||||
/** MAC layer **/
|
||||
// Add a non-QoS upper MAC, and disable rate control
|
||||
NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
|
||||
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager", "DataMode",
|
||||
StringValue (phyMode), "ControlMode",
|
||||
StringValue (phyMode));
|
||||
// Set it to ad-hoc mode
|
||||
wifiMac.SetType ("ns3::AdhocWifiMac");
|
||||
|
||||
/** install PHY + MAC **/
|
||||
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, networkNodes);
|
||||
|
||||
/** mobility **/
|
||||
MobilityHelper mobility;
|
||||
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
|
||||
positionAlloc->Add (Vector (0.0, 0.0, 0.0));
|
||||
positionAlloc->Add (Vector (2 * distanceToRx, 0.0, 0.0));
|
||||
mobility.SetPositionAllocator (positionAlloc);
|
||||
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
|
||||
mobility.Install (c);
|
||||
|
||||
/** Energy Model **/
|
||||
/***************************************************************************/
|
||||
/* energy source */
|
||||
BasicEnergySourceHelper basicSourceHelper;
|
||||
// configure energy source
|
||||
basicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (1.0));
|
||||
// install source
|
||||
EnergySourceContainer sources = basicSourceHelper.Install (c);
|
||||
/* device energy model */
|
||||
WifiRadioEnergyModelHelper radioEnergyHelper;
|
||||
// configure radio energy model
|
||||
radioEnergyHelper.Set ("TxCurrentA", DoubleValue (0.0174));
|
||||
radioEnergyHelper.Set ("RxCurrentA", DoubleValue (0.0197));
|
||||
// install device model
|
||||
DeviceEnergyModelContainer deviceModels = radioEnergyHelper.Install (devices, sources);
|
||||
|
||||
/* energy harvester */
|
||||
BasicEnergyHarvesterHelper basicHarvesterHelper;
|
||||
// configure energy harvester
|
||||
basicHarvesterHelper.Set ("PeriodicHarvestedPowerUpdateInterval", TimeValue (Seconds (harvestingUpdateInterval)));
|
||||
basicHarvesterHelper.Set ("HarvestablePower", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=0.1]"));
|
||||
// install harvester on all energy sources
|
||||
EnergyHarvesterContainer harvesters = basicHarvesterHelper.Install (sources);
|
||||
/***************************************************************************/
|
||||
|
||||
/** Internet stack **/
|
||||
InternetStackHelper internet;
|
||||
internet.Install (networkNodes);
|
||||
|
||||
Ipv4AddressHelper ipv4;
|
||||
NS_LOG_INFO ("Assign IP Addresses.");
|
||||
ipv4.SetBase ("10.1.1.0", "255.255.255.0");
|
||||
Ipv4InterfaceContainer i = ipv4.Assign (devices);
|
||||
|
||||
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");
|
||||
Ptr<Socket> recvSink = Socket::CreateSocket (networkNodes.Get (1), tid); // node 1, Destination
|
||||
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
|
||||
recvSink->Bind (local);
|
||||
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket));
|
||||
|
||||
Ptr<Socket> source = Socket::CreateSocket (networkNodes.Get (0), tid); // node 0, Source
|
||||
InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetBroadcast (), 80);
|
||||
source->SetAllowBroadcast (true);
|
||||
source->Connect (remote);
|
||||
|
||||
/** connect trace sources **/
|
||||
/***************************************************************************/
|
||||
// all traces are connected to node 1 (Destination)
|
||||
// energy source
|
||||
Ptr<BasicEnergySource> basicSourcePtr = DynamicCast<BasicEnergySource> (sources.Get (1));
|
||||
basicSourcePtr->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
|
||||
// device energy model
|
||||
Ptr<DeviceEnergyModel> basicRadioModelPtr =
|
||||
basicSourcePtr->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
|
||||
NS_ASSERT (basicRadioModelPtr != 0);
|
||||
basicRadioModelPtr->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
|
||||
// energy harvester
|
||||
Ptr<BasicEnergyHarvester> basicHarvesterPtr = DynamicCast<BasicEnergyHarvester> (harvesters.Get (1));
|
||||
basicHarvesterPtr->TraceConnectWithoutContext ("HarvestedPower", MakeCallback (&HarvestedPower));
|
||||
basicHarvesterPtr->TraceConnectWithoutContext ("TotalEnergyHarvested", MakeCallback (&TotalEnergyHarvested));
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
/** simulation setup **/
|
||||
// start traffic
|
||||
Simulator::Schedule (Seconds (startTime), &GenerateTraffic, source, PpacketSize,
|
||||
networkNodes.Get (0), numPackets, interPacketInterval);
|
||||
|
||||
Simulator::Stop (Seconds (10.0));
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3,3 +3,5 @@
|
||||
def build(bld):
|
||||
obj = bld.create_ns3_program('energy-model-example', ['core', 'mobility', 'wifi', 'energy', 'internet'])
|
||||
obj.source = 'energy-model-example.cc'
|
||||
obj = bld.create_ns3_program('energy-model-with-harvesting-example', ['core', 'mobility', 'wifi', 'energy', 'internet'])
|
||||
obj.source = 'energy-model-with-harvesting-example.cc'
|
||||
@@ -1,7 +1,7 @@
|
||||
Energy Framework
|
||||
----------------
|
||||
|
||||
Energy consumption is a key issue for wireless devices, and wireless network researchers often need to investigate the energy consumption at a node or in the overall network while running network simulations in ns-3. This requires ns-3 to support energy consumption modeling. Further, as concepts such as fuel cells and energy scavenging are becoming viable for low power wireless devices, incorporating the effect of these emerging technologies into simulations requires support for modeling diverse energy sources in ns-3. The ns-3 Energy Framework provides the basis for energy consumption and energy source modeling.
|
||||
Energy consumption is a key issue for wireless devices, and wireless network researchers often need to investigate the energy consumption at a node or in the overall network while running network simulations in ns-3. This requires ns-3 to support energy consumption modeling. Further, as concepts such as fuel cells and energy scavenging are becoming viable for low power wireless devices, incorporating the effect of these emerging technologies into simulations requires support for modeling diverse energy sources in ns-3. The ns-3 Energy Framework provides the basis for energy consumption, energy source and energy harvesting modeling.
|
||||
|
||||
|
||||
Model Description
|
||||
@@ -12,8 +12,8 @@ The source code for the Energy Framework is currently at: ``src/energy``.
|
||||
Design
|
||||
******
|
||||
|
||||
The ns-3 Energy Framework is composed of 2 parts: Energy Source and Device Energy Model.
|
||||
The framework will be implemented into the ``src/energy/models`` folder.
|
||||
The ns-3 Energy Framework is composed of 3 parts: Energy Source, Device Energy Model and Energy Harvester.
|
||||
The framework is implemented into the ``src/energy/models`` folder.
|
||||
|
||||
Energy Source
|
||||
#############
|
||||
@@ -25,21 +25,28 @@ In order to model a wide range of power supplies such as batteries, the Energy S
|
||||
* Rate Capacity Effect: Decrease of battery lifetime when the current draw is higher than the rated value of the battery.
|
||||
* Recovery Effect: Increase of battery lifetime when the battery is alternating between discharge and idle states.
|
||||
|
||||
In order to incorporate the Rate Capacity Effect, the Energy Source uses current draw from all devices on the same node to calculate energy consumption. The Energy Source polls all devices on the same node periodically to calculate the total current draw and hence the energy consumption. When a device changes state, its corresponding Device Energy Model will notify the Energy Source of this change and new total current draw will be calculated.
|
||||
In order to incorporate the Rate Capacity Effect, the Energy Source uses current draw from all the devices on the same node to calculate energy consumption. Moreover, multiple Energy Harvesters can be connected to the Energy Source in order to replenish its energy. The Energy Source periodically polls all the devices and energy harvesters on the same node to calculate the total current drain and hence the energy consumption. When a device changes state, its corresponding Device Energy Model will notify the Energy Source of this change and new total current draw will be calculated. Similarly, every Energy Harvester update triggers an update to the connected Energy Source.
|
||||
|
||||
The Energy Source base class keeps a list of devices (Device Energy Model objects) and energy harvesters (Energy Harvester objects) that are using the particular Energy Source as power supply. When energy is completely drained, the Energy Source will notify all devices on this list. Each device can then handle this event independently, based on the desired behavior that should be followed in case of power outage.
|
||||
|
||||
The Energy Source base class keeps a list of devices (Device Energy Model objects) using the particular Energy Source as power supply. When energy is completely drained, the Energy Source will notify all devices on this list. Each device can then handle this event independently, based on the desired behavior when power supply is drained.
|
||||
|
||||
Device Energy Model
|
||||
###################
|
||||
|
||||
The Device Energy Model is the energy consumption model of a device on node. It is designed to be a state based model where each device is assumed to have a number of states, and each state is associated with a power consumption value. Whenever the state of the device changes, the corresponding Device Energy Model will notify the Energy Source of the new current draw of the device. The Energy Source will then calculate the new total current draw and update the remaining energy.
|
||||
The Device Energy Model is the energy consumption model of a device installed on the node. It is designed to be a state based model where each device is assumed to have a number of states, and each state is associated with a power consumption value. Whenever the state of the device changes, the corresponding Device Energy Model will notify the Energy Source of the new current draw of the device. The Energy Source will then calculate the new total current draw and update the remaining energy.
|
||||
|
||||
The Device Energy Model can also be used for devices that do not have finite number of states. For example, in an electric vehicle, the current draw of the motor is determined by its speed. Since the vehicle's speed can take continuous values within a certain range, it is infeasible to define a set of discrete states of operation. However, by converting the speed value into current directly, the same set of Device Energy Model APIs can still be used.
|
||||
|
||||
Energy Harvester
|
||||
#############
|
||||
|
||||
The energy harvester represents the elements that harvest energy from the environment and recharge the Energy Source to which it is connected. The energy harvester includes the complete implementation of the actual energy harvesting device (e.g., a solar panel) and the environment (e.g., the solar radiation). This means that in implementing an energy harvester, the energy contribution of the environment and the additional energy requirements of the energy harvesting device such as the conversion efficiency and the internal power consumption of the device needs to be jointly modeled.
|
||||
|
||||
|
||||
Future Work
|
||||
***********
|
||||
|
||||
For Device Energy Models, we are planning to include support for other PHY layer models provided in ns-3 such as WiMAX. For Energy Sources, we are planning to included new types of Energy Sources such as energy scavenging.
|
||||
For Device Energy Models, we are planning to include support for other PHY layer models provided in ns-3 such as WiMAX, and to model the energy consumptions of other non communicating devices, like a generic sensor and a CPU. For Energy Sources, we are planning to included new types of Energy Sources such as Supercapacitor and NickelÐMetal Hydride (Ni-MH) battery. For the Energy Harvesters, we are planning to implement an energy harvester that recharges the energy sources according to the power levels defined in a user customizable dataset of real measurements.
|
||||
|
||||
References
|
||||
**********
|
||||
@@ -51,19 +58,21 @@ References
|
||||
(ASM), 2003.
|
||||
.. [4] D. N. Rakhmatov and S. B. Vrudhula. An analytical high-level battery model for use in energy
|
||||
management of portable electronic systems. In Proc. of IEEE/ACM International Conference on
|
||||
Computer Aided Design (ICCAD’01), pages 488–493, November 2001.
|
||||
Computer Aided Design (ICCAD'01), pages 488-493, November 2001.
|
||||
.. [5] D. N. Rakhmatov, S. B. Vrudhula, and D. A. Wallach. Battery lifetime prediction for
|
||||
energy-aware computing. In Proc. of the 2002 International Symposium on Low Power
|
||||
Electronics and Design (ISLPED’02), pages 154–159, 2002.
|
||||
Electronics and Design (ISLPED'02), pages 154-159, 2002.
|
||||
.. [6] C. Tapparello, H. Ayatollahi and W. Heinzelman. Extending the Energy Framework for Network
|
||||
Simulator 3 (ns-3). Workshop on ns-3 (WNS3), Poster Session, Atlanta, GA, USA. May, 2014.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
The main way that ns-3 users will typically interact with the Energy Framework is through the helper API and through the publicly visible attributes of the framework. The helper API is defined in ``src/energy/helper/*.h``.
|
||||
|
||||
In order to use the energy framework, the user must install an Energy Source for the node of interest and the corresponding Device Energy Model for the network devices. Energy Source (objects) are aggregated onto each node by the Energy Source Helper. In order to allow multiple energy sources per node, we aggregate an Energy Source Container rather than directly aggregating a source object.
|
||||
In order to use the energy framework, the user must install an Energy Source for the node of interest, the corresponding Device Energy Model for the network devices and, if necessary, the one or more Energy Harvester. Energy Source (objects) are aggregated onto each node by the Energy Source Helper. In order to allow multiple energy sources per node, we aggregate an Energy Source Container rather than directly aggregating a source object.
|
||||
|
||||
The Energy Source object also keeps a list of Device Energy Model objects using the source as power supply. Device Energy Model objects are installed onto the Energy Source by the Device Energy Model Helper. User can access the Device Energy Model objects through the Energy Source object to obtain energy consumption information of individual devices.
|
||||
The Energy Source object keeps a list of Device Energy Model and Energy Harvester objects using the source as power supply. Device Energy Model objects are installed onto the Energy Source by the Device Energy Model Helper, while Energy Harvester object are installed by the Energy Harvester Helper. User can access the Device Energy Model objects through the Energy Source object to obtain energy consumption information of individual devices. Moreover, the user can access to the Energy Harvester objects in order to gather information regarding the current harvestable power and the total energy harvested by the harvester.
|
||||
|
||||
|
||||
Examples
|
||||
@@ -86,10 +95,16 @@ Device Energy Model Helper
|
||||
|
||||
Base helper class for Device Energy Model objects, this helper attaches Device Energy Model objects onto Energy Source objects. Child implementation of this class creates the actual Device Energy Model object.
|
||||
|
||||
Energy Harvesting Helper
|
||||
##########################
|
||||
|
||||
Base helper class for Energy Harvester objects, this helper attaches Energy Harvester objects onto Energy Source objects. Child implementation of this class creates the actual Energy Harvester object.
|
||||
|
||||
|
||||
Attributes
|
||||
**********
|
||||
|
||||
Attributes differ between Energy Sources and Devices Energy Models implementations, please look at the specific child class for details.
|
||||
Attributes differ between Energy Sources, Devices Energy Models and Energy Harvesters implementations, please look at the specific child class for details.
|
||||
|
||||
Basic Energy Source
|
||||
###################
|
||||
@@ -117,10 +132,16 @@ WiFi Radio Energy Model
|
||||
* ``RxCurrentA``: The radio Rx current in Ampere.
|
||||
* ``SwitchingCurrentA``: The default radio Channel Switch current in Ampere.
|
||||
|
||||
Basic Energy Harvester
|
||||
#######################
|
||||
|
||||
* ``PeriodicHarvestedPowerUpdateInterval``: Time between two consecutive periodic updates of the harvested power.
|
||||
* ``HarvestablePower``: Random variables that represents the amount of power that is provided by the energy harvester.
|
||||
|
||||
Tracing
|
||||
*******
|
||||
|
||||
Traced values differ between Energy Sources and Devices Energy Models implementations, please look at the specific child class for details.
|
||||
Traced values differ between Energy Sources, Devices Energy Models and Energy Harvesters implementations, please look at the specific child class for details.
|
||||
|
||||
Basic Energy Source
|
||||
###################
|
||||
@@ -138,6 +159,13 @@ WiFi Radio Energy Model
|
||||
|
||||
* ``TotalEnergyConsumption``: Total energy consumption of the radio device.
|
||||
|
||||
Basic Energy Harvester
|
||||
#######################
|
||||
|
||||
* ``HarvestedPower``: Current power provided by the BasicEnergyHarvester.
|
||||
* ``TotalEnergyHarvested``: Total energy harvested by the BasicEnergyHarvester.
|
||||
|
||||
|
||||
Validation
|
||||
**********
|
||||
|
||||
|
||||
59
src/energy/helper/basic-energy-harvester-helper.cc
Normal file
59
src/energy/helper/basic-energy-harvester-helper.cc
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "basic-energy-harvester-helper.h"
|
||||
#include "ns3/energy-harvester.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
BasicEnergyHarvesterHelper::BasicEnergyHarvesterHelper ()
|
||||
{
|
||||
m_basicEnergyHarvester.SetTypeId ("ns3::BasicEnergyHarvester");
|
||||
}
|
||||
|
||||
BasicEnergyHarvesterHelper::~BasicEnergyHarvesterHelper ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
BasicEnergyHarvesterHelper::Set (std::string name, const AttributeValue &v)
|
||||
{
|
||||
m_basicEnergyHarvester.Set (name, v);
|
||||
}
|
||||
|
||||
Ptr<EnergyHarvester>
|
||||
BasicEnergyHarvesterHelper::DoInstall (Ptr<EnergySource> source) const
|
||||
{
|
||||
NS_ASSERT (source != 0);
|
||||
Ptr<Node> node = source->GetNode ();
|
||||
|
||||
// Create a new Basic Energy Harvester
|
||||
Ptr<EnergyHarvester> harvester = m_basicEnergyHarvester.Create<EnergyHarvester> ();
|
||||
NS_ASSERT (harvester != 0);
|
||||
|
||||
// Connect the Basic Energy Harvester to the Energy Source
|
||||
source->ConnectEnergyHarvester (harvester);
|
||||
harvester->SetNode (node);
|
||||
harvester->SetEnergySource (source);
|
||||
return harvester;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
53
src/energy/helper/basic-energy-harvester-helper.h
Normal file
53
src/energy/helper/basic-energy-harvester-helper.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#ifndef BASIC_ENERGY_HARVESTER_HELPER_H
|
||||
#define BASIC_ENERGY_HARVESTER_HELPER_H
|
||||
|
||||
#include "energy-harvester-helper.h"
|
||||
#include "ns3/energy-source.h"
|
||||
#include "ns3/node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup energy
|
||||
* \brief Creates a BasicEnergyHarvester object.
|
||||
*/
|
||||
class BasicEnergyHarvesterHelper : public EnergyHarvesterHelper
|
||||
{
|
||||
public:
|
||||
BasicEnergyHarvesterHelper ();
|
||||
~BasicEnergyHarvesterHelper ();
|
||||
|
||||
void Set (std::string name, const AttributeValue &v);
|
||||
|
||||
private:
|
||||
virtual Ptr<EnergyHarvester> DoInstall (Ptr<EnergySource> source) const;
|
||||
|
||||
private:
|
||||
ObjectFactory m_basicEnergyHarvester;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* defined(BASIC_ENERGY_HARVESTER_HELPER_H) */
|
||||
164
src/energy/helper/energy-harvester-container.cc
Normal file
164
src/energy/helper/energy-harvester-container.cc
Normal file
@@ -0,0 +1,164 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "energy-harvester-container.h"
|
||||
|
||||
#include "ns3/names.h"
|
||||
#include "ns3/log.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("EnergyHarvesterContainer");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
TypeId
|
||||
EnergyHarvesterContainer::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::EnergyHarvesterContainer")
|
||||
.SetParent<Object> ()
|
||||
.AddConstructor<EnergyHarvesterContainer> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::EnergyHarvesterContainer ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::~EnergyHarvesterContainer ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::EnergyHarvesterContainer (Ptr<EnergyHarvester> harvester)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << harvester);
|
||||
NS_ASSERT (harvester != 0);
|
||||
m_harvesters.push_back (harvester);
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::EnergyHarvesterContainer (std::string harvesterName)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << harvesterName);
|
||||
Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
|
||||
NS_ASSERT (harvester != 0);
|
||||
m_harvesters.push_back (harvester);
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::EnergyHarvesterContainer (const EnergyHarvesterContainer &a,
|
||||
const EnergyHarvesterContainer &b)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &a << &b);
|
||||
*this = a;
|
||||
Add (b);
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::Iterator
|
||||
EnergyHarvesterContainer::Begin (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_harvesters.begin ();
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer::Iterator
|
||||
EnergyHarvesterContainer::End (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_harvesters.end ();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
EnergyHarvesterContainer::GetN (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_harvesters.size ();
|
||||
}
|
||||
|
||||
Ptr<EnergyHarvester>
|
||||
EnergyHarvesterContainer::Get (uint32_t i) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this << i);
|
||||
return m_harvesters[i];
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvesterContainer::Add (EnergyHarvesterContainer container)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << &container);
|
||||
for (Iterator i = container.Begin (); i != container.End (); i++)
|
||||
{
|
||||
m_harvesters.push_back (*i);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvesterContainer::Add (Ptr<EnergyHarvester> harvester)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << harvester);
|
||||
NS_ASSERT (harvester != 0);
|
||||
m_harvesters.push_back (harvester);
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvesterContainer::Add (std::string harvesterName)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << harvesterName);
|
||||
Ptr<EnergyHarvester> harvester = Names::Find<EnergyHarvester> (harvesterName);
|
||||
NS_ASSERT (harvester != 0);
|
||||
m_harvesters.push_back (harvester);
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvesterContainer::Clear (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_harvesters.clear ();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Private functions start here.
|
||||
*/
|
||||
|
||||
void
|
||||
EnergyHarvesterContainer::DoDispose (void)
|
||||
{
|
||||
// call Object::Dispose for all EnergyHarvester objects
|
||||
for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
|
||||
i != m_harvesters.end (); i++)
|
||||
{
|
||||
(*i)->Dispose ();
|
||||
}
|
||||
m_harvesters.clear ();
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvesterContainer::DoInitialize (void)
|
||||
{
|
||||
// call Object::Initialize for all EnergyHarvester objects
|
||||
for (std::vector< Ptr<EnergyHarvester> >::iterator i = m_harvesters.begin ();
|
||||
i != m_harvesters.end (); i++)
|
||||
{
|
||||
(*i)->Initialize ();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
190
src/energy/helper/energy-harvester-container.h
Normal file
190
src/energy/helper/energy-harvester-container.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#ifndef ENERGY_HARVESTER_CONTAINER_H
|
||||
#define ENERGY_HARVESTER_CONTAINER_H
|
||||
|
||||
#include "ns3/energy-harvester.h"
|
||||
#include "ns3/object.h"
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class EnergyHarvester;
|
||||
|
||||
/**
|
||||
* \ingroup energy
|
||||
* \brief Holds a vector of ns3::EnergyHarvester pointers.
|
||||
*
|
||||
* EnergyHarvesterContainer returns a list of EnergyHarvester pointers
|
||||
* installed on a node. Users can use this list to access EnergyHarvester
|
||||
* objects to obtain the total energy harvested on a node easily.
|
||||
*
|
||||
* \see NetDeviceContainer
|
||||
*
|
||||
*/
|
||||
class EnergyHarvesterContainer : public Object
|
||||
{
|
||||
public:
|
||||
typedef std::vector< Ptr<EnergyHarvester> >::const_iterator Iterator;
|
||||
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
/**
|
||||
* Creates an empty EnergyHarvesterContainer.
|
||||
*/
|
||||
EnergyHarvesterContainer ();
|
||||
~EnergyHarvesterContainer ();
|
||||
|
||||
/**
|
||||
* \param harvester Pointer to an EnergyHarvester.
|
||||
*
|
||||
* Creates a EnergyHarvesterContainer with exactly one EnergyHarvester
|
||||
* previously instantiated.
|
||||
*/
|
||||
EnergyHarvesterContainer (Ptr<EnergyHarvester> harvester);
|
||||
|
||||
/**
|
||||
* \param harvesterName Name of EnergyHarvester.
|
||||
*
|
||||
* Creates an EnergyHarvesterContainer with exactly one EnergyHarvester
|
||||
* previously instantiated and assigned a name using the Object name service.
|
||||
* This EnergyHarvester is specified by its assigned name.
|
||||
*/
|
||||
EnergyHarvesterContainer (std::string harvesterName);
|
||||
|
||||
/**
|
||||
* \param a A EnergyHarvesterContainer.
|
||||
* \param b Another EnergyHarvesterContainer.
|
||||
*
|
||||
* Creates a EnergyHarvesterContainer by concatenating EnergyHarvesterContainer b
|
||||
* to EnergyHarvesterContainer a.
|
||||
*
|
||||
* \note Can be used to concatenate 2 Ptr<EnergyHarvester> directly. C++
|
||||
* will be calling EnergyHarvesterContainer constructor with Ptr<EnergyHarvester>
|
||||
* first.
|
||||
*/
|
||||
EnergyHarvesterContainer (const EnergyHarvesterContainer &a,
|
||||
const EnergyHarvesterContainer &b);
|
||||
|
||||
/**
|
||||
* \brief Get an iterator which refers to the first EnergyHarvester pointer
|
||||
* in the container.
|
||||
*
|
||||
* \returns An iterator which refers to the first EnergyHarvester in container.
|
||||
*
|
||||
* EnergyHarvesters can be retrieved from the container in two ways. First,
|
||||
* directly by an index into the container, and second, using an iterator.
|
||||
* This method is used in the iterator method and is typically used in a
|
||||
* for-loop to run through the EnergyHarvesters.
|
||||
*
|
||||
* \code
|
||||
* EnergyHarvesterContainer::Iterator i;
|
||||
* for (i = container.Begin (); i != container.End (); ++i)
|
||||
* {
|
||||
* (*i)->method (); // some EnergyHarvester method
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
Iterator Begin (void) const;
|
||||
|
||||
/**
|
||||
* \brief Get an iterator which refers to the last EnergyHarvester pointer
|
||||
* in the container.
|
||||
*
|
||||
* \returns An iterator which refers to the last EnergyHarvester in container.
|
||||
*
|
||||
* EnergyHarvesters can be retrieved from the container in two ways. First,
|
||||
* directly by an index into the container, and second, using an iterator.
|
||||
* This method is used in the iterator method and is typically used in a
|
||||
* for-loop to run through the EnergyHarvesters.
|
||||
*
|
||||
* \code
|
||||
* EnergyHarvesterContainer::Iterator i;
|
||||
* for (i = container.Begin (); i != container.End (); ++i)
|
||||
* {
|
||||
* (*i)->method (); // some EnergyHarvester method
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
Iterator End (void) const;
|
||||
|
||||
/**
|
||||
* \brief Get the number of Ptr<EnergyHarvester> stored in this container.
|
||||
*
|
||||
* \returns The number of Ptr<EnergyHarvester> stored in this container.
|
||||
*/
|
||||
uint32_t GetN (void) const;
|
||||
|
||||
/**
|
||||
* \brief Get the i-th Ptr<EnergyHarvester> stored in this container.
|
||||
*
|
||||
* \param i Index of the requested Ptr<EnergyHarvester>.
|
||||
* \returns The requested Ptr<EnergyHarvester>.
|
||||
*/
|
||||
Ptr<EnergyHarvester> Get (uint32_t i) const;
|
||||
|
||||
/**
|
||||
* \param container Another EnergyHarvesterContainer.
|
||||
*
|
||||
* Appends the contents of another EnergyHarvesterContainer to the end of
|
||||
* this EnergyHarvesterContainer.
|
||||
*/
|
||||
void Add (EnergyHarvesterContainer container);
|
||||
|
||||
/**
|
||||
* \brief Append a single Ptr<EnergyHarvester> to the end of this container.
|
||||
*
|
||||
* \param harvester Pointer to an EnergyHarvester.
|
||||
*/
|
||||
void Add (Ptr<EnergyHarvester> harvester);
|
||||
|
||||
/**
|
||||
* \brief Append a single Ptr<EnergyHarvester> referred to by its object
|
||||
* name to the end of this container.
|
||||
*
|
||||
* \param harvesterName Name of EnergyHarvester object.
|
||||
*/
|
||||
void Add (std::string harvesterName);
|
||||
|
||||
/**
|
||||
* \brief Removes all elements in the container.
|
||||
*/
|
||||
void Clear (void);
|
||||
|
||||
private:
|
||||
virtual void DoDispose (void);
|
||||
|
||||
/**
|
||||
* \brief Calls Object::Initialize () for all EnergySource objects.
|
||||
*/
|
||||
virtual void DoInitialize (void);
|
||||
|
||||
private:
|
||||
std::vector< Ptr<EnergyHarvester> > m_harvesters;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
|
||||
#endif /* defined(ENERGY_HARVESTER_CONTAINER_H) */
|
||||
79
src/energy/helper/energy-harvester-helper.cc
Normal file
79
src/energy/helper/energy-harvester-helper.cc
Normal file
@@ -0,0 +1,79 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "energy-harvester-helper.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/names.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/*
|
||||
* EnergyHarvesterHelper
|
||||
*/
|
||||
EnergyHarvesterHelper::~EnergyHarvesterHelper ()
|
||||
{
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer
|
||||
EnergyHarvesterHelper::Install (Ptr<EnergySource> source) const
|
||||
{
|
||||
return Install (EnergySourceContainer (source));
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer
|
||||
EnergyHarvesterHelper::Install (EnergySourceContainer sourceContainer) const
|
||||
{
|
||||
EnergyHarvesterContainer container;
|
||||
for (EnergySourceContainer::Iterator i = sourceContainer.Begin (); i != sourceContainer.End (); ++i)
|
||||
{
|
||||
Ptr<EnergyHarvester> harvester = DoInstall (*i);
|
||||
container.Add (harvester);
|
||||
Ptr<Node> node = (*i)->GetNode ();
|
||||
/*
|
||||
* Check if EnergyHarvesterContainer is already aggregated to target node. If
|
||||
* not, create a new EnergyHarvesterContainer and aggregate it to the node.
|
||||
*/
|
||||
Ptr<EnergyHarvesterContainer> EnergyHarvesterContainerOnNode =
|
||||
node->GetObject<EnergyHarvesterContainer> ();
|
||||
if (EnergyHarvesterContainerOnNode == 0)
|
||||
{
|
||||
ObjectFactory fac;
|
||||
fac.SetTypeId ("ns3::EnergyHarvesterContainer");
|
||||
EnergyHarvesterContainerOnNode = fac.Create<EnergyHarvesterContainer> ();
|
||||
EnergyHarvesterContainerOnNode->Add (harvester);
|
||||
node->AggregateObject (EnergyHarvesterContainerOnNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnergyHarvesterContainerOnNode->Add (harvester); // append new EnergyHarvester
|
||||
}
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
EnergyHarvesterContainer
|
||||
EnergyHarvesterHelper::Install (std::string sourceName) const
|
||||
{
|
||||
Ptr<EnergySource> source = Names::Find<EnergySource> (sourceName);
|
||||
return Install (source);
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
98
src/energy/helper/energy-harvester-helper.h
Normal file
98
src/energy/helper/energy-harvester-helper.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#ifndef ENERGY_HARVESTER_HELPER_H
|
||||
#define ENERGY_HARVESTER_HELPER_H
|
||||
|
||||
#include "ns3/attribute.h"
|
||||
#include "ns3/object-factory.h"
|
||||
#include "ns3/node-container.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/energy-harvester.h"
|
||||
#include "ns3/energy-harvester-container.h"
|
||||
|
||||
#include "ns3/energy-source.h"
|
||||
#include "ns3/energy-source-container.h"
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup energy
|
||||
* \brief Creates EnergyHarvester objects.
|
||||
*
|
||||
* This class creates and installs energy harvesters onto network nodes.
|
||||
*
|
||||
*/
|
||||
class EnergyHarvesterHelper
|
||||
{
|
||||
public:
|
||||
virtual ~EnergyHarvesterHelper ();
|
||||
|
||||
/**
|
||||
* \param name Name of attribute to set.
|
||||
* \param v Value of the attribute.
|
||||
*
|
||||
* Sets one of the attributes of underlying EnergyHarvester.
|
||||
*/
|
||||
virtual void Set (std::string name, const AttributeValue &v) = 0;
|
||||
|
||||
/**
|
||||
* \param source Pointer to the energy source where EnergyHarvester will be installed.
|
||||
* \returns An EnergyHarvesterContainer which contains all the EnergyHarvesters.
|
||||
*
|
||||
* This function installs an EnergyHarvester onto an energy source.
|
||||
*/
|
||||
EnergyHarvesterContainer Install (Ptr<EnergySource> source) const;
|
||||
|
||||
/**
|
||||
* \param sourceContainer List of nodes where EnergyHarvester will be installed.
|
||||
* \returns An EnergyHarvesterContainer which contains all the EnergyHarvester.
|
||||
*
|
||||
* This function installs an EnergyHarvester onto a list of energy sources.
|
||||
*/
|
||||
EnergyHarvesterContainer Install (EnergySourceContainer sourceContainer) const;
|
||||
|
||||
/**
|
||||
* \param nodeName Name of node where EnergyHarvester will be installed.
|
||||
* \returns An EnergyHarvesterContainer which contains all the EnergyHarvesters.
|
||||
*
|
||||
* This function installs an EnergyHarvester onto a node.
|
||||
*/
|
||||
EnergyHarvesterContainer Install (std::string sourceName) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* \param node Pointer to node where the energy harvester is to be installed.
|
||||
* \returns Pointer to the created EnergyHarvester.
|
||||
*
|
||||
* Child classes of EnergyHarvesterHelper only have to implement this function,
|
||||
* to create and aggregate an EnergyHarvester object onto a single node. Rest of
|
||||
* the installation process (eg. installing EnergyHarvester on set of nodes) is
|
||||
* implemented in the EnergyHarvesterHelper base class.
|
||||
*/
|
||||
virtual Ptr<EnergyHarvester> DoInstall (Ptr<EnergySource> source) const = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* defined(ENERGY_HARVESTER_HELPER_H) */
|
||||
180
src/energy/model/basic-energy-harvester.cc
Normal file
180
src/energy/model/basic-energy-harvester.cc
Normal file
@@ -0,0 +1,180 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "basic-energy-harvester.h"
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/pointer.h"
|
||||
#include "ns3/string.h"
|
||||
#include "ns3/trace-source-accessor.h"
|
||||
#include "ns3/simulator.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("BasicEnergyHarvester");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (BasicEnergyHarvester);
|
||||
|
||||
TypeId
|
||||
BasicEnergyHarvester::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::BasicEnergyHarvester")
|
||||
.SetParent<EnergyHarvester> ()
|
||||
.AddConstructor<BasicEnergyHarvester> ()
|
||||
.AddAttribute ("PeriodicHarvestedPowerUpdateInterval",
|
||||
"Time between two consecutive periodic updates of the harvested power. By default, the value is updated every 1 s",
|
||||
TimeValue (Seconds (1.0)),
|
||||
MakeTimeAccessor (&BasicEnergyHarvester::SetHarvestedPowerUpdateInterval,
|
||||
&BasicEnergyHarvester::GetHarvestedPowerUpdateInterval),
|
||||
MakeTimeChecker ())
|
||||
.AddAttribute ("HarvestablePower",
|
||||
"The harvestable power [Watts] that the energy harvester is allowed to harvest. By default, the model will allow to harvest an amount of power defined by a uniformly distributed random variable in 0 and 2.0 Watts",
|
||||
StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=2.0]"),
|
||||
MakePointerAccessor (&BasicEnergyHarvester::m_harvestablePower),
|
||||
MakePointerChecker<RandomVariableStream> ())
|
||||
.AddTraceSource ("HarvestedPower",
|
||||
"Harvested power by the BasicEnergyHarvester.",
|
||||
MakeTraceSourceAccessor (&BasicEnergyHarvester::m_harvestedPower))
|
||||
.AddTraceSource ("TotalEnergyHarvested",
|
||||
"Total energy harvested by the harvester.",
|
||||
MakeTraceSourceAccessor (&BasicEnergyHarvester::m_totalEnergyHarvestedJ))
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
BasicEnergyHarvester::BasicEnergyHarvester ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
BasicEnergyHarvester::BasicEnergyHarvester (Time updateInterval)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << updateInterval);
|
||||
m_harvestedPowerUpdateInterval = updateInterval;
|
||||
}
|
||||
|
||||
BasicEnergyHarvester::~BasicEnergyHarvester ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
int64_t
|
||||
BasicEnergyHarvester::AssignStreams (int64_t stream)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << stream);
|
||||
m_harvestablePower->SetStream (stream);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
BasicEnergyHarvester::SetHarvestedPowerUpdateInterval (Time updateInterval)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << updateInterval);
|
||||
m_harvestedPowerUpdateInterval = updateInterval;
|
||||
}
|
||||
|
||||
Time
|
||||
BasicEnergyHarvester::GetHarvestedPowerUpdateInterval (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_harvestedPowerUpdateInterval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Private functions start here.
|
||||
*/
|
||||
|
||||
void
|
||||
BasicEnergyHarvester::UpdateHarvestedPower (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
|
||||
<< "s BasicEnergyHarvester(" << GetNode ()->GetId () << "): Updating harvesting power.");
|
||||
|
||||
Time duration = Simulator::Now () - m_lastHarvestingUpdateTime;
|
||||
|
||||
NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid
|
||||
|
||||
double energyHarvested = 0.0;
|
||||
|
||||
// do not update if simulation has finished
|
||||
if (Simulator::IsFinished ())
|
||||
{
|
||||
NS_LOG_DEBUG ("BasicEnergyHarvester: Simulation Finished.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_energyHarvestingUpdateEvent.Cancel ();
|
||||
|
||||
CalculateHarvestedPower ();
|
||||
|
||||
energyHarvested = duration.GetSeconds () * m_harvestedPower;
|
||||
|
||||
// update total energy harvested
|
||||
m_totalEnergyHarvestedJ += energyHarvested;
|
||||
|
||||
// notify energy source
|
||||
GetEnergySource ()->UpdateEnergySource ();
|
||||
|
||||
// update last harvesting time stamp
|
||||
m_lastHarvestingUpdateTime = Simulator::Now ();
|
||||
|
||||
m_energyHarvestingUpdateEvent = Simulator::Schedule (m_harvestedPowerUpdateInterval,
|
||||
&BasicEnergyHarvester::UpdateHarvestedPower,
|
||||
this);
|
||||
}
|
||||
|
||||
void
|
||||
BasicEnergyHarvester::DoInitialize (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
m_lastHarvestingUpdateTime = Simulator::Now ();
|
||||
|
||||
UpdateHarvestedPower (); // start periodic harvesting update
|
||||
}
|
||||
|
||||
void
|
||||
BasicEnergyHarvester::DoDispose (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
void
|
||||
BasicEnergyHarvester::CalculateHarvestedPower (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
m_harvestedPower = m_harvestablePower->GetValue ();
|
||||
|
||||
NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
|
||||
<< "s BasicEnergyHarvester:Harvested energy = " << m_harvestedPower);
|
||||
}
|
||||
|
||||
double
|
||||
BasicEnergyHarvester::DoGetPower (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_harvestedPower;
|
||||
}
|
||||
|
||||
} // namespace ns3
|
||||
131
src/energy/model/basic-energy-harvester.h
Normal file
131
src/energy/model/basic-energy-harvester.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#ifndef BASIC_ENERGY_HARVESTER
|
||||
#define BASIC_ENERGY_HARVESTER
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// include from ns-3
|
||||
#include "ns3/traced-value.h"
|
||||
#include "ns3/nstime.h"
|
||||
#include "ns3/event-id.h"
|
||||
#include "energy-harvester.h"
|
||||
#include "ns3/random-variable-stream.h"
|
||||
#include "ns3/device-energy-model.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* \ingroup energy
|
||||
* BasicEnergyHarvester increases remaining energy stored in an associated
|
||||
* Energy Source. The BasicEnergyHarvester implements a simple model in which
|
||||
* the amount of power provided by the harvester varies over time according
|
||||
* to a customizable generic random variable and time update intervals.
|
||||
*
|
||||
* Unit of power is chosen as Watt since energy models typically calculate
|
||||
* energy as (time in seconds * power in Watt).
|
||||
*
|
||||
*/
|
||||
class BasicEnergyHarvester: public EnergyHarvester
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
BasicEnergyHarvester ();
|
||||
|
||||
/**
|
||||
* \param updateInterval Energy harvesting update interval.
|
||||
*
|
||||
* BasicEnergyHarvester constructor function that sets the interval
|
||||
* between each update of the value of the power harvested by this
|
||||
* energy harvester.
|
||||
*/
|
||||
BasicEnergyHarvester (Time updateInterval);
|
||||
|
||||
virtual ~BasicEnergyHarvester ();
|
||||
|
||||
/**
|
||||
* \param updateInterval Energy harvesting update interval.
|
||||
*
|
||||
* This function sets the interval between each update of the value of the
|
||||
* power harvested by this energy harvester.
|
||||
*/
|
||||
void SetHarvestedPowerUpdateInterval (Time updateInterval);
|
||||
|
||||
/**
|
||||
* \returns The interval between each update of the harvested power.
|
||||
*
|
||||
* This function returns the interval between each update of the value of the
|
||||
* power harvested by this energy harvester.
|
||||
*/
|
||||
Time GetHarvestedPowerUpdateInterval (void) const;
|
||||
|
||||
/**
|
||||
* \param stream Random variable stream number.
|
||||
* \returns The number of stream indices assigned by this model.
|
||||
*
|
||||
* This function sets the stream number to be used by the random variable that
|
||||
* determines the amount of power that can be harvested by this energy harvester.
|
||||
*/
|
||||
int64_t AssignStreams (int64_t stream);
|
||||
|
||||
private:
|
||||
/// Defined in ns3::Object
|
||||
void DoInitialize (void);
|
||||
|
||||
/// Defined in ns3::Object
|
||||
void DoDispose (void);
|
||||
|
||||
/**
|
||||
* Calculates harvested Power.
|
||||
*/
|
||||
void CalculateHarvestedPower (void);
|
||||
|
||||
/**
|
||||
* \returns m_harvestedPower The power currently provided by the Basic Energy Harvester.
|
||||
* Implements DoGetPower defined in EnergyHarvester.
|
||||
*/
|
||||
virtual double DoGetPower (void) const;
|
||||
|
||||
/**
|
||||
* This function is called every m_energyHarvestingUpdateInterval in order to
|
||||
* update the amount of power that will be provided by the harvester in the
|
||||
* next interval.
|
||||
*/
|
||||
void UpdateHarvestedPower (void);
|
||||
|
||||
private:
|
||||
|
||||
Ptr<RandomVariableStream> m_harvestablePower; // Random variable for the harvestable power
|
||||
|
||||
TracedValue<double> m_harvestedPower; // current harvested power, in Watt
|
||||
TracedValue<double> m_totalEnergyHarvestedJ; // total harvested energy, in Joule
|
||||
|
||||
EventId m_energyHarvestingUpdateEvent; // energy harvesting event
|
||||
Time m_lastHarvestingUpdateTime; // last harvesting time
|
||||
Time m_harvestedPowerUpdateInterval; // harvestable energy update interval
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* defined(BASIC_ENERGY_HARVESTER) */
|
||||
105
src/energy/model/energy-harvester.cc
Normal file
105
src/energy/model/energy-harvester.cc
Normal file
@@ -0,0 +1,105 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "energy-harvester.h"
|
||||
#include "ns3/log.h"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("EnergyHarvester");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
NS_OBJECT_ENSURE_REGISTERED (EnergyHarvester);
|
||||
|
||||
TypeId
|
||||
EnergyHarvester::GetTypeId (void)
|
||||
{
|
||||
static TypeId tid = TypeId ("ns3::EnergyHarvester")
|
||||
.SetParent<Object> ()
|
||||
;
|
||||
return tid;
|
||||
}
|
||||
|
||||
EnergyHarvester::EnergyHarvester ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
EnergyHarvester::~EnergyHarvester ()
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvester::SetNode (Ptr<Node> node)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
NS_ASSERT (node != 0);
|
||||
m_node = node;
|
||||
}
|
||||
|
||||
Ptr<Node>
|
||||
EnergyHarvester::GetNode (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_node;
|
||||
}
|
||||
|
||||
void
|
||||
EnergyHarvester::SetEnergySource (Ptr<EnergySource> source)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
NS_ASSERT (source != 0);
|
||||
m_energySource = source;
|
||||
}
|
||||
|
||||
Ptr<EnergySource>
|
||||
EnergyHarvester::GetEnergySource (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return m_energySource;
|
||||
}
|
||||
|
||||
|
||||
double
|
||||
EnergyHarvester::GetPower (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return DoGetPower ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Private function starts here.
|
||||
*/
|
||||
|
||||
void
|
||||
EnergyHarvester::DoDispose (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
}
|
||||
|
||||
double
|
||||
EnergyHarvester::DoGetPower (void) const
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
137
src/energy/model/energy-harvester.h
Normal file
137
src/energy/model/energy-harvester.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#ifndef ENERGY_HARVESTER_H
|
||||
#define ENERGY_HARVESTER_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// include from ns-3
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/type-id.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/energy-source-container.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class EnergySource;
|
||||
|
||||
/**
|
||||
* \defgroup energy Energy Models
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \ingroup energy
|
||||
*
|
||||
* \brief Energy harvester base class.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
class EnergyHarvester : public Object
|
||||
{
|
||||
public:
|
||||
static TypeId GetTypeId (void);
|
||||
|
||||
EnergyHarvester ();
|
||||
|
||||
virtual ~EnergyHarvester ();
|
||||
|
||||
/**
|
||||
* \brief Sets pointer to node containing this EnergyHarvester.
|
||||
*
|
||||
* \param node Pointer to node containing this EnergyHarvester.
|
||||
*/
|
||||
void SetNode (Ptr<Node> node);
|
||||
|
||||
/**
|
||||
* \returns Pointer to node containing this EnergyHarvester.
|
||||
*
|
||||
* When a subclass needs to get access to the underlying node base class to
|
||||
* print the nodeId for example, it can invoke this method.
|
||||
*/
|
||||
Ptr<Node> GetNode (void) const;
|
||||
|
||||
/**
|
||||
* \param source Pointer to energy source to which this EnergyHarvester is
|
||||
* installed.
|
||||
*
|
||||
* This function sets the pointer to the energy source connected to the energy
|
||||
* harvester.
|
||||
*/
|
||||
void SetEnergySource (Ptr<EnergySource> source);
|
||||
|
||||
/**
|
||||
* \returns source Pointer to energy source connected to the harvester.
|
||||
*
|
||||
* When a subclass needs to get access to the connected energy source,
|
||||
* it can invoke this method.
|
||||
*/
|
||||
Ptr<EnergySource> GetEnergySource (void) const;
|
||||
|
||||
/**
|
||||
* \returns power Amount of power currently provided by the harvester.
|
||||
*
|
||||
* This method is called by the energy source connected to the harvester in order
|
||||
* to determine the amount of energy that the harvester provided since last update.
|
||||
*/
|
||||
double GetPower (void) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
*
|
||||
* Defined in ns3::Object
|
||||
*/
|
||||
virtual void DoDispose (void);
|
||||
|
||||
/**
|
||||
* This method is called by the GetPower method and it needs to be implemented by the
|
||||
* subclasses of the energy harvester. It returns the actual amount of power that is
|
||||
* currently provided by the energy harvester.
|
||||
*
|
||||
* This method should be used to connect the logic behind the particular implementation
|
||||
* of the energy harvester with the energy source.
|
||||
*/
|
||||
virtual double DoGetPower (void) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* Pointer to node containing this EnergyHarvester. Used by helper class to make
|
||||
* sure energy harvesters are installed onto the corresponding node.
|
||||
*/
|
||||
Ptr<Node> m_node;
|
||||
|
||||
/**
|
||||
* Pointer to the Energy Source to which this EnergyHarvester is connected. Used
|
||||
* by helper class to make sure energy harvesters are installed onto the
|
||||
* corresponding energy source.
|
||||
*/
|
||||
Ptr<EnergySource> m_energySource;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* defined(ENERGY_HARVESTER_H) */
|
||||
@@ -16,6 +16,11 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
|
||||
*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* Modifications made by: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "energy-source.h"
|
||||
@@ -130,6 +135,14 @@ EnergySource::DisposeDeviceModels (void)
|
||||
(*i)->Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EnergySource::ConnectEnergyHarvester (Ptr<EnergyHarvester> energyHarvesterPtr)
|
||||
{
|
||||
NS_LOG_FUNCTION (this << energyHarvesterPtr);
|
||||
NS_ASSERT (energyHarvesterPtr != 0); // energy harvester must exist
|
||||
m_harvesters.push_back (energyHarvesterPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Private function starts here.
|
||||
@@ -156,6 +169,22 @@ EnergySource::CalculateTotalCurrent (void)
|
||||
{
|
||||
totalCurrentA += (*i)->GetCurrentA ();
|
||||
}
|
||||
|
||||
double totalHarvestedPower = 0.0;
|
||||
|
||||
std::vector< Ptr<EnergyHarvester> >::const_iterator harvester;
|
||||
for (harvester = m_harvesters.begin (); harvester != m_harvesters.end (); harvester++)
|
||||
{
|
||||
totalHarvestedPower += (*harvester)->GetPower ();
|
||||
}
|
||||
|
||||
NS_LOG_DEBUG ("EnergySource("<< GetNode ()->GetId () << "): Total harvested power = " << totalHarvestedPower);
|
||||
|
||||
double currentHarvestersA = totalHarvestedPower / GetSupplyVoltage ();
|
||||
NS_LOG_DEBUG ("EnergySource("<< GetNode ()->GetId () << "): Current from harvesters = " << currentHarvestersA);
|
||||
|
||||
totalCurrentA -= currentHarvestersA;
|
||||
|
||||
return totalCurrentA;
|
||||
}
|
||||
|
||||
@@ -176,6 +205,7 @@ EnergySource::BreakDeviceEnergyModelRefCycle (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
m_models.Clear ();
|
||||
m_harvesters.clear ();
|
||||
m_node = NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,14 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
|
||||
*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* Modifications made by: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ENERGY_SOURCE_H
|
||||
#define ENERGY_SOURCE_H
|
||||
|
||||
@@ -26,9 +32,10 @@
|
||||
#include "ns3/type-id.h"
|
||||
#include "ns3/node.h"
|
||||
#include "device-energy-model-container.h" // #include "device-energy-model.h"
|
||||
#include "ns3/energy-harvester.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
|
||||
/**
|
||||
* \defgroup energy Energy Models
|
||||
*
|
||||
@@ -68,6 +75,9 @@ namespace ns3 {
|
||||
* energy in different units (eg. kWh), a simple converter function should
|
||||
* suffice.
|
||||
*/
|
||||
|
||||
class EnergyHarvester;
|
||||
|
||||
class EnergySource : public Object
|
||||
{
|
||||
public:
|
||||
@@ -158,6 +168,17 @@ public:
|
||||
* here. Called by EnergySourceContainer, which is aggregated to the node.
|
||||
*/
|
||||
void DisposeDeviceModels (void);
|
||||
|
||||
/**
|
||||
* \param energyHarvesterPtr Pointer to energy harvester.
|
||||
*
|
||||
* This function connect an energy harvester to the energy source. After the
|
||||
* execution of this method, the pointer to the energy harvester is appended
|
||||
* to the end of a vector of EnergyHarvester pointer.
|
||||
* Note that the order in which different energy harvester are added to the
|
||||
* energy source does not impact the simulation results.
|
||||
*/
|
||||
void ConnectEnergyHarvester (Ptr<EnergyHarvester> energyHarvesterPtr);
|
||||
|
||||
|
||||
private:
|
||||
@@ -180,6 +201,13 @@ private:
|
||||
* sure device models are installed onto the corresponding node.
|
||||
*/
|
||||
Ptr<Node> m_node;
|
||||
|
||||
/**
|
||||
* Vector of EnergyHarvester pointer connected to the same energy source.
|
||||
* This vector is used by the CalculateTotalCurrent method to determine the
|
||||
* total power provided by the energy harvesters connected to the energy source.
|
||||
*/
|
||||
std::vector< Ptr<EnergyHarvester> > m_harvesters;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
134
src/energy/test/basic-energy-harvester-test.cc
Normal file
134
src/energy/test/basic-energy-harvester-test.cc
Normal file
@@ -0,0 +1,134 @@
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2014 Wireless Communications and Networking Group (WCNG),
|
||||
* University of Rochester, Rochester, NY, USA.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation;
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Cristiano Tapparello <cristiano.tapparello@rochester.edu>
|
||||
*/
|
||||
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/test.h"
|
||||
#include "ns3/node.h"
|
||||
#include "ns3/simulator.h"
|
||||
#include "ns3/double.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/string.h"
|
||||
#include "ns3/basic-energy-harvester.h"
|
||||
#include "ns3/basic-energy-source.h"
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("BasicEnergyHarvesterTestSuite");
|
||||
|
||||
class BasicEnergyHarvesterTestCase : public TestCase
|
||||
{
|
||||
public:
|
||||
BasicEnergyHarvesterTestCase ();
|
||||
~BasicEnergyHarvesterTestCase ();
|
||||
|
||||
void DoRun (void);
|
||||
|
||||
double m_timeS; // in seconds
|
||||
double m_tolerance; // tolerance for energy estimation
|
||||
|
||||
ObjectFactory m_energySource;
|
||||
ObjectFactory m_energyHarvester;
|
||||
|
||||
};
|
||||
|
||||
BasicEnergyHarvesterTestCase::BasicEnergyHarvesterTestCase ()
|
||||
: TestCase ("Basic Energy Harvester test case")
|
||||
{
|
||||
m_timeS = 15; // harvest energy for 15 seconds
|
||||
m_tolerance = 1.0e-13; //
|
||||
}
|
||||
|
||||
BasicEnergyHarvesterTestCase::~BasicEnergyHarvesterTestCase ()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
BasicEnergyHarvesterTestCase::DoRun ()
|
||||
{
|
||||
// set types
|
||||
m_energySource.SetTypeId ("ns3::BasicEnergySource");
|
||||
m_energyHarvester.SetTypeId ("ns3::BasicEnergyHarvester");
|
||||
// create node
|
||||
Ptr<Node> node = CreateObject<Node> ();
|
||||
|
||||
// create Energy Source
|
||||
Ptr<BasicEnergySource> source = m_energySource.Create<BasicEnergySource> ();
|
||||
// aggregate Energy Source to the node
|
||||
node->AggregateObject (source);
|
||||
|
||||
//create energy harvester
|
||||
Ptr<BasicEnergyHarvester> harvester = m_energyHarvester.Create<BasicEnergyHarvester> ();
|
||||
// Set the Energy Harvesting update interval to a value grater than the
|
||||
// simulation duration, so that the power provided by the harvester is constant
|
||||
harvester->SetHarvestedPowerUpdateInterval (Seconds (m_timeS + 1.0));
|
||||
// Connect the Basic Energy Harvester to the Energy Source
|
||||
source->ConnectEnergyHarvester (harvester);
|
||||
harvester->SetNode (node);
|
||||
harvester->SetEnergySource (source);
|
||||
|
||||
Time now = Simulator::Now ();
|
||||
|
||||
/*
|
||||
* The energy harvester will recharge the energy source for m_timeS seconds.
|
||||
*/
|
||||
|
||||
// Calculate remaining energy at simulation stop time
|
||||
Simulator::Schedule (Seconds (m_timeS),
|
||||
&BasicEnergySource::UpdateEnergySource, source);
|
||||
|
||||
double timeDelta = 0.000000001; // 1 nanosecond
|
||||
// run simulation; stop just after last scheduled event
|
||||
Simulator::Stop (Seconds (m_timeS + timeDelta));
|
||||
Simulator::Run ();
|
||||
|
||||
// calculate energy harvested
|
||||
double estRemainingEnergy = source->GetInitialEnergy ();
|
||||
// energy = power * time
|
||||
estRemainingEnergy += harvester->GetPower () * m_timeS;
|
||||
|
||||
// obtain remaining energy from source
|
||||
double remainingEnergy = source->GetRemainingEnergy ();
|
||||
NS_LOG_DEBUG ("Remaining energy is " << remainingEnergy);
|
||||
NS_LOG_DEBUG ("Estimated remaining energy is " << estRemainingEnergy);
|
||||
NS_LOG_DEBUG ("Difference is " << estRemainingEnergy - remainingEnergy);
|
||||
|
||||
Simulator::Destroy ();
|
||||
|
||||
// check remaining energy
|
||||
NS_TEST_ASSERT_MSG_EQ_TOL (remainingEnergy, estRemainingEnergy, m_tolerance,
|
||||
"Incorrect Remaining energy!");
|
||||
|
||||
}
|
||||
|
||||
class BasicEnergyHarvesterTestSuite : public TestSuite
|
||||
{
|
||||
public:
|
||||
BasicEnergyHarvesterTestSuite ();
|
||||
};
|
||||
|
||||
BasicEnergyHarvesterTestSuite::BasicEnergyHarvesterTestSuite ()
|
||||
: TestSuite ("basic-energy-harvester", UNIT)
|
||||
{
|
||||
AddTestCase (new BasicEnergyHarvesterTestCase, TestCase::QUICK);
|
||||
}
|
||||
|
||||
// create an instance of the test suite
|
||||
static BasicEnergyHarvesterTestSuite g_basicEnergyHarvesterTestSuite;
|
||||
@@ -11,11 +11,16 @@ def build(bld):
|
||||
'model/device-energy-model.cc',
|
||||
'model/device-energy-model-container.cc',
|
||||
'model/simple-device-energy-model.cc',
|
||||
'model/energy-harvester.cc',
|
||||
'model/basic-energy-harvester.cc',
|
||||
'helper/energy-source-container.cc',
|
||||
'helper/energy-model-helper.cc',
|
||||
'helper/basic-energy-source-helper.cc',
|
||||
'helper/wifi-radio-energy-model-helper.cc',
|
||||
'helper/rv-battery-model-helper.cc',
|
||||
'helper/energy-harvester-container.cc',
|
||||
'helper/energy-harvester-helper.cc',
|
||||
'helper/basic-energy-harvester-helper.cc',
|
||||
]
|
||||
|
||||
obj_test = bld.create_ns3_module_test_library('energy')
|
||||
@@ -23,6 +28,7 @@ def build(bld):
|
||||
'test/basic-energy-model-test.cc',
|
||||
'test/rv-battery-model-test.cc',
|
||||
'test/li-ion-energy-source-test.cc',
|
||||
'test/basic-energy-harvester-test.cc',
|
||||
]
|
||||
|
||||
headers = bld(features='ns3header')
|
||||
@@ -36,11 +42,16 @@ def build(bld):
|
||||
'model/device-energy-model.h',
|
||||
'model/device-energy-model-container.h',
|
||||
'model/simple-device-energy-model.h',
|
||||
'model/energy-harvester.h',
|
||||
'model/basic-energy-harvester.h',
|
||||
'helper/energy-source-container.h',
|
||||
'helper/energy-model-helper.h',
|
||||
'helper/basic-energy-source-helper.h',
|
||||
'helper/wifi-radio-energy-model-helper.h',
|
||||
'helper/rv-battery-model-helper.h',
|
||||
'helper/energy-harvester-container.h',
|
||||
'helper/energy-harvester-helper.h',
|
||||
'helper/basic-energy-harvester-helper.h',
|
||||
]
|
||||
|
||||
if (bld.env['ENABLE_EXAMPLES']):
|
||||
|
||||
Reference in New Issue
Block a user