A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::energy::EnergySource Class Referenceabstract

Energy source base class. More...

#include "energy-source.h"

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

Public Member Functions

 EnergySource ()
 
 ~EnergySource () override
 
void AppendDeviceEnergyModel (Ptr< DeviceEnergyModel > deviceEnergyModelPtr)
 
void ConnectEnergyHarvester (Ptr< EnergyHarvester > energyHarvesterPtr)
 
void DisposeDeviceModels ()
 Calls Dispose () method of the device energy models.
 
DeviceEnergyModelContainer FindDeviceEnergyModels (std::string name)
 
DeviceEnergyModelContainer FindDeviceEnergyModels (TypeId tid)
 
virtual double GetEnergyFraction ()=0
 
virtual double GetInitialEnergy () const =0
 
Ptr< NodeGetNode () const
 
virtual double GetRemainingEnergy ()=0
 
virtual double GetSupplyVoltage () const =0
 
void InitializeDeviceModels ()
 Calls Start () method of the device energy models.
 
void SetNode (Ptr< Node > node)
 Sets pointer to node containing this EnergySource.
 
virtual void UpdateEnergySource ()=0
 This function goes through the list of DeviceEnergyModels to obtain total current draw at the energy source and updates remaining energy.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the type ID.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Protected Member Functions

void BreakDeviceEnergyModelRefCycle ()
 This function is called to break reference cycle between EnergySource and DeviceEnergyModel.
 
double CalculateTotalCurrent ()
 
void NotifyEnergyChanged ()
 This function notifies all DeviceEnergyModel of energy changed event.
 
void NotifyEnergyDrained ()
 This function notifies all DeviceEnergyModel of energy depletion event.
 
void NotifyEnergyRecharged ()
 This function notifies all DeviceEnergyModel of energy recharged event.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void DoInitialize ()
 Initialize() implementation.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Private Member Functions

void DoDispose () override
 All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to DeviceEnergyModel objects are broken.
 

Private Attributes

std::vector< Ptr< EnergyHarvester > > m_harvesters
 Vector of EnergyHarvester pointer connected to the same energy source.
 
DeviceEnergyModelContainer m_models
 List of device energy models installed on the same node.
 
Ptr< Nodem_node
 Pointer to node containing this EnergySource.
 

Additional Inherited Members

Detailed Description

Energy source base class.

Introspection did not find any typical Config paths.

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.


No Attributes are defined for this type.
No TraceSources are defined for this type.
Group: Energy

Size of this type is 112 bytes (on a 64-bit architecture).

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

Constructor & Destructor Documentation

◆ EnergySource()

ns3::energy::EnergySource::EnergySource ( )

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

References NS_LOG_FUNCTION.

◆ ~EnergySource()

ns3::energy::EnergySource::~EnergySource ( )
override

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

References NS_LOG_FUNCTION.

Member Function Documentation

◆ AppendDeviceEnergyModel()

void ns3::energy::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::energy::DeviceEnergyModelContainer::Add(), m_models, NS_ASSERT, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ BreakDeviceEnergyModelRefCycle()

void ns3::energy::EnergySource::BreakDeviceEnergyModelRefCycle ( )
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 225 of file energy-source.cc.

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalculateTotalCurrent()

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

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

References ns3::energy::DeviceEnergyModelContainer::Begin(), ns3::energy::DeviceEnergyModelContainer::End(), GetSupplyVoltage(), m_harvesters, m_models, NS_LOG_DEBUG, and NS_LOG_FUNCTION.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConnectEnergyHarvester()

void ns3::energy::EnergySource::ConnectEnergyHarvester ( Ptr< EnergyHarvester > energyHarvesterPtr)
Parameters
energyHarvesterPtrPointer 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.

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

References m_harvesters, NS_ASSERT, and NS_LOG_FUNCTION.

◆ DisposeDeviceModels()

void ns3::energy::EnergySource::DisposeDeviceModels ( )

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 116 of file energy-source.cc.

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

+ Here is the call graph for this function:

◆ DoDispose()

void ns3::energy::EnergySource::DoDispose ( )
overrideprivatevirtual

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

Defined in ns3::Object

Reimplemented from ns3::Object.

Reimplemented in ns3::energy::GenericBatteryModel, ns3::energy::LiIonEnergySource, and ns3::energy::RvBatteryModel.

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

References BreakDeviceEnergyModelRefCycle(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ FindDeviceEnergyModels() [1/2]

DeviceEnergyModelContainer ns3::energy::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::energy::DeviceEnergyModelContainer::Begin(), ns3::energy::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ FindDeviceEnergyModels() [2/2]

DeviceEnergyModelContainer ns3::energy::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::energy::DeviceEnergyModelContainer::Begin(), ns3::energy::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetEnergyFraction()

virtual double ns3::energy::EnergySource::GetEnergyFraction ( )
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::energy::BasicEnergySource, ns3::energy::GenericBatteryModel, ns3::energy::LiIonEnergySource, and ns3::energy::RvBatteryModel.

◆ GetInitialEnergy()

virtual double ns3::energy::EnergySource::GetInitialEnergy ( ) 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::energy::BasicEnergySource, ns3::energy::GenericBatteryModel, ns3::energy::LiIonEnergySource, and ns3::energy::RvBatteryModel.

◆ GetNode()

Ptr< Node > ns3::energy::EnergySource::GetNode ( ) 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::energy::LiIonEnergySource::HandleEnergyDrainedEvent(), and ns3::energy::LiIonEnergySource::UpdateEnergySource().

+ Here is the caller graph for this function:

◆ GetRemainingEnergy()

virtual double ns3::energy::EnergySource::GetRemainingEnergy ( )
pure virtual

◆ GetSupplyVoltage()

virtual double ns3::energy::EnergySource::GetSupplyVoltage ( ) 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::energy::BasicEnergySource, ns3::energy::GenericBatteryModel, ns3::energy::LiIonEnergySource, and ns3::energy::RvBatteryModel.

Referenced by CalculateTotalCurrent().

+ Here is the caller graph for this function:

◆ GetTypeId()

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

Get the type ID.

Returns
The object TypeId.

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

References ns3::TypeId::AddDeprecatedName(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ InitializeDeviceModels()

void ns3::energy::EnergySource::InitializeDeviceModels ( )

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::energy::DeviceEnergyModelContainer::Begin(), ns3::energy::DeviceEnergyModelContainer::End(), m_models, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ NotifyEnergyChanged()

void ns3::energy::EnergySource::NotifyEnergyChanged ( )
protected

This function notifies all DeviceEnergyModel of energy changed event.

It is called by the child EnergySource class when energy source is changed.

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

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

Referenced by ns3::energy::BasicEnergySource::UpdateEnergySource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NotifyEnergyDrained()

void ns3::energy::EnergySource::NotifyEnergyDrained ( )
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 189 of file energy-source.cc.

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

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ NotifyEnergyRecharged()

void ns3::energy::EnergySource::NotifyEnergyRecharged ( )
protected

This function notifies all DeviceEnergyModel of energy recharged event.

It is called by the child EnergySource class when energy source is recharged.

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

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

Referenced by ns3::energy::GenericBatteryModel::BatteryChargedEvent(), and ns3::energy::BasicEnergySource::HandleEnergyRechargedEvent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetNode()

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

Sets pointer to node containing this EnergySource.

Parameters
nodePointer to node containing this EnergySource.

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

References m_node, NS_ASSERT, and NS_LOG_FUNCTION.

◆ UpdateEnergySource()

virtual void ns3::energy::EnergySource::UpdateEnergySource ( )
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::energy::BasicEnergySource, ns3::energy::GenericBatteryModel, ns3::energy::LiIonEnergySource, and ns3::energy::RvBatteryModel.

Member Data Documentation

◆ m_harvesters

std::vector<Ptr<EnergyHarvester> > ns3::energy::EnergySource::m_harvesters
private

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.

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

Referenced by BreakDeviceEnergyModelRefCycle(), CalculateTotalCurrent(), and ConnectEnergyHarvester().

◆ m_models

◆ m_node

Ptr<Node> ns3::energy::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 201 of file energy-source.h.

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


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