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-2015 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 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // static initialisation methods
50 // ---------------------------------------------------------------------------
51 void
53  insertDefaultAssignmentOptions("emissions", "Emissions", OptionsCont::getOptions());
54 }
55 
56 
57 void
58 MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
60  // build the device
61  MSDevice_Emissions* device = new MSDevice_Emissions(v, "emissions_" + v.getID());
62  into.push_back(device);
63  }
64 }
65 
66 
67 // ---------------------------------------------------------------------------
68 // MSDevice_Emissions-methods
69 // ---------------------------------------------------------------------------
70 MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder, const std::string& id)
71  : MSDevice(holder, id), myEmissions() {
72 }
73 
74 
76 }
77 
78 
79 bool
80 MSDevice_Emissions::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal newSpeed) {
82  const SUMOReal a = veh.getAcceleration();
83  const SUMOReal slope = veh.getSlope();
85  return true;
86 }
87 
88 
89 void
91  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
92  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
93  (os.openTag("emissions") <<
94  " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
95  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
96  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
97  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
98  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
99  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
100  "\"").closeTag();
101  }
102 }
103 
104 
105 
106 /****************************************************************************/
107 
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Computes current emission values and adds them to their sums.
void addScaled(const Emissions &a, const SUMOReal scale=1.)
Add the values of the other struct to this one, scaling the values if needed.
MSDevice_Emissions(SUMOVehicle &holder, const std::string &id)
Constructor.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
PollutantsInterface::Emissions myEmissions
Internal storages for pollutant/fuel sum in mg or ml.
#define TS
Definition: SUMOTime.h:52
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
~MSDevice_Emissions()
Destructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:65
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:85
Abstract in-vehicle device.
Definition: MSDevice.h:69
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:99
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
static void insertOptions()
Inserts MSDevice_Emissions-options.
virtual SUMOReal getAcceleration() const =0
Returns the vehicle's acceleration.
static std::string realString(const SUMOReal v, const int precision=OUTPUT_ACCURACY)
Helper method for string formatting.
void generateOutput() const
Called on writing tripinfo output.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
#define SUMOReal
Definition: config.h:218
virtual SUMOReal getSlope() const =0
Returns the slope of the road at vehicle's position.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
A device which collects vehicular emissions.
virtual const std::string & getID() const =0
Get the vehicle's ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.