/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 HelpersHBEFA4.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Mon, 10.05.200417///18// Helper methods for HBEFA4-based emission computation19/****************************************************************************/20#pragma once21#include <config.h>2223#include <vector>24#include <limits>25#include <cmath>26#include <utils/common/StdDefs.h>27#include <utils/geom/GeomHelper.h>28#include <utils/common/SUMOVehicleClass.h>29#include "EnergyParams.h"30#include "PollutantsInterface.h"313233// ===========================================================================34// class definitions35// ===========================================================================36/**37* @class HelpersHBEFA438* @brief Helper methods for HBEFA4-based emission computation39*40* The parameter are stored per vehicle class; 6*6 parameter are used, sorted by41* the pollutant (CO2, CO, HC, fuel, NOx, PMx), and the function part42* (c0, cav1, cav2, c1, c2, c3).43*/44class HelpersHBEFA4 : public PollutantsInterface::Helper {45private:46static const int HBEFA4_BASE = 7 << 16;4748public:49/** @brief Constructor (initializes myEmissionClassStrings)50*/51HelpersHBEFA4();5253/** @brief Returns the emission class described by the given parameters.54* @param[in] base the base class giving the default55* @param[in] vClass the vehicle class as described in the Amitran interface (Passenger, ...)56* @param[in] fuel the fuel type as described in the Amitran interface (Gasoline, Diesel, ...)57* @param[in] eClass the emission class as described in the Amitran interface (Euro0, ...)58* @param[in] weight the vehicle weight in kg as described in the Amitran interface59* @return the class described by the parameters60*/61SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight) const;6263/** @brief Returns the vehicle class described by this emission class as described in the Amitran interface (Passenger, ...)64* @param[in] c the emission class65* @return the name of the vehicle class66*/67std::string getAmitranVehicleClass(const SUMOEmissionClass c) const;6869/** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)70* @param[in] c the emission class71* @return the fuel type72*/73std::string getFuel(const SUMOEmissionClass c) const;7475/** @brief Returns the Euro emission class described by this emission class as described in the Amitran interface (0, ..., 6)76* @param[in] c the emission class77* @return the Euro class78*/79int getEuroClass(const SUMOEmissionClass c) const;808182/** @brief Computes the emitted pollutant amount using the given speed and acceleration83*84* For most emissions the function yields mg/s. For fuel ml/s is returned if volumetric fuel has been requested.85* Coasting and an engine which is off by the given param result directly in zero emission.86*87* @param[in] c emission class for the function parameters to use88* @param[in] e the type of emission (CO, CO2, ...)89* @param[in] v The vehicle's current velocity90* @param[in] a The vehicle's current acceleration91* @param[in] slope The road's slope at vehicle's position [deg]92* @param[in] param parameter of the emission model (only used for the coasting deceleration and to determine whether the engine is off)93* @return The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]94*/95inline double compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const {96if (param != nullptr && param->isEngineOff()) {97return 0.;98}99const std::string& fuel = getFuel(c);100if (fuel != "Electricity" && v > ZERO_SPEED_ACCURACY && a < getCoastingDecel(c, v, a, slope, param)) {101return 0.;102}103const int index = (c & ~PollutantsInterface::HEAVY_BIT) - HBEFA4_BASE;104double scale = 1.;105if (e == PollutantsInterface::FUEL && myVolumetricFuel) {106if (fuel == "Diesel") {107scale *= 836.;108} else if (fuel == "Gasoline") {109scale *= 742.;110}111}112const double a2 = a + GRAVITY * sin(DEG2RAD(slope));113const double* f = myFunctionParameter[index][e];114double result = (f[0] + f[1] * v + f[2] * a2 + f[3] * v * v + f[4] * v * v * v + f[5] * a2 * v + f[6] * a2 * v * v) / scale;115if (e != PollutantsInterface::ELEC) {116// no negative emissions117result = MAX2(0.0, result);118}119return result;120}121122123private:124/// @brief The function parameter125static double myFunctionParameter[833][7][7];126127};128129130