SUMO - Simulation of Urban MObility
MSDevice_Emissions.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A device which collects vehicular emissions
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include "MSDevice_Emissions.h"
32 #include <microsim/MSNet.h>
33 #include <microsim/MSLane.h>
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 // ---------------------------------------------------------------------------
44 // static initialisation methods
45 // ---------------------------------------------------------------------------
46 void
48  insertDefaultAssignmentOptions("emissions", "Emissions", OptionsCont::getOptions());
49 }
50 
51 
52 void
53 MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
55  // build the device
56  MSDevice_Emissions* device = new MSDevice_Emissions(v, "emissions_" + v.getID());
57  into.push_back(device);
58  }
59 }
60 
61 
62 // ---------------------------------------------------------------------------
63 // MSDevice_Emissions-methods
64 // ---------------------------------------------------------------------------
65 MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder, const std::string& id)
66  : MSDevice(holder, id), myEmissions() {
67 }
68 
69 
71 }
72 
73 
74 bool
75 MSDevice_Emissions::notifyMove(SUMOVehicle& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
77  const double a = veh.getAcceleration();
78  const double slope = veh.getSlope();
80  return true;
81 }
82 
83 
84 void
86  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
87  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
88  (os.openTag("emissions") <<
89  " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
90  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
91  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
92  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
93  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
94  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
95  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
96  "\"").closeTag();
97  }
98 }
99 
100 
101 
102 /****************************************************************************/
103 
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:51
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:64
~MSDevice_Emissions()
Destructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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:101
Abstract in-vehicle device.
Definition: MSDevice.h:70
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:115
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:70
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.