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 /****************************************************************************/
18 // Realises dumping Emission Data
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
30 #include <utils/geom/GeomHelper.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.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  const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
48  if (veh->isOnRoad()) {
49  std::string fclass = veh->getVehicleType().getID();
50  fclass = fclass.substr(0, fclass.find_first_of("@"));
52  of.openTag("vehicle").writeAttr("id", veh->getID()).writeAttr("eclass", PollutantsInterface::getName(veh->getVehicleType().getEmissionClass()));
53  of.writeAttr("CO2", emiss.CO2).writeAttr("CO", emiss.CO).writeAttr("HC", emiss.HC).writeAttr("NOx", emiss.NOx);
54  of.writeAttr("PMx", emiss.PMx).writeAttr("fuel", emiss.fuel).writeAttr("electricity", emiss.electricity);
56  of.writeAttr("route", veh->getRoute().getID()).writeAttr("type", fclass);
57  if (microVeh != nullptr) {
58  of.writeAttr("waiting", microVeh->getWaitingSeconds());
59  of.writeAttr("lane", microVeh->getLane()->getID());
60  }
61  of.writeAttr("pos", veh->getPositionOnLane()).writeAttr("speed", veh->getSpeed());
62  of.writeAttr("angle", GeomHelper::naviDegree(veh->getAngle())).writeAttr("x", veh->getPosition().x()).writeAttr("y", veh->getPosition().y());
63  of.closeTag();
64  }
65  }
67  of.closeTag();
68 }
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:194
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:94
SUMOVehicle::getAngle
virtual double getAngle() const =0
Get the vehicle's angle.
MSNet.h
PollutantsInterface::Emissions::PMx
double PMx
Definition: PollutantsInterface.h:68
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:64
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
PollutantsInterface::Emissions::CO
double CO
Definition: PollutantsInterface.h:64
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:222
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
GeomHelper::naviDegree
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
SUMOVehicle::isOnRoad
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:100
MSVehicleControl::constVehIt
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
Definition: MSVehicleControl.h:75
MSVehicle.h
OutputDevice::closeTag
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
Definition: OutputDevice.cpp:254
HelpersHarmonoise.h
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:256
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:97
PollutantsInterface::Emissions::CO2
double CO2
Definition: PollutantsInterface.h:63
PollutantsInterface.h
MSVehicleControl::loadedVehEnd
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
Definition: MSVehicleControl.h:186
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:155
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
MSVehicle::getLane
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
PollutantsInterface::Emissions::electricity
double electricity
Definition: PollutantsInterface.h:69
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:240
PollutantsInterface::Emissions::NOx
double NOx
Definition: PollutantsInterface.h:67
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
PollutantsInterface::Emissions
Storage for collected values of all emission types.
Definition: PollutantsInterface.h:62
PollutantsInterface::Emissions::HC
double HC
Definition: PollutantsInterface.h:65
config.h
MSVehicleControl
The class responsible for building and deletion of vehicles.
Definition: MSVehicleControl.h:72
GeomHelper.h
gPrecision
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
MSVehicleControl::loadedVehBegin
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
Definition: MSVehicleControl.h:178
PollutantsInterface::Emissions::fuel
double fuel
Definition: PollutantsInterface.h:66
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:77
MSNet::getVehicleControl
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
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:657
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80