11#include "ns3/assert.h"
12#include "ns3/double.h"
14#include "ns3/simulator.h"
15#include "ns3/trace-source-accessor.h"
31 TypeId(
"ns3::energy::RvBatteryModel")
34 .SetGroupName(
"Energy")
36 .AddAttribute(
"RvBatteryModelPeriodicEnergyUpdateInterval",
37 "RV battery model sampling interval.",
42 .AddAttribute(
"RvBatteryModelLowBatteryThreshold",
43 "Low battery threshold.",
47 .AddAttribute(
"RvBatteryModelOpenCircuitVoltage",
48 "RV battery model open circuit voltage.",
53 .AddAttribute(
"RvBatteryModelCutoffVoltage",
54 "RV battery model cutoff voltage.",
59 .AddAttribute(
"RvBatteryModelAlphaValue",
60 "RV battery model alpha value.",
64 .AddAttribute(
"RvBatteryModelBetaValue",
65 "RV battery model beta value.",
70 "RvBatteryModelNumOfTerms",
71 "The number of terms of the infinite sum for estimating battery level.",
75 .AddTraceSource(
"RvBatteryModelBatteryLevel",
76 "RV battery model battery level.",
78 "ns3::TracedValueCallback::Double")
79 .AddTraceSource(
"RvBatteryModelBatteryLifetime",
80 "RV battery model battery lifetime.",
82 "ns3::TracedValueCallback::Time");
149 NS_LOG_DEBUG(
"RvBatteryModel:Updating remaining energy!");
156 NS_LOG_DEBUG(
"RvBatteryModel:Calculated alpha = " << calculatedAlpha <<
" time = "
170 NS_LOG_DEBUG(
"RvBatteryModel:Battery level below threshold!");
291 NS_LOG_DEBUG(
"RvBatteryModel:Starting battery level update!");
335 double calculatedAlpha = 0.0;
351 return calculatedAlpha;
360 double firstDelta = (t - sk).GetMinutes();
361 double secondDelta = (t - sk_1).GetMinutes();
362 double delta = (sk - sk_1).GetMinutes();
367 double square = beta * beta * m * m;
368 sum += (std::exp(-square * (firstDelta)) - std::exp(-square * (secondDelta))) / square;
370 return delta + 2 * sum;
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Hold a signed integer type.
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 AddDeprecatedName(const std::string &name)
Add an deprecated name for a TypeId.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Energy source base class.
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.
double CalculateTotalCurrent()
Rakhmatov Vrudhula non-linear battery model.
double m_beta
beta value of RV model, in second^-1
double RvModelAFunction(Time t, Time sk, Time sk_1, double beta)
RV model A function.
static TypeId GetTypeId()
Get the type ID.
TracedValue< Time > m_lifetime
time of death of the battery
TracedValue< double > m_batteryLevel
Battery level is defined as: output of Discharge function / alpha value.
Time m_lastSampleTime
Last sample time.
double GetRemainingEnergy() override
EventId m_currentSampleEvent
Current sample event.
void DoDispose() override
Defined in ns3::Object.
double GetInitialEnergy() const override
double GetOpenCircuitVoltage() const
double GetSupplyVoltage() const override
std::vector< double > m_load
load profile
void UpdateEnergySource() override
Implements UpdateEnergySource.
double Discharge(double load, Time t)
Discharges the battery.
Time GetSamplingInterval() const
void SetNumOfTerms(int num)
Sets the number of terms of the infinite sum for estimating battery level.
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
double m_alpha
alpha value of RV model, in Coulomb
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
int m_numOfTerms
Number# of terms for infinite sum in battery level estimation.
void SetBeta(double beta)
Sets the beta value for the battery model.
double GetCutoffVoltage() const
double m_openCircuitVoltage
Open circuit voltage (in Volts)
std::vector< Time > m_timeStamps
time stamps of load profile
~RvBatteryModel() override
int GetNumOfTerms() const
void DoInitialize() override
Defined in ns3::Object.
void SetCutoffVoltage(double voltage)
Sets cutoff voltage of battery.
void SetAlpha(double alpha)
Sets the alpha value for the battery model.
double m_previousLoad
load value (total current) of previous sampling
double GetEnergyFraction() override
void SetSamplingInterval(Time interval)
double m_cutoffVoltage
Cutoff voltage (in Volts)
Time m_samplingInterval
Sampling interval.
void SetOpenCircuitVoltage(double voltage)
Sets open circuit voltage of battery.
#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 AttributeChecker > MakeIntegerChecker()
Ptr< const AttributeAccessor > MakeIntegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeDoubleChecker()
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.