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-sim.org/
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  myEmissions(), myParent(parent) {}
59 
60 
62 }
63 
64 
65 void
67  sampleSeconds = 0.;
68  travelledDistance = 0.;
69  myEmissions = PollutantsInterface::Emissions();
70 }
71 
72 
73 void
76  v.sampleSeconds += sampleSeconds;
77  v.travelledDistance += travelledDistance;
78  v.myEmissions.addScaled(myEmissions);
79 }
80 
81 
82 void
84  sampleSeconds += timeOnLane;
85  travelledDistance += speed * timeOnLane;
86  const double a = veh.getAcceleration();
87  myEmissions.addScaled(PollutantsInterface::computeAll(veh.getVehicleType().getEmissionClass(), speed, a, veh.getSlope()), timeOnLane);
88 }
89 
90 
91 void
93  const SUMOReal /*numLanes*/, const SUMOReal defaultTravelTime, const int /*numVehicles*/) const {
94  const SUMOReal normFactor = SUMOReal(3600. / STEPS2TIME(period) / myLaneLength);
95  dev << " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
96  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
97  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
98  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
99  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
100  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
101  "\"\n CO_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO, 6) <<
102  "\" CO2_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO2, 6) <<
103  "\" HC_normed=\"" << OutputDevice::realString(normFactor * myEmissions.HC, 6) <<
104  "\" PMx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.PMx, 6) <<
105  "\" NOx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.NOx, 6) <<
106  "\" fuel_normed=\"" << OutputDevice::realString(normFactor * myEmissions.fuel, 6);
107  if (sampleSeconds > myParent->myMinSamples) {
108  SUMOReal vehFactor = myParent->myMaxTravelTime / sampleSeconds;
109  SUMOReal traveltime = myParent->myMaxTravelTime;
110  if (travelledDistance > 0.f) {
111  vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
112  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
113  }
114  dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
115  "\" CO_perVeh=\"" << OutputDevice::realString(myEmissions.CO * vehFactor, 6) <<
116  "\" CO2_perVeh=\"" << OutputDevice::realString(myEmissions.CO2 * vehFactor, 6) <<
117  "\" HC_perVeh=\"" << OutputDevice::realString(myEmissions.HC * vehFactor, 6) <<
118  "\" PMx_perVeh=\"" << OutputDevice::realString(myEmissions.PMx * vehFactor, 6) <<
119  "\" NOx_perVeh=\"" << OutputDevice::realString(myEmissions.NOx * vehFactor, 6) <<
120  "\" fuel_perVeh=\"" << OutputDevice::realString(myEmissions.fuel * vehFactor, 6);
121  } else if (defaultTravelTime >= 0.) {
123  const SUMOReal 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  }
132  dev << "\"";
133  dev.closeTag();
134 }
135 
136 
137 
138 // ---------------------------------------------------------------------------
139 // MSMeanData_Emissions - methods
140 // ---------------------------------------------------------------------------
142  const SUMOTime dumpBegin,
143  const SUMOTime dumpEnd,
144  const bool useLanes, const bool withEmpty,
145  const bool printDefaults,
146  const bool withInternal,
147  const bool trackVehicles,
148  const SUMOReal maxTravelTime,
149  const SUMOReal minSamples,
150  const std::set<std::string> vTypes)
151  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
152  withInternal, trackVehicles, maxTravelTime, minSamples, vTypes) {
153 }
154 
155 
157 
158 
160 MSMeanData_Emissions::createValues(MSLane* const lane, const SUMOReal length, const bool doAdd) const {
161  return new MSLaneMeanDataValues(lane, length, doAdd, &myVehicleTypes, this);
162 }
163 
164 
165 /****************************************************************************/