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

#include <SimpleEpEnergyManagement.h>

Inheritance diagram for inet::power::SimpleEpEnergyManagement:
inet::power::IEpEnergyManagement inet::LifecycleController inet::power::IEnergyManagement

Public Member Functions

virtual ~SimpleEpEnergyManagement ()
 
virtual IEnergyStoragegetEnergyStorage () const override
 Returns the energy storage that is managed by this energy management. More...
 
virtual J getEstimatedEnergyCapacity () const override
 Returns the estimated energy capacity in the range [0, +infinity). More...
 
virtual void receiveSignal (cComponent *source, simsignal_t signal, double value, cObject *details) override
 
- Public Member Functions inherited from inet::power::IEnergyManagement
virtual ~IEnergyManagement ()
 
- 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 executeNodeOperation (J estimatedEnergyCapacity)
 
virtual void scheduleLifecycleOperationTimer ()
 
- 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 nodeShutdownCapacity = J(NaN)
 
J nodeStartCapacity = J(NaN)
 
IEpEnergyStorageenergyStorage = nullptr
 
cModule * networkNode = nullptr
 
NodeStatusnodeStatus = nullptr
 
cMessage * lifecycleOperationTimer = nullptr
 
J targetCapacity = J(NaN)
 
- Protected Attributes inherited from inet::LifecycleController
CallbackspareCallback = nullptr
 

Constructor & Destructor Documentation

◆ ~SimpleEpEnergyManagement()

inet::power::SimpleEpEnergyManagement::~SimpleEpEnergyManagement ( )
virtual
20 {
21  cancelAndDelete(lifecycleOperationTimer);
22 }

Member Function Documentation

◆ executeNodeOperation()

void inet::power::SimpleEpEnergyManagement::executeNodeOperation ( J  estimatedEnergyCapacity)
protectedvirtual
68 {
69  if (!std::isnan(nodeShutdownCapacity.get()) && estimatedEnergyCapacity <= nodeShutdownCapacity && nodeStatus->getState() == NodeStatus::UP) {
70  EV_WARN << "Capacity reached node shutdown threshold" << endl;
72  ModuleStopOperation *operation = new ModuleStopOperation();
73  operation->initialize(networkNode, params);
74  initiateOperation(operation);
75  }
76  else if (!std::isnan(nodeStartCapacity.get()) && estimatedEnergyCapacity >= nodeStartCapacity && nodeStatus->getState() == NodeStatus::DOWN) {
77  EV_INFO << "Capacity reached node start threshold" << endl;
79  ModuleStartOperation *operation = new ModuleStartOperation();
80  operation->initialize(networkNode, params);
81  initiateOperation(operation);
82  }
83 }

Referenced by handleMessage(), and receiveSignal().

◆ getEnergyStorage()

virtual IEnergyStorage* inet::power::SimpleEpEnergyManagement::getEnergyStorage ( ) const
inlineoverridevirtual

Returns the energy storage that is managed by this energy management.

This function never returns nullptr.

Implements inet::power::IEnergyManagement.

45 { return energyStorage; }

◆ getEstimatedEnergyCapacity()

J inet::power::SimpleEpEnergyManagement::getEstimatedEnergyCapacity ( ) const
overridevirtual

Returns the estimated energy capacity in the range [0, +infinity).

It specifies the amount of energy that the energy storage contains at the moment according to the estimation of the management.

Implements inet::power::IEpEnergyManagement.

114 {
115  // NOTE: cheat with estimation and return the actual energy capacity known by the energy storage
117 }

Referenced by handleMessage(), receiveSignal(), and scheduleLifecycleOperationTimer().

◆ handleMessage()

void inet::power::SimpleEpEnergyManagement::handleMessage ( cMessage *  message)
overrideprotectedvirtual
42 {
43  if (message == lifecycleOperationTimer) {
46  }
47  else
48  throw cRuntimeError("Unknown message");
49 }

◆ initialize()

void inet::power::SimpleEpEnergyManagement::initialize ( int  stage)
overrideprotectedvirtual
25 {
26  if (stage == INITSTAGE_LOCAL) {
27  nodeShutdownCapacity = J(par("nodeShutdownCapacity"));
28  nodeStartCapacity = J(par("nodeStartCapacity"));
30  energyStorage = check_and_cast<IEpEnergyStorage *>(networkNode->getSubmodule("energyStorage"));
31  auto energyStorageModule = check_and_cast<cModule *>(energyStorage);
32  energyStorageModule->subscribe(IEpEnergySource::powerConsumptionChangedSignal, this);
33  energyStorageModule->subscribe(IEpEnergySink::powerGenerationChangedSignal, this);
34  nodeStatus = dynamic_cast<NodeStatus *>(networkNode->getSubmodule("status"));
35  if (!nodeStatus)
36  throw cRuntimeError("Cannot find node status");
37  lifecycleOperationTimer = new cMessage("lifecycleOperation");
38  }
39 }

◆ receiveSignal()

void inet::power::SimpleEpEnergyManagement::receiveSignal ( cComponent *  source,
simsignal_t  signal,
double  value,
cObject *  details 
)
overridevirtual
120 {
121  Enter_Method("%s", cComponent::getSignalName(signal));
122 
126  }
127 }

◆ refreshDisplay()

void inet::power::SimpleEpEnergyManagement::refreshDisplay ( ) const
overrideprotectedvirtual
52 {
53  std::string text;
54  if (std::isnan(targetCapacity.get()))
55  text = "";
57  text = "shutdown";
59  text = "start";
60  else
61  throw cRuntimeError("Invalid state");
62  if (text.length() != 0)
63  text += " in " + (lifecycleOperationTimer->getArrivalTime() - simTime()).str() + " s";
64  getDisplayString().setTagArg("t", 0, text.c_str());
65 }

◆ scheduleLifecycleOperationTimer()

void inet::power::SimpleEpEnergyManagement::scheduleLifecycleOperationTimer ( )
protectedvirtual
86 {
87  targetCapacity = J(NaN);
88  J estimatedResidualCapacity = getEstimatedEnergyCapacity();
90  if (totalPower > W(0)) {
91  // override target capacity if start is needed
92  if (!std::isnan(nodeStartCapacity.get()) && nodeStatus->getState() == NodeStatus::DOWN && estimatedResidualCapacity < nodeStartCapacity)
94  }
95  else if (totalPower < W(0)) {
96  // override target capacity if shutdown is needed
97  if (!std::isnan(nodeShutdownCapacity.get()) && nodeStatus->getState() == NodeStatus::UP && estimatedResidualCapacity > nodeShutdownCapacity)
99  }
100  if (lifecycleOperationTimer->isScheduled())
101  cancelEvent(lifecycleOperationTimer);
102  if (totalPower != W(0)) {
103  // enforce target capacity to be in range
104  simtime_t remainingTime = unit((targetCapacity - estimatedResidualCapacity) / totalPower / s(1)).get();
105  // make sure the targetCapacity is reached despite floating point arithmetic
106  remainingTime.setRaw(remainingTime.raw() + 1);
107  // don't schedule if there's no progress
108  if (remainingTime > 0)
109  scheduleAfter(remainingTime, lifecycleOperationTimer);
110  }
111 }

Referenced by handleMessage(), and receiveSignal().

Member Data Documentation

◆ energyStorage

IEpEnergyStorage* inet::power::SimpleEpEnergyManagement::energyStorage = nullptr
protected

◆ lifecycleOperationTimer

cMessage* inet::power::SimpleEpEnergyManagement::lifecycleOperationTimer = nullptr
protected

◆ networkNode

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

Referenced by executeNodeOperation(), and initialize().

◆ nodeShutdownCapacity

J inet::power::SimpleEpEnergyManagement::nodeShutdownCapacity = J(NaN)
protected

◆ nodeStartCapacity

J inet::power::SimpleEpEnergyManagement::nodeStartCapacity = J(NaN)
protected

◆ nodeStatus

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

◆ targetCapacity

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

The documentation for this class was generated from the following files:
inet::findContainingNode
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
inet::power::SimpleEpEnergyManagement::executeNodeOperation
virtual void executeNodeOperation(J estimatedEnergyCapacity)
Definition: SimpleEpEnergyManagement.cc:67
inet::power::SimpleEpEnergyManagement::networkNode
cModule * networkNode
Definition: SimpleEpEnergyManagement.h:29
inet::power::SimpleEpEnergyManagement::getEstimatedEnergyCapacity
virtual J getEstimatedEnergyCapacity() const override
Returns the estimated energy capacity in the range [0, +infinity).
Definition: SimpleEpEnergyManagement.cc:113
inet::units::units::W
compose< J, pow< s, -1 > > W
Definition: Units.h:939
inet::power::SimpleEpEnergyManagement::energyStorage
IEpEnergyStorage * energyStorage
Definition: SimpleEpEnergyManagement.h:26
inet::NodeStatus::DOWN
@ DOWN
Definition: NodeStatus.h:28
inet::power::SimpleEpEnergyManagement::nodeStatus
NodeStatus * nodeStatus
Definition: SimpleEpEnergyManagement.h:30
inet::power::SimpleEpEnergyManagement::nodeStartCapacity
J nodeStartCapacity
Definition: SimpleEpEnergyManagement.h:25
inet::power::IEpEnergyStorage::getResidualEnergyCapacity
virtual J getResidualEnergyCapacity() const =0
Returns the residual energy capacity in the range [0, nominalCapacity].
inet::units::values::s
value< double, units::s > s
Definition: Units.h:1235
inet::LifecycleOperation::StringMap
std::map< std::string, std::string > StringMap
Definition: LifecycleOperation.h:28
inet::power::SimpleEpEnergyManagement::scheduleLifecycleOperationTimer
virtual void scheduleLifecycleOperationTimer()
Definition: SimpleEpEnergyManagement.cc:85
inet::power::IEpEnergySource::getTotalPowerConsumption
virtual W getTotalPowerConsumption() const =0
Returns the total power consumption in the range [0, +infinity).
NaN
#define NaN
Definition: INETMath.h:91
inet::INITSTAGE_LOCAL
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
inet::LifecycleController::initiateOperation
virtual bool initiateOperation(LifecycleOperation *operation, IDoneCallback *completionCallback=nullptr)
Initiate an operation.
Definition: LifecycleController.cc:46
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::SimpleEpEnergyManagement::lifecycleOperationTimer
cMessage * lifecycleOperationTimer
Definition: SimpleEpEnergyManagement.h:31
inet::NodeStatus::UP
@ UP
Definition: NodeStatus.h:28
Enter_Method
#define Enter_Method(...)
Definition: SelfDoc.h:71
inet::power::SimpleEpEnergyManagement::targetCapacity
J targetCapacity
Definition: SimpleEpEnergyManagement.h:32
inet::power::IEpEnergySink::getTotalPowerGeneration
virtual W getTotalPowerGeneration() const =0
Returns the total power generation in the range [0, +infinity).
inet::units::value::get
const value_type & get() const
Definition: Units.h:108
inet::power::IEpEnergySink::powerGenerationChangedSignal
static simsignal_t powerGenerationChangedSignal
The signal that is used to publish power generation changes.
Definition: IEpEnergySink.h:29
inet::power::IEpEnergySource::powerConsumptionChangedSignal
static simsignal_t powerConsumptionChangedSignal
The signal that is used to publish power consumption changes.
Definition: IEpEnergySource.h:32
inet::power::SimpleEpEnergyManagement::nodeShutdownCapacity
J nodeShutdownCapacity
Definition: SimpleEpEnergyManagement.h:24
inet::NodeStatus::getState
virtual State getState() const
Definition: NodeStatus.h:35