LCOV - code coverage report
Current view: top level - src/utils/emissions - HelpersHBEFA3.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 9 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    HelpersHBEFA3.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 10.05.2004
      18              : ///
      19              : // Helper methods for HBEFA3-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 HelpersHBEFA3
      39              :  * @brief Helper methods for HBEFA3-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 HelpersHBEFA3 : public PollutantsInterface::Helper {
      46              : private:
      47              :     static const int HBEFA3_BASE = 2 << 16;
      48              : 
      49              : public:
      50              :     /** @brief Constructor (initializes myEmissionClassStrings)
      51              :      */
      52              :     HelpersHBEFA3();
      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              :      * As the functions are defining emissions in g/hour, the function's result is normed
      86              :      *  by 3.6 (seconds in an hour/1000) yielding mg/s. For fuel ml/s is returned if volumetric fuel has been requested.
      87              :      *  Coasting and an engine which is off by the given param result directly in zero emission.
      88              :      *
      89              :      * @param[in] c emission class for the function parameters to use
      90              :      * @param[in] e the type of emission (CO, CO2, ...)
      91              :      * @param[in] v The vehicle's current velocity
      92              :      * @param[in] a The vehicle's current acceleration
      93              :      * @param[in] slope The road's slope at vehicle's position [deg]
      94              :      * @param[in] param parameter of the emission model (only used for the coasting deceleration and to determine whether the engine is off)
      95              :      * @return The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]
      96              :      */
      97    691651109 :     inline double compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const {
      98    691651109 :         if (e == PollutantsInterface::ELEC || (param != nullptr && param->isEngineOff())) {
      99    114700100 :             return 0.;
     100              :         }
     101    576951009 :         if (v > ZERO_SPEED_ACCURACY && a < getCoastingDecel(c, v, a, slope, param)) {
     102              :             return 0.;
     103              :         }
     104    554920155 :         const int index = (c & ~PollutantsInterface::HEAVY_BIT) - HBEFA3_BASE;
     105              :         double scale = 3.6;
     106    554920155 :         if (e == PollutantsInterface::FUEL && myVolumetricFuel) {
     107         6090 :             if (getFuel(c) == "Diesel") {
     108              :                 scale *= 836.;
     109              :             } else {
     110              :                 scale *= 742.;
     111              :             }
     112              :         }
     113    554920155 :         const double* f = myFunctionParameter[index][e];
     114    554920155 :         return MAX2((f[0] + f[1] * a * v + f[2] * a * a * v + f[3] * v + f[4] * v * v + f[5] * v * v * v) / scale, 0.);
     115              :     }
     116              : 
     117              : 
     118              : private:
     119              :     /// @brief The function parameter
     120              :     static double myFunctionParameter[45][6][6];
     121              : 
     122              : };
        

Generated by: LCOV version 2.0-1