22 #include "ns3/assert.h"
23 #include "ns3/double.h"
25 #include "ns3/simulator.h"
26 #include "ns3/trace-source-accessor.h"
41 TypeId(
"ns3::RvBatteryModel")
43 .SetGroupName(
"Energy")
45 .AddAttribute(
"RvBatteryModelPeriodicEnergyUpdateInterval",
46 "RV battery model sampling interval.",
51 .AddAttribute(
"RvBatteryModelLowBatteryThreshold",
52 "Low battery threshold.",
55 MakeDoubleChecker<double>())
56 .AddAttribute(
"RvBatteryModelOpenCircuitVoltage",
57 "RV battery model open circuit voltage.",
61 MakeDoubleChecker<double>())
62 .AddAttribute(
"RvBatteryModelCutoffVoltage",
63 "RV battery model cutoff voltage.",
67 MakeDoubleChecker<double>())
68 .AddAttribute(
"RvBatteryModelAlphaValue",
69 "RV battery model alpha value.",
72 MakeDoubleChecker<double>())
73 .AddAttribute(
"RvBatteryModelBetaValue",
74 "RV battery model beta value.",
77 MakeDoubleChecker<double>())
79 "RvBatteryModelNumOfTerms",
80 "The number of terms of the infinite sum for estimating battery level.",
83 MakeIntegerChecker<int>())
84 .AddTraceSource(
"RvBatteryModelBatteryLevel",
85 "RV battery model battery level.",
87 "ns3::TracedValueCallback::Double")
88 .AddTraceSource(
"RvBatteryModelBatteryLifetime",
89 "RV battery model battery lifetime.",
91 "ns3::TracedValueCallback::Time");
158 NS_LOG_DEBUG(
"RvBatteryModel:Updating remaining energy!");
165 NS_LOG_DEBUG(
"RvBatteryModel:Calculated alpha = " << calculatedAlpha <<
" time = "
179 NS_LOG_DEBUG(
"RvBatteryModel:Battery level below threshold!");
300 NS_LOG_DEBUG(
"RvBatteryModel:Starting battery level update!");
344 double calculatedAlpha = 0.0;
360 return calculatedAlpha;
369 double firstDelta = (t - sk).GetMinutes();
370 double secondDelta = (t - sk_1).GetMinutes();
371 double delta = (sk - sk_1).GetMinutes();
376 double square = beta * beta *
m *
m;
377 sum += (std::exp(-square * (firstDelta)) - std::exp(-square * (secondDelta))) / square;
379 return delta + 2 * sum;
This class can be used to hold variables of floating point type such as 'double' or 'float'.
double CalculateTotalCurrent()
void BreakDeviceEnergyModelRefCycle()
This function is called to break reference cycle between EnergySource and DeviceEnergyModel.
void NotifyEnergyDrained()
This function notifies all DeviceEnergyModel of energy depletion event.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Hold a signed integer type.
Rakhmatov Vrudhula non-linear battery model.
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
void DoDispose() override
Defined in ns3::Object.
double m_openCircuitVoltage
Open circuit voltage (in Volts)
void SetNumOfTerms(int num)
Sets the number of terms of the infinite sum for estimating battery level.
double m_cutoffVoltage
Cutoff voltage (in Volts)
EventId m_currentSampleEvent
Current sample event.
void SetSamplingInterval(Time interval)
int GetNumOfTerms() const
Time m_lastSampleTime
Last sample time.
double GetCutoffVoltage() const
static TypeId GetTypeId()
Get the type ID.
double m_previousLoad
load value (total current) of previous sampling
std::vector< Time > m_timeStamps
time stamps of load profile
int m_numOfTerms
Number# of terms for infinite sum in battery level estimation.
double Discharge(double load, Time t)
Discharges the battery.
Time GetSamplingInterval() const
void SetCutoffVoltage(double voltage)
Sets cutoff voltage of battery.
void SetBeta(double beta)
Sets the beta value for the battery model.
double GetEnergyFraction() override
double GetInitialEnergy() const override
double GetOpenCircuitVoltage() const
std::vector< double > m_load
load profile
~RvBatteryModel() override
TracedValue< Time > m_lifetime
time of death of the battery
Time m_samplingInterval
Sampling interval.
void SetOpenCircuitVoltage(double voltage)
Sets open circuit voltage of battery.
double RvModelAFunction(Time t, Time sk, Time sk_1, double beta)
RV model A function.
void SetAlpha(double alpha)
Sets the alpha value for the battery model.
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
void DoInitialize() override
Defined in ns3::Object.
double m_alpha
alpha value of RV model, in Coulomb
double GetSupplyVoltage() const override
TracedValue< double > m_batteryLevel
Battery level is defined as: output of Discharge function / alpha value.
void UpdateEnergySource() override
Implements UpdateEnergySource.
double GetRemainingEnergy() override
double m_beta
beta value of RV model, in second^-1
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static bool IsFinished()
Check if the simulation should finish.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)