SUMO - Simulation of Urban MObility
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.dlr.de/
11 // Copyright (C) 2001-2017 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 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // MSMeanData_Emissions::MSLaneMeanDataValues - methods
48 // ---------------------------------------------------------------------------
50  const double length, const bool doAdd,
51  const MSMeanData_Emissions* parent)
52  : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
53  myEmissions() {}
54 
55 
57 }
58 
59 
60 void
62  sampleSeconds = 0.;
63  travelledDistance = 0.;
65 }
66 
67 
68 void
74 }
75 
76 
77 void
78 MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal(const SUMOVehicle& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane) {
79  sampleSeconds += timeOnLane;
80  travelledDistance += travelledDistanceVehicleOnLane;
81  const double a = veh.getAcceleration();
83  // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
84  meanSpeedVehicleOnLane, a, veh.getSlope()), timeOnLane);
85 }
86 
87 
88 void
90  const double /*numLanes*/, const double defaultTravelTime, const int /*numVehicles*/) const {
91  const double normFactor = double(3600. / STEPS2TIME(period) / myLaneLength);
92  dev << " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
93  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
94  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
95  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
96  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
97  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
98  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
99  "\"\n CO_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO, 6) <<
100  "\" CO2_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO2, 6) <<
101  "\" HC_normed=\"" << OutputDevice::realString(normFactor * myEmissions.HC, 6) <<
102  "\" PMx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.PMx, 6) <<
103  "\" NOx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.NOx, 6) <<
104  "\" fuel_normed=\"" << OutputDevice::realString(normFactor * myEmissions.fuel, 6) <<
105  "\" electricity_normed=\"" << OutputDevice::realString(normFactor * myEmissions.electricity, 6);
107  double vehFactor = myParent->getMaxTravelTime() / sampleSeconds;
108  double traveltime = myParent->getMaxTravelTime();
109  if (travelledDistance > 0.f) {
110  vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
111  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
112  }
113  dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
114  "\" CO_perVeh=\"" << OutputDevice::realString(myEmissions.CO * vehFactor, 6) <<
115  "\" CO2_perVeh=\"" << OutputDevice::realString(myEmissions.CO2 * vehFactor, 6) <<
116  "\" HC_perVeh=\"" << OutputDevice::realString(myEmissions.HC * vehFactor, 6) <<
117  "\" PMx_perVeh=\"" << OutputDevice::realString(myEmissions.PMx * vehFactor, 6) <<
118  "\" NOx_perVeh=\"" << OutputDevice::realString(myEmissions.NOx * vehFactor, 6) <<
119  "\" fuel_perVeh=\"" << OutputDevice::realString(myEmissions.fuel * vehFactor, 6) <<
120  "\" electricity_perVeh=\"" << OutputDevice::realString(myEmissions.electricity * vehFactor, 6);
121  } else if (defaultTravelTime >= 0.) {
123  const double speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
124  dev << "\"\n traveltime=\"" << OutputDevice::realString(defaultTravelTime) <<
125  "\" CO_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
126  "\" CO2_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO2, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
127  "\" HC_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::HC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
128  "\" PMx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::PM_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
129  "\" NOx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::NO_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
130  "\" fuel_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::FUEL, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
131  "\" electricity_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::ELEC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6); // @todo: give correct slope
132  }
133  dev << "\"";
134  dev.closeTag();
135 }
136 
137 
138 
139 // ---------------------------------------------------------------------------
140 // MSMeanData_Emissions - methods
141 // ---------------------------------------------------------------------------
143  const SUMOTime dumpBegin,
144  const SUMOTime dumpEnd,
145  const bool useLanes, const bool withEmpty,
146  const bool printDefaults,
147  const bool withInternal,
148  const bool trackVehicles,
149  const double maxTravelTime,
150  const double minSamples,
151  const std::string& vTypes)
152  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
153  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
154 }
155 
156 
158 
159 
161 MSMeanData_Emissions::createValues(MSLane* const lane, const double length, const bool doAdd) const {
162  return new MSLaneMeanDataValues(lane, length, doAdd, this);
163 }
164 
165 
166 /****************************************************************************/
Data collector for edges/lanes.
Definition: MSMeanData.h:67
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map< int, double > *param=0)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
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 double minSamples, const double maxTravelTime, const std::string &vTypes)
Constructor.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
Storage for collected values of all emission types.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:158
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
PollutantsInterface::Emissions myEmissions
Collected values.
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
MSLaneMeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData_Emissions *parent)
Constructor.
The car-following model and parameter.
Definition: MSVehicleType.h:74
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:193
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:183
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
Representation of a vehicle.
Definition: SUMOVehicle.h:67
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
void write(OutputDevice &dev, const SUMOTime period, const double numLanes, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
T MIN2(T a, T b)
Definition: StdDefs.h:64
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:175
Emission data collector for edges/lanes.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
void notifyMoveInternal(const SUMOVehicle &veh, const double, const double timeOnLane, const double, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane)
Internal notification about the vehicle moves.
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:172
virtual ~MSMeanData_Emissions()
Destructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
long long int SUMOTime
Definition: TraCIDefs.h:52
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
static double computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const std::map< int, double > *param=0)
Returns the amount of emitted pollutant given the vehicle type and default values for the state (in m...
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
double getMaxTravelTime() const
Definition: MSMeanData.h:364
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.
Data structure for mean (aggregated) edge/lane values.
double getMinSamples() const
Definition: MSMeanData.h:360
virtual double getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.