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::StringFormat::IDirectiveResolver inet::LifecycleController 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 ()
 
- Public Member Functions inherited from inet::LifecycleController
 LifecycleController ()
 
virtual ~LifecycleController ()
 
virtual bool initiateOperation (LifecycleOperation *operation, IDoneCallback *completionCallback=nullptr)
 Initiate an operation. More...
 

Protected Member Functions

virtual void initialize (int stage) override
 
virtual void handleMessage (cMessage *message) override
 
virtual void refreshDisplay () const override
 
virtual void updateDisplayString () const
 
virtual const char * resolveDirective (char directive) const 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::EpEnergySourceBase
virtual W computeTotalPowerConsumption () const
 
- Protected Member Functions inherited from inet::power::EpEnergySinkBase
virtual W computeTotalPowerGeneration () const
 
- Protected Member Functions inherited from inet::LifecycleController
virtual bool resumeOperation (LifecycleOperation *operation)
 
virtual void doOneStage (LifecycleOperation *operation, cModule *submodule)
 
virtual void moduleOperationStageCompleted (Callback *callback)
 

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...
 
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
 
- Protected Attributes inherited from inet::LifecycleController
CallbackspareCallback = nullptr
 

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.

Constructor & Destructor Documentation

◆ ~SimpleEpEnergyStorage()

inet::power::SimpleEpEnergyStorage::~SimpleEpEnergyStorage ( )
virtual
21 {
22  cancelAndDelete(timer);
23 }

Member Function Documentation

◆ executeNodeOperation()

void inet::power::SimpleEpEnergyStorage::executeNodeOperation ( J  newResidualCapacity)
protectedvirtual
99 {
100  if (newResidualCapacity <= J(0) && nodeStatus->getState() == NodeStatus::UP) {
101  EV_WARN << "Energy storage failed" << endl;
103  ModuleCrashOperation *operation = new ModuleCrashOperation();
104  operation->initialize(networkNode, params);
105  initiateOperation(operation);
106  }
107 }

Referenced by setResidualCapacity().

◆ getNominalEnergyCapacity()

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.

94 { return nominalCapacity; }

Referenced by resolveDirective().

◆ getResidualEnergyCapacity()

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.

110 {
111  const_cast<SimpleEpEnergyStorage *>(this)->updateResidualCapacity();
112  return residualCapacity;
113 }

Referenced by resolveDirective().

◆ handleMessage()

void inet::power::SimpleEpEnergyStorage::handleMessage ( cMessage *  message)
overrideprotectedvirtual
45 {
46  if (message == timer) {
48  scheduleTimer();
49  EV_INFO << "Residual capacity = " << residualCapacity.get() << " (" << (int)round(unit(residualCapacity / nominalCapacity).get() * 100) << "%)" << endl;
50  }
51  else
52  throw cRuntimeError("Unknown message");
53 }

◆ initialize()

void inet::power::SimpleEpEnergyStorage::initialize ( int  stage)
overrideprotectedvirtual

Reimplemented from inet::power::EpEnergyStorageBase.

26 {
28  if (stage == INITSTAGE_LOCAL) {
29  nominalCapacity = J(par("nominalCapacity"));
30  printCapacityStep = J(par("printCapacityStep"));
31  timer = new cMessage("timer");
33  if (networkNode != nullptr) {
34  nodeStatus = dynamic_cast<NodeStatus *>(networkNode->getSubmodule("status"));
35  if (!nodeStatus)
36  throw cRuntimeError("Cannot find node status");
37  }
38  setResidualCapacity(J(par("initialCapacity")));
39  scheduleTimer();
40  WATCH(residualCapacity);
41  }
42 }

◆ refreshDisplay()

void inet::power::SimpleEpEnergyStorage::refreshDisplay ( ) const
overrideprotectedvirtual
56 {
58 }

◆ resolveDirective()

const char * inet::power::SimpleEpEnergyStorage::resolveDirective ( char  directive) const
overrideprotectedvirtual

Implements inet::StringFormat::IDirectiveResolver.

69 {
70  static std::string result;
71  switch (directive) {
72  case 'c':
73  result = getResidualEnergyCapacity().str();
74  break;
75  case 'p':
76  result = std::to_string((int)std::round(100 * unit(getResidualEnergyCapacity() / getNominalEnergyCapacity()).get())) + "%";
77  break;
78  default:
79  throw cRuntimeError("Unknown directive: %c", directive);
80  }
81  return result.c_str();
82 }

◆ scheduleTimer()

void inet::power::SimpleEpEnergyStorage::scheduleTimer ( )
protectedvirtual
142 {
145  if (totalPower > W(0)) {
147  // NOTE: make sure capacity will change over time despite double arithmetic
148  simtime_t remainingTime = unit((targetCapacity - residualCapacity) / totalPower / s(1)).get();
149  if (remainingTime == 0)
151  }
152  else if (totalPower < W(0)) {
154  // make sure capacity will change over time despite double arithmetic
155  simtime_t remainingTime = unit((targetCapacity - residualCapacity) / totalPower / s(1)).get();
156  if (remainingTime == 0)
158  }
159  // enforce target capacity to be in range
160  if (targetCapacity < J(0))
161  targetCapacity = J(0);
162  else if (targetCapacity > nominalCapacity)
164  if (timer->isScheduled())
165  cancelEvent(timer);
166  // don't schedule if there's no progress
167  if (totalPower != W(0)) {
168  simtime_t remainingTime = unit((targetCapacity - residualCapacity) / totalPower / s(1)).get();
169  if (remainingTime > 0)
170  scheduleAfter(remainingTime, timer);
171  }
172 }

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

◆ setResidualCapacity()

void inet::power::SimpleEpEnergyStorage::setResidualCapacity ( J  newResidualCapacity)
protectedvirtual
116 {
117  residualCapacity = newResidualCapacity;
118  lastResidualCapacityUpdate = simTime();
119  if (residualCapacity == J(0))
120  EV_WARN << "Energy storage depleted" << endl;
121  else if (residualCapacity == nominalCapacity)
122  EV_INFO << "Energy storage charged" << endl;
123  if (networkNode != nullptr)
124  executeNodeOperation(newResidualCapacity);
126 }

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

◆ updateDisplayString()

void inet::power::SimpleEpEnergyStorage::updateDisplayString ( ) const
protectedvirtual
61 {
62  if (getEnvir()->isGUI()) {
63  auto text = StringFormat::formatString(par("displayStringTextFormat"), this);
64  getDisplayString().setTagArg("t", 0, text);
65  }
66 }

Referenced by refreshDisplay().

◆ updateResidualCapacity()

void inet::power::SimpleEpEnergyStorage::updateResidualCapacity ( )
protectedvirtual
129 {
130  simtime_t currentSimulationTime = simTime();
131  if (currentSimulationTime != lastResidualCapacityUpdate) {
132  J newResidualCapacity = residualCapacity + s((currentSimulationTime - lastResidualCapacityUpdate).dbl()) * (totalPowerGeneration - totalPowerConsumption);
133  if (newResidualCapacity < J(0))
134  newResidualCapacity = J(0);
135  else if (newResidualCapacity > nominalCapacity)
136  newResidualCapacity = nominalCapacity;
137  setResidualCapacity(newResidualCapacity);
138  }
139 }

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

◆ updateTotalPowerConsumption()

void inet::power::SimpleEpEnergyStorage::updateTotalPowerConsumption ( )
overrideprotectedvirtual

◆ updateTotalPowerGeneration()

void inet::power::SimpleEpEnergyStorage::updateTotalPowerGeneration ( )
overrideprotectedvirtual

Member Data Documentation

◆ lastResidualCapacityUpdate

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

The simulation time when the residual capacity was last updated.

Referenced by setResidualCapacity(), and updateResidualCapacity().

◆ networkNode

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

The containing node module.

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

◆ nodeStatus

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

The status of the node.

Referenced by executeNodeOperation(), and initialize().

◆ nominalCapacity

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().

◆ printCapacityStep

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

Specifies the amount of capacity change which will be reported.

Referenced by initialize(), and scheduleTimer().

◆ residualCapacity

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().

◆ targetCapacity

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

The capacity that will be set when the timer expires.

Referenced by handleMessage(), and scheduleTimer().

◆ timer

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:
inet::power::SimpleEpEnergyStorage::networkNode
cModule * networkNode
The containing node module.
Definition: SimpleEpEnergyStorage.h:69
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::units::value::str
std::string str() const
Definition: Units.h:101
inet::power::SimpleEpEnergyStorage::nominalCapacity
J nominalCapacity
The nominal capacity is in the range [0, +infinity).
Definition: SimpleEpEnergyStorage.h:38
inet::power::SimpleEpEnergyStorage::residualCapacity
J residualCapacity
The residual capacity is in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.h:43
inet::power::SimpleEpEnergyStorage::nodeStatus
NodeStatus * nodeStatus
The status of the node.
Definition: SimpleEpEnergyStorage.h:74
inet::power::SimpleEpEnergyStorage::timer
cMessage * timer
The timer that is scheduled to the earliest time when the energy storage will be depleted,...
Definition: SimpleEpEnergyStorage.h:59
inet::units::units::W
compose< J, pow< s, -1 > > W
Definition: Units.h:939
inet::power::EpEnergySourceBase::totalPowerConsumption
W totalPowerConsumption
Definition: EpEnergySourceBase.h:22
inet::power::IEpEnergyStorage::residualEnergyCapacityChangedSignal
static simsignal_t residualEnergyCapacityChangedSignal
The signal that is used to publish residual energy capacity changes also including when the energy st...
Definition: IEpEnergyStorage.h:32
inet::power::SimpleEpEnergyStorage::executeNodeOperation
virtual void executeNodeOperation(J newResidualCapacity)
Definition: SimpleEpEnergyStorage.cc:98
inet::power::SimpleEpEnergyStorage::targetCapacity
J targetCapacity
The capacity that will be set when the timer expires.
Definition: SimpleEpEnergyStorage.h:64
inet::power::EpEnergyStorageBase::updateTotalPowerConsumption
virtual void updateTotalPowerConsumption() override
Definition: EpEnergyStorageBase.cc:24
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::power::SimpleEpEnergyStorage::lastResidualCapacityUpdate
simtime_t lastResidualCapacityUpdate
The simulation time when the residual capacity was last updated.
Definition: SimpleEpEnergyStorage.h:53
inet::power::EpEnergyStorageBase::initialize
virtual void initialize(int stage) override
Definition: EpEnergyStorageBase.cc:14
inet::LifecycleOperation::StringMap
std::map< std::string, std::string > StringMap
Definition: LifecycleOperation.h:28
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::power::SimpleEpEnergyStorage::printCapacityStep
J printCapacityStep
Specifies the amount of capacity change which will be reported.
Definition: SimpleEpEnergyStorage.h:48
inet::LifecycleController::initiateOperation
virtual bool initiateOperation(LifecycleOperation *operation, IDoneCallback *completionCallback=nullptr)
Initiate an operation.
Definition: LifecycleController.cc:46
inet::math::round
int round(double d)
Returns an integer that corresponds to rounded double parameter.
Definition: INETMath.h:143
inet::units::unit
pow< internal::none, 0 > unit
Definition: Units.h:72
inet::units::units::J
compose< N, m > J
Definition: Units.h:938
inet::power::SimpleEpEnergyStorage::updateResidualCapacity
virtual void updateResidualCapacity()
Definition: SimpleEpEnergyStorage.cc:128
inet::power::SimpleEpEnergyStorage::getNominalEnergyCapacity
virtual J getNominalEnergyCapacity() const override
Returns the nominal energy capacity in the range [0, +infinity].
Definition: SimpleEpEnergyStorage.h:94
inet::NodeStatus::UP
@ UP
Definition: NodeStatus.h:28
inet::StringFormat::formatString
const char * formatString(IDirectiveResolver *resolver) const
Definition: StringFormat.cc:17
inet::units::value::get
const value_type & get() const
Definition: Units.h:108
inet::power::SimpleEpEnergyStorage::getResidualEnergyCapacity
virtual J getResidualEnergyCapacity() const override
Returns the residual energy capacity in the range [0, nominalCapacity].
Definition: SimpleEpEnergyStorage.cc:109
inet::power::SimpleEpEnergyStorage::setResidualCapacity
virtual void setResidualCapacity(J newResidualCapacity)
Definition: SimpleEpEnergyStorage.cc:115
inet::power::SimpleEpEnergyStorage::scheduleTimer
virtual void scheduleTimer()
Definition: SimpleEpEnergyStorage.cc:141
inet::power::EpEnergyStorageBase::updateTotalPowerGeneration
virtual void updateTotalPowerGeneration() override
Definition: EpEnergyStorageBase.cc:30
inet::power::SimpleEpEnergyStorage::updateDisplayString
virtual void updateDisplayString() const
Definition: SimpleEpEnergyStorage.cc:60
inet::NodeStatus::getState
virtual State getState() const
Definition: NodeStatus.h:35
inet::power::EpEnergySinkBase::totalPowerGeneration
W totalPowerGeneration
Definition: EpEnergySinkBase.h:22