Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSEmissionExport.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-2024 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/****************************************************************************/
21// Realises dumping Emission Data
22/****************************************************************************/
23#include <config.h>
24
30#include <microsim/MSLane.h>
31#include <microsim/MSNet.h>
32#include <microsim/MSVehicle.h>
34#include <mesosim/MEVehicle.h>
36#include "MSEmissionExport.h"
37
38
39// ===========================================================================
40// method definitions
41// ===========================================================================
42void
43MSEmissionExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
45 const SUMOTime period = string2time(oc.getString("device.emissions.period"));
46 const SUMOTime begin = string2time(oc.getString("device.emissions.begin"));
47 const bool scaled = oc.getBool("emission-output.step-scaled");
48 const bool useGeo = oc.getBool("emission-output.geo");
49 if ((period > 0 && (timestep - begin) % period != 0) || timestep < begin) {
50 return;
51 }
53
54 of.openTag("timestep").writeAttr("time", time2string(timestep));
55 of.setPrecision(precision);
57 for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
58 const SUMOVehicle* veh = it->second;
59 MSDevice_Emissions* emissionsDevice = (MSDevice_Emissions*)veh->getDevice(typeid(MSDevice_Emissions));
60 if (emissionsDevice != nullptr && (veh->isOnRoad() || veh->isIdling())) {
61 std::string fclass = veh->getVehicleType().getID();
62 fclass = fclass.substr(0, fclass.find_first_of("@"));
65 veh->getSpeed(), veh->getAcceleration(), veh->getSlope(),
67 if (scaled) {
69 tmp.addScaled(emiss, TS);
70 emiss = tmp;
71 }
72 of.openTag("vehicle");
73 of.writeAttr(SUMO_ATTR_ID, veh->getID());
75 of.writeOptionalAttr(SUMO_ATTR_CO2, emiss.CO2, mask);
76 of.writeOptionalAttr(SUMO_ATTR_CO, emiss.CO, mask);
77 of.writeOptionalAttr(SUMO_ATTR_HC, emiss.HC, mask);
78 of.writeOptionalAttr(SUMO_ATTR_NOX, emiss.NOx, mask);
79 of.writeOptionalAttr(SUMO_ATTR_PMX, emiss.PMx, mask);
80 of.writeOptionalAttr(SUMO_ATTR_FUEL, emiss.fuel, mask);
84 of.writeOptionalAttr(SUMO_ATTR_TYPE, fclass, mask);
86 const MEVehicle* mesoVeh = dynamic_cast<const MEVehicle*>(veh);
88 of.writeOptionalAttr(SUMO_ATTR_EDGE, veh->getEdge()->getID(), mask);
89 } else {
90 const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
92 of.writeOptionalAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID(), mask);
93 }
97
98 Position pos = veh->getPosition();
99 if (useGeo) {
100 of.setPrecision(MAX2(gPrecisionGeo, precision));
102 }
103 of.writeOptionalAttr(SUMO_ATTR_X, pos.x(), mask);
104 of.writeOptionalAttr(SUMO_ATTR_Y, pos.y(), mask);
105 if (MSNet::getInstance()->hasElevation()) {
106 of.writeOptionalAttr(SUMO_ATTR_Z, pos.z(), mask);
107 }
108 of.setPrecision(precision);
109
110 of.closeTag();
111 }
112 }
114 of.closeTag();
115}
long long int SUMOTime
Definition GUI.h:36
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition SUMOTime.cpp:46
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:69
#define TS
Definition SUMOTime.h:42
std::bitset< 96 > SumoXMLAttrMask
@ SUMO_ATTR_LANE
@ SUMO_ATTR_NOISE
MSMeanData_Harmonoise.
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_PMX
@ SUMO_ATTR_Y
@ SUMO_ATTR_Z
@ SUMO_ATTR_EDGE
@ SUMO_ATTR_WAITING
@ SUMO_ATTR_X
@ SUMO_ATTR_HC
@ SUMO_ATTR_FUEL
@ SUMO_ATTR_ELECTRICITY
@ SUMO_ATTR_CO
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_CO2
@ SUMO_ATTR_ID
@ SUMO_ATTR_ECLASS
@ SUMO_ATTR_NOX
@ SUMO_ATTR_POSITION
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
int gPrecisionGeo
Definition StdDefs.cpp:27
T MAX2(T a, T b)
Definition StdDefs.h:82
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
static double naviDegree(const double angle)
static double computeNoise(SUMOEmissionClass c, double v, double a)
Returns the noise produced by the a vehicle of the given type at the given speed.
A vehicle from the mesoscopic point of view.
Definition MEVehicle.h:42
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
A device which collects vehicular emissions.
static SumoXMLAttrMask getWrittenAttributes()
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
static bool gUseMesoSim
Definition MSGlobals.h:106
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:378
The class responsible for building and deletion of vehicles.
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
const std::string & getID() const
Returns the name of the vehicle type.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A storage for options typed value containers)
Definition OptionsCont.h:89
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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, long long int attributeMask)
writes a named attribute unless filtered
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
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...
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
double x() const
Returns the x-position.
Definition Position.h:55
double z() const
Returns the z-position.
Definition Position.h:65
double y() const
Returns the y-position.
Definition Position.h:60
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.
virtual MSDevice * getDevice(const std::type_info &type) const =0
Returns a device of the given type if it exists or nullptr if not.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:62
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
virtual bool isIdling() const =0
Returns whether the vehicle is idling (waiting to re-enter the net.
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
virtual double getAngle() const =0
Get the vehicle's angle.
virtual const MSRoute & getRoute() const =0
Returns the current route.
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.