SUMO - Simulation of Urban MObility
MSDevice_Emissions.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A device which collects vehicular emissions
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include "MSDevice_Emissions.h"
33 #include <microsim/MSNet.h>
34 #include <microsim/MSLane.h>
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 // ---------------------------------------------------------------------------
45 // static initialisation methods
46 // ---------------------------------------------------------------------------
47 void
49  insertDefaultAssignmentOptions("emissions", "Emissions", OptionsCont::getOptions());
50 }
51 
52 
53 void
54 MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
56  // build the device
57  MSDevice_Emissions* device = new MSDevice_Emissions(v, "emissions_" + v.getID());
58  into.push_back(device);
59  }
60 }
61 
62 
63 // ---------------------------------------------------------------------------
64 // MSDevice_Emissions-methods
65 // ---------------------------------------------------------------------------
66 MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder, const std::string& id)
67  : MSDevice(holder, id), myEmissions() {
68 }
69 
70 
72 }
73 
74 
75 bool
76 MSDevice_Emissions::notifyMove(SUMOVehicle& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
78  const double a = veh.getAcceleration();
79  const double slope = veh.getSlope();
81  return true;
82 }
83 
84 
85 void
87  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
88  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
89  (os.openTag("emissions") <<
90  " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
91  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
92  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
93  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
94  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
95  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
96  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
97  "\"").closeTag();
98  }
99 }
100 
101 
102 
103 /****************************************************************************/
104 
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...
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
MSDevice_Emissions(SUMOVehicle &holder, const std::string &id)
Constructor.
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Computes current emission values and adds them to their sums.
PollutantsInterface::Emissions myEmissions
Internal storages for pollutant/fuel sum in mg or ml.
void generateOutput() const
Called on writing tripinfo output.
virtual double getSlope() const =0
Returns the slope of the road at vehicle&#39;s position.
#define TS
Definition: SUMOTime.h:52
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
~MSDevice_Emissions()
Destructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
int SUMOEmissionClass
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:93
Abstract in-vehicle device.
Definition: MSDevice.h:71
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:107
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static void insertOptions()
Inserts MSDevice_Emissions-options.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
A device which collects vehicular emissions.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.
virtual double getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.