Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSMeanData_Emissions.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// Emission data collector for edges/lanes that
20/****************************************************************************/
21#include <config.h>
22
23#include <limits>
24#include <microsim/MSNet.h>
25#include <microsim/MSLane.h>
26#include <microsim/MSVehicle.h>
33
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38// ---------------------------------------------------------------------------
39// MSMeanData_Emissions::MSLaneMeanDataValues - methods
40// ---------------------------------------------------------------------------
42 const double length, const bool doAdd,
43 const MSMeanData_Emissions* parent)
44 : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
45 myEmissions() {}
46
47
50
51
52void
54 sampleSeconds = 0.;
55 travelledDistance = 0.;
56 myEmissions = PollutantsInterface::Emissions();
57 resetTime = SIMSTEP;
58}
59
60
61void
68
69
70void
71MSMeanData_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*/) {
72 if (myParent != nullptr && !myParent->vehicleApplies(veh)) {
73 return;
74 }
75 if (veh.isVehicle()) {
76 sampleSeconds += frontOnLane;
77 travelledDistance += travelledDistanceFrontOnLane;
78 const double a = veh.getAcceleration();
80 // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
81 meanSpeedFrontOnLane, a, veh.getSlope(),
82 static_cast<const SUMOVehicle&>(veh).getEmissionParameters()), frontOnLane);
83 }
84}
85
86bool
88 if (veh.isVehicle()) {
90 0., 0., 0.,
91 static_cast<const SUMOVehicle&>(veh).getEmissionParameters()), TS);
92 }
93 return true;
94}
95
96
97void
99 const int /*numLanes*/, const double /*speedLimit*/, const double defaultTravelTime, const int /*numVehicles*/) const {
100 const double normFactor = double(3600. / STEPS2TIME(period) / myLaneLength);
102 dev.writeOptionalAttr(SUMO_ATTR_CO_ABS, myEmissions.CO, attributeMask);
103 dev.writeOptionalAttr(SUMO_ATTR_CO2_ABS, myEmissions.CO2, attributeMask);
104 dev.writeOptionalAttr(SUMO_ATTR_HC_ABS, myEmissions.HC, attributeMask);
105 dev.writeOptionalAttr(SUMO_ATTR_PMX_ABS, myEmissions.PMx, attributeMask);
106 dev.writeOptionalAttr(SUMO_ATTR_NOX_ABS, myEmissions.NOx, attributeMask);
107 dev.writeOptionalAttr(SUMO_ATTR_FUEL_ABS, myEmissions.fuel, attributeMask);
108 dev.writeOptionalAttr(SUMO_ATTR_ELECTRICITY_ABS, myEmissions.electricity, attributeMask);
109 if (attributeMask == 0) {
110 dev.writePadding("\n ");
111 }
112 dev.writeOptionalAttr(SUMO_ATTR_CO_NORMED, normFactor * myEmissions.CO, attributeMask);
113 dev.writeOptionalAttr(SUMO_ATTR_CO2_NORMED, normFactor * myEmissions.CO2, attributeMask);
114 dev.writeOptionalAttr(SUMO_ATTR_HC_NORMED, normFactor * myEmissions.HC, attributeMask);
115 dev.writeOptionalAttr(SUMO_ATTR_PMX_NORMED, normFactor * myEmissions.PMx, attributeMask);
116 dev.writeOptionalAttr(SUMO_ATTR_NOX_NORMED, normFactor * myEmissions.NOx, attributeMask);
117 dev.writeOptionalAttr(SUMO_ATTR_FUEL_NORMED, normFactor * myEmissions.fuel, attributeMask);
118 dev.writeOptionalAttr(SUMO_ATTR_ELECTRICITY_NORMED, normFactor * myEmissions.electricity, attributeMask);
119
120 if (sampleSeconds > myParent->getMinSamples()) {
121 double vehFactor = myParent->getMaxTravelTime() / sampleSeconds;
122 double traveltime = myParent->getMaxTravelTime();
123 if (travelledDistance > 0.f) {
124 vehFactor = MIN2(vehFactor, myLaneLength / travelledDistance);
125 traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
126 }
127 if (attributeMask == 0) {
128 dev.writePadding("\n ");
129 }
131 dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask);
133 dev.writeOptionalAttr(SUMO_ATTR_CO_PERVEH, vehFactor * myEmissions.CO, attributeMask);
134 dev.writeOptionalAttr(SUMO_ATTR_CO2_PERVEH, vehFactor * myEmissions.CO2, attributeMask);
135 dev.writeOptionalAttr(SUMO_ATTR_HC_PERVEH, vehFactor * myEmissions.HC, attributeMask);
136 dev.writeOptionalAttr(SUMO_ATTR_PMX_PERVEH, vehFactor * myEmissions.PMx, attributeMask);
137 dev.writeOptionalAttr(SUMO_ATTR_NOX_PERVEH, vehFactor * myEmissions.NOx, attributeMask);
138 dev.writeOptionalAttr(SUMO_ATTR_FUEL_PERVEH, vehFactor * myEmissions.fuel, attributeMask);
139 dev.writeOptionalAttr(SUMO_ATTR_ELECTRICITY_PERVEH, vehFactor * myEmissions.electricity, attributeMask);
140 } else if (defaultTravelTime >= 0.) {
142 const double speed = MIN2(myLaneLength / defaultTravelTime, t->getMaxSpeed());
143
144 if (attributeMask == 0) {
145 dev.writePadding("\n ");
146 }
148 dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, defaultTravelTime, attributeMask);
157 }
159 dev.closeTag();
160}
161
162
163
164// ---------------------------------------------------------------------------
165// MSMeanData_Emissions - methods
166// ---------------------------------------------------------------------------
168 const SUMOTime dumpBegin,
169 const SUMOTime dumpEnd,
170 const bool useLanes, const bool withEmpty,
171 const bool printDefaults,
172 const bool withInternal,
173 const bool trackVehicles,
174 const double maxTravelTime,
175 const double minSamples,
176 const std::string& vTypes,
177 const std::string& writeAttributes,
178 const std::vector<MSEdge*>& edges,
179 bool aggregate) :
180 MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
181 withInternal, trackVehicles, 0, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate)
182{ }
183
184
186
187
189MSMeanData_Emissions::createValues(MSLane* const lane, const double length, const bool doAdd) const {
190 return new MSLaneMeanDataValues(lane, length, doAdd, this);
191}
192
193
194/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SIMSTEP
Definition SUMOTime.h:61
#define TS
Definition SUMOTime.h:42
std::bitset< 96 > SumoXMLAttrMask
@ SUMO_ATTR_NOX_ABS
@ SUMO_ATTR_FUEL_PERVEH
@ SUMO_ATTR_HC_NORMED
@ SUMO_ATTR_FUEL_NORMED
@ SUMO_ATTR_CO_PERVEH
@ SUMO_ATTR_ELECTRICITY_ABS
@ SUMO_ATTR_PMX_PERVEH
@ SUMO_ATTR_HC_PERVEH
@ SUMO_ATTR_CO2_NORMED
@ SUMO_ATTR_NOX_NORMED
@ SUMO_ATTR_TRAVELTIME
@ SUMO_ATTR_PMX_ABS
@ SUMO_ATTR_ELECTRICITY_PERVEH
@ SUMO_ATTR_CO_ABS
MSMeanData_Emissions.
@ SUMO_ATTR_FUEL_ABS
@ SUMO_ATTR_CO_NORMED
@ SUMO_ATTR_NOX_PERVEH
@ SUMO_ATTR_HC_ABS
@ SUMO_ATTR_CO2_PERVEH
@ SUMO_ATTR_PMX_NORMED
@ SUMO_ATTR_ELECTRICITY_NORMED
@ SUMO_ATTR_CO2_ABS
int gPrecisionEmissions
Definition StdDefs.cpp:27
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
T MIN2(T a, T b)
Definition StdDefs.h:80
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:261
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Data structure for mean (aggregated) edge/lane values.
Definition MSMeanData.h:66
double travelledDistance
The sum of the distances the vehicles travelled.
Definition MSMeanData.h:190
Data structure for mean (aggregated) edge/lane values.
MSLaneMeanDataValues(MSLane *const lane, const double length, const bool doAdd, const MSMeanData_Emissions *parent)
Constructor.
bool notifyIdle(SUMOTrafficObject &veh)
Computes idling emission values and adds them to the aggregate emission sums.
void write(OutputDevice &dev, const SumoXMLAttrMask &attributeMask, const SUMOTime period, const int numLanes, const double speedLimit, const double defaultTravelTime, const int numVehicles=-1) const
Writes output values into the given stream.
PollutantsInterface::Emissions myEmissions
Collected values.
void reset(bool afterWrite=false)
Resets values so they may be used for the next interval.
void addTo(MSMeanData::MeanDataValues &val) const
Add the values of this to the given one and store them there.
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.
Emission data collector for edges/lanes.
MSMeanData::MeanDataValues * createValues(MSLane *const lane, const double length, const bool doAdd) const
Create an instance of MeanDataValues.
virtual ~MSMeanData_Emissions()
Destructor.
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, const std::string &writeAttributes, const std::vector< MSEdge * > &edges, bool aggregate)
Constructor.
Data collector for edges/lanes.
Definition MSMeanData.h:57
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:384
MSVehicleType * getVType(const std::string &id=DEFAULT_VTYPE_ID, SumoRNG *rng=nullptr, bool readOnly=false)
Returns the named vehicle type or a sample from the named distribution.
The car-following model and parameter.
const EnergyParams * getEmissionParameters() const
retrieve parameters for the energy consumption model
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
const MSCFModel & getCarFollowModel() const
Returns the vehicle type's car following model definition (const version)
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
OutputDevice & writeOptionalAttr(const SumoXMLAttr attr, const T &val, const SumoXMLAttrMask &attributeMask, const bool isNull=false)
writes a named attribute unless filtered
static double computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const EnergyParams *param)
Returns the amount of emitted pollutant given the vehicle type and default values for the state (in m...
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams *param)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
Representation of a vehicle, person, or container.
virtual bool isVehicle() const
Whether it is a vehicle.
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
Storage for collected values of all emission types.
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.