energy: Time arithmetic and logging changes

This commit is contained in:
Anna Poon
2020-10-22 15:52:49 -07:00
committed by Tom Henderson
parent b3bdd14ad5
commit 9a7cc2445f
6 changed files with 18 additions and 19 deletions

View File

@@ -47,7 +47,7 @@ using namespace ns3;
static void
PrintCellInfo (Ptr<LiIonEnergySource> es)
{
std::cout << "At " << Simulator::Now ().GetSeconds () << " Cell voltage: " << es->GetSupplyVoltage () << " V Remaining Capacity: " <<
std::cout << "At " << Simulator::Now ().As (Time::S) << " Cell voltage: " << es->GetSupplyVoltage () << " V Remaining Capacity: " <<
es->GetRemainingEnergy () / (3.6 * 3600) << " Ah" << std::endl;
if (!Simulator::IsFinished ())

View File

@@ -780,8 +780,8 @@ BatteryLifetimeTest::ConstantLoadTest (double load, Time expLifetime)
Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
actualLifetime = srcPtr->GetLifetime ();
NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.As (Time::S));
NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.As (Time::S));
Simulator::Destroy ();
@@ -876,15 +876,14 @@ BatteryLifetimeTest::VariableLoadTest (std::vector<double> loads,
Ptr<RvBatteryModel> srcPtr = DynamicCast<RvBatteryModel> (sources.Get (0));
actualLifetime = srcPtr->GetLifetime ();
NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.GetSeconds () << "s");
NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.GetSeconds () << "s");
NS_LOG_DEBUG ("Difference = " << expLifetime.GetSeconds () - actualLifetime.GetSeconds () << "s");
NS_LOG_DEBUG ("Expected lifetime = " << expLifetime.As (Time::S));
NS_LOG_DEBUG ("Actual lifetime = " << actualLifetime.As (Time::S));
NS_LOG_DEBUG ("Difference = " << (expLifetime - actualLifetime).As (Time::S));
Simulator::Destroy ();
// error tolerance = 120s
if ((actualLifetime.GetSeconds ()) > (expLifetime.GetSeconds ()) + (120) ||
(actualLifetime.GetSeconds ()) < (expLifetime.GetSeconds ()) - (120))
if (Abs (actualLifetime - expLifetime) > Seconds (120))
{
std::cerr << "VariableLoadTest: Incorrect lifetime." << std::endl;
return true;

View File

@@ -110,8 +110,8 @@ void
BasicEnergyHarvester::UpdateHarvestedPower (void)
{
NS_LOG_FUNCTION (this);
NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
<< "s BasicEnergyHarvester(" << GetNode ()->GetId () << "): Updating harvesting power.");
NS_LOG_DEBUG (Simulator::Now ().As (Time::S)
<< " BasicEnergyHarvester(" << GetNode ()->GetId () << "): Updating harvesting power.");
Time duration = Simulator::Now () - m_lastHarvestingUpdateTime;
@@ -169,8 +169,8 @@ BasicEnergyHarvester::CalculateHarvestedPower (void)
m_harvestedPower = m_harvestablePower->GetValue ();
NS_LOG_DEBUG (Simulator::Now ().GetSeconds ()
<< "s BasicEnergyHarvester:Harvested energy = " << m_harvestedPower);
NS_LOG_DEBUG (Simulator::Now ().As (Time::S)
<< " BasicEnergyHarvester:Harvested energy = " << m_harvestedPower);
}
double

View File

@@ -224,7 +224,7 @@ BasicEnergySource::CalculateRemainingEnergy (void)
Time duration = Simulator::Now () - m_lastUpdateTime;
NS_ASSERT (duration.IsPositive ());
// energy = current * voltage * time
double energyToDecreaseJ = (totalCurrentA * m_supplyVoltageV * duration.GetNanoSeconds ()) / 1e9;
double energyToDecreaseJ = (totalCurrentA * m_supplyVoltageV * duration).GetSeconds ();
NS_ASSERT (m_remainingEnergyJ >= energyToDecreaseJ);
m_remainingEnergyJ -= energyToDecreaseJ;
NS_LOG_DEBUG ("BasicEnergySource:Remaining energy = " << m_remainingEnergyJ);

View File

@@ -277,7 +277,7 @@ LiIonEnergySource::CalculateRemainingEnergy (void)
// energy = current * voltage * time
double energyToDecreaseJ = totalCurrentA * m_supplyVoltageV * duration.GetSeconds ();
if (m_remainingEnergyJ < energyToDecreaseJ)
if (m_remainingEnergyJ < energyToDecreaseJ)
{
m_remainingEnergyJ = 0; // energy never goes below 0
}
@@ -286,7 +286,7 @@ LiIonEnergySource::CalculateRemainingEnergy (void)
m_remainingEnergyJ -= energyToDecreaseJ;
}
m_drainedCapacity += (totalCurrentA * duration.GetSeconds () / 3600);
m_drainedCapacity += (totalCurrentA * duration).GetHours ();
// update the supply voltage
m_supplyVoltageV = GetVoltage (totalCurrentA);
NS_LOG_DEBUG ("LiIonEnergySource:Remaining energy = " << m_remainingEnergyJ);

View File

@@ -163,7 +163,7 @@ RvBatteryModel::UpdateEnergySource (void)
double calculatedAlpha = Discharge (currentLoad, Simulator::Now ());
NS_LOG_DEBUG ("RvBatteryModel:Calculated alpha = " << calculatedAlpha <<
" time = " << Simulator::Now ().GetSeconds ());
" time = " << Simulator::Now ().As (Time::S));
// calculate battery level
m_batteryLevel = 1 - (calculatedAlpha / m_alpha);
@@ -369,9 +369,9 @@ RvBatteryModel::RvModelAFunction (Time t, Time sk, Time sk_1, double beta)
NS_LOG_FUNCTION (this << t << sk << sk_1 << beta);
// everything is in minutes
double firstDelta = (t.GetSeconds () - sk.GetSeconds ()) / 60;
double secondDelta = (t.GetSeconds () - sk_1.GetSeconds ()) / 60;
double delta = (sk.GetSeconds () - sk_1.GetSeconds ()) / 60;
double firstDelta = (t - sk).GetMinutes ();
double secondDelta = (t - sk_1).GetMinutes ();
double delta = (sk - sk_1).GetMinutes ();
double sum = 0.0;
for (int m = 1; m <= m_numOfTerms; m++)