LCOV - code coverage report
Current view: top level - src/utils/emissions - HelpersHBEFA.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 13 13
Test Date: 2024-12-21 15:45:41 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    HelpersHBEFA.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 10.05.2004
      18              : ///
      19              : // Helper methods for HBEFA-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 HelpersHBEFA
      39              :  * @brief Helper methods for HBEFA-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 HelpersHBEFA : public PollutantsInterface::Helper {
      46              : private:
      47              :     static const int HBEFA_BASE = 1 << 16;
      48              : 
      49              : public:
      50              :     /** @brief Constructor (initializes myEmissionClassStrings)
      51              :      */
      52              :     HelpersHBEFA();
      53              : 
      54              : 
      55              :     /** @brief Computes the emitted pollutant amount using the given speed and acceleration
      56              :      *
      57              :      * As the functions are defining emissions in g/hour, the function's result is normed
      58              :      *  by 3.6 (seconds in an hour/1000) yielding mg/s. For fuel ml/s is returned.
      59              :      *  Negative acceleration results directly in zero emission.
      60              :      *
      61              :      * @param[in] c emission class for the function parameters to use
      62              :      * @param[in] e the type of emission (CO, CO2, ...)
      63              :      * @param[in] v The vehicle's current velocity
      64              :      * @param[in] a The vehicle's current acceleration
      65              :      * @param[in] slope The road's slope at vehicle's position [deg]
      66              :      * @return The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]
      67              :      */
      68      4142931 :     inline double compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const {
      69      4142931 :         if (e == PollutantsInterface::ELEC || (param != nullptr && param->isEngineOff())) {
      70       609787 :             return 0.;
      71              :         }
      72      3533144 :         if (v > ZERO_SPEED_ACCURACY && a < getCoastingDecel(c, v, a, slope, param)) {
      73              :             return 0.;
      74              :         }
      75      3346274 :         const int index = (c & ~PollutantsInterface::HEAVY_BIT) - HBEFA_BASE;
      76      3346274 :         const double kmh = v * 3.6;
      77      3346274 :         const double scale = (e == PollutantsInterface::FUEL && myVolumetricFuel) ? 3.6 * 790. : 3.6;
      78      3346274 :         if (index >= 42) {
      79       957300 :             const double* f = myFunctionParameter[index - 42] + 6 * e;
      80       957300 :             return MAX2((f[0] + f[3] * kmh + f[4] * kmh * kmh + f[5] * kmh * kmh * kmh) / scale, 0.);
      81              :         }
      82      2388974 :         const double* f = myFunctionParameter[index] + 6 * e;
      83      2388974 :         const double alpha = RAD2DEG(asin(a / GRAVITY));
      84      2388974 :         return MAX2((f[0] + f[1] * alpha * kmh + f[2] * alpha * alpha * kmh + f[3] * kmh + f[4] * kmh * kmh + f[5] * kmh * kmh * kmh) / scale, 0.);
      85              :     }
      86              : 
      87              : 
      88              : private:
      89              :     /// @brief The function parameter
      90              :     static double myFunctionParameter[42][36];
      91              : 
      92              : };
        

Generated by: LCOV version 2.0-1