Eclipse SUMO - Simulation of Urban MObility
MSMeanData_Emissions.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Emission data collector for edges/lanes that
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <microsim/MSNet.h>
26 #include <microsim/MSLane.h>
27 #include <microsim/MSVehicle.h>
29 #include <utils/common/SUMOTime.h>
30 #include <utils/common/ToString.h>
32 #include "MSMeanData_Emissions.h"
34 #include <limits>
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 // ---------------------------------------------------------------------------
41 // MSMeanData_Emissions::MSLaneMeanDataValues - methods
42 // ---------------------------------------------------------------------------
44  const double length, const bool doAdd,
45  const MSMeanData_Emissions* parent)
46  : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
47  myEmissions() {}
48 
49 
51 }
52 
53 
54 void
56  sampleSeconds = 0.;
57  travelledDistance = 0.;
59 }
60 
61 
62 void
68 }
69 
70 
71 void
72 MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */) {
73  sampleSeconds += timeOnLane;
74  travelledDistance += travelledDistanceVehicleOnLane;
75  const double a = veh.getAcceleration();
77  // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
78  meanSpeedVehicleOnLane, a, veh.getSlope()), timeOnLane);
79 }
80 
81 
82 void
84  const double /*numLanes*/, const double defaultTravelTime, const int /*numVehicles*/) const {
85  const double normFactor = double(3600. / STEPS2TIME(period) / myLaneLength);
86  dev << " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
87  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
88  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
89  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
90  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
91  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
92  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
93  "\"\n CO_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO, 6) <<
94  "\" CO2_normed=\"" << OutputDevice::realString(normFactor * myEmissions.CO2, 6) <<
95  "\" HC_normed=\"" << OutputDevice::realString(normFactor * myEmissions.HC, 6) <<
96  "\" PMx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.PMx, 6) <<
97  "\" NOx_normed=\"" << OutputDevice::realString(normFactor * myEmissions.NOx, 6) <<
98  "\" fuel_normed=\"" << OutputDevice::realString(normFactor * myEmissions.fuel, 6) <<
99  "\" electricity_normed=\"" << OutputDevice::realString(normFactor * myEmissions.electricity, 6);
101  double vehFactor = myParent->getMaxTravelTime() / sampleSeconds;
102  double traveltime = myParent->getMaxTravelTime();
103  if (travelledDistance > 0.f) {
104  vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
105  traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
106  }
107  dev << "\"\n traveltime=\"" << OutputDevice::realString(traveltime) <<
108  "\" CO_perVeh=\"" << OutputDevice::realString(myEmissions.CO * vehFactor, 6) <<
109  "\" CO2_perVeh=\"" << OutputDevice::realString(myEmissions.CO2 * vehFactor, 6) <<
110  "\" HC_perVeh=\"" << OutputDevice::realString(myEmissions.HC * vehFactor, 6) <<
111  "\" PMx_perVeh=\"" << OutputDevice::realString(myEmissions.PMx * vehFactor, 6) <<
112  "\" NOx_perVeh=\"" << OutputDevice::realString(myEmissions.NOx * vehFactor, 6) <<
113  "\" fuel_perVeh=\"" << OutputDevice::realString(myEmissions.fuel * vehFactor, 6) <<
114  "\" electricity_perVeh=\"" << OutputDevice::realString(myEmissions.electricity * vehFactor, 6);
115  } else if (defaultTravelTime >= 0.) {
117  const double speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
118  dev << "\"\n traveltime=\"" << OutputDevice::realString(defaultTravelTime) <<
119  "\" CO_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
120  "\" CO2_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::CO2, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
121  "\" HC_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::HC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
122  "\" PMx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::PM_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
123  "\" NOx_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::NO_X, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
124  "\" fuel_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::FUEL, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6) << // @todo: give correct slope
125  "\" electricity_perVeh=\"" << OutputDevice::realString(PollutantsInterface::computeDefault(t->getEmissionClass(), PollutantsInterface::ELEC, speed, t->getCarFollowModel().getMaxAccel(), 0, defaultTravelTime), 6); // @todo: give correct slope
126  }
127  dev << "\"";
128  dev.closeTag();
129 }
130 
131 
132 
133 // ---------------------------------------------------------------------------
134 // MSMeanData_Emissions - methods
135 // ---------------------------------------------------------------------------
137  const SUMOTime dumpBegin,
138  const SUMOTime dumpEnd,
139  const bool useLanes, const bool withEmpty,
140  const bool printDefaults,
141  const bool withInternal,
142  const bool trackVehicles,
143  const double maxTravelTime,
144  const double minSamples,
145  const std::string& vTypes)
146  : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
147  withInternal, trackVehicles, 0, maxTravelTime, minSamples, vTypes) {
148 }
149 
150 
152 
153 
155 MSMeanData_Emissions::createValues(MSLane* const lane, const double length, const bool doAdd) const {
156  return new MSLaneMeanDataValues(lane, length, doAdd, this);
157 }
158 
159 
160 /****************************************************************************/
Data collector for edges/lanes.
Definition: MSMeanData.h:60
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...
long long int SUMOTime
Definition: SUMOTime.h:35
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.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
virtual double getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, std::mt19937 *rng=nullptr)
Returns the named vehicle type or a sample from the named distribution.
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:168
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:66
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:210
double travelledDistance
The sum of the distances the vehicles travelled.
Definition: MSMeanData.h:176
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
void notifyMoveInternal(const SUMOTrafficObject &veh, const double, const double timeOnLane, const double, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double)
Internal notification about the vehicle moves.
Data structure for mean (aggregated) edge/lane values.
Definition: MSMeanData.h:69
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
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:74
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
const double myLaneLength
The length of the lane / edge the data collector is on.
Definition: MSMeanData.h:168
Emission data collector for edges/lanes.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
const MSMeanData *const myParent
The meandata parent.
Definition: MSMeanData.h:165
Representation of a vehicle or person.
virtual ~MSMeanData_Emissions()
Destructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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:83
double getMaxTravelTime() const
Definition: MSMeanData.h:359
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:355