SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSMeanData_Emissions.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Emission data collector for edges/lanes that
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <microsim/MSNet.h>
33 #include <microsim/MSLane.h>
34 #include <microsim/MSVehicle.h>
35 #include <utils/common/SUMOTime.h>
36 #include <utils/common/ToString.h>
38 #include "MSMeanData_Emissions.h"
40 #include <limits>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 // ---------------------------------------------------------------------------
51 // MSMeanData_Emissions::MSLaneMeanDataValues - methods
52 // ---------------------------------------------------------------------------
54  const SUMOReal length, const bool doAdd,
55  const std::set<std::string>* const vTypes,
56  const MSMeanData_Emissions* parent)
57  : MSMeanData::MeanDataValues(lane, length, doAdd, vTypes),
58  CO2(0), CO(0), HC(0), NOx(0), PMx(0), fuel(0), myParent(parent) {}
59 
60 
62 }
63 
64 
65 void
67  sampleSeconds = 0.;
68  travelledDistance = 0.;
69  CO2 = 0;
70  CO = 0;
71  HC = 0;
72  NOx = 0;
73  PMx = 0;
74  fuel = 0;
75 }
76 
77 
78 void
81  v.sampleSeconds += sampleSeconds;
82  v.travelledDistance += travelledDistance;
83  v.CO2 += CO2;
84  v.CO += CO;
85  v.HC += HC;
86  v.NOx += NOx;
87  v.PMx += PMx;
88  v.fuel += fuel;
89 }
90 
91 
92 void
94  sampleSeconds += timeOnLane;
95  travelledDistance += speed * timeOnLane;
96  const double a = veh.getAcceleration();
97  CO += (timeOnLane * PollutantsInterface::computeCO(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
98  CO2 += (timeOnLane * PollutantsInterface::computeCO2(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
99  HC += (timeOnLane * PollutantsInterface::computeHC(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
100  NOx += (timeOnLane * PollutantsInterface::computeNOx(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
101  PMx += (timeOnLane * PollutantsInterface::computePMx(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
102  fuel += (timeOnLane * PollutantsInterface::computeFuel(veh.getVehicleType().getEmissionClass(), (double) speed, a, veh.getSlope()));
103 }
104 
105 
106 void
108  const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
109  const SUMOReal normFactor = SUMOReal(3600. / STEPS2TIME(period) / myLaneLength);
110  dev << " CO_abs=\"" << OutputDevice::realString(CO, 6) <<
111  "\" CO2_abs=\"" << OutputDevice::realString(CO2, 6) <<
112  "\" HC_abs=\"" << OutputDevice::realString(HC, 6) <<
113  "\" PMx_abs=\"" << OutputDevice::realString(PMx, 6) <<
114  "\" NOx_abs=\"" << OutputDevice::realString(NOx, 6) <<
115  "\" fuel_abs=\"" << OutputDevice::realString(fuel, 6) <<
116  "\"\n CO_normed=\"" << OutputDevice::realString(normFactor * CO, 6) <<
117  "\" CO2_normed=\"" << OutputDevice::realString(normFactor * CO2, 6) <<
118  "\" HC_normed=\"" << OutputDevice::realString(normFactor * HC, 6) <<
119  "\" PMx_normed=\"" << OutputDevice::realString(normFactor * PMx, 6) <<
120  "\" NOx_normed=\"" << OutputDevice::realString(normFactor * NOx, 6) <<
121  "\" fuel_normed=\"" << OutputDevice::realString(normFactor * fuel, 6);
122  if (sampleSeconds > myParent->myMinSamples) {
123  SUMOReal vehFactor = myParent->myMaxTravelTime / sampleSeconds;
124  SUMOReal traveltime = myParent->myMaxTravelTime;
125  if (travelledDistance > 0.f) {
126  vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
127  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
128  }
129  dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
130  "\" CO_perVeh=\"" << OutputDevice::realString(CO * vehFactor, 6) <<
131  "\" CO2_perVeh=\"" << OutputDevice::realString(CO2 * vehFactor, 6) <<
132  "\" HC_perVeh=\"" << OutputDevice::realString(HC * vehFactor, 6) <<
133  "\" PMx_perVeh=\"" << OutputDevice::realString(PMx * vehFactor, 6) <<
134  "\" NOx_perVeh=\"" << OutputDevice::realString(NOx * vehFactor, 6) <<
135  "\" fuel_perVeh=\"" << OutputDevice::realString(fuel * vehFactor, 6);
136  } else if (defaultTravelTime >= 0.) {
138  const SUMOReal speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
139  dev << "\"\n traveltime=\"" << OutputDevice::realString(defaultTravelTime) <<
140  "\" CO_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultCO(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
141  "\" CO2_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultCO2(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
142  "\" HC_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultHC(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
143  "\" PMx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultPMx(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
144  "\" NOx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultNOx(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
145  "\" fuel_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefaultFuel(t->getEmissionClass(), speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6); // @todo: give correct slope
146  }
147  dev << "\"";
148  dev.closeTag();
149 }
150 
151 
152 
153 // ---------------------------------------------------------------------------
154 // MSMeanData_Emissions - methods
155 // ---------------------------------------------------------------------------
157  const SUMOTime dumpBegin,
158  const SUMOTime dumpEnd,
159  const bool useLanes, const bool withEmpty,
160  const bool printDefaults,
161  const bool withInternal,
162  const bool trackVehicles,
163  const SUMOReal maxTravelTime,
164  const SUMOReal minSamples,
165  const std::set<std::string> vTypes)
166  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
167  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
168 }
169 
170 
172 
173 
175 MSMeanData_Emissions::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
176  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
177 }
178 
179 
180 /****************************************************************************/
static SUMOReal computeDefaultCO2(SUMOEmissionClass c, double v, double a, double slope, SUMOReal tt)
Returns the amount of emitted CO2 given the vehicle type and default values for the state (in mg) ...
Data collector for edges/lanes.
Definition: MSMeanData.h:66
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
MSMeanData_Emissions(const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool printDefaults, const bool withInternal, const bool trackVehicles, const SUMOReal minSamples, const SUMOReal maxTravelTime, const std::set< std::string > vTypes)
Constructor.
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:180
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID)
Returns the named vehicle type or a sample from the named distribution.
static SUMOReal computeDefaultHC(SUMOEmissionClass c, double v, double a, double slope, SUMOReal tt)
Returns the amount of emitted HC given the vehicle type and default values for the state (in mg) ...
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
const std::set< std::string > myVehicleTypes
The vehicle types to look for (empty means all)
Definition: MSMeanData.h:420
The car-following model and parameter.
Definition: MSVehicleType.h:74
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
static SUMOReal computeDefaultNOx(SUMOEmissionClass c, double v, double a, double slope, SUMOReal tt)
Returns the amount of emitted NOx given the vehicle type and default values for the state (in mg) ...
static SUMOReal computeFuel(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of consumed fuel given the vehicle type and state (in ml/s)
static SUMOReal computeCO2(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted CO2 given the vehicle type and state (in mg/s)
static SUMOReal computeDefaultPMx(SUMOEmissionClass c, double v, double a, double slope, SUMOReal tt)
Returns the amount of emitted PMx given the vehicle type and default values for the state (in mg) ...
SUMOReal CO
Sum of CO emissions in mg.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:75
static SUMOReal computeNOx(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted NOx given the vehicle type and state (in mg/s)
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:263
static SUMOReal computeHC(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted HC given the vehicle type and state (in mg/s)
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
SUMOReal fuel
Sum of consumed fuel in ml.
T MIN2(T a, T b)
Definition: StdDefs.h:65
static SUMOReal computeDefaultFuel(SUMOEmissionClass c, double v, double a, double slope, SUMOReal tt)
Returns the amount of fuel given the vehicle type and default values for the state (in ml) ...
SUMOReal NOx
Sum of NOx emissions in mg.
Emission data collector for edges/lanes.
SUMOReal HC
Sum of HC emissions in mg.
static SUMOReal computeDefaultCO(SUMOEmissionClass c, double v, double a, double slope, SUMOReal tt)
Returns the amount of emitted CO given the vehicle type and default values for the state (in mg) ...
SUMOReal getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:157
static SUMOReal computeCO(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted CO given the vehicle type and state (in mg/s)
virtual SUMOReal getAcceleration() const =0
Returns the vehicle's acceleration.
SUMOReal PMx
Sum of PMx emissions in mg.
static std::string realString(const SUMOReal v, const int precision=OUTPUT_ACCURACY)
Helper method for string formatting.
void notifyMoveInternal(SUMOVehicle &veh, SUMOReal timeOnLane, SUMOReal speed)
Internal notification about the vehicle moves.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
virtual ~MSMeanData_Emissions()
Destructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:215
virtual SUMOReal getSlope() const =0
Returns the slope of the road at vehicle's position.
MSLaneMeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const std::set< std::string > *const vTypes=0, const MSMeanData_Emissions *parent=0)
Constructor.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const SUMOReal length, const bool doAdd) const
Create an instance of MeanDataValues.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
void write(OutputDevice &dev, const SUMOTime period, const SUMOReal numLanes, const SUMOReal defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
static SUMOReal computePMx(SUMOEmissionClass c, double v, double a, double slope)
Returns the amount of emitted PMx given the vehicle type and state (in mg/s)
Data structure for mean (aggregated) edge/lane values.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.