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.dev/sumo
3// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// A device which collects vehicular emissions
21/****************************************************************************/
22#include <config.h>
23
24#include <microsim/MSNet.h>
25#include <microsim/MSLane.h>
26#include <microsim/MSStop.h>
33#include "MSDevice_Emissions.h"
34
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39// ---------------------------------------------------------------------------
40// static initialisation methods
41// ---------------------------------------------------------------------------
42void
44 insertDefaultAssignmentOptions("emissions", "Emissions", oc);
45
46 oc.doRegister("device.emissions.begin", new Option_String("-1"));
47 oc.addDescription("device.emissions.begin", "Emissions", TL("Recording begin time for emission-data"));
48
49 oc.doRegister("device.emissions.period", new Option_String("0"));
50 oc.addDescription("device.emissions.period", "Emissions", TL("Recording period for emission-output"));
51}
52
53
54void
55MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
57 if (equippedByDefaultAssignmentOptions(oc, "emissions", v, oc.isSet("emission-output"))) {
58 into.push_back(new MSDevice_Emissions(v));
59 }
60}
61
62
63// ---------------------------------------------------------------------------
64// MSDevice_Emissions-methods
65// ---------------------------------------------------------------------------
67 : MSVehicleDevice(holder, "emissions_" + holder.getID()), myEmissions() {
68}
69
70
72}
73
74
75bool
76MSDevice_Emissions::notifyMove(SUMOTrafficObject& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
79 return true;
80}
81
82
83bool
87 return true;
88}
89
90
91void
93 const double /* frontOnLane */,
94 const double timeOnLane,
95 const double /* meanSpeedFrontOnLane */,
96 const double meanSpeedVehicleOnLane,
97 const double /* travelledDistanceFrontOnLane */,
98 const double /* travelledDistanceVehicleOnLane */,
99 const double /* meanLengthOnLane */) {
100
101 // called by meso (see MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal)
103 myEmissions.addScaled(PollutantsInterface::computeAll(c, meanSpeedVehicleOnLane, veh.getAcceleration(), veh.getSlope(), myHolder.getEmissionParameters()), timeOnLane);
104}
105
106
107
108void
110 if (tripinfoOut != nullptr) {
112 const int precision = MAX2(
113 oc.isDefault("emission-output.precision") ? 6 : oc.getInt("emission-output.precision"),
114 gPrecision);
115 tripinfoOut->openTag("emissions");
116 tripinfoOut->writeAttr("CO_abs", OutputDevice::realString(myEmissions.CO, precision));
117 tripinfoOut->writeAttr("CO2_abs", OutputDevice::realString(myEmissions.CO2, precision));
118 tripinfoOut->writeAttr("HC_abs", OutputDevice::realString(myEmissions.HC, precision));
119 tripinfoOut->writeAttr("PMx_abs", OutputDevice::realString(myEmissions.PMx, precision));
120 tripinfoOut->writeAttr("NOx_abs", OutputDevice::realString(myEmissions.NOx, precision));
121 tripinfoOut->writeAttr("fuel_abs", OutputDevice::realString(myEmissions.fuel, precision));
122 tripinfoOut->writeAttr("electricity_abs", OutputDevice::realString(myEmissions.electricity, precision));
123 tripinfoOut->closeTag();
124 }
125}
126
127
128/****************************************************************************/
#define TL(string)
Definition: MsgHandler.h:287
#define TS
Definition: SUMOTime.h:42
int SUMOEmissionClass
int gPrecision
the precision for floating point outputs
Definition: StdDefs.cpp:26
T MAX2(T a, T b)
Definition: StdDefs.h:82
void generateOutput(OutputDevice *tripinfoOut) const
Called on writing tripinfo output.
bool notifyIdle(SUMOTrafficObject &veh)
Computes idling emission values and adds them to the emission sums.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Computes current emission values and adds them to their sums.
MSDevice_Emissions(SUMOVehicle &holder)
Constructor.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_Emissions-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
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()
PollutantsInterface::Emissions myEmissions
Internal storages for pollutant/fuel sum in mg or ml.
~MSDevice_Emissions()
Destructor.
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:148
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:202
Abstract in-vehicle device.
SUMOVehicle & myHolder
The vehicle that stores the device.
SUMOEmissionClass getEmissionClass() const
Get this vehicle type's emission class.
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
Definition: OptionsCont.cpp:76
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:60
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
static std::string realString(const double v, const int precision=gPrecision)
Helper method for string formatting.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams *param)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
Representation of a vehicle, person, or container.
virtual double getAcceleration() const =0
Returns the object's acceleration.
virtual const MSVehicleType & getVehicleType() const =0
Returns the object's "vehicle" type.
virtual double getSlope() const =0
Returns the slope of the road at object's position in degrees.
Representation of a vehicle.
Definition: SUMOVehicle.h:62
virtual EnergyParams * getEmissionParameters() const =0
Returns the vehicle's emission model parameter.
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.