A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
basic-energy-source.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
7
*/
8
9
#ifndef BASIC_ENERGY_SOURCE_H
10
#define BASIC_ENERGY_SOURCE_H
11
12
#include "
energy-source.h
"
13
14
#include "ns3/event-id.h"
15
#include "ns3/nstime.h"
16
#include "ns3/traced-value.h"
17
18
namespace
ns3
19
{
20
namespace
energy
21
{
22
23
/**
24
* \ingroup energy
25
* BasicEnergySource decreases/increases remaining energy stored in itself in
26
* linearly.
27
*
28
*/
29
class
BasicEnergySource
:
public
EnergySource
30
{
31
public
:
32
/**
33
* \brief Get the type ID.
34
* \return The object TypeId.
35
*/
36
static
TypeId
GetTypeId
();
37
BasicEnergySource
();
38
~BasicEnergySource
()
override
;
39
40
/**
41
* \return Initial energy stored in energy source, in Joules.
42
*
43
* Implements GetInitialEnergy.
44
*/
45
double
GetInitialEnergy
()
const override
;
46
47
/**
48
* \returns Supply voltage at the energy source.
49
*
50
* Implements GetSupplyVoltage.
51
*/
52
double
GetSupplyVoltage
()
const override
;
53
54
/**
55
* \return Remaining energy in energy source, in Joules
56
*
57
* Implements GetRemainingEnergy.
58
*/
59
double
GetRemainingEnergy
()
override
;
60
61
/**
62
* \returns Energy fraction.
63
*
64
* Implements GetEnergyFraction.
65
*/
66
double
GetEnergyFraction
()
override
;
67
68
/**
69
* Implements UpdateEnergySource.
70
*/
71
void
UpdateEnergySource
()
override
;
72
73
/**
74
* \param initialEnergyJ Initial energy, in Joules
75
*
76
* Sets initial energy stored in the energy source. Note that initial energy
77
* is assumed to be set before simulation starts and is set only once per
78
* simulation.
79
*/
80
void
SetInitialEnergy
(
double
initialEnergyJ);
81
82
/**
83
* \param supplyVoltageV Supply voltage at the energy source, in Volts.
84
*
85
* Sets supply voltage of the energy source.
86
*/
87
void
SetSupplyVoltage
(
double
supplyVoltageV);
88
89
/**
90
* \param interval Energy update interval.
91
*
92
* This function sets the interval between each energy update.
93
*/
94
void
SetEnergyUpdateInterval
(
Time
interval);
95
96
/**
97
* \returns The interval between each energy update.
98
*/
99
Time
GetEnergyUpdateInterval
()
const
;
100
101
private
:
102
/// Defined in ns3::Object
103
void
DoInitialize
()
override
;
104
105
/// Defined in ns3::Object
106
void
DoDispose
()
override
;
107
108
/**
109
* Handles the remaining energy going to zero event. This function notifies
110
* all the energy models aggregated to the node about the energy being
111
* depleted. Each energy model is then responsible for its own handler.
112
*/
113
void
HandleEnergyDrainedEvent
();
114
115
/**
116
* Handles the remaining energy exceeding the high threshold after it went
117
* below the low threshold. This function notifies all the energy models
118
* aggregated to the node about the energy being recharged. Each energy model
119
* is then responsible for its own handler.
120
*/
121
void
HandleEnergyRechargedEvent
();
122
123
/**
124
* Calculates remaining energy. This function uses the total current from all
125
* device models to calculate the amount of energy to decrease. The energy to
126
* decrease is given by:
127
* energy to decrease = total current * supply voltage * time duration
128
* This function subtracts the calculated energy to decrease from remaining
129
* energy.
130
*/
131
void
CalculateRemainingEnergy
();
132
133
private
:
134
double
m_initialEnergyJ
;
//!< initial energy, in Joules
135
double
m_supplyVoltageV
;
//!< supply voltage, in Volts
136
double
m_lowBatteryTh
;
//!< low battery threshold, as a fraction of the initial energy
137
double
m_highBatteryTh
;
//!< high battery threshold, as a fraction of the initial energy
138
/**
139
* set to true when the remaining energy goes below the low threshold,
140
* set to false again when the remaining energy exceeds the high threshold
141
*/
142
bool
m_depleted
;
143
TracedValue<double>
m_remainingEnergyJ
;
//!< remaining energy, in Joules
144
EventId
m_energyUpdateEvent
;
//!< energy update event
145
Time
m_lastUpdateTime
;
//!< last update time
146
Time
m_energyUpdateInterval
;
//!< energy update interval
147
};
148
149
}
// namespace energy
150
}
// namespace ns3
151
152
#endif
/* BASIC_ENERGY_SOURCE_H */
ns3::EventId
An identifier for simulation events.
Definition
event-id.h:45
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:94
ns3::TracedValue
Trace classes with value semantics.
Definition
traced-value.h:105
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::energy::BasicEnergySource
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
Definition
basic-energy-source.h:30
ns3::energy::BasicEnergySource::m_lowBatteryTh
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
Definition
basic-energy-source.h:136
ns3::energy::BasicEnergySource::m_initialEnergyJ
double m_initialEnergyJ
initial energy, in Joules
Definition
basic-energy-source.h:134
ns3::energy::BasicEnergySource::m_lastUpdateTime
Time m_lastUpdateTime
last update time
Definition
basic-energy-source.h:145
ns3::energy::BasicEnergySource::GetEnergyFraction
double GetEnergyFraction() override
Definition
basic-energy-source.cc:135
ns3::energy::BasicEnergySource::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
basic-energy-source.cc:26
ns3::energy::BasicEnergySource::GetSupplyVoltage
double GetSupplyVoltage() const override
Definition
basic-energy-source.cc:112
ns3::energy::BasicEnergySource::GetRemainingEnergy
double GetRemainingEnergy() override
Definition
basic-energy-source.cc:126
ns3::energy::BasicEnergySource::m_energyUpdateInterval
Time m_energyUpdateInterval
energy update interval
Definition
basic-energy-source.h:146
ns3::energy::BasicEnergySource::m_energyUpdateEvent
EventId m_energyUpdateEvent
energy update event
Definition
basic-energy-source.h:144
ns3::energy::BasicEnergySource::BasicEnergySource
BasicEnergySource()
Definition
basic-energy-source.cc:69
ns3::energy::BasicEnergySource::SetInitialEnergy
void SetInitialEnergy(double initialEnergyJ)
Definition
basic-energy-source.cc:82
ns3::energy::BasicEnergySource::m_depleted
bool m_depleted
set to true when the remaining energy goes below the low threshold, set to false again when the remai...
Definition
basic-energy-source.h:142
ns3::energy::BasicEnergySource::~BasicEnergySource
~BasicEnergySource() override
Definition
basic-energy-source.cc:76
ns3::energy::BasicEnergySource::m_remainingEnergyJ
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
Definition
basic-energy-source.h:143
ns3::energy::BasicEnergySource::DoDispose
void DoDispose() override
Defined in ns3::Object.
Definition
basic-energy-source.cc:189
ns3::energy::BasicEnergySource::SetSupplyVoltage
void SetSupplyVoltage(double supplyVoltageV)
Definition
basic-energy-source.cc:91
ns3::energy::BasicEnergySource::SetEnergyUpdateInterval
void SetEnergyUpdateInterval(Time interval)
Definition
basic-energy-source.cc:98
ns3::energy::BasicEnergySource::GetEnergyUpdateInterval
Time GetEnergyUpdateInterval() const
Definition
basic-energy-source.cc:105
ns3::energy::BasicEnergySource::GetInitialEnergy
double GetInitialEnergy() const override
Definition
basic-energy-source.cc:119
ns3::energy::BasicEnergySource::HandleEnergyDrainedEvent
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
Definition
basic-energy-source.cc:196
ns3::energy::BasicEnergySource::UpdateEnergySource
void UpdateEnergySource() override
Implements UpdateEnergySource.
Definition
basic-energy-source.cc:144
ns3::energy::BasicEnergySource::CalculateRemainingEnergy
void CalculateRemainingEnergy()
Calculates remaining energy.
Definition
basic-energy-source.cc:212
ns3::energy::BasicEnergySource::m_highBatteryTh
double m_highBatteryTh
high battery threshold, as a fraction of the initial energy
Definition
basic-energy-source.h:137
ns3::energy::BasicEnergySource::HandleEnergyRechargedEvent
void HandleEnergyRechargedEvent()
Handles the remaining energy exceeding the high threshold after it went below the low threshold.
Definition
basic-energy-source.cc:204
ns3::energy::BasicEnergySource::DoInitialize
void DoInitialize() override
Defined in ns3::Object.
Definition
basic-energy-source.cc:182
ns3::energy::BasicEnergySource::m_supplyVoltageV
double m_supplyVoltageV
supply voltage, in Volts
Definition
basic-energy-source.h:135
ns3::energy::EnergySource
Energy source base class.
Definition
energy-source.h:77
energy-source.h
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
energy
model
basic-energy-source.h
Generated on Fri Nov 8 2024 13:59:00 for ns-3 by
1.11.0