/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2013-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 PHEMCEP.h14/// @author Nikolaus Furian15/// @author Daniel Krajzewicz16/// @author Michael Behrisch17/// @author Marek Heinrich18/// @date Thu, 13.06.201319///20// Helper class for PHEM Light, holds a specific CEP for a PHEM emission class21/****************************************************************************/22#pragma once23#include <config.h>2425#include <vector>26#include <utils/common/SUMOVehicleClass.h>27#include <utils/common/StringBijection.h>28#include "PHEMConstants.h"29303132// ===========================================================================33// enumerations34// ===========================================================================35enum NormalizingType {36RatedPower,37DrivingPower38};394041// ===========================================================================42// class definitions43// ===========================================================================44/**45* @class PHEMCEP46* @brief Data Handler for a single CEP emission data set47*/48class PHEMCEP {49public:50/*** @brief Constructor51* @param[in] emissionClass PHEM emission class of vehicle52* @param[in] vehicleMass vehicle mass53* @param[in] vehicleLoading vehicle loading54* @param[in] vehicleMassRot rotational mass of vehicle55* @param[in] crossArea crosssectional area of vehicle56* @param[in] cWValue cw-value57* @param[in] f0 Rolling resistance f058* @param[in] f1 Rolling resistance f159* @param[in] f2 Rolling resistance f260* @param[in] f3 Rolling resistance f361* @param[in] f4 Rolling resistance f462* @param[in] ratedPower rated power of vehicle63* @param[in] pNormV0 out variable for step function to get maximum normalized rated power over speed64* @param[in] pNormP0 out variable for step function to get maximum normalized rated power over speed65* @param[in] pNormV1 out variable for step function to get maximum normalized rated power over speed66* @param[in] pNormP1 out variable for step function to get maximum normalized rated power over speed67* @param[in] vehicleFuelType out variable for fuel type (D, G) of vehicle, needed for density of fuel68* @param[in] matrixFC Coefficients of the fuel consumption69* @param[in] headerLine Definition of covered pollutants70* @param[in] headerLinePollutants Coefficients of the pollutants71* @param[in] matrixPollutants Coefficients of the pollutants72* @param[in] matrixSpeedRotational Table for rotational coefficients over speed73*/74PHEMCEP(bool heavyVehicel, SUMOEmissionClass emissionClass, const std::string& emissionClassIdentifier,75double vehicleMass, double vehicleLoading, double vehicleMassRot,76double crossArea, double cdValue,77double f0, double f1, double f2, double f3, double f4,78double ratedPower, double pNormV0, double pNormP0, double pNormV1, double pNormP1,79double axleRatio, double engineIdlingSpeed, double engineRatedSpeed, double effectiveWheelDiameter,80double idlingFC,81const std::string& vehicleFuelType,82const std::vector< std::vector<double> >& matrixFC,83const std::vector<std::string>& headerLinePollutants,84const std::vector< std::vector<double> >& matrixPollutants,85const std::vector< std::vector<double> >& matrixSpeedRotational,86const std::vector< std::vector<double> >& normedDragTable,87const std::vector<double>& idlingValuesPollutants);8889/// @brief Destructor90~PHEMCEP();9192/** @brief Returns the power of used for a vehicle at state v,a, slope and loading93* @param[in] v The vehicle's average velocity94* @param[in] a The vehicle's average acceleration95* @param[in] slope The road's slope at vehicle's position [deg]96* @param{in] vehicleCep vehicles CEP data97* @param{in] loading vehicle loading [kg]98* @return The power demand for desired state [kW]99*/100double CalcPower(double v, double a, double slope, double vehicleLoading = 0) const;101102103/** @brief Returns the maximum accelaration for a vehicle at state v,a, slope and loading104* @param[in] v The vehicle's average velocity105* @param[in] a The vehicle's average acceleration106* @param[in] slope The road's slope at vehicle's position [deg]107* @param{in] vehicleCep vehicles CEP data108* @param{in] loading vehicle loading [kg]109* @return The maximum accelaration for desired state [kW]110*/111double GetMaxAccel(double v, double a, double gradient, double vehicleLoading = 0) const;112113/** @brief Returns a emission measure for power[kW] level114* @param[in] pollutantIdentifier Desired pollutant, e.g. NOx115* @param[in] power in [kW]116* @return emission in [g/h]117*/118double GetEmission(const std::string& pollutantIdentifier, double power, double speed, bool normalized = false) const;119double GetDecelCoast(double speed, double acc, double gradient, double vehicleLoading) const;120121122/** @brief Getter function to recieve vehicle data from CEP123* @return PHEM emission class of vehicle124*/125SUMOEmissionClass GetEmissionClass() const {126return _emissionClass;127}128129130/** @brief Getter function to recieve vehicle data from CEP131* @return Rolling resistance f0132*/133double GetResistanceF0() const {134return _resistanceF0;135}136137138/** @brief Getter function to recieve vehicle data from CEP139* @return Rolling resistance f1140*/141double GetResistanceF1() const {142return _resistanceF1;143}144145146/** @brief Getter function to recieve vehicle data from CEP147* @return Rolling resistance f2148*/149double GetResistanceF2() const {150return _resistanceF2;151}152153154/** @brief Getter function to recieve vehicle data from CEP155* @return Rolling resistance f3156*/157double GetResistanceF3() const {158return _resistanceF3;159}160161162/** @brief Getter function to recieve vehicle data from CEP163* @return Rolling resistance f4164*/165double GetResistanceF4() const {166return _resistanceF4;167}168169170/** @brief Getter function to recieve vehicle data from CEP171* @return Cw value172* @todo: Why is it named "cdValue", here?173*/174double GetCdValue() const {175return _cdValue;176}177178/** @brief Getter function to recieve vehicle data from CEP179* @return crosssectional area of vehicle180*/181double GetCrossSectionalArea() const {182return _crossSectionalArea;183}184185186/** @brief Getter function to recieve vehicle data from CEP187* @return vehicle mass188*/189double GetMassVehicle() const {190return _massVehicle;191}192193/** @brief Getter function to recieve vehicle data from CEP194* @return vehicle loading195*/196double GetVehicleLoading() const {197return _vehicleLoading;198}199200201/** @brief Getter function to recieve vehicle data from CEP202* @return rotational mass of vehicle203*/204double GetMassRot() const {205return _massRot;206}207208209/** @brief Getter function to recieve vehicle data from CEP210* @return rated power of vehicle211*/212double GetRatedPower() const {213return _ratedPower;214}215216/** @brief Getter function to recieve vehicle data from CEP217* @return fuel type of vehicle218*/219const std::string& GetVehicleFuelType() const {220return _vehicleFuelType;221}222223private:224/** @brief Interpolates emission linearly between two known power-emission pairs225* @param[in] px power-value to interpolate226* @param[in] p1 first known power value227* @param[in] p2 second known power value228* @param[in] e1 emission value for p1229* @param[in] e2 emission value for p2230* @return emission value for px231*/232double Interpolate(double px, double p1, double p2, double e1, double e2) const;233234/** @brief Finds bounding upper and lower index in pattern for value235* @param[out] lowerIndex out variable for lower index236* @param[out] upperIndex out variable for lower index237* @param[in] pattern to search238* @param[in] value to search239*/240void FindLowerUpperInPattern(int& lowerIndex, int& upperIndex, const std::vector<double>& pattern, double value) const;241242/** @brief Calculates rotational index for speed243* @param[in] speed desired speed244*/245double GetRotationalCoeffecient(double speed) const;246double GetGearCoeffecient(double speed) const;247double GetDragCoeffecient(double nNorm) const;248249/** @brief Calculates maximum available rated power for speed250* @param[in] speed desired speed251*/252double GetPMaxNorm(double speed) const;253254private:255/// @brief PHEM emission class of vehicle256SUMOEmissionClass _emissionClass;257NormalizingType _normalizingType;258/// @brief Rolling resistance f0259double _resistanceF0;260/// @brief Rolling resistance f1261double _resistanceF1;262/// @brief Rolling resistance f2263double _resistanceF2;264/// @brief Rolling resistance f3265double _resistanceF3;266/// @brief Rolling resistance f4267double _resistanceF4;268/// @brief Cw value269double _cdValue;270/// @brief crosssectional area of vehicle271double _crossSectionalArea;272/// @brief vehicle mass273double _massVehicle;274/// @brief vehicle loading275double _vehicleLoading;276/// @brief rotational mass of vehicle277double _massRot;278/// @brief rated power of vehicle279double _ratedPower;280/// @brief Step functions parameter for maximum rated power281double _pNormV0;282/// @brief Step functions parameter for maximum rated power283double _pNormP0;284/// @brief Step functions parameter for maximum rated power285double _pNormV1;286/// @brief Step functions parameter for maximum rated power287double _pNormP1;288double _axleRatio;289double _engineIdlingSpeed;290double _engineRatedSpeed;291double _effictiveWheelDiameter;292double _idlingFC;293std::string _vehicleFuelType;294int _sizeOfPatternFC;295/// @todo describe296int _sizeOfPatternPollutants;297double _normalizingPower;298double _drivingPower;299bool _heavyVehicle;300std::vector<double> _speedPatternRotational;301/// @todo describe302std::vector<double> _powerPatternFC;303/// @todo describe304std::vector<double> _powerPatternPollutants;305std::vector<double> _normalizedPowerPatternFC;306std::vector<double> _normailzedPowerPatternPollutants;307/// @todo describe308std::vector<double> _cepCurveFC;309/// @todo describe310std::vector<double> _normedCepCurveFC;311std::vector<double> _speedCurveRotational;312std::vector<double> _gearTransmissionCurve;313std::vector<double> _nNormTable;314std::vector<double> _dragNormTable;315StringBijection< std::vector<double> > _cepCurvePollutants;316StringBijection<std::vector<double> > _normalizedCepCurvePollutants;317StringBijection<double> _idlingValuesPollutants;318319};320321322