Bug 2309

Summary: AcousticModemEnergyModel::ChangeState
Product: ns-3 Reporter: Hossam Khader <hossamkhader>
Component: uanAssignee: Andrea Sacco <andrea.sacco85>
Status: RESOLVED DUPLICATE    
Severity: normal CC: andrea.sacco85, cristiano.tapparello, ns-bugs, pdbarnes, tommaso.pecorella
Priority: P5    
Version: unspecified   
Hardware: All   
OS: All   

Description Hossam Khader 2016-02-26 16:21:25 UTC
The calculation of the energy to decrease is wrong

energyToDecrease = duration.GetSeconds () * m_txPowerW * supplyVoltage;
energyToDecrease = duration.GetSeconds () * m_rxPowerW * supplyVoltage;
energyToDecrease = duration.GetSeconds () * m_idlePowerW * supplyVoltage;
energyToDecrease = duration.GetSeconds () * m_sleepPowerW * supplyVoltage;

Should be changed to 

energyToDecrease = duration.GetSeconds () * m_txPowerW;
energyToDecrease = duration.GetSeconds () * m_rxPowerW;
energyToDecrease = duration.GetSeconds () * m_idlePowerW;
energyToDecrease = duration.GetSeconds () * m_sleepPowerW;
Comment 1 Tommaso Pecorella 2016-02-26 17:51:27 UTC
Indeed, Amps = Watts * Seconds, the Volts is already included.

If we want to have a voltage-dependent model, we'd need to specify the current drawn by the modem in each state in Amperes, just like the Wi-Fi model does.
Comment 2 Hossam Khader 2016-03-02 21:01:27 UTC
Please have a look at the below code.

void
AcousticModemEnergyModel::ChangeState (int newState)
{
  NS_LOG_FUNCTION (this << newState);
  // NS_ASSERT (IsStateTransitionValid ((MicroModemState) newState));

  Time duration = Simulator::Now () - m_lastUpdateTime;
  NS_ASSERT (duration.GetNanoSeconds () >= 0); // check if duration is valid

  // energy to decrease = current * voltage * time
  double energyToDecrease = 0.0;
  double supplyVoltage = m_source->GetSupplyVoltage ();
  switch (m_currentState)
    {
    case UanPhy::TX:
      energyToDecrease = duration.GetSeconds () * m_txPowerW;
      m_txCurrentA = m_txPowerW / supplyVoltage;
      break;
    case UanPhy::RX:
      energyToDecrease = duration.GetSeconds () * m_rxPowerW;
      m_rxCurrentA = m_rxPowerW / supplyVoltage;
      break;
    case UanPhy::IDLE:
      energyToDecrease = duration.GetSeconds () * m_idlePowerW;
      m_idleCurrentA = m_idlePowerW / supplyVoltage;
      break;
    case UanPhy::SLEEP:
      energyToDecrease = duration.GetSeconds () * m_sleepPowerW;
      m_sleepCurrentA = m_sleepPowerW / supplyVoltage;
      break;
    default:
      NS_FATAL_ERROR ("AcousticModemEnergyModel:Undefined radio state!");
    }

  // update total energy consumption
  m_totalEnergyConsumption += energyToDecrease;

  // update last update time stamp
  m_lastUpdateTime = Simulator::Now ();

  // notify energy source
  m_source->UpdateEnergySource ();
  
  // update current state & last update time stamp
  SetMicroModemState (newState);

  // some debug message
  NS_LOG_DEBUG ("AcousticModemEnergyModel:Total energy consumption at node #" <<
                m_node->GetId () << " is " << m_totalEnergyConsumption << "J");
}



double
AcousticModemEnergyModel::DoGetCurrentA (void) const
{
  NS_LOG_FUNCTION (this);
  switch (m_currentState)
    {
    case UanPhy::TX:
      return m_txCurrentA;
    case UanPhy::RX:
      return m_rxCurrentA;
    case UanPhy::IDLE:
      return m_idleCurrentA;
    case UanPhy::SLEEP:
      return m_sleepCurrentA;
    default:
      NS_FATAL_ERROR ("AcousticModemEnergyModel:Undefined radio state!");
    }
}
Comment 3 Cristiano Tapparello 2016-03-11 15:39:06 UTC
This is a duplicate of Bug 1631 https://www.nsnam.org/bugzilla/﷒0﷓.

My suggestion is to remove the multiplication by supplyVoltage as suggested both here and in 1631.

Andrea, do you agree on this?
Comment 4 Peter Barnes 2016-03-11 20:46:02 UTC

*** This bug has been marked as a duplicate of bug 1631 ***