A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::EnergySource Class Reference

Energy source base class. More...

#include <energy-source.h>

+ Inheritance diagram for ns3::EnergySource:
+ Collaboration diagram for ns3::EnergySource:

Public Member Functions

 EnergySource ()
virtual ~EnergySource ()
void AppendDeviceEnergyModel (Ptr< DeviceEnergyModel > deviceEnergyModelPtr)
void DisposeDeviceModels (void)
DeviceEnergyModelContainer FindDeviceEnergyModels (TypeId tid)
DeviceEnergyModelContainer FindDeviceEnergyModels (std::string name)
virtual double GetEnergyFraction (void)=0
virtual double GetInitialEnergy (void) const =0
Ptr< NodeGetNode (void) const
virtual double GetRemainingEnergy (void)=0
virtual double GetSupplyVoltage (void) const =0
void SetNode (Ptr< Node > node)
 Sets pointer to node containing this EnergySource.
void StartDeviceModels (void)
virtual void UpdateEnergySource (void)=0
- Public Member Functions inherited from ns3::Object
 Object ()
virtual ~Object ()
void AggregateObject (Ptr< Object > other)
void Dispose (void)
AggregateIterator GetAggregateIterator (void) const
virtual TypeId GetInstanceTypeId (void) const
template<typename T >
Ptr< T > GetObject (void) const
template<typename T >
Ptr< T > GetObject (TypeId tid) const
void Start (void)
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 SimpleRefCount (const SimpleRefCount &o)
uint32_t GetReferenceCount (void) const
SimpleRefCountoperator= (const SimpleRefCount &o)
void Ref (void) const
void Unref (void) const
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
void GetAttribute (std::string name, AttributeValue &value) const
bool GetAttributeFailSafe (std::string name, AttributeValue &attribute) const
void SetAttribute (std::string name, const AttributeValue &value)
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)

Static Public Member Functions

static TypeId GetTypeId (void)
 This method returns the TypeId associated to ns3::EnergySource.

Protected Member Functions

void BreakDeviceEnergyModelRefCycle (void)
double CalculateTotalCurrent (void)
void NotifyEnergyDrained (void)
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
virtual void DoDispose (void)
virtual void DoStart (void)
virtual void NotifyNewAggregate (void)

Private Member Functions

virtual void DoDispose (void)

Private Attributes

DeviceEnergyModelContainer m_models
Ptr< Nodem_node

Detailed Description

Energy source base class.

This is the base class for energy sources. Energy sources keep track of remaining energy. Device energy models will be updating the remaining energy in the energy source. The energy source itself does not update the remaining energy. Energy source also keeps a list of device energy models installed on the same node. When the remaining energy level reaches 0, the energy source will notify all device energy models stored in the list.

EnergySource provides 2 types of interfaces for DeviceEnergyModels to update the remaining energy stored in EnergySource: -Direct energy update interface (Joules): DecreaseRemainingEnergy IncreaseRemainingEnergy -Indirect energy update interface (Current): UpdateEnergySource Direct energy update interface will decrease/increase energy from the source directly (in Joules). Direct energy update interface is typically used by simple DeviceEnergyModel which knows only average power consumption for each of its state. Indirect energy update interface uses the total current cumulated from all DeviceEnergyModel to calculate energy to decrease from the source. Indirect energy update interface is typically used by DeviceEnergyModel who knows its current draw for each of its states. Nonlinear EnergySource also uses this interface.

Unit of energy is chosen as Joules since energy models typically calculate energy as (time in seconds * power in Watts). If the energy source stores energy in different units (eg. kWh), a simple converter function should suffice.

Definition at line 71 of file energy-source.h.

Constructor & Destructor Documentation

ns3::EnergySource::EnergySource ( )

Definition at line 39 of file energy-source.cc.

ns3::EnergySource::~EnergySource ( )
virtual

Definition at line 43 of file energy-source.cc.

Member Function Documentation

void ns3::EnergySource::AppendDeviceEnergyModel ( Ptr< DeviceEnergyModel deviceEnergyModelPtr)
Parameters
deviceEnergyModelPtrPointer to device energy model.

This function appends a device energy model to the end of a list of DeviceEnergyModelInfo structs.

Definition at line 61 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Add(), m_models, NS_ASSERT, and NS_LOG_FUNCTION.

Referenced by ns3::AcousticModemEnergyModelHelper::DoInstall(), and ns3::WifiRadioEnergyModelHelper::DoInstall().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::EnergySource::BreakDeviceEnergyModelRefCycle ( void  )
protected

This function is called to break reference cycle between EnergySource and DeviceEnergyModel. Child of the EnergySource base class must call this function in their implementation of DoDispose to make sure the reference cycle is broken.

Normally this work will be completed by the DoDispose function. However it will be overridden in the child class. Hence we introduced this function.

Definition at line 169 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Clear(), m_models, m_node, and NS_LOG_FUNCTION.

Referenced by ns3::BasicEnergySource::DoDispose(), ns3::LiIonEnergySource::DoDispose(), DoDispose(), and ns3::RvBatteryModel::DoDispose().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double ns3::EnergySource::CalculateTotalCurrent ( void  )
protected
Returns
Total current draw from all DeviceEnergyModels.

Definition at line 144 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Begin(), ns3::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

Referenced by ns3::BasicEnergySource::CalculateRemainingEnergy(), ns3::LiIonEnergySource::CalculateRemainingEnergy(), and ns3::RvBatteryModel::UpdateEnergySource().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::EnergySource::DisposeDeviceModels ( void  )

Calls Dispose () method of the device energy models. Device energy models are not aggregated to the node, therefore we need to manually start them here. Called by EnergySourceContainer, which is aggregated to the node.

Definition at line 115 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Begin(), ns3::DeviceEnergyModelContainer::End(), and m_models.

+ Here is the call graph for this function:

void ns3::EnergySource::DoDispose ( void  )
privatevirtual

All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to DeviceEnergyModel objects are broken.

Defined in ns3::Object

Definition at line 133 of file energy-source.cc.

References BreakDeviceEnergyModelRefCycle(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

DeviceEnergyModelContainer ns3::EnergySource::FindDeviceEnergyModels ( TypeId  tid)
Parameters
tidTypeId of the DeviceEnergyModel we are searching for.
Returns
List of pointers to DeviceEnergyModel objects installed on node.

Definition at line 69 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Add(), ns3::DeviceEnergyModelContainer::Begin(), ns3::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

DeviceEnergyModelContainer ns3::EnergySource::FindDeviceEnergyModels ( std::string  name)
Parameters
namename of the DeviceEnergyModel we are searching for.
Returns
List of pointers to DeviceEnergyModel objects installed on node.

Definition at line 85 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Add(), ns3::DeviceEnergyModelContainer::Begin(), ns3::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

virtual double ns3::EnergySource::GetEnergyFraction ( void  )
pure virtual
Returns
Energy fraction = remaining energy / initial energy [0, 1]

This function returns the percentage of energy left in the energy source.

Implemented in ns3::LiIonEnergySource, ns3::RvBatteryModel, and ns3::BasicEnergySource.

virtual double ns3::EnergySource::GetInitialEnergy ( void  ) const
pure virtual
Returns
Initial energy (capacity) of the energy source.

Set method is to be defined in child class only if necessary. For sources with a fixed initial energy (energy capacity), set method is not needed.

Implemented in ns3::LiIonEnergySource, ns3::RvBatteryModel, and ns3::BasicEnergySource.

Referenced by ns3::AcousticModemEnergyTestCase::DoRun().

+ Here is the caller graph for this function:

Ptr< Node > ns3::EnergySource::GetNode ( void  ) const
Returns
Pointer to node containing this EnergySource.

When a subclass needs to get access to the underlying node base class to print the nodeId for example, it can invoke this method.

Definition at line 55 of file energy-source.cc.

References m_node.

Referenced by ns3::LiIonEnergySource::HandleEnergyDrainedEvent(), ns3::DeviceEnergyModelHelper::Install(), and ns3::LiIonEnergySource::UpdateEnergySource().

+ Here is the caller graph for this function:

virtual double ns3::EnergySource::GetRemainingEnergy ( void  )
pure virtual
Returns
Remaining energy at the energy source.

Implemented in ns3::LiIonEnergySource, ns3::RvBatteryModel, and ns3::BasicEnergySource.

Referenced by ns3::AcousticModemEnergyTestCase::DoRun().

+ Here is the caller graph for this function:

virtual double ns3::EnergySource::GetSupplyVoltage ( void  ) const
pure virtual
Returns
Supply voltage of the energy source.

Set method is to be defined in child class only if necessary. For sources with a fixed supply voltage, set method is not needed.

Implemented in ns3::LiIonEnergySource, ns3::RvBatteryModel, and ns3::BasicEnergySource.

Referenced by ns3::AcousticModemEnergyModel::ChangeState(), ns3::WifiRadioEnergyModel::ChangeState(), ns3::AcousticModemEnergyModel::DoGetCurrentA(), and ns3::SimpleDeviceEnergyModel::SetCurrentA().

+ Here is the caller graph for this function:

TypeId ns3::EnergySource::GetTypeId ( void  )
static

This method returns the TypeId associated to ns3::EnergySource.

No Attributes defined for this type.
No TraceSources defined for this type.

Reimplemented from ns3::Object.

Reimplemented in ns3::LiIonEnergySource, ns3::RvBatteryModel, and ns3::BasicEnergySource.

Definition at line 31 of file energy-source.cc.

References ns3::TypeId::SetParent().

+ Here is the call graph for this function:

void ns3::EnergySource::NotifyEnergyDrained ( void  )
protected

This function notifies all DeviceEnergyModel of energy depletion event. It is called by the child EnergySource class when energy depletion happens.

Definition at line 157 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Begin(), ns3::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

Referenced by ns3::BasicEnergySource::HandleEnergyDrainedEvent(), ns3::LiIonEnergySource::HandleEnergyDrainedEvent(), and ns3::RvBatteryModel::HandleEnergyDrainedEvent().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ns3::EnergySource::SetNode ( Ptr< Node node)

Sets pointer to node containing this EnergySource.

Parameters
nodePointer to node containing this EnergySource.

Definition at line 48 of file energy-source.cc.

References m_node, and NS_ASSERT.

Referenced by ns3::BasicEnergySourceHelper::DoInstall(), ns3::RvBatteryModelHelper::DoInstall(), and ns3::AcousticModemEnergyModelHelper::DoInstall().

+ Here is the caller graph for this function:

void ns3::EnergySource::StartDeviceModels ( void  )

Calls Start () method of the device energy models. Device energy models are not aggregated to the node, therefore we need to manually start them here. Called by EnergySourceContainer, which is aggregated to the node.

Definition at line 101 of file energy-source.cc.

References ns3::DeviceEnergyModelContainer::Begin(), ns3::DeviceEnergyModelContainer::End(), and m_models.

+ Here is the call graph for this function:

virtual void ns3::EnergySource::UpdateEnergySource ( void  )
pure virtual

This function goes through the list of DeviceEnergyModels to obtain total current draw at the energy source and updates remaining energy. Called by DeviceEnergyModels to inform EnergySource of a state change.

Implemented in ns3::LiIonEnergySource, ns3::RvBatteryModel, and ns3::BasicEnergySource.

Referenced by ns3::AcousticModemEnergyModel::ChangeState(), ns3::WifiRadioEnergyModel::ChangeState(), and ns3::SimpleDeviceEnergyModel::SetCurrentA().

+ Here is the caller graph for this function:

Member Data Documentation

DeviceEnergyModelContainer ns3::EnergySource::m_models
private
Ptr<Node> ns3::EnergySource::m_node
private

Pointer to node containing this EnergySource. Used by helper class to make sure device models are installed onto the corresponding node.

Definition at line 182 of file energy-source.h.

Referenced by BreakDeviceEnergyModelRefCycle(), GetNode(), and SetNode().


The documentation for this class was generated from the following files: