Eclipse SUMO - Simulation of Urban MObility
PollutantsInterface.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Interface to capsulate different emission models
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <limits>
26 #include <cmath>
28 #include "HelpersHBEFA.h"
29 #include "HelpersHBEFA3.h"
30 #include "HelpersPHEMlight.h"
31 #include "HelpersEnergy.h"
32 #include "PollutantsInterface.h"
33 
34 
35 // ===========================================================================
36 // static definitions
37 // ===========================================================================
38 
46 };
47 std::vector<std::string> PollutantsInterface::myAllClassesStr;
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 
54 PollutantsInterface::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
55  const std::string::size_type sep = eClass.find("/");
56  if (sep != std::string::npos) {
57  const std::string model = eClass.substr(0, sep);
58  const std::string subClass = eClass.substr(sep + 1);
59  for (int i = 0; i < 4; i++) {
60  if (myHelpers[i]->getName() == model) {
61  return myHelpers[i]->getClassByName(subClass, vc);
62  }
63  }
64  } else {
65  // default HBEFA2
66  return myHelpers[0]->getClassByName(eClass, vc);
67  }
68  throw InvalidArgument("Unknown emission class '" + eClass + "'.");
69 }
70 
71 
72 const std::vector<SUMOEmissionClass>
74  std::vector<SUMOEmissionClass> result;
75  for (int i = 0; i < 3; i++) {
76  myHelpers[i]->addAllClassesInto(result);
77  }
78  return result;
79 }
80 
81 
82 const std::vector<std::string>&
84  // first check if myAllClassesStr has to be filled
85  if (myAllClassesStr.empty()) {
86  // first obtain all emissionClasses
87  std::vector<SUMOEmissionClass> emissionClasses;
88  for (int i = 0; i < 3; i++) {
89  myHelpers[i]->addAllClassesInto(emissionClasses);
90  }
91  // now write all emissionClasses in myAllClassesStr
92  for (const auto& i : emissionClasses) {
93  myAllClassesStr.push_back(getName(i));
94  }
95  }
96  return myAllClassesStr;
97 }
98 
99 std::string
101  return myHelpers[c >> 16]->getClassName(c);
102 }
103 
104 
105 bool
107  return (c & HEAVY_BIT) != 0;
108 }
109 
110 
111 bool
113  return myHelpers[c >> 16]->isSilent(c);
114 }
115 
116 
118 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
119  const std::string& fuel, const std::string& eClass, const double weight) {
120  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
121 }
122 
123 
124 std::string
126  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
127 }
128 
129 
130 std::string
132  return myHelpers[c >> 16]->getFuel(c);
133 }
134 
135 
136 int
138  return myHelpers[c >> 16]->getEuroClass(c);
139 }
140 
141 
142 double
144  return myHelpers[c >> 16]->getWeight(c);
145 }
146 
147 
148 double
149 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map<int, double>* param) {
150  return myHelpers[c >> 16]->compute(c, e, v, a, slope, param);
151 }
152 
153 
155 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param) {
156  const Helper* const h = myHelpers[c >> 16];
157  return Emissions(h->compute(c, CO2, v, a, slope, param), h->compute(c, CO, v, a, slope, param), h->compute(c, HC, v, a, slope, param),
158  h->compute(c, FUEL, v, a, slope, param), h->compute(c, NO_X, v, a, slope, param), h->compute(c, PM_X, v, a, slope, param),
159  h->compute(c, ELEC, v, a, slope, param));
160 }
161 
162 
163 double
164 PollutantsInterface::computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const std::map<int, double>* param) {
165  const Helper* const h = myHelpers[c >> 16];
166  return (h->compute(c, e, v, 0, slope, param) + h->compute(c, e, v - a, a, slope, param)) * tt / 2.;
167 }
168 
169 
170 double
171 PollutantsInterface::getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) {
172  return myHelpers[c >> 16]->getModifiedAccel(c, v, a, slope);
173 }
174 
175 /****************************************************************************/
176 
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:134
PollutantsInterface::myEnergyHelper
static HelpersEnergy myEnergyHelper
Instance of EnergyHelper which gets cleaned up automatically.
Definition: PollutantsInterface.h:390
PollutantsInterface::Helper::compute
virtual double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map< int, double > *param) const =0
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
PollutantsInterface::isSilent
static bool isSilent(const SUMOEmissionClass c)
Checks whether the emission class describes an electric or similar silent vehicle.
Definition: PollutantsInterface.cpp:112
PollutantsInterface::isHeavy
static bool isHeavy(const SUMOEmissionClass c)
Checks whether the emission class describes a bus, truck or similar vehicle.
Definition: PollutantsInterface.cpp:106
PollutantsInterface::Helper::isSilent
virtual bool isSilent(const SUMOEmissionClass c)
Returns whether the class denotes a silent vehicle for interfacing with the noise model....
Definition: PollutantsInterface.h:149
PollutantsInterface::Helper::addAllClassesInto
void addAllClassesInto(std::vector< SUMOEmissionClass > &list) const
Add all known emission classes of this model to the given container.
Definition: PollutantsInterface.h:245
PollutantsInterface::EmissionType
EmissionType
Enumerating all emission types, including fuel.
Definition: PollutantsInterface.h:56
PollutantsInterface::FUEL
Definition: PollutantsInterface.h:56
PollutantsInterface::getEuroClass
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
Definition: PollutantsInterface.cpp:137
PollutantsInterface::Helper::getAmitranVehicleClass
virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const
Returns the vehicle class described by this emission class as described in the Amitran interface (Pas...
Definition: PollutantsInterface.h:180
HelpersEnergy.h
PollutantsInterface::Helper::getModifiedAccel
virtual double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) const
Returns the adapted acceleration value, useful for comparing with external PHEMlight references....
Definition: PollutantsInterface.h:235
PollutantsInterface::Helper
abstract superclass for the model helpers
Definition: PollutantsInterface.h:103
PollutantsInterface::Helper::getClass
virtual SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string &vClass, const std::string &fuel, const std::string &eClass, const double weight) const
Returns the emission class described by the given parameters. The base is used to determine the model...
Definition: PollutantsInterface.h:166
SUMOEmissionClass
int SUMOEmissionClass
Definition: SUMOVehicleClass.h:232
PollutantsInterface::HEAVY_BIT
static const int HEAVY_BIT
the bit to set for denoting heavy vehicles
Definition: PollutantsInterface.h:265
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:100
HelpersPHEMlight
Helper methods for PHEMlight-based emission computation.
Definition: HelpersPHEMlight.h:49
PollutantsInterface::Helper::getWeight
virtual double getWeight(const SUMOEmissionClass c) const
Returns a reference weight in kg described by this emission class as described in the Amitran interfa...
Definition: PollutantsInterface.h:211
PollutantsInterface::Helper::getFuel
virtual std::string getFuel(const SUMOEmissionClass c) const
Returns the fuel type described by this emission class as described in the Amitran interface (Gasolin...
Definition: PollutantsInterface.h:190
PollutantsInterface::CO
Definition: PollutantsInterface.h:56
PollutantsInterface::Helper::getClassName
const std::string getClassName(const SUMOEmissionClass c) const
Returns the complete name of the emission class including the model.
Definition: PollutantsInterface.h:140
HelpersPHEMlight.h
PollutantsInterface::getModifiedAccel
static double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope)
Returns the adapted acceleration value, useful for comparing with external PHEMlight references.
Definition: PollutantsInterface.cpp:171
PollutantsInterface::getClass
static SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string &vClass, const std::string &fuel, const std::string &eClass, const double weight)
Returns the emission class fittig the given parameters.
Definition: PollutantsInterface.cpp:118
HelpersEnergy
Helper methods for energy-based electricity consumption computation based on the battery device.
Definition: HelpersEnergy.h:43
PollutantsInterface.h
PollutantsInterface::getAllClasses
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:73
HelpersHBEFA3
Helper methods for HBEFA3-based emission computation.
Definition: HelpersHBEFA3.h:47
PollutantsInterface::getAmitranVehicleClass
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
Definition: PollutantsInterface.cpp:125
PollutantsInterface::PM_X
Definition: PollutantsInterface.h:56
SUMOVehicleClass.h
PollutantsInterface::HC
Definition: PollutantsInterface.h:56
PollutantsInterface::computeAll
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map< int, double > *param=0)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
Definition: PollutantsInterface.cpp:155
PollutantsInterface::NO_X
Definition: PollutantsInterface.h:56
PollutantsInterface::ELEC
Definition: PollutantsInterface.h:56
PollutantsInterface::CO2
Definition: PollutantsInterface.h:56
PollutantsInterface::computeDefault
static double computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const std::map< int, double > *param=0)
Returns the amount of emitted pollutant given the vehicle type and default values for the state (in m...
Definition: PollutantsInterface.cpp:164
HelpersHBEFA3.h
PollutantsInterface::getWeight
static double getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7....
Definition: PollutantsInterface.cpp:143
PollutantsInterface::getClassByName
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:54
PollutantsInterface::getFuel
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
Definition: PollutantsInterface.cpp:131
PollutantsInterface::myHBEFA2Helper
static HelpersHBEFA myHBEFA2Helper
Instance of HBEFA2Helper which gets cleaned up automatically.
Definition: PollutantsInterface.h:381
PollutantsInterface::Helper::getClassByName
virtual SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc)
Returns the emission class associated with the given name, aliases are possible If this method is ask...
Definition: PollutantsInterface.h:126
HelpersHBEFA
Helper methods for HBEFA-based emission computation.
Definition: HelpersHBEFA.h:47
PollutantsInterface::myHBEFA3Helper
static HelpersHBEFA3 myHBEFA3Helper
Instance of HBEFA3Helper which gets cleaned up automatically.
Definition: PollutantsInterface.h:384
PollutantsInterface::Emissions
Storage for collected values of all emission types.
Definition: PollutantsInterface.h:62
InvalidArgument
Definition: UtilExceptions.h:57
PollutantsInterface::compute
static double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map< int, double > *param=0)
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
Definition: PollutantsInterface.cpp:149
config.h
PollutantsInterface::getAllClassesStr
static const std::vector< std::string > & getAllClassesStr()
Get all SUMOEmissionClass in string format.
Definition: PollutantsInterface.cpp:83
PollutantsInterface::myHelpers
static Helper * myHelpers[]
the known model helpers
Definition: PollutantsInterface.h:393
HelpersHBEFA.h
PollutantsInterface::Helper::getEuroClass
virtual int getEuroClass(const SUMOEmissionClass c) const
Returns the Euro emission class described by this emission class as described in the Amitran interfac...
Definition: PollutantsInterface.h:200
PollutantsInterface::myPHEMlightHelper
static HelpersPHEMlight myPHEMlightHelper
Instance of PHEMlightHelper which gets cleaned up automatically.
Definition: PollutantsInterface.h:387
PollutantsInterface::myAllClassesStr
static std::vector< std::string > myAllClassesStr
get all emission classes in strin format
Definition: PollutantsInterface.h:396