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 /****************************************************************************/
10 /// @file MSEmissionExport.cpp
11 /// @author Daniel Krajzewicz
12 /// @author Mario Krumnow
13 /// @author Michael Behrisch
14 /// @author Jakob Erdmann
15 /// @date 2012-04-26
16 /// @version $Id$
17 ///
18 // Realises dumping Emission Data
19 /****************************************************************************/
20
21
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26
27 #include <utils/iodevices/OutputDevice.h>
28 #include <utils/emissions/PollutantsInterface.h>
29 #include <utils/emissions/HelpersHarmonoise.h>
30 #include <utils/geom/GeomHelper.h>
31 #include <microsim/MSNet.h>
32 #include <microsim/MSVehicle.h>
33 #include <microsim/MSVehicleControl.h>
34 #include "MSEmissionExport.h"
35
36
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
40 void
write(OutputDevice & of,SUMOTime timestep,int precision)41 MSEmissionExport::write(OutputDevice& of, SUMOTime timestep, int precision) {
42 of.openTag("timestep").writeAttr("time", time2string(timestep));
43 of.setPrecision(precision);
44 MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
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("@"));
51 PollutantsInterface::Emissions emiss = PollutantsInterface::computeAll(veh->getVehicleType().getEmissionClass(), veh->getSpeed(), veh->getAcceleration(), veh->getSlope());
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);
55 of.writeAttr("noise", HelpersHarmonoise::computeNoise(veh->getVehicleType().getEmissionClass(), veh->getSpeed(), veh->getAcceleration()));
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 }
66 of.setPrecision(gPrecision);
67 of.closeTag();
68 }
69