INET Framework for OMNeT++/OMNEST
inet::power::SimpleEpEnergyStorage Class Reference

This class implements a simple total power integrating energy storage. More...

#include <SimpleEpEnergyStorage.h>

Inheritance diagram for inet::power::SimpleEpEnergyStorage:
inet::power::EpEnergyStorageBase inet::power::EpEnergySourceBase inet::power::EpEnergySinkBase inet::power::IEpEnergyStorage inet::power::IEnergyStorage inet::power::IEpEnergySink inet::power::IEpEnergySource inet::power::IEpEnergySink inet::power::EnergySinkBase inet::power::IEpEnergySource inet::power::EnergySourceBase

Public Member Functions

virtual ~SimpleEpEnergyStorage ()
 
virtual J getNominalEnergyCapacity () const override
 Returns the nominal energy capacity in the range [0, +infinity]. More...
 
virtual J getResidualEnergyCapacity () const override
 Returns the residual energy capacity in the range [0, nominalCapacity]. More...
 
- Public Member Functions inherited from inet::power::EpEnergyStorageBase
virtual void addEnergyConsumer (const IEnergyConsumer *energyConsumer) override
 Adds a new energy consumer to the energy source. More...
 
virtual void removeEnergyConsumer (const IEnergyConsumer *energyConsumer) override
 Removes a previously added energy consumer from this energy source. More...
 
virtual void addEnergyGenerator (const IEnergyGenerator *energyGenerator) override
 Adds a new energy generator to the energy sink. More...
 
virtual void removeEnergyGenerator (const IEnergyGenerator *energyGenerator) override
 Removes a previously added energy generator from this energy sink. More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double value, cObject *details) override
 
- Public Member Functions inherited from inet::power::EpEnergySourceBase
virtual W getTotalPowerConsumption () const override
 Returns the total power consumption in the range [0, +infinity). More...
 
- Public Member Functions inherited from inet::power::EnergySourceBase
virtual int getNumEnergyConsumers () const override
 Returns the number of energy consumers in the range [0, +infinity). More...
 
virtual const IEnergyConsumergetEnergyConsumer (int index) const override
 Returns the energy consumer for the provided index. More...
 
- Public Member Functions inherited from inet::power::IEnergySource
virtual ~IEnergySource ()
 
- Public Member Functions inherited from inet::power::EpEnergySinkBase
virtual W getTotalPowerGeneration () const override
 Returns the total power generation in the range [0, +infinity). More...
 
- Public Member Functions inherited from inet::power::EnergySinkBase
virtual int getNumEnergyGenerators () const override
 Returns the number of energy generators in the range [0, +infinity). More...
 
virtual const IEnergyGeneratorgetEnergyGenerator (int index) const override
 Returns the energy generator for the provided index. More...
 
- Public Member Functions inherited from inet::power::IEnergySink
virtual ~IEnergySink ()
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void updateTotalPowerConsumption () override
 
virtual void updateTotalPowerGeneration () override
 
virtual void executeNodeOperation (J newResidualCapacity)
 
virtual void setResidualCapacity (J newResidualCapacity)
 
virtual void updateResidualCapacity ()
 
virtual void scheduleTimer ()
 
- Protected Member Functions inherited from inet::power::EpEnergyStorageBase
void initialize (int stage) override
 
- Protected Member Functions inherited from inet::power::EpEnergySourceBase
virtual W computeTotalPowerConsumption () const
 
- Protected Member Functions inherited from inet::power::EpEnergySinkBase
virtual W computeTotalPowerGeneration () const
 

Protected Attributes

J nominalCapacity = J(NaN)
 The nominal capacity is in the range [0, +infinity). More...
 
J residualCapacity = J(NaN)
 The residual capacity is in the range [0, nominalCapacity]. More...
 
J printCapacityStep = J(NaN)
 Specifies the amount of capacity change which will be reported. More...
 
simtime_t lastResidualCapacityUpdate = -1
 The simulation time when the residual capacity was last updated. More...
 
cMessage * timer = nullptr
 The timer that is scheduled to the earliest time when the energy storage will be depleted, the energy storage will be charged. More...
 
J targetCapacity = J(NaN)
 The capacity that will be set when the timer expires. More...
 
LifecycleControllerlifecycleController = nullptr
 The lifecycle controller used to shutdown and start the node. More...
 
cModule * networkNode = nullptr
 The containing node module. More...
 
NodeStatusnodeStatus = nullptr
 The status of the node. More...
 
- Protected Attributes inherited from inet::power::EpEnergySourceBase
W totalPowerConsumption = W(NaN)
 
- Protected Attributes inherited from inet::power::EnergySourceBase
std::vector< const IEnergyConsumer * > energyConsumers
 
- Protected Attributes inherited from inet::power::EpEnergySinkBase
W totalPowerGeneration = W(NaN)
 
- Protected Attributes inherited from inet::power::EnergySinkBase
std::vector< const IEnergyGenerator * > energyGenerators
 

Additional Inherited Members

- Static Public Attributes inherited from inet::power::IEpEnergySource
static simsignal_t powerConsumptionChangedSignal = cComponent::registerSignal("powerConsumptionChanged")
 The signal that is used to publish power consumption changes. More...
 
- Static Public Attributes inherited from inet::power::IEpEnergySink
static simsignal_t powerGenerationChangedSignal = cComponent::registerSignal("powerGenerationChanged")
 The signal that is used to publish power generation changes. More...
 
- Static Public Attributes inherited from inet::power::IEpEnergyStorage
static simsignal_t residualEnergyCapacityChangedSignal = cComponent::registerSignal("residualEnergyCapacityChanged")
 The signal that is used to publish residual energy capacity changes also including when the energy storage becomes completely depleted or charged. More...
 

Detailed Description

This class implements a simple total power integrating energy storage.

It maintains its residual capacity by repeatedly scheduling a single timer to the next capacity update. The next update happens when either the storage becomes completely depleted, completely charged, or the next capacity report is done. Besides, it immediately updates the capacity when the total absorbed or provided power changes, and it also reschedules the timer.

See the corresponding NED file for more details.

Author
Levente Meszaros

Constructor & Destructor Documentation

inet::power::SimpleEpEnergyStorage::~SimpleEpEnergyStorage ( )
virtual
29 {
30  cancelAndDelete(timer);
31 }
cMessage * timer
The timer that is scheduled to the earliest time when the energy storage will be depleted, the energy storage will be charged.
Definition: SimpleEpEnergyStorage.h:69

Member Function Documentation

void inet::power::SimpleEpEnergyStorage::executeNodeOperation ( J  newResidualCapacity)
protectedvirtual

Referenced by setResidualCapacity().

81 {
82  if (newResidualCapacity <= J(0) && nodeStatus->getState() == NodeStatus::UP) {
83  EV_WARN << "Energy storage failed" << endl;
85  NodeCrashOperation *operation = new NodeCrashOperation();
86  operation->initialize(networkNode, params);
88  }
89 }
std::map< std::string, std::string > StringMap
Definition: LifecycleOperation.h:37
NodeStatus * nodeStatus
The status of the node.
Definition: SimpleEpEnergyStorage.h:89
cModule * networkNode
The containing node module.
Definition: SimpleEpEnergyStorage.h:84
LifecycleController * lifecycleController
The lifecycle controller used to shutdown and start the node.
Definition: SimpleEpEnergyStorage.h:79
compose< N, m > J
Definition: Units.h:769
virtual bool initiateOperation(LifecycleOperation *operation, IDoneCallback *completionCallback=nullptr)
Initiate an operation.
Definition: LifecycleController.cc:87
virtual State getState() const
Definition: NodeStatus.h:48
Definition: NodeStatus.h:40
virtual J inet::power::SimpleEpEnergyStorage::getNominalEnergyCapacity ( ) const
inlineoverridevirtual

Returns the nominal energy capacity in the range [0, +infinity].

It specifies the maximum amount of energy that the energy storage can contain.

Implements inet::power::IEpEnergyStorage.

106 { return nominalCapacity; }
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:48
J inet::power::SimpleEpEnergyStorage::getResidualEnergyCapacity ( ) const
overridevirtual

Returns the residual energy capacity in the range [0, nominalCapacity].

It specifies the amount of energy that the energy storage contains at the moment.

Implements inet::power::IEpEnergyStorage.

92 {
93  const_cast<SimpleEpEnergyStorage *>(this)->updateResidualCapacity();
94  return residualCapacity;
95 }
virtual void updateResidualCapacity()
Definition: SimpleEpEnergyStorage.cc:110
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:53
void inet::power::SimpleEpEnergyStorage::handleMessage ( cMessage *  message)
overrideprotectedvirtual
56 {
57  if (message == timer) {
59  scheduleTimer();
60  EV_INFO << "Residual capacity = " << residualCapacity.get() << " (" << (int)round(unit(residualCapacity / nominalCapacity).get() * 100) << "%)" << endl;
61  }
62  else
63  throw cRuntimeError("Unknown message");
64 }
virtual void scheduleTimer()
Definition: SimpleEpEnergyStorage.cc:123
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:53
const value_type & get() const
Definition: Units.h:89
J targetCapacity
The capacity that will be set when the timer expires.
Definition: SimpleEpEnergyStorage.h:74
int round(double d)
Returns an integer that corresponds to rounded double parameter.
Definition: INETMath.h:151
cMessage * timer
The timer that is scheduled to the earliest time when the energy storage will be depleted, the energy storage will be charged.
Definition: SimpleEpEnergyStorage.h:69
pow< internal::none, 0 > unit
Definition: Units.h:60
virtual void setResidualCapacity(J newResidualCapacity)
Definition: SimpleEpEnergyStorage.cc:97
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:48
void inet::power::SimpleEpEnergyStorage::initialize ( int  stage)
overrideprotectedvirtual
34 {
36  if (stage == INITSTAGE_LOCAL) {
37  nominalCapacity = J(par("nominalCapacity"));
38  printCapacityStep = J(par("printCapacityStep"));
39  timer = new cMessage("timer");
41  if (networkNode != nullptr) {
42  nodeStatus = dynamic_cast<NodeStatus *>(networkNode->getSubmodule("status"));
43  if (!nodeStatus)
44  throw cRuntimeError("Cannot find node status");
45  lifecycleController = dynamic_cast<LifecycleController *>(getModuleByPath("lifecycleController"));
47  throw cRuntimeError("Cannot find lifecycle controller");
48  }
49  setResidualCapacity(J(par("initialCapacity")));
50  scheduleTimer();
51  WATCH(residualCapacity);
52  }
53 }
J printCapacityStep
Specifies the amount of capacity change which will be reported.
Definition: SimpleEpEnergyStorage.h:58
virtual void scheduleTimer()
Definition: SimpleEpEnergyStorage.cc:123
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:53
NodeStatus * nodeStatus
The status of the node.
Definition: SimpleEpEnergyStorage.h:89
void initialize(int stage) override
Definition: EpEnergyStorageBase.cc:24
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:56
Local initializations.
Definition: InitStages.h:35
cModule * networkNode
The containing node module.
Definition: SimpleEpEnergyStorage.h:84
LifecycleController * lifecycleController
The lifecycle controller used to shutdown and start the node.
Definition: SimpleEpEnergyStorage.h:79
cMessage * timer
The timer that is scheduled to the earliest time when the energy storage will be depleted, the energy storage will be charged.
Definition: SimpleEpEnergyStorage.h:69
virtual void setResidualCapacity(J newResidualCapacity)
Definition: SimpleEpEnergyStorage.cc:97
compose< N, m > J
Definition: Units.h:769
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:48
void inet::power::SimpleEpEnergyStorage::scheduleTimer ( )
protectedvirtual

Referenced by handleMessage(), initialize(), updateTotalPowerConsumption(), and updateTotalPowerGeneration().

124 {
127  if (totalPower > W(0)) {
129  // NOTE: make sure capacity will change over time despite double arithmetic
130  simtime_t remainingTime = unit((targetCapacity - residualCapacity) / totalPower / s(1)).get();
131  if (remainingTime == 0)
133  }
134  else if (totalPower < W(0)) {
136  // make sure capacity will change over time despite double arithmetic
137  simtime_t remainingTime = unit((targetCapacity - residualCapacity) / totalPower / s(1)).get();
138  if (remainingTime == 0)
140  }
141  // enforce target capacity to be in range
142  if (targetCapacity < J(0))
143  targetCapacity = J(0);
144  else if (targetCapacity > nominalCapacity)
146  simtime_t remainingTime = unit((targetCapacity - residualCapacity) / totalPower / s(1)).get();
147  if (timer->isScheduled())
148  cancelEvent(timer);
149  // don't schedule if there's no progress
150  if (remainingTime > 0)
151  scheduleAt(simTime() + remainingTime, timer);
152 }
J printCapacityStep
Specifies the amount of capacity change which will be reported.
Definition: SimpleEpEnergyStorage.h:58
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:53
const value_type & get() const
Definition: Units.h:89
W totalPowerConsumption
Definition: EpEnergySourceBase.h:32
J targetCapacity
The capacity that will be set when the timer expires.
Definition: SimpleEpEnergyStorage.h:74
compose< J, pow< s,-1 > > W
Definition: Units.h:770
cMessage * timer
The timer that is scheduled to the earliest time when the energy storage will be depleted, the energy storage will be charged.
Definition: SimpleEpEnergyStorage.h:69
pow< internal::none, 0 > unit
Definition: Units.h:60
W totalPowerGeneration
Definition: EpEnergySinkBase.h:32
value< double, units::s > s
Definition: Units.h:1049
compose< N, m > J
Definition: Units.h:769
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:48
void inet::power::SimpleEpEnergyStorage::setResidualCapacity ( J  newResidualCapacity)
protectedvirtual

Referenced by handleMessage(), initialize(), and updateResidualCapacity().

98 {
99  residualCapacity = newResidualCapacity;
100  lastResidualCapacityUpdate = simTime();
101  if (residualCapacity == J(0))
102  EV_WARN << "Energy storage depleted" << endl;
103  else if (residualCapacity == nominalCapacity)
104  EV_INFO << "Energy storage charged" << endl;
105  if (networkNode != nullptr)
106  executeNodeOperation(newResidualCapacity);
108 }
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:53
const value_type & get() const
Definition: Units.h:89
simtime_t lastResidualCapacityUpdate
The simulation time when the residual capacity was last updated.
Definition: SimpleEpEnergyStorage.h:63
cModule * networkNode
The containing node module.
Definition: SimpleEpEnergyStorage.h:84
virtual void executeNodeOperation(J newResidualCapacity)
Definition: SimpleEpEnergyStorage.cc:80
static simsignal_t residualEnergyCapacityChangedSignal
The signal that is used to publish residual energy capacity changes also including when the energy st...
Definition: IEpEnergyStorage.h:43
compose< N, m > J
Definition: Units.h:769
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:48
void inet::power::SimpleEpEnergyStorage::updateResidualCapacity ( )
protectedvirtual

Referenced by getResidualEnergyCapacity(), updateTotalPowerConsumption(), and updateTotalPowerGeneration().

111 {
112  simtime_t currentSimulationTime = simTime();
113  if (currentSimulationTime != lastResidualCapacityUpdate) {
114  J newResidualCapacity = residualCapacity + s((currentSimulationTime - lastResidualCapacityUpdate).dbl()) * (totalPowerGeneration - totalPowerConsumption);
115  if (newResidualCapacity < J(0))
116  newResidualCapacity = J(0);
117  else if (newResidualCapacity > nominalCapacity)
118  newResidualCapacity = nominalCapacity;
119  setResidualCapacity(newResidualCapacity);
120  }
121 }
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:53
simtime_t lastResidualCapacityUpdate
The simulation time when the residual capacity was last updated.
Definition: SimpleEpEnergyStorage.h:63
W totalPowerConsumption
Definition: EpEnergySourceBase.h:32
W totalPowerGeneration
Definition: EpEnergySinkBase.h:32
virtual void setResidualCapacity(J newResidualCapacity)
Definition: SimpleEpEnergyStorage.cc:97
value< double, units::s > s
Definition: Units.h:1049
compose< N, m > J
Definition: Units.h:769
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:48
void inet::power::SimpleEpEnergyStorage::updateTotalPowerConsumption ( )
overrideprotectedvirtual

Reimplemented from inet::power::EpEnergyStorageBase.

67 {
70  scheduleTimer();
71 }
virtual void updateResidualCapacity()
Definition: SimpleEpEnergyStorage.cc:110
virtual void scheduleTimer()
Definition: SimpleEpEnergyStorage.cc:123
virtual void updateTotalPowerConsumption() override
Definition: EpEnergyStorageBase.cc:34
void inet::power::SimpleEpEnergyStorage::updateTotalPowerGeneration ( )
overrideprotectedvirtual

Reimplemented from inet::power::EpEnergyStorageBase.

74 {
77  scheduleTimer();
78 }
virtual void updateResidualCapacity()
Definition: SimpleEpEnergyStorage.cc:110
virtual void scheduleTimer()
Definition: SimpleEpEnergyStorage.cc:123
virtual void updateTotalPowerGeneration() override
Definition: EpEnergyStorageBase.cc:40

Member Data Documentation

simtime_t inet::power::SimpleEpEnergyStorage::lastResidualCapacityUpdate = -1
protected

The simulation time when the residual capacity was last updated.

Referenced by setResidualCapacity(), and updateResidualCapacity().

LifecycleController* inet::power::SimpleEpEnergyStorage::lifecycleController = nullptr
protected

The lifecycle controller used to shutdown and start the node.

Referenced by executeNodeOperation(), and initialize().

cModule* inet::power::SimpleEpEnergyStorage::networkNode = nullptr
protected

The containing node module.

Referenced by executeNodeOperation(), initialize(), and setResidualCapacity().

NodeStatus* inet::power::SimpleEpEnergyStorage::nodeStatus = nullptr
protected

The status of the node.

Referenced by executeNodeOperation(), and initialize().

J inet::power::SimpleEpEnergyStorage::nominalCapacity = J(NaN)
protected

The nominal capacity is in the range [0, +infinity).

Referenced by handleMessage(), initialize(), scheduleTimer(), setResidualCapacity(), and updateResidualCapacity().

J inet::power::SimpleEpEnergyStorage::printCapacityStep = J(NaN)
protected

Specifies the amount of capacity change which will be reported.

Referenced by initialize(), and scheduleTimer().

J inet::power::SimpleEpEnergyStorage::residualCapacity = J(NaN)
protected

The residual capacity is in the range [0, nominalCapacity].

Referenced by getResidualEnergyCapacity(), handleMessage(), initialize(), scheduleTimer(), setResidualCapacity(), and updateResidualCapacity().

J inet::power::SimpleEpEnergyStorage::targetCapacity = J(NaN)
protected

The capacity that will be set when the timer expires.

Referenced by handleMessage(), and scheduleTimer().

cMessage* inet::power::SimpleEpEnergyStorage::timer = nullptr
protected

The timer that is scheduled to the earliest time when the energy storage will be depleted, the energy storage will be charged.

Referenced by handleMessage(), initialize(), scheduleTimer(), and ~SimpleEpEnergyStorage().


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