Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2013-2024 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 : /****************************************************************************/ 14 : /// @file HelpersPHEMlight.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Nikolaus Furian 17 : /// @date Sat, 20.04.2013 18 : /// 19 : // Helper methods for PHEMlight-based emission computation 20 : /****************************************************************************/ 21 : #pragma once 22 : #include <config.h> 23 : 24 : #define INTERNAL_PHEM 25 : 26 : #include <vector> 27 : #include <limits> 28 : #include <cmath> 29 : #ifdef INTERNAL_PHEM 30 : #include "PHEMCEPHandler.h" 31 : #endif 32 : #include <foreign/PHEMlight/cpp/CEP.h> 33 : #include <foreign/PHEMlight/cpp/CEPHandler.h> 34 : #include <foreign/PHEMlight/cpp/Helpers.h> 35 : #include <utils/common/StdDefs.h> 36 : #include "PollutantsInterface.h" 37 : 38 : 39 : // =========================================================================== 40 : // class definitions 41 : // =========================================================================== 42 : /** 43 : * @class HelpersPHEMlight 44 : * @brief Helper methods for PHEMlight-based emission computation 45 : */ 46 : class HelpersPHEMlight : public PollutantsInterface::Helper { 47 : private: 48 : static const int PHEMLIGHT_BASE = 3 << 16; 49 : 50 : public: 51 : /** @brief Constructor 52 : */ 53 : HelpersPHEMlight(); 54 : 55 : /** @brief Destructor 56 : */ 57 : virtual ~HelpersPHEMlight(); 58 : 59 : protected: 60 : /** @brief Constructor for subclasses 61 : * @param[in] name the name of the model (string before the '/' in the emission class attribute) 62 : */ 63 45820 : HelpersPHEMlight(std::string name, const int baseIndex, const int defaultClass) 64 91640 : : PollutantsInterface::Helper(name, baseIndex, defaultClass) {} 65 : 66 : public: 67 : /** @brief Checks whether the string describes a known vehicle class 68 : * @param[in] eClass The string describing the vehicle emission class 69 : * @return whether it describes a valid emission class 70 : */ 71 : virtual SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc); 72 : 73 : /** @brief Returns the emission class described by the given parameters. 74 : * @param[in] base the base class giving the default 75 : * @param[in] vClass the vehicle class as described in the Amitran interface (Passenger, ...) 76 : * @param[in] fuel the fuel type as described in the Amitran interface (Gasoline, Diesel, ...) 77 : * @param[in] eClass the emission class as described in the Amitran interface (Euro0, ...) 78 : * @param[in] weight the vehicle weight in kg as described in the Amitran interface 79 : * @return the class described by the parameters 80 : */ 81 : SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight) const; 82 : 83 : /** @brief Returns the vehicle class described by this emission class as described in the Amitran interface (Passenger, ...) 84 : * @param[in] c the emission class 85 : * @return the name of the vehicle class 86 : */ 87 : std::string getAmitranVehicleClass(const SUMOEmissionClass c) const; 88 : 89 : /** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...) 90 : * @param[in] c the emission class 91 : * @return the fuel type 92 : */ 93 : std::string getFuel(const SUMOEmissionClass c) const; 94 : 95 : /** @brief Returns the Euro emission class described by this emission class as described in the Amitran interface (0, ..., 6) 96 : * @param[in] c the emission class 97 : * @return the Euro class 98 : */ 99 : int getEuroClass(const SUMOEmissionClass c) const; 100 : 101 : /** @brief Returns a reference weight in kg described by this emission class as described in the Amitran interface 102 : * This implementation returns only meaningful values for Solo_LKW (truck without trailer) and LNF (light duty vehicles). 103 : * @param[in] c the emission class 104 : * @return a reference weight 105 : */ 106 : double getWeight(const SUMOEmissionClass c) const; 107 : 108 : /** @brief Returns the amount of emitted pollutant given the vehicle type and state (in mg/s or in ml/s for fuel) 109 : * @param[in] c The vehicle emission class 110 : * @param[in] v The vehicle's current velocity 111 : * @param[in] a The vehicle's current acceleration 112 : * @param[in] slope The road's slope at vehicle's position [deg] 113 : * @return The amount of the pollutant emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s] 114 : */ 115 : virtual double compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const; 116 : 117 : /** @brief Returns the adapted acceleration value, useful for comparing with external PHEMlight references. 118 : * @param[in] c the emission class 119 : * @param[in] v the speed value 120 : * @param[in] a the acceleration value 121 : * @param[in] slope The road's slope at vehicle's position [deg] 122 : * @return the modified acceleration 123 : */ 124 : virtual double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param) const; 125 : 126 : /** @brief Returns the maximum deceleration value (as a negative number), which can still be considered as non-braking. 127 : * @param[in] c the emission class 128 : * @param[in] v the speed value 129 : * @param[in] a the acceleration value 130 : * @param[in] slope The road's slope at vehicle's position [deg] 131 : * @param[in] param parameter of the emission model affecting the computation 132 : * @return the coasting deceleration 133 : */ 134 : virtual double getCoastingDecel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param) const; 135 : 136 : private: 137 : /** @brief Returns the amount of emitted pollutant given the vehicle type and state (in mg/s or in ml/s for fuel) 138 : * @param[in] currCep The vehicle emission class 139 : * @param[in] e The emission type 140 : * @param[in] p The vehicle's current power 141 : * @param[in] v The vehicle's current velocity 142 : * @return The amount of the pollutant emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s] 143 : */ 144 : double getEmission(const PHEMCEP* oldCep, PHEMlightdll::CEP* currCep, const std::string& e, const double p, const double v) const; 145 : 146 : /// @brief the index of the next class 147 : int myIndex; 148 : PHEMlightdll::CEPHandler myCEPHandler; 149 : mutable PHEMlightdll::Helpers myHelper; 150 : std::map<SUMOEmissionClass, PHEMlightdll::CEP*> myCEPs; 151 : };