Skip to content

Commit

Permalink
{amitran} refactoring pollutants interface and adding emissions outpu…
Browse files Browse the repository at this point in the history
…t to driving cycle app, refs #12

git-svn-id: file:///home/behr_mi/git/sumo_synched/branches/amitran@16156 afbd958f-9f77-42d5-a016-97a22340ccf4
  • Loading branch information
behrisch committed Apr 8, 2014
1 parent 78abdeb commit 9bef912
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 314 deletions.
12 changes: 6 additions & 6 deletions sumo/src/microsim/MSVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2127,37 +2127,37 @@ MSVehicle::getTimeGap() const {

SUMOReal
MSVehicle::getCO2Emissions() const {
return PollutantsInterface::computeCO2(myType->getEmissionClass(), myState.speed(), myAcceleration, getSlope());
return PollutantsInterface::compute(myType->getEmissionClass(), PollutantsInterface::CO2, myState.speed(), myAcceleration, getSlope());
}


SUMOReal
MSVehicle::getCOEmissions() const {
return PollutantsInterface::computeCO(myType->getEmissionClass(), myState.speed(), myAcceleration, getSlope());
return PollutantsInterface::compute(myType->getEmissionClass(), PollutantsInterface::CO, myState.speed(), myAcceleration, getSlope());
}


SUMOReal
MSVehicle::getHCEmissions() const {
return PollutantsInterface::computeHC(myType->getEmissionClass(), myState.speed(), myAcceleration, getSlope());
return PollutantsInterface::compute(myType->getEmissionClass(), PollutantsInterface::HC, myState.speed(), myAcceleration, getSlope());
}


SUMOReal
MSVehicle::getNOxEmissions() const {
return PollutantsInterface::computeNOx(myType->getEmissionClass(), myState.speed(), myAcceleration, getSlope());
return PollutantsInterface::compute(myType->getEmissionClass(), PollutantsInterface::NO_X, myState.speed(), myAcceleration, getSlope());
}


SUMOReal
MSVehicle::getPMxEmissions() const {
return PollutantsInterface::computePMx(myType->getEmissionClass(), myState.speed(), myAcceleration, getSlope());
return PollutantsInterface::compute(myType->getEmissionClass(), PollutantsInterface::PM_X, myState.speed(), myAcceleration, getSlope());
}


SUMOReal
MSVehicle::getFuelConsumption() const {
return PollutantsInterface::computeFuel(myType->getEmissionClass(), myState.speed(), myAcceleration, getSlope());
return PollutantsInterface::compute(myType->getEmissionClass(), PollutantsInterface::FUEL, myState.speed(), myAcceleration, getSlope());
}


Expand Down
22 changes: 8 additions & 14 deletions sumo/src/microsim/devices/MSDevice_Emissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>&
// MSDevice_Emissions-methods
// ---------------------------------------------------------------------------
MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder, const std::string& id)
: MSDevice(holder, id),
myCO2(0), myCO(0), myHC(0), myPMx(0), myNOx(0), myFuel(0) {
: MSDevice(holder, id), myEmissions() {
}


Expand All @@ -105,12 +104,7 @@ MSDevice_Emissions::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /
const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
const SUMOReal a = veh.getAcceleration();
const SUMOReal slope = veh.getSlope();
myCO2 += TS * PollutantsInterface::computeCO2(c, newSpeed, a, slope);
myCO += TS * PollutantsInterface::computeCO(c, newSpeed, a, slope);
myHC += TS * PollutantsInterface::computeHC(c, newSpeed, a, slope);
myPMx += TS * PollutantsInterface::computePMx(c, newSpeed, a, slope);
myNOx += TS * PollutantsInterface::computeNOx(c, newSpeed, a, slope);
myFuel += TS * PollutantsInterface::computeFuel(c, newSpeed, a, slope);
myEmissions.addScaled(PollutantsInterface::computeAll(c, newSpeed, a, slope), TS);
return true;
}

Expand All @@ -120,12 +114,12 @@ MSDevice_Emissions::generateOutput() const {
if (OptionsCont::getOptions().isSet("tripinfo-output")) {
OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
(os.openTag("emissions") <<
" CO_abs=\"" << OutputDevice::realString(myCO, 6) <<
"\" CO2_abs=\"" << OutputDevice::realString(myCO2, 6) <<
"\" HC_abs=\"" << OutputDevice::realString(myHC, 6) <<
"\" PMx_abs=\"" << OutputDevice::realString(myPMx, 6) <<
"\" NOx_abs=\"" << OutputDevice::realString(myNOx, 6) <<
"\" fuel_abs=\"" << OutputDevice::realString(myFuel, 6) <<
" CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
"\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
"\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
"\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
"\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
"\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
"\"").closeTag();
}
}
Expand Down
13 changes: 5 additions & 8 deletions sumo/src/microsim/devices/MSDevice_Emissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
#include <set>
#include <vector>
#include <map>
#include "MSDevice.h"
#include <utils/common/SUMOTime.h>
#include <microsim/MSVehicle.h>
#include <utils/common/WrappingCommand.h>
#include <utils/emissions/PollutantsInterface.h>
#include <microsim/MSVehicle.h>
#include "MSDevice.h"


// ===========================================================================
Expand Down Expand Up @@ -128,12 +129,8 @@ class MSDevice_Emissions : public MSDevice {


private:
/// @name Internal storages for pollutant/fuel sum in mg or ml
/// @{

SUMOReal myCO2, myCO, myHC, myPMx, myNOx, myFuel;

/// @}
/// @brief Internal storages for pollutant/fuel sum in mg or ml
PollutantsInterface::Emissions myEmissions;


private:
Expand Down
71 changes: 28 additions & 43 deletions sumo/src/microsim/output/MSMeanData_Emissions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ MSMeanData_Emissions::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const l
const std::map<std::string, unsigned>* const vTypes,
const MSMeanData_Emissions* parent)
: MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
CO2(0), CO(0), HC(0), NOx(0), PMx(0), fuel(0), myParent(parent) {}
myEmissions(), myParent(parent) {}


MSMeanData_Emissions::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
Expand All @@ -66,12 +66,7 @@ void
MSMeanData_Emissions::MSLaneMeanDataValues::reset(bool) {
sampleSeconds = 0.;
travelledDistance = 0.;
CO2 = 0;
CO = 0;
HC = 0;
NOx = 0;
PMx = 0;
fuel = 0;
myEmissions = PollutantsInterface::Emissions();
}


Expand All @@ -80,12 +75,7 @@ MSMeanData_Emissions::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& va
MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
v.sampleSeconds += sampleSeconds;
v.travelledDistance += travelledDistance;
v.CO2 += CO2;
v.CO += CO;
v.HC += HC;
v.NOx += NOx;
v.PMx += PMx;
v.fuel += fuel;
v.myEmissions.addScaled(myEmissions);
}


Expand All @@ -94,31 +84,26 @@ MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal(SUMOVehicle& veh,
sampleSeconds += timeOnLane;
travelledDistance += speed * timeOnLane;
const double a = veh.getAcceleration();
CO += (timeOnLane * PollutantsInterface::computeCO(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
CO2 += (timeOnLane * PollutantsInterface::computeCO2(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
HC += (timeOnLane * PollutantsInterface::computeHC(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
NOx += (timeOnLane * PollutantsInterface::computeNOx(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
PMx += (timeOnLane * PollutantsInterface::computePMx(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
fuel += (timeOnLane * PollutantsInterface::computeFuel(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
myEmissions.addScaled(PollutantsInterface::computeAll(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()), timeOnLane);
}


void
MSMeanData_Emissions::MSLaneMeanDataValues::write(OutputDevice& dev, const SUMOTime period,
const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
const SUMOReal normFactor = SUMOReal(3600. / STEPS2TIME(period) / myLaneLength);
dev << " CO_abs=\"" << OutputDevice::realString(CO, 6) <<
"\" CO2_abs=\"" << OutputDevice::realString(CO2, 6) <<
"\" HC_abs=\"" << OutputDevice::realString(HC, 6) <<
"\" PMx_abs=\"" << OutputDevice::realString(PMx, 6) <<
"\" NOx_abs=\"" << OutputDevice::realString(NOx, 6) <<
"\" fuel_abs=\"" << OutputDevice::realString(fuel, 6) <<
"\"\n CO_normed=\"" << OutputDevice::realString(normFactor * CO, 6) <<
"\" CO2_normed=\"" << OutputDevice::realString(normFactor * CO2, 6) <<
"\" HC_normed=\"" << OutputDevice::realString(normFactor * HC, 6) <<
"\" PMx_normed=\"" << OutputDevice::realString(normFactor * PMx, 6) <<
"\" NOx_normed=\"" << OutputDevice::realString(normFactor * NOx, 6) <<
"\" fuel_normed=\"" << OutputDevice::realString(normFactor * fuel, 6);
dev << " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
"\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
"\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
"\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
"\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
"\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
"\"\n CO_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO, 6) <<
"\" CO2_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO2, 6) <<
"\" HC_normed=\"" << OutputDevice::realString(normFactor * myEmissions.HC, 6) <<
"\" PMx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.PMx, 6) <<
"\" NOx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.NOx, 6) <<
"\" fuel_normed=\"" << OutputDevice::realString(normFactor * myEmissions.fuel, 6);
if (sampleSeconds > myParent->myMinSamples) {
SUMOReal vehFactor = myParent->myMaxTravelTime / sampleSeconds;
SUMOReal traveltime = myParent->myMaxTravelTime;
Expand All @@ -127,22 +112,22 @@ MSMeanData_Emissions::MSLaneMeanDataValues::write(OutputDevice& dev, const SUMOT
traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
}
dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
"\" CO_perVeh=\"" << OutputDevice::realString(CO * vehFactor, 6) <<
"\" CO2_perVeh=\"" << OutputDevice::realString(CO2 * vehFactor, 6) <<
"\" HC_perVeh=\"" << OutputDevice::realString(HC * vehFactor, 6) <<
"\" PMx_perVeh=\"" << OutputDevice::realString(PMx * vehFactor, 6) <<
"\" NOx_perVeh=\"" << OutputDevice::realString(NOx * vehFactor, 6) <<
"\" fuel_perVeh=\"" << OutputDevice::realString(fuel * vehFactor, 6);
"\" CO_perVeh=\"" << OutputDevice::realString(myEmissions.CO * vehFactor, 6) <<
"\" CO2_perVeh=\"" << OutputDevice::realString(myEmissions.CO2 * vehFactor, 6) <<
"\" HC_perVeh=\"" << OutputDevice::realString(myEmissions.HC * vehFactor, 6) <<
"\" PMx_perVeh=\"" << OutputDevice::realString(myEmissions.PMx * vehFactor, 6) <<
"\" NOx_perVeh=\"" << OutputDevice::realString(myEmissions.NOx * vehFactor, 6) <<
"\" fuel_perVeh=\"" << OutputDevice::realString(myEmissions.fuel * vehFactor, 6);
} else if (defaultTravelTime >= 0.) {
const MSVehicleType* t = MSNet::getInstance()->getVehicleControl().getVType();
const SUMOReal speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
dev << "\"\n traveltime=\"" << OutputDevice::realString(defaultTravelTime) <<
"\" CO_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultCO(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" CO2_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultCO2(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" HC_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultHC(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" PMx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultPMx(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" NOx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultNOx(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" fuel_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultFuel(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6); // @todo: give correct slope
"\" CO_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" CO2_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO2, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" HC_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::HC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" PMx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::PM_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" NOx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::NO_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
"\" fuel_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::FUEL, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6); // @todo: give correct slope
}
dev << "\"";
dev.closeTag();
Expand Down
20 changes: 4 additions & 16 deletions sumo/src/microsim/output/MSMeanData_Emissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@

#include <vector>
#include <set>
#include "MSMeanData.h"
#include <limits>
#include <utils/emissions/PollutantsInterface.h>
#include "MSMeanData.h"


// ===========================================================================
Expand Down Expand Up @@ -120,21 +121,8 @@ class MSMeanData_Emissions : public MSMeanData {


private:
/// @name Collected values
/// @{
/// @brief Sum of CO2 emissions in mg
SUMOReal CO2;
/// @brief Sum of CO emissions in mg
SUMOReal CO;
/// @brief Sum of HC emissions in mg
SUMOReal HC;
/// @brief Sum of NOx emissions in mg
SUMOReal NOx;
/// @brief Sum of PMx emissions in mg
SUMOReal PMx;
/// @brief Sum of consumed fuel in ml
SUMOReal fuel;
//@}
/// @brief Collected values
PollutantsInterface::Emissions myEmissions;
/// @brief The meandata parent
const MSMeanData_Emissions* myParent;

Expand Down
Loading

0 comments on commit 9bef912

Please sign in to comment.