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 }
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:256
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...
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
Definition: MSVehicle.h:657
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
virtual const MSRoute & getRoute() const =0
Returns the current route.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:27
virtual double getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
double y() const
Returns the y-position.
Definition: Position.h:62
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
void setPrecision(int precision=gPrecision)
Sets the precison or resets it to default.
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
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. ...
const std::string & getID() const
Returns the id.
Definition: Named.h:77
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
Representation of a vehicle.
Definition: SUMOVehicle.h:61
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
virtual double getAngle() const =0
Get the vehicle&#39;s angle.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
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.
The class responsible for building and deletion of vehicles.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)