Skip to content

energy: RvBatteryModel has multiple unit issues

The header src/energy/model/rv-battery-model.h makes these claims for units:

   * \param load Load value (total current form devices, in mA).
  double Discharge (double load, Time t);
   * This function computes alpha value using the recorded load profile.
  double RvModelAFunction (Time t, Time sk, Time sk_1, double beta);
  ...
  double m_alpha; // alpha value of RV model, in Coulomb
  double m_beta;  // beta value of RV model, in second^-1

But the code has these statements:

UpdateEnergySource():
  double currentLoad = CalculateTotalCurrent () * 1000; // must be in mA
  double calculatedAlpha = Discharge (currentLoad, Simulator::Now ());
  // calculate battery level
  m_batteryLevel = 1 - (calculatedAlpha / m_alpha);

So calculatedAlpha should be in Coulombs, to match m_alpha, and Discharge() should return Coulombs.

Discharge():
  calculatedAlpha = m_load[0] * RvModelAFunction (t, t, Seconds (0.0), m_beta);
  return calculatedAlpha;

Loads are in mA, so the return value of RvModelAFunction should be seconds/1000 .

RvModelAFunction():
  double firstDelta = (t.GetSeconds () - sk.GetSeconds ()) / 60;
  double secondDelta = (t.GetSeconds () - sk_1.GetSeconds ()) / 60;
  double delta = (sk.GetSeconds () - sk_1.GetSeconds ()) / 60;

  double sum = 0.0;
  for (int m = 1; m <= m_numOfTerms; m++)
    {
      double square = beta * beta * m * m;
      sum += (std::exp (-square * (firstDelta)) - std::exp (-square * (secondDelta))) / square;
    }
  return delta + 2 * sum;

The deltas are all minutes. square has units second^-2.

Lots of problems:

  1. The exponential arguments s have units of minutes/seconds^2 ! These arguments should be dimensionless.
  2. The sum has units seconds^2 (from dividing by square), which is then added to minutes !
  3. And that doesn't agree with what Discharge() needs.

Need to track down the three papers referenced in the header...