Path: blob/main/src/utils/emissions/PollutantsInterface.h
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2013-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file PollutantsInterface.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Mon, 19.08.201317///18// Interface to capsulate different emission models19/****************************************************************************/20#pragma once21#include <config.h>2223#include <vector>24#include <limits>25#include <cmath>26#include <algorithm>27#include <utils/common/StdDefs.h>28#include <utils/common/SUMOVehicleClass.h>293031// ===========================================================================32// class declarations33// ===========================================================================34class EnergyParams;35class HelpersHBEFA;36class HelpersHBEFA3;37class HelpersHBEFA4;38class HelpersEnergy;39class HelpersMMPEVEM;40class HelpersPHEMlight;41class HelpersPHEMlight5;424344// ===========================================================================45// class definitions46// ===========================================================================47/**48* @class PollutantsInterface49* @brief Helper methods for PHEMlight-based emission computation50*/51class PollutantsInterface {5253public:54/// @brief Enumerating all emission types, including fuel55enum EmissionType { CO2, CO, HC, FUEL, NO_X, PM_X, ELEC };5657/**58* @struct Emissions59* @brief Storage for collected values of all emission types60*/61struct Emissions {62/** @brief Constructor, intializes all members63* @param[in] co2 initial value for CO2, defaults to 064* @param[in] co initial value for CO, defaults to 065* @param[in] hc initial value for HC, defaults to 066* @param[in] f initial value for fuel, defaults to 067* @param[in] nox initial value for NOx, defaults to 068* @param[in] pmx initial value for PMx, defaults to 069* @param[in] elec initial value for electricity, defaults to 070*/71Emissions(double co2 = 0, double co = 0, double hc = 0, double f = 0, double nox = 0, double pmx = 0, double elec = 0);7273/** @brief Add the values of the other struct to this one, scaling the values if needed74* @param[in] a the other emission valuess75* @param[in] scale scaling factor, defaulting to 1 (no scaling)76*/77void addScaled(const Emissions& a, const double scale = 1.);7879/// @brief emission types80/// @{81double CO2;82double CO;83double HC;84double fuel;85double NOx;86double PMx;87double electricity;88/// @}89};9091/**92* @class Helper93* @brief zero emission model, used as superclass for the other model helpers94*/95class Helper {96public:97/** @brief Constructor, intializes the name98* @param[in] name the name of the model (string before the '/' in the emission class attribute)99*/100Helper(std::string name, const int baseIndex, const int defaultClass);101102/// @brief empty destructor103virtual ~Helper() {}104105/** @brief Returns the name of the model106* @return the name of the model (string before the '/' in the emission class attribute)107*/108const std::string& getName() const;109110/** @brief Returns the emission class associated with the given name, aliases are possible111* If this method is asked for the "unknown" class it should return the default112* (possibly depending on the given vehicle class).113* The class name is case insensitive.114*115* @param[in] eClass the name of the emission class (string after the '/' in the emission class attribute)116* @param[in] vc the vehicle class to use when determining default class117* @return the name of the model (string before the '/' in the emission class)118*/119virtual SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc);120121/** @brief Returns the complete name of the emission class including the model122* @param[in] c the emission class123* @return the name of the class (the complete emission class attribute)124*/125const std::string getClassName(const SUMOEmissionClass c) const;126127/** @brief Returns whether the class denotes a silent vehicle for interfacing with the noise model.128* By default the first class in each model is the silent class.129* @param[in] c the emission class130* @return whether the class denotes a silent vehicle131*/132virtual bool isSilent(const SUMOEmissionClass c);133134/// @name Methods for Amitran interfaces135/// @{136137/** @brief Returns the emission class described by the given parameters.138* The base is used to determine the model to use and as default return values.139* Default implementation returns always base.140* @param[in] base the base class giving the model and the default141* @param[in] vClass the vehicle class as described in the Amitran interface (Passenger, ...)142* @param[in] fuel the fuel type as described in the Amitran interface (Gasoline, Diesel, ...)143* @param[in] eClass the emission class as described in the Amitran interface (Euro0, ...)144* @param[in] weight the vehicle weight in kg as described in the Amitran interface145* @return the class described by the parameters146*/147virtual SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel,148const std::string& eClass, const double weight) const;149150/** @brief Returns the vehicle class described by this emission class as described in the Amitran interface (Passenger, ...)151* Default implementation returns always "Passenger".152* @param[in] c the emission class153* @return the name of the vehicle class154*/155virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const;156157/** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)158* Default implementation returns always "Gasoline".159* @param[in] c the emission class160* @return the fuel type161*/162virtual std::string getFuel(const SUMOEmissionClass c) const;163164/** @brief Returns the Euro emission class described by this emission class as described in the Amitran interface (0, ..., 6)165* Default implementation returns always 0.166* @param[in] c the emission class167* @return the Euro class168*/169virtual int getEuroClass(const SUMOEmissionClass c) const;170171/** @brief Returns a reference weight in kg described by this emission class as described in the Amitran interface172* It might return -1, if the weight is not important to distinguish different emission classes.173* Default implementation returns always -1.174* @param[in] c the emission class175* @return a reference weight176*/177virtual double getWeight(const SUMOEmissionClass c) const;178/// @}179180/** @brief Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fuel)181* @param[in] c The vehicle emission class182* @param[in] e the type of emission (CO, CO2, ...)183* @param[in] v The vehicle's current velocity184* @param[in] a The vehicle's current acceleration185* @param[in] slope The road's slope at vehicle's position [deg]186* @param[in] param parameter of the emission model affecting the computation187* @return The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]188*/189virtual double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const;190191/** @brief Returns the adapted acceleration value, useful for comparing with external PHEMlight references.192* Default implementation returns always the input accel.193* @param[in] c the emission class194* @param[in] v the speed value195* @param[in] a the acceleration value196* @param[in] slope The road's slope at vehicle's position [deg]197* @return the modified acceleration198*/199virtual double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param) const;200201/** @brief Returns the maximum deceleration value (as a negative number), which can still be considered as non-braking.202* Default implementation returns always zero.203* @param[in] c the emission class204* @param[in] v the speed value205* @param[in] a the acceleration value206* @param[in] slope The road's slope at vehicle's position [deg]207* @param[in] param parameter of the emission model affecting the computation208* @return the coasting deceleration209*/210virtual double getCoastingDecel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param) const;211212/** @brief Add all known emission classes of this model to the given container213* @param[in] list the vector to add to214*/215void addAllClassesInto(std::vector<SUMOEmissionClass>& list) const;216217bool includesClass(const SUMOEmissionClass c) const;218219protected:220/// @brief the lowest speed which allows reliable coasting calculations221static const double ZERO_SPEED_ACCURACY;222223/// @brief the name of the model224const std::string myName;225226/// @brief the starting index for classes of this model227const int myBaseIndex;228229/// @brief return fuel consumption in l instead of mg230bool myVolumetricFuel;231232/// @brief Mapping between emission class names and integer representations233StringBijection<SUMOEmissionClass> myEmissionClassStrings;234235private:236/// @brief invalidate copy constructor237Helper& operator=(const Helper&) = delete;238};239240/// @brief the first class in each model representing a zero emission vehicle241static const int ZERO_EMISSIONS = 0;242243/// @brief the bit to set for denoting heavy vehicles244static const int HEAVY_BIT = 1 << 15;245246/** @brief Checks whether the string describes a known vehicle class247* @param[in] eClass The string describing the vehicle emission class248* @return whether it describes a valid emission class249*/250static SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc = SVC_IGNORING);251252/** @brief Checks whether the string describes a known vehicle class253* @param[in] eClass The string describing the vehicle emission class254* @return whether it describes a valid emission class255*/256static const std::vector<SUMOEmissionClass> getAllClasses();257258/// @brief Get all SUMOEmissionClass in string format259static const std::vector<std::string>& getAllClassesStr();260261/** @brief Checks whether the string describes a known vehicle class262* @param[in] eClass The string describing the vehicle emission class263* @return whether it describes a valid emission class264*/265static std::string getName(const SUMOEmissionClass c);266267/// @brief return the name for the given emission type268static std::string getPollutantName(const EmissionType e);269270/** @brief Checks whether the emission class describes a bus, truck or similar vehicle271* @param[in] c The vehicle emission class272* @return whether it describes a heavy vehicle273*/274static bool isHeavy(const SUMOEmissionClass c);275276/** @brief Checks whether the emission class describes an electric or similar silent vehicle277* @param[in] c The vehicle emission class278* @return whether it describes a silent vehicle279*/280static bool isSilent(const SUMOEmissionClass c);281282/** @brief Returns the emission class fittig the given parameters283* @param[in] base The base emission class to derive from284* @param[in] vClass The vehicle class description (like "truck")285* @param[in] eClass The emission class description (like "Euro5")286* @param[in] fuel The fuel type (like "Diesel")287* @param[in] weight The weight in kg288* @return The best fitting emission class related to the base289*/290static SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight);291292/** @brief Returns the vehicle class described by the given emission class293* @param[in] c The vehicle emission class294* @return The Amitran string describing the vehicle class295*/296static std::string getAmitranVehicleClass(const SUMOEmissionClass c);297298/** @brief Returns the fuel type of the given emission class299* @param[in] c The vehicle emission class300* @return "Diesel", "Gasoline", "HybridDiesel", "HybridGasoline", or "Electricity"301*/302static std::string getFuel(const SUMOEmissionClass c);303304/** @brief Returns the Euro norm described by the given emission class305* @param[in] c The vehicle emission class306* @return A value between 0 and 6 (inclusive)307*/308static int getEuroClass(const SUMOEmissionClass c);309310/** @brief Returns a representative weight for the given emission class311* see http://colombo-fp7.eu/deliverables/COLOMBO_D4.2_ExtendedPHEMSUMO_v1.7.pdf312* @param[in] c The vehicle emission class313* @return the weight in kg if it matters, -1 otherwise314*/315static double getWeight(const SUMOEmissionClass c);316317/** @brief Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fuel)318* @param[in] c The vehicle emission class319* @param[in] e the type of emission (CO, CO2, ...)320* @param[in] v The vehicle's current velocity321* @param[in] a The vehicle's current acceleration322* @param[in] slope The road's slope at vehicle's position [deg]323* @return The amount emitted by the given vehicle class when moving with the given velocity and acceleration [mg/s]324*/325static double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const EnergyParams* param);326327/** @brief Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fuel)328* @param[in] c The vehicle emission class329* @param[in] v The vehicle's current velocity330* @param[in] a The vehicle's current acceleration331* @param[in] slope The road's slope at vehicle's position [deg]332* @return The amount emitted by the given vehicle class when moving with the given velocity and acceleration [mg/s]333*/334static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param);335336/** @brief Returns the amount of emitted pollutant given the vehicle type and default values for the state (in mg)337* @param[in] c The vehicle emission class338* @param[in] e the type of emission (CO, CO2, ...)339* @param[in] v The vehicle's average velocity340* @param[in] a The vehicle's average acceleration341* @param[in] slope The road's slope at vehicle's position [deg]342* @param{in] tt the time the vehicle travels343* @param[in] param parameter of the emission model affecting the computation344* @return The amount emitted by the given vehicle class [mg]345*/346static double computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const EnergyParams* param);347348/** @brief Returns the adapted acceleration value, useful for comparing with external PHEMlight references.349* @param[in] c the emission class350* @param[in] v the speed value351* @param[in] a the acceleration value352* @param[in] slope The road's slope at vehicle's position [deg]353* @return the modified acceleration354*/355static double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param);356357/** @brief Returns the coasting deceleration value, useful for comparing with external PHEMlight references.358* @param[in] c the emission class359* @param[in] v the speed value360* @param[in] a the acceleration value361* @param[in] slope The road's slope at vehicle's position [deg]362* @param[in] param parameter of the emission model affecting the computation363* @return the coasting deceleration364*/365static double getCoastingDecel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param);366367/// @brief get energy helper368static const HelpersEnergy& getEnergyHelper();369370private:371/// @brief Instance of Helper which gets cleaned up automatically372static Helper myZeroHelper;373374/// @brief Instance of HBEFA2Helper which gets cleaned up automatically375static HelpersHBEFA myHBEFA2Helper;376377/// @brief Instance of HBEFA3Helper which gets cleaned up automatically378static HelpersHBEFA3 myHBEFA3Helper;379380/// @brief Instance of PHEMlightHelper which gets cleaned up automatically381static HelpersPHEMlight myPHEMlightHelper;382383/// @brief Instance of EnergyHelper which gets cleaned up automatically384static HelpersEnergy myEnergyHelper;385386/// @brief Instance of HelpersMMPEVEM which gets cleaned up automatically387static HelpersMMPEVEM myMMPEVEMHelper;388389/// @brief Instance of PHEMlight5Helper which gets cleaned up automatically390static HelpersPHEMlight5 myPHEMlight5Helper;391392/// @brief Instance of HBEFA4Helper which gets cleaned up automatically393static HelpersHBEFA4 myHBEFA4Helper;394395/// @brief the known model helpers396static Helper* myHelpers[];397398/// @brief get all emission classes in string format399static std::vector<std::string> myAllClassesStr;400};401402403