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-2018 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 /****************************************************************************/
17 // A device which collects vehicular emissions
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include "MSDevice_Emissions.h"
26 #include <microsim/MSNet.h>
27 #include <microsim/MSLane.h>
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 // ---------------------------------------------------------------------------
38 // static initialisation methods
39 // ---------------------------------------------------------------------------
40 void
42  insertDefaultAssignmentOptions("emissions", "Emissions", OptionsCont::getOptions());
43 }
44 
45 
46 void
47 MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
48  if (equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "emissions", v, false)) {
49  // build the device
50  MSDevice_Emissions* device = new MSDevice_Emissions(v, "emissions_" + v.getID());
51  into.push_back(device);
52  }
53 }
54 
55 
56 // ---------------------------------------------------------------------------
57 // MSDevice_Emissions-methods
58 // ---------------------------------------------------------------------------
59 MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder, const std::string& id)
60  : MSVehicleDevice(holder, id), myEmissions() {
61 }
62 
63 
65 }
66 
67 
68 bool
69 MSDevice_Emissions::notifyMove(SUMOVehicle& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
71  const double a = veh.getAcceleration();
72  const double slope = veh.getSlope();
74  return true;
75 }
76 
77 
78 void
80  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
81  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
82  (os.openTag("emissions") <<
83  " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
84  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
85  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
86  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
87  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
88  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
89  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
90  "\"").closeTag();
91  }
92 }
93 
94 
95 
96 /****************************************************************************/
97 
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...
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:45
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:58
~MSDevice_Emissions()
Destructor.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
int SUMOEmissionClass
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:121
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:208
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &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.
Abstract in-vehicle device.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
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.