Eclipse SUMO - Simulation of Urban MObility
MSEmissionExport.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-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 /****************************************************************************/
17 // Realises dumping Emission Data
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
29 #include <utils/geom/GeomHelper.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSVehicle.h>
32 #include <mesosim/MEVehicle.h>
34 #include "MSEmissionExport.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 void
41 MSEmissionExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
42  of.openTag("timestep").writeAttr("time", time2string(timestep));
43  of.setPrecision(precision);
45  for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
46  const SUMOVehicle* veh = it->second;
47  if (veh->isOnRoad()) {
48  std::string fclass = veh->getVehicleType().getID();
49  fclass = fclass.substr(0, fclass.find_first_of("@"));
52  veh->getSpeed(), veh->getAcceleration(), veh->getSlope(),
53  veh->getEmissionParameters());
54  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
55  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
56  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
58  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
60  const MEVehicle* mesoVeh = dynamic_cast<const MEVehicle*>(veh);
61  of.writeAttr("waiting", mesoVeh->getWaitingSeconds());
62  of.writeAttr("edge", veh->getEdge()->getID());
63  } else {
64  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
65  of.writeAttr("waiting", microVeh->getWaitingSeconds());
66  of.writeAttr("lane", microVeh->getLane()->getID());
67  }
68  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
69  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
70  of.closeTag();
71  }
72  }
74  of.closeTag();
75 }
MEVehicle
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:44
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:193
SUMOTrafficObject::getPosition
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
MSVehicleType::getID
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:93
SUMOVehicle::getAngle
virtual double getAngle() const =0
Get the vehicle's angle.
MSNet.h
PollutantsInterface::Emissions::PMx
double PMx
Definition: PollutantsInterface.h:67
SUMOTrafficObject::getAcceleration
virtual double getAcceleration() const =0
Returns the vehicle's acceleration.
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
SUMOTrafficObject::getEdge
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
PollutantsInterface::Emissions::CO
double CO
Definition: PollutantsInterface.h:63
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
MSEmissionExport::write
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
Definition: MSEmissionExport.cpp:41
OutputDevice::setPrecision
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
Definition: OutputDevice.cpp:221
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:193
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:90
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:99
SUMOVehicle::getEmissionParameters
virtual const std::map< int, double > * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:74
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:253
HelpersHarmonoise.h
MEVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MEVehicle.h:310
SUMOVehicle::getRoute
virtual const MSRoute & getRoute() const =0
Returns the current route.
OutputDevice::writeAttr
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:255
HelpersHarmonoise::computeNoise
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.
Definition: HelpersHarmonoise.cpp:96
PollutantsInterface::Emissions::CO2
double CO2
Definition: PollutantsInterface.h:62
PollutantsInterface.h
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:185
MSEmissionExport.h
OutputDevice.h
SUMOTrafficObject::getSlope
virtual double getSlope() const =0
Returns the slope of the road at vehicle's position.
PollutantsInterface::computeAll
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...
Definition: PollutantsInterface.cpp:154
Position::x
double x() const
Returns the x-position.
Definition: Position.h:56
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:560
PollutantsInterface::Emissions::electricity
double electricity
Definition: PollutantsInterface.h:68
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
PollutantsInterface::Emissions::NOx
double NOx
Definition: PollutantsInterface.h:66
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
Position::y
double y() const
Returns the y-position.
Definition: Position.h:61
PollutantsInterface::Emissions
Storage for collected values of all emission types.
Definition: PollutantsInterface.h:61
PollutantsInterface::Emissions::HC
double HC
Definition: PollutantsInterface.h:64
MEVehicle.h
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:71
GeomHelper.h
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:26
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:177
PollutantsInterface::Emissions::fuel
double fuel
Definition: PollutantsInterface.h:65
SUMOTrafficObject::getPositionOnLane
virtual double getPositionOnLane() const =0
Get the vehicle's position along the lane.
MSVehicleControl.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:336
SUMOTrafficObject::getSpeed
virtual double getSpeed() const =0
Returns the vehicle's current speed.
MSVehicle::getWaitingSeconds
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:656
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79