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 /****************************************************************************/
15 // Interface to capsulate different emission models
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <limits>
25 #include <cmath>
27 #include "HelpersHBEFA.h"
28 #include "HelpersHBEFA3.h"
29 #include "HelpersPHEMlight.h"
30 #include "HelpersEnergy.h"
31 #include "PollutantsInterface.h"
32 
33 
34 // ===========================================================================
35 // static definitions
36 // ===========================================================================
37 
45 };
46 std::vector<std::string> PollutantsInterface::myAllClassesStr;
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 
53 PollutantsInterface::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
54  const std::string::size_type sep = eClass.find("/");
55  if (sep != std::string::npos) {
56  const std::string model = eClass.substr(0, sep);
57  const std::string subClass = eClass.substr(sep + 1);
58  for (int i = 0; i < 4; i++) {
59  if (myHelpers[i]->getName() == model) {
60  return myHelpers[i]->getClassByName(subClass, vc);
61  }
62  }
63  } else {
64  // default HBEFA2
65  return myHelpers[0]->getClassByName(eClass, vc);
66  }
67  throw InvalidArgument("Unknown emission class '" + eClass + "'.");
68 }
69 
70 
71 const std::vector<SUMOEmissionClass>
73  std::vector<SUMOEmissionClass> result;
74  for (int i = 0; i < 3; i++) {
75  myHelpers[i]->addAllClassesInto(result);
76  }
77  return result;
78 }
79 
80 
81 const std::vector<std::string>&
83  // first check if myAllClassesStr has to be filled
84  if (myAllClassesStr.empty()) {
85  // first obtain all emissionClasses
86  std::vector<SUMOEmissionClass> emissionClasses;
87  for (int i = 0; i < 3; i++) {
88  myHelpers[i]->addAllClassesInto(emissionClasses);
89  }
90  // now write all emissionClasses in myAllClassesStr
91  for (const auto& i : emissionClasses) {
92  myAllClassesStr.push_back(getName(i));
93  }
94  }
95  return myAllClassesStr;
96 }
97 
98 std::string
100  return myHelpers[c >> 16]->getClassName(c);
101 }
102 
103 
104 bool
106  return (c & HEAVY_BIT) != 0;
107 }
108 
109 
110 bool
112  return myHelpers[c >> 16]->isSilent(c);
113 }
114 
115 
117 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
118  const std::string& fuel, const std::string& eClass, const double weight) {
119  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
120 }
121 
122 
123 std::string
125  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
126 }
127 
128 
129 std::string
131  return myHelpers[c >> 16]->getFuel(c);
132 }
133 
134 
135 int
137  return myHelpers[c >> 16]->getEuroClass(c);
138 }
139 
140 
141 double
143  return myHelpers[c >> 16]->getWeight(c);
144 }
145 
146 
147 double
148 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map<int, double>* param) {
149  return myHelpers[c >> 16]->compute(c, e, v, a, slope, param);
150 }
151 
152 
154 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param) {
155  const Helper* const h = myHelpers[c >> 16];
156  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),
157  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),
158  h->compute(c, ELEC, v, a, slope, param));
159 }
160 
161 
162 double
163 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) {
164  const Helper* const h = myHelpers[c >> 16];
165  return (h->compute(c, e, v, 0, slope, param) + h->compute(c, e, v - a, a, slope, param)) * tt / 2.;
166 }
167 
168 
169 double
170 PollutantsInterface::getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) {
171  return myHelpers[c >> 16]->getModifiedAccel(c, v, a, slope);
172 }
173 
174 /****************************************************************************/
175 
SUMOVehicleClass
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
Definition: SUMOVehicleClass.h:133
PollutantsInterface::myEnergyHelper
static HelpersEnergy myEnergyHelper
Instance of EnergyHelper which gets cleaned up automatically.
Definition: PollutantsInterface.h:389
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:111
PollutantsInterface::isHeavy
static bool isHeavy(const SUMOEmissionClass c)
Checks whether the emission class describes a bus, truck or similar vehicle.
Definition: PollutantsInterface.cpp:105
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:148
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:244
PollutantsInterface::EmissionType
EmissionType
Enumerating all emission types, including fuel.
Definition: PollutantsInterface.h:55
PollutantsInterface::FUEL
Definition: PollutantsInterface.h:55
PollutantsInterface::getEuroClass
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
Definition: PollutantsInterface.cpp:136
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:179
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:234
PollutantsInterface::Helper
abstract superclass for the model helpers
Definition: PollutantsInterface.h:102
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:165
SUMOEmissionClass
int SUMOEmissionClass
Definition: SUMOVehicleClass.h:231
PollutantsInterface::HEAVY_BIT
static const int HEAVY_BIT
the bit to set for denoting heavy vehicles
Definition: PollutantsInterface.h:264
PollutantsInterface::getName
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:99
HelpersPHEMlight
Helper methods for PHEMlight-based emission computation.
Definition: HelpersPHEMlight.h:48
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:210
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:189
PollutantsInterface::CO
Definition: PollutantsInterface.h:55
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:139
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:170
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:117
HelpersEnergy
Helper methods for energy-based electricity consumption computation based on the battery device.
Definition: HelpersEnergy.h:42
PollutantsInterface.h
PollutantsInterface::getAllClasses
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
Definition: PollutantsInterface.cpp:72
HelpersHBEFA3
Helper methods for HBEFA3-based emission computation.
Definition: HelpersHBEFA3.h:46
PollutantsInterface::getAmitranVehicleClass
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
Definition: PollutantsInterface.cpp:124
PollutantsInterface::PM_X
Definition: PollutantsInterface.h:55
SUMOVehicleClass.h
PollutantsInterface::HC
Definition: PollutantsInterface.h:55
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:154
PollutantsInterface::NO_X
Definition: PollutantsInterface.h:55
PollutantsInterface::ELEC
Definition: PollutantsInterface.h:55
PollutantsInterface::CO2
Definition: PollutantsInterface.h:55
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:163
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:142
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:53
PollutantsInterface::getFuel
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
Definition: PollutantsInterface.cpp:130
PollutantsInterface::myHBEFA2Helper
static HelpersHBEFA myHBEFA2Helper
Instance of HBEFA2Helper which gets cleaned up automatically.
Definition: PollutantsInterface.h:380
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:125
HelpersHBEFA
Helper methods for HBEFA-based emission computation.
Definition: HelpersHBEFA.h:46
PollutantsInterface::myHBEFA3Helper
static HelpersHBEFA3 myHBEFA3Helper
Instance of HBEFA3Helper which gets cleaned up automatically.
Definition: PollutantsInterface.h:383
PollutantsInterface::Emissions
Storage for collected values of all emission types.
Definition: PollutantsInterface.h:61
InvalidArgument
Definition: UtilExceptions.h:56
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:148
config.h
PollutantsInterface::getAllClassesStr
static const std::vector< std::string > & getAllClassesStr()
Get all SUMOEmissionClass in string format.
Definition: PollutantsInterface.cpp:82
PollutantsInterface::myHelpers
static Helper * myHelpers[]
the known model helpers
Definition: PollutantsInterface.h:392
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:199
PollutantsInterface::myPHEMlightHelper
static HelpersPHEMlight myPHEMlightHelper
Instance of PHEMlightHelper which gets cleaned up automatically.
Definition: PollutantsInterface.h:386
PollutantsInterface::myAllClassesStr
static std::vector< std::string > myAllClassesStr
get all emission classes in strin format
Definition: PollutantsInterface.h:395