SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.dlr.de/
11 // Copyright (C) 2001-2016 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 MSMeanData_Emissions* parent)
56  : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
57  myEmissions() {}
58 
59 
61 }
62 
63 
64 void
66  sampleSeconds = 0.;
67  travelledDistance = 0.;
68  myEmissions = PollutantsInterface::Emissions();
69 }
70 
71 
72 void
75  v.sampleSeconds += sampleSeconds;
76  v.travelledDistance += travelledDistance;
77  v.myEmissions.addScaled(myEmissions);
78 }
79 
80 
81 void
82 MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal(const SUMOVehicle& veh, const SUMOReal /* frontOnLane */, const SUMOReal timeOnLane, const SUMOReal /*meanSpeedFrontOnLane*/, const SUMOReal meanSpeedVehicleOnLane, const SUMOReal /*travelledDistanceFrontOnLane*/, const SUMOReal travelledDistanceVehicleOnLane) {
83  sampleSeconds += timeOnLane;
84  travelledDistance += travelledDistanceVehicleOnLane;
85  const double a = veh.getAcceleration();
87  // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
88  meanSpeedVehicleOnLane, a, veh.getSlope()), timeOnLane);
89 }
90 
91 
92 void
94  const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
95  const SUMOReal normFactor = SUMOReal(3600. / STEPS2TIME(period) / myLaneLength);
96  dev << " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
97  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
98  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
99  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
100  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
101  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
102  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
103  "\"\n CO_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO, 6) <<
104  "\" CO2_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO2, 6) <<
105  "\" HC_normed=\"" << OutputDevice::realString(normFactor * myEmissions.HC, 6) <<
106  "\" PMx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.PMx, 6) <<
107  "\" NOx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.NOx, 6) <<
108  "\" fuel_normed=\"" << OutputDevice::realString(normFactor * myEmissions.fuel, 6) <<
109  "\" electricity_normed=\"" << OutputDevice::realString(normFactor * myEmissions.electricity, 6);
110  if (sampleSeconds > myParent->getMinSamples()) {
111  SUMOReal vehFactor = myParent->getMaxTravelTime() / sampleSeconds;
112  SUMOReal traveltime = myParent->getMaxTravelTime();
113  if (travelledDistance > 0.f) {
114  vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
115  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
116  }
117  dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
118  "\" CO_perVeh=\"" << OutputDevice::realString(myEmissions.CO * vehFactor, 6) <<
119  "\" CO2_perVeh=\"" << OutputDevice::realString(myEmissions.CO2 * vehFactor, 6) <<
120  "\" HC_perVeh=\"" << OutputDevice::realString(myEmissions.HC * vehFactor, 6) <<
121  "\" PMx_perVeh=\"" << OutputDevice::realString(myEmissions.PMx * vehFactor, 6) <<
122  "\" NOx_perVeh=\"" << OutputDevice::realString(myEmissions.NOx * vehFactor, 6) <<
123  "\" fuel_perVeh=\"" << OutputDevice::realString(myEmissions.fuel * vehFactor, 6) <<
124  "\" electricity_perVeh=\"" << OutputDevice::realString(myEmissions.electricity * vehFactor, 6);
125  } else if (defaultTravelTime >= 0.) {
127  const SUMOReal speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
128  dev << "\"\n traveltime=\"" << OutputDevice::realString(defaultTravelTime) <<
129  "\" CO_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
130  "\" CO2_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO2, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
131  "\" HC_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::HC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
132  "\" PMx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::PM_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
133  "\" NOx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::NO_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
134  "\" fuel_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::FUEL, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
135  "\" electricity_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::ELEC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6); // @todo: give correct slope
136  }
137  dev << "\"";
138  dev.closeTag();
139 }
140 
141 
142 
143 // ---------------------------------------------------------------------------
144 // MSMeanData_Emissions - methods
145 // ---------------------------------------------------------------------------
147  const SUMOTime dumpBegin,
148  const SUMOTime dumpEnd,
149  const bool useLanes, const bool withEmpty,
150  const bool printDefaults,
151  const bool withInternal,
152  const bool trackVehicles,
153  const SUMOReal maxTravelTime,
154  const SUMOReal minSamples,
155  const std::string& vTypes)
156  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
157  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
158 }
159 
160 
162 
163 
165 MSMeanData_Emissions::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
166  return new MSLaneMeanDataValues(lane, length, doAdd, this);
167 }
168 
169 
170 /****************************************************************************/
Data collector for edges/lanes.
Definition: MSMeanData.h:67
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
long long int SUMOTime
Definition: SUMOTime.h:43
void addScaled(const Emissions &a, const SUMOReal scale=1.)
Add the values of the other struct to this one, scaling the values if needed.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
SUMOReal travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:183
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:159
PollutantsInterface::Emissions myEmissions
Collected values.
MSLaneMeanDataValues(MSLane *const lane, const SUMOReal length, const bool doAdd, const MSMeanData_Emissions *parent)
Constructor.
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)
Representation of a vehicle.
Definition: SUMOVehicle.h:66
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:76
static SUMOReal computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const SUMOReal tt)
Returns the amount of emitted pollutant given the vehicle type and default values for the state (in m...
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:307
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
T MIN2(T a, T b)
Definition: StdDefs.h:69
Emission data collector for edges/lanes.
SUMOReal getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:193
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::string &vTypes)
Constructor.
virtual SUMOReal getAcceleration() const =0
Returns the vehicle's acceleration.
static std::string realString(const SUMOReal v, const int precision=OUTPUT_ACCURACY)
Helper method for string formatting.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
virtual ~MSMeanData_Emissions()
Destructor.
void notifyMoveInternal(const SUMOVehicle &veh, const SUMOReal, const SUMOReal timeOnLane, const SUMOReal, const SUMOReal meanSpeedVehicleOnLane, const SUMOReal travelledDistanceFrontOnLane, const SUMOReal travelledDistanceVehicleOnLane)
Internal notification about the vehicle moves.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:214
virtual SUMOReal getSlope() const =0
Returns the slope of the road at vehicle's position.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, MTRand *rng=0)
Returns the named vehicle type or a sample from the named distribution.
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:79
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.
Data structure for mean (aggregated) edge/lane values.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.