Eclipse 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-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 /****************************************************************************/
16 // A device which collects vehicular emissions
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <microsim/MSNet.h>
25 #include <microsim/MSLane.h>
30 #include "MSDevice_Emissions.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
36 // ---------------------------------------------------------------------------
37 // static initialisation methods
38 // ---------------------------------------------------------------------------
39 void
41  insertDefaultAssignmentOptions("emissions", "Emissions", OptionsCont::getOptions());
42 }
43 
44 
45 void
46 MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
47  if (equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "emissions", v, false)) {
48  // build the device
49  MSDevice_Emissions* device = new MSDevice_Emissions(v, "emissions_" + v.getID());
50  into.push_back(device);
51  }
52 }
53 
54 
55 // ---------------------------------------------------------------------------
56 // MSDevice_Emissions-methods
57 // ---------------------------------------------------------------------------
58 MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder, const std::string& id)
59  : MSVehicleDevice(holder, id), myEmissions() {
60 }
61 
62 
64 }
65 
66 
67 bool
68 MSDevice_Emissions::notifyMove(SUMOTrafficObject& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
70  const double a = veh.getAcceleration();
71  const double slope = veh.getSlope();
73  static_cast<const SUMOVehicle&>(veh).getEmissionParameters()), TS);
74  return true;
75 }
76 
77 
78 void
80  const double /* frontOnLane */,
81  const double timeOnLane,
82  const double /* meanSpeedFrontOnLane */,
83  const double meanSpeedVehicleOnLane,
84  const double /* travelledDistanceFrontOnLane */,
85  const double /* travelledDistanceVehicleOnLane */,
86  const double /* meanLengthOnLane */) {
87 
88  // called by meso (see MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal)
89  const double a = veh.getAcceleration();
91  meanSpeedVehicleOnLane, a, veh.getSlope(),
92  static_cast<const SUMOVehicle&>(veh).getEmissionParameters()), timeOnLane);
93 }
94 
95 
96 
97 void
99  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
100  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
101  (os.openTag("emissions") <<
102  " CO_abs=\"" << OutputDevice::realString(myEmissions.CO, 6) <<
103  "\" CO2_abs=\"" << OutputDevice::realString(myEmissions.CO2, 6) <<
104  "\" HC_abs=\"" << OutputDevice::realString(myEmissions.HC, 6) <<
105  "\" PMx_abs=\"" << OutputDevice::realString(myEmissions.PMx, 6) <<
106  "\" NOx_abs=\"" << OutputDevice::realString(myEmissions.NOx, 6) <<
107  "\" fuel_abs=\"" << OutputDevice::realString(myEmissions.fuel, 6) <<
108  "\" electricity_abs=\"" << OutputDevice::realString(myEmissions.electricity, 6) <<
109  "\"").closeTag();
110  }
111 }
112 
113 
114 /****************************************************************************/
115 
MSDevice_Emissions::insertOptions
static void insertOptions()
Inserts MSDevice_Emissions-options.
Definition: MSDevice_Emissions.cpp:40
MSVehicleType::getEmissionClass
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
Definition: MSVehicleType.h:193
SUMOTrafficObject
Representation of a vehicle or person.
Definition: SUMOTrafficObject.h:47
MSNet.h
PollutantsInterface::Emissions::PMx
double PMx
Definition: PollutantsInterface.h:67
SUMOTrafficObject::getAcceleration
virtual double getAcceleration() const =0
Returns the vehicle's acceleration.
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:63
OptionsCont.h
SUMOTrafficObject::getVehicleType
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle's type.
PollutantsInterface::Emissions::CO
double CO
Definition: PollutantsInterface.h:63
MSDevice_Emissions::~MSDevice_Emissions
~MSDevice_Emissions()
Destructor.
Definition: MSDevice_Emissions.cpp:63
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
MSDevice_Emissions::notifyMove
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Computes current emission values and adds them to their sums.
Definition: MSDevice_Emissions.cpp:68
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
SUMOEmissionClass
int SUMOEmissionClass
Definition: SUMOVehicleClass.h:231
SUMOVehicle::getEmissionParameters
virtual const std::map< int, double > * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
MSDevice_Emissions::MSDevice_Emissions
MSDevice_Emissions(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice_Emissions.cpp:58
MSDevice::insertDefaultAssignmentOptions
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:126
PollutantsInterface::Emissions::CO2
double CO2
Definition: PollutantsInterface.h:62
PollutantsInterface.h
TS
#define TS
Definition: SUMOTime.h:43
OutputDevice.h
SUMOTrafficObject::getSlope
virtual double getSlope() const =0
Returns the slope of the road at vehicle's position.
PollutantsInterface::computeAll
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...
Definition: PollutantsInterface.cpp:154
PollutantsInterface::Emissions::addScaled
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.
Definition: PollutantsInterface.h:87
PollutantsInterface::Emissions::electricity
double electricity
Definition: PollutantsInterface.h:68
OutputDevice::openTag
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
Definition: OutputDevice.cpp:239
PollutantsInterface::Emissions::NOx
double NOx
Definition: PollutantsInterface.h:66
MSDevice::equippedByDefaultAssignmentOptions
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:203
PollutantsInterface::Emissions::HC
double HC
Definition: PollutantsInterface.h:64
MSDevice_Emissions::notifyMoveInternal
void notifyMoveInternal(const SUMOTrafficObject &veh, const double frontOnLane, const double timeOnLane, const double meanSpeedFrontOnLane, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double meanLengthOnLane)
Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
Definition: MSDevice_Emissions.cpp:79
MSDevice_Emissions
A device which collects vehicular emissions.
Definition: MSDevice_Emissions.h:57
config.h
OutputDevice::realString
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
Definition: OutputDevice.cpp:159
MSLane.h
MSDevice_Emissions.h
PollutantsInterface::Emissions::fuel
double fuel
Definition: PollutantsInterface.h:65
MSDevice_Emissions::buildVehicleDevices
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice_Emissions.cpp:46
MSVehicleControl.h
MSDevice_Emissions::myEmissions
PollutantsInterface::Emissions myEmissions
Internal storages for pollutant/fuel sum in mg or ml.
Definition: MSDevice_Emissions.h:141
OutputDevice::getDeviceByOption
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
Definition: OutputDevice.cpp:116
MSDevice_Emissions::generateOutput
void generateOutput() const
Called on writing tripinfo output.
Definition: MSDevice_Emissions.cpp:98
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:54