LCOV - code coverage report
Current view: top level - src/utils/emissions - HelpersHBEFA4.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 81.8 % 11 9
Test Date: 2024-11-21 15:56:26 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    HelpersHBEFA4.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 10.05.2004
      18              : ///
      19              : // Helper methods for HBEFA4-based emission computation
      20              : /****************************************************************************/
      21              : #pragma once
      22              : #include <config.h>
      23              : 
      24              : #include <vector>
      25              : #include <limits>
      26              : #include <cmath>
      27              : #include <utils/common/StdDefs.h>
      28              : #include <utils/geom/GeomHelper.h>
      29              : #include <utils/common/SUMOVehicleClass.h>
      30              : #include "EnergyParams.h"
      31              : #include "PollutantsInterface.h"
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // class definitions
      36              : // ===========================================================================
      37              : /**
      38              :  * @class HelpersHBEFA4
      39              :  * @brief Helper methods for HBEFA4-based emission computation
      40              :  *
      41              :  * The parameter are stored per vehicle class; 6*6 parameter are used, sorted by
      42              :  *  the pollutant (CO2, CO, HC, fuel, NOx, PMx), and the function part
      43              :  *  (c0, cav1, cav2, c1, c2, c3).
      44              :  */
      45              : class HelpersHBEFA4 : public PollutantsInterface::Helper {
      46              : private:
      47              :     static const int HBEFA4_BASE = 7 << 16;
      48              : 
      49              : public:
      50              :     /** @brief Constructor (initializes myEmissionClassStrings)
      51              :      */
      52              :     HelpersHBEFA4();
      53              : 
      54              :     /** @brief Returns the emission class described by the given parameters.
      55              :      * @param[in] base the base class giving the default
      56              :      * @param[in] vClass the vehicle class as described in the Amitran interface (Passenger, ...)
      57              :      * @param[in] fuel the fuel type as described in the Amitran interface (Gasoline, Diesel, ...)
      58              :      * @param[in] eClass the emission class as described in the Amitran interface (Euro0, ...)
      59              :      * @param[in] weight the vehicle weight in kg as described in the Amitran interface
      60              :      * @return the class described by the parameters
      61              :      */
      62              :     SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight) const;
      63              : 
      64              :     /** @brief Returns the vehicle class described by this emission class as described in the Amitran interface (Passenger, ...)
      65              :      * @param[in] c the emission class
      66              :      * @return the name of the vehicle class
      67              :      */
      68              :     std::string getAmitranVehicleClass(const SUMOEmissionClass c) const;
      69              : 
      70              :     /** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)
      71              :      * @param[in] c the emission class
      72              :      * @return the fuel type
      73              :      */
      74              :     std::string getFuel(const SUMOEmissionClass c) const;
      75              : 
      76              :     /** @brief Returns the Euro emission class described by this emission class as described in the Amitran interface (0, ..., 6)
      77              :      * @param[in] c the emission class
      78              :      * @return the Euro class
      79              :      */
      80              :     int getEuroClass(const SUMOEmissionClass c) const;
      81              : 
      82              : 
      83              :     /** @brief Computes the emitted pollutant amount using the given speed and acceleration
      84              :      *
      85              :      * For most emissions the function yields mg/s. For fuel ml/s is returned if volumetric fuel has been requested.
      86              :      *  Coasting and an engine which is off by the given param result directly in zero emission.
      87              :      *
      88              :      * @param[in] c emission class for the function parameters to use
      89              :      * @param[in] e the type of emission (CO, CO2, ...)
      90              :      * @param[in] v The vehicle's current velocity
      91              :      * @param[in] a The vehicle's current acceleration
      92              :      * @param[in] slope The road's slope at vehicle's position [deg]
      93              :      * @param[in] param parameter of the emission model (only used for the coasting deceleration and to determine whether the engine is off)
      94              :      * @return The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]
      95              :      */
      96      7258454 :     inline double compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const {
      97      7258454 :         if (param != nullptr && param->isEngineOff()) {
      98              :             return 0.;
      99              :         }
     100      7258454 :         const std::string& fuel = getFuel(c);
     101      7258454 :         if (fuel != "Electricity" && v > ZERO_SPEED_ACCURACY && a < getCoastingDecel(c, v, a, slope, param)) {
     102              :             return 0.;
     103              :         }
     104      6170724 :         const int index = (c & ~PollutantsInterface::HEAVY_BIT) - HBEFA4_BASE;
     105              :         double scale = 1.;
     106      6170724 :         if (e == PollutantsInterface::FUEL && myVolumetricFuel) {
     107            0 :             if (fuel == "Diesel") {
     108              :                 scale *= 836.;
     109            0 :             } else if (fuel == "Gasoline") {
     110              :                 scale *= 742.;
     111              :             }
     112              :         }
     113      6170724 :         const double* f = myFunctionParameter[index][e];
     114      6170724 :         double result = (f[0] + f[1] * v + f[2] * a + f[3] * v * v + f[4] * v * v * v + f[5] * a * v + f[6] * a * v * v) / scale;
     115      6170724 :         if (e != PollutantsInterface::ELEC) {
     116              :             // no negative emissions
     117              :             result = MAX2(0.0, result);
     118              :         }
     119              :         return result;
     120              :     }
     121              : 
     122              : 
     123              : private:
     124              :     /// @brief The function parameter
     125              :     static double myFunctionParameter[833][7][7];
     126              : 
     127              : };
        

Generated by: LCOV version 2.0-1