Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-2025 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>
34#include "MSDevice_Emissions.h"
35
36// ===========================================================================
37// static members
38// ===========================================================================
41
42// ===========================================================================
43// method definitions
44// ===========================================================================
45// ---------------------------------------------------------------------------
46// static initialisation methods
47// ---------------------------------------------------------------------------
48void
50 insertDefaultAssignmentOptions("emissions", "Emissions", oc);
51
52 oc.doRegister("device.emissions.begin", new Option_String("-1"));
53 oc.addDescription("device.emissions.begin", "Emissions", TL("Recording begin time for emission-data"));
54
55 oc.doRegister("device.emissions.period", new Option_String("0"));
56 oc.addDescription("device.emissions.period", "Emissions", TL("Recording period for emission-output"));
57}
58
59
60void
61MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
63 if (equippedByDefaultAssignmentOptions(oc, "emissions", v, oc.isSet("emission-output"))) {
64 into.push_back(new MSDevice_Emissions(v));
65 }
66}
67
68
71 SumoXMLAttrMask mask;
72 // set all bits to 1
73 mask.set();
74 return mask;
75}
76
77void
82
83void
85 if (myAmInitialized) {
86 return;
87 }
88 myAmInitialized = true;
90 if (oc.isSet("emission-output.attributes")) {
91 myWrittenAttributes.reset();
92 for (std::string attrName : oc.getStringVector("emission-output.attributes")) {
93 if (!SUMOXMLDefinitions::Attrs.hasString(attrName)) {
94 if (attrName == "all") {
96 } else {
97 WRITE_ERRORF(TL("Unknown attribute '%' to write in emission output."), attrName);
98 }
99 continue;
100 }
101 int attr = SUMOXMLDefinitions::Attrs.get(attrName);
102 myWrittenAttributes.set(attr);
103 }
104 }
106}
107
108
109
110// ---------------------------------------------------------------------------
111// MSDevice_Emissions-methods
112// ---------------------------------------------------------------------------
114 : MSVehicleDevice(holder, "emissions_" + holder.getID()), myEmissions() {
115}
116
117
120
121
122bool
123MSDevice_Emissions::notifyMove(SUMOTrafficObject& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
126 return true;
127}
128
129
130bool
136
137
138void
140 const double /* frontOnLane */,
141 const double timeOnLane,
142 const double /* meanSpeedFrontOnLane */,
143 const double meanSpeedVehicleOnLane,
144 const double /* travelledDistanceFrontOnLane */,
145 const double /* travelledDistanceVehicleOnLane */,
146 const double /* meanLengthOnLane */) {
147
148 // called by meso (see MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal)
150 myEmissions.addScaled(PollutantsInterface::computeAll(c, meanSpeedVehicleOnLane, veh.getAcceleration(), veh.getSlope(), myHolder.getEmissionParameters()), timeOnLane);
151}
152
153
154
155void
157 if (tripinfoOut != nullptr) {
158 tripinfoOut->setPrecision(gPrecisionEmissions);
159 tripinfoOut->openTag("emissions");
167 tripinfoOut->closeTag();
168 tripinfoOut->setPrecision(gPrecision);
169 }
170}
171
172
173/****************************************************************************/
#define WRITE_ERRORF(...)
Definition MsgHandler.h:297
#define TL(string)
Definition MsgHandler.h:305
#define TS
Definition SUMOTime.h:42
int SUMOEmissionClass
std::bitset< 96 > SumoXMLAttrMask
@ SUMO_ATTR_NOX_ABS
@ SUMO_ATTR_ELECTRICITY_ABS
@ SUMO_ATTR_PMX_ABS
@ SUMO_ATTR_CO_ABS
MSMeanData_Emissions.
@ SUMO_ATTR_FUEL_ABS
@ SUMO_ATTR_HC_ABS
@ SUMO_ATTR_CO2_ABS
int gPrecisionEmissions
Definition StdDefs.cpp:27
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:26
A device which collects vehicular emissions.
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.
static SumoXMLAttrMask myWrittenAttributes
bit mask for checking attributes to be written
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Computes current emission values and adds them to their sums.
static void cleanup()
resets the attribute mask
MSDevice_Emissions(SUMOVehicle &holder)
Constructor.
static SumoXMLAttrMask getDefaultMask()
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.
static void initOnce()
initialize attribute mask (once)
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:157
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:200
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.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
void setExpectedAttributes(const SumoXMLAttrMask &expected, const int depth=2)
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
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.
static SequentialStringBijection Attrs
The names of SUMO-XML attributes for use in netbuild.
int get(const std::string &str) const
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.