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-2020 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 /****************************************************************************/
19 // Interface to capsulate different emission models
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <limits>
24 #include <cmath>
26 #include <utils/common/ToString.h>
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 
47 };
48 std::vector<std::string> PollutantsInterface::myAllClassesStr;
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 
55 PollutantsInterface::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
56  const std::string::size_type sep = eClass.find("/");
57  const std::string model = eClass.substr(0, sep); // this includes the case of no separator
58  for (int i = 0; i < 5; i++) {
59  if (myHelpers[i]->getName() == model) {
60  if (sep != std::string::npos) {
61  const std::string subClass = eClass.substr(sep + 1);
62  if (subClass == "zero") {
63  return myZeroHelper.getClassByName("default", vc);
64  }
65  return myHelpers[i]->getClassByName(subClass, vc);
66  }
67  return myHelpers[i]->getClassByName("default", vc);
68  }
69  }
70  if (sep == std::string::npos) {
71  if (eClass == "zero") {
72  return myZeroHelper.getClassByName("default", vc);
73  }
74  // default HBEFA2
75  return myHBEFA2Helper.getClassByName(eClass, vc);
76  }
77  throw InvalidArgument("Unknown emission class '" + eClass + "'.");
78 }
79 
80 
81 const std::vector<SUMOEmissionClass>
83  std::vector<SUMOEmissionClass> result;
84  for (int i = 0; i < 5; i++) {
85  myHelpers[i]->addAllClassesInto(result);
86  }
87  return result;
88 }
89 
90 
91 const std::vector<std::string>&
93  // first check if myAllClassesStr has to be filled
94  if (myAllClassesStr.empty()) {
95  // first obtain all emissionClasses
96  std::vector<SUMOEmissionClass> emissionClasses;
97  for (int i = 0; i < 5; i++) {
98  myHelpers[i]->addAllClassesInto(emissionClasses);
99  }
100  // now write all emissionClasses in myAllClassesStr
101  for (const auto& i : emissionClasses) {
102  myAllClassesStr.push_back(getName(i));
103  }
104  }
105  return myAllClassesStr;
106 }
107 
108 std::string
110  return myHelpers[c >> 16]->getClassName(c);
111 }
112 
113 
114 std::string
116  switch (e) {
117  case CO2:
118  return "CO2";
119  case CO:
120  return "CO";
121  case HC:
122  return "HC";
123  case FUEL:
124  return "fuel";
125  case NO_X:
126  return "NOx";
127  case PM_X:
128  return "PMx";
129  case ELEC:
130  return "electricity";
131  default:
132  throw InvalidArgument("Unknown emission type '" + toString(e) + "'");
133  }
134 }
135 
136 bool
138  return (c & HEAVY_BIT) != 0;
139 }
140 
141 
142 bool
144  return myHelpers[c >> 16]->isSilent(c);
145 }
146 
147 
149 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
150  const std::string& fuel, const std::string& eClass, const double weight) {
151  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
152 }
153 
154 
155 std::string
157  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
158 }
159 
160 
161 std::string
163  return myHelpers[c >> 16]->getFuel(c);
164 }
165 
166 
167 int
169  return myHelpers[c >> 16]->getEuroClass(c);
170 }
171 
172 
173 double
175  return myHelpers[c >> 16]->getWeight(c);
176 }
177 
178 
179 double
180 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map<int, double>* param) {
181  return myHelpers[c >> 16]->compute(c, e, v, a, slope, param);
182 }
183 
184 
186 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param) {
187  const Helper* const h = myHelpers[c >> 16];
188  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),
189  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),
190  h->compute(c, ELEC, v, a, slope, param));
191 }
192 
193 
194 double
195 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) {
196  const Helper* const h = myHelpers[c >> 16];
197  return (h->compute(c, e, v, 0, slope, param) + h->compute(c, e, v - a, a, slope, param)) * tt / 2.;
198 }
199 
200 
201 double
202 PollutantsInterface::getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) {
203  return myHelpers[c >> 16]->getModifiedAccel(c, v, a, slope);
204 }
205 
206 
207 /****************************************************************************/
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
int SUMOEmissionClass
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Helper methods for energy-based electricity consumption computation based on the battery device.
Definition: HelpersEnergy.h:40
Helper methods for HBEFA3-based emission computation.
Definition: HelpersHBEFA3.h:44
Helper methods for HBEFA-based emission computation.
Definition: HelpersHBEFA.h:44
Helper methods for PHEMlight-based emission computation.
zero emission model, used as superclass for the other model helpers
virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const
Returns the vehicle class described by this emission class as described in the Amitran interface (Pas...
virtual bool isSilent(const SUMOEmissionClass c)
Returns whether the class denotes a silent vehicle for interfacing with the noise model....
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....
const std::string getClassName(const SUMOEmissionClass c) const
Returns the complete name of the emission class including the model.
void addAllClassesInto(std::vector< SUMOEmissionClass > &list) const
Add all known emission classes of this model to the given container.
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...
virtual std::string getFuel(const SUMOEmissionClass c) const
Returns the fuel type described by this emission class as described in the Amitran interface (Gasolin...
virtual int getEuroClass(const SUMOEmissionClass c) const
Returns the Euro emission class described by this emission class as described in the Amitran interfac...
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
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
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...
virtual double getWeight(const SUMOEmissionClass c) const
Returns a reference weight in kg described by this emission class as described in the Amitran interfa...
static bool isSilent(const SUMOEmissionClass c)
Checks whether the emission class describes an electric or similar silent vehicle.
static HelpersHBEFA3 myHBEFA3Helper
Instance of HBEFA3Helper which gets cleaned up automatically.
static HelpersPHEMlight myPHEMlightHelper
Instance of PHEMlightHelper which gets cleaned up automatically.
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.
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...
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
static std::string getPollutantName(const EmissionType e)
return the name for the given emission type
EmissionType
Enumerating all emission types, including fuel.
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
static bool isHeavy(const SUMOEmissionClass c)
Checks whether the emission class describes a bus, truck or similar vehicle.
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...
static double getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7....
static std::vector< std::string > myAllClassesStr
get all emission classes in string format
static HelpersHBEFA myHBEFA2Helper
Instance of HBEFA2Helper which gets cleaned up automatically.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
static const int ZERO_EMISSIONS
the first class in each model representing a zero emission vehicle
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.
static const int HEAVY_BIT
the bit to set for denoting heavy vehicles
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
static HelpersEnergy myEnergyHelper
Instance of EnergyHelper which gets cleaned up automatically.
static const std::vector< std::string > & getAllClassesStr()
Get all SUMOEmissionClass in string format.
static Helper * myHelpers[]
the known model helpers
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...
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
static Helper myZeroHelper
Instance of Helper which gets cleaned up automatically.
Storage for collected values of all emission types.