SUMO - Simulation of Urban MObility
PollutantsInterface.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // Interface to capsulate different emission models
19 /****************************************************************************/
20 #ifndef PollutantsInterface_h
21 #define PollutantsInterface_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <limits>
35 #include <cmath>
36 #include <algorithm>
37 #include <utils/common/StdDefs.h>
39 #include "PHEMCEP.h"
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class HelpersHBEFA;
46 class HelpersHBEFA3;
47 class HelpersPHEMlight;
48 class HelpersEnergy;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
59 public:
60 
62  enum EmissionType { CO2, CO, HC, FUEL, NO_X, PM_X, ELEC };
63 
64 
69  struct Emissions {
70  double CO2;
71  double CO;
72  double HC;
73  double fuel;
74  double NOx;
75  double PMx;
76  double electricity;
77 
87  Emissions(double co2 = 0, double co = 0, double hc = 0, double f = 0, double nox = 0, double pmx = 0, double elec = 0)
88  : CO2(co2), CO(co), HC(hc), fuel(f), NOx(nox), PMx(pmx), electricity(elec) {
89  }
90 
95  void addScaled(const Emissions& a, const double scale = 1.) {
96  CO2 += scale * a.CO2;
97  CO += scale * a.CO;
98  HC += scale * a.HC;
99  fuel += scale * a.fuel;
100  NOx += scale * a.NOx;
101  PMx += scale * a.PMx;
102  electricity += scale * a.electricity;
103  }
104  };
105 
106 
111  class Helper {
112  public:
116  Helper(std::string name) : myName(name) {}
117 
121  const std::string& getName() const {
122  return myName;
123  }
124 
134  virtual SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
135  UNUSED_PARAMETER(vc);
136  if (myEmissionClassStrings.hasString(eClass)) {
137  return myEmissionClassStrings.get(eClass);
138  }
139  std::string eclower = eClass;
140  std::transform(eclower.begin(), eclower.end(), eclower.begin(), tolower);
141  return myEmissionClassStrings.get(eclower);
142  }
143 
148  const std::string getClassName(const SUMOEmissionClass c) const {
149  return myName + "/" + myEmissionClassStrings.getString(c);
150  }
151 
157  virtual bool isSilent(const SUMOEmissionClass c) {
158  return (c & 0xffffffff & ~HEAVY_BIT) == 0;
159  }
160 
163 
174  virtual SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass,
175  const std::string& fuel, const std::string& eClass, const double weight) const {
176  UNUSED_PARAMETER(vClass);
177  UNUSED_PARAMETER(fuel);
178  UNUSED_PARAMETER(eClass);
179  UNUSED_PARAMETER(weight);
180  return base;
181  }
182 
188  virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const {
189  UNUSED_PARAMETER(c);
190  return "Passenger";
191  }
192 
198  virtual std::string getFuel(const SUMOEmissionClass c) const {
199  UNUSED_PARAMETER(c);
200  return "Gasoline";
201  }
202 
208  virtual int getEuroClass(const SUMOEmissionClass c) const {
209  UNUSED_PARAMETER(c);
210  return 0;
211  }
212 
219  virtual double getWeight(const SUMOEmissionClass c) const {
220  UNUSED_PARAMETER(c);
221  return -1.;
222  }
224 
233  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;
234 
243  virtual double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) const {
244  UNUSED_PARAMETER(c);
245  UNUSED_PARAMETER(v);
246  UNUSED_PARAMETER(slope);
247  return a;
248  }
249 
253  void addAllClassesInto(std::vector<SUMOEmissionClass>& list) const {
254  myEmissionClassStrings.addKeysInto(list);
255  }
256 
257 
258  protected:
260  const std::string myName;
261 
264 
265  private:
266  Helper& operator=(const Helper&); // just to avoid a compiler warning
267 
268 
269  };
270 
271 
273  static const int ZERO_EMISSIONS = 0;
274 
276  static const int HEAVY_BIT = 1 << 15;
277 
282  static SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc = SVC_IGNORING);
283 
284 
289  static const std::vector<SUMOEmissionClass> getAllClasses();
290 
291 
296  static std::string getName(const SUMOEmissionClass c);
297 
298 
303  static bool isHeavy(const SUMOEmissionClass c);
304 
305 
310  static bool isSilent(const SUMOEmissionClass c);
311 
312 
321  static SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight);
322 
323 
328  static std::string getAmitranVehicleClass(const SUMOEmissionClass c);
329 
330 
335  static std::string getFuel(const SUMOEmissionClass c);
336 
337 
342  static int getEuroClass(const SUMOEmissionClass c);
343 
344 
350  static double getWeight(const SUMOEmissionClass c);
351 
352 
361  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);
362 
363 
371  static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param = 0);
372 
373 
383  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);
384 
392  static double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope);
393 
394  static const HelpersEnergy& getEnergyHelper() {
395  return myEnergyHelper;
396  }
397 
398 private:
408  static Helper* myHelpers[];
409 
410 };
411 
412 
413 #endif
414 
415 /****************************************************************************/
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...
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
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 bool isSilent(const SUMOEmissionClass c)
Returns whether the class denotes a silent vehicle for interfacing with the noise model...
EmissionType
Enumerating all emission types, including fuel.
Storage for collected values of all emission types.
const std::string myName
the name of the model
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...
Emissions(double co2=0, double co=0, double hc=0, double f=0, double nox=0, double pmx=0, double elec=0)
Constructor, intializes all members.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
static const int HEAVY_BIT
the bit to set for denoting heavy vehicles
Helper methods for PHEMlight-based emission computation.
static const int ZERO_EMISSIONS
the first class in each model representing a zero emission vehicle
Helper methods for energy-based electricity consumption computation based on the battery device...
Definition: HelpersEnergy.h:49
static Helper * myHelpers[]
the known model helpers
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
static HelpersPHEMlight myPHEMlightHelper
Instance of PHEMlightHelper which gets cleaned up automatically.
abstract superclass for the model helpers
int SUMOEmissionClass
Helper methods for HBEFA3-based emission computation.
Definition: HelpersHBEFA3.h:53
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 HelpersHBEFA3 myHBEFA3Helper
Instance of HBEFA3Helper which gets cleaned up automatically.
static const std::vector< SUMOEmissionClass > getAllClasses()
Checks whether the string describes a known vehicle class.
static bool isSilent(const SUMOEmissionClass c)
Checks whether the emission class describes an electric or similar silent vehicle.
static std::string getName(const SUMOEmissionClass c)
Checks whether the string describes a known vehicle class.
static bool isHeavy(const SUMOEmissionClass c)
Checks whether the emission class describes a bus, truck or similar vehicle.
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 getWeight(const SUMOEmissionClass c) const
Returns a reference weight in kg described by this emission class as described in the Amitran interfa...
static int getEuroClass(const SUMOEmissionClass c)
Returns the Euro norm described by the given emission class.
Helper(std::string name)
Constructor, intializes the name.
Helper methods for HBEFA-based emission computation.
Definition: HelpersHBEFA.h:53
const std::string & getName() const
Returns the name of the model.
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...
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...
static double getWeight(const SUMOEmissionClass c)
Returns a representative weight for the given emission class see http://colombo-fp7.eu/deliverables/COLOMBO_D4.2_ExtendedPHEMSUMO_v1.7.pdf.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
StringBijection< SUMOEmissionClass > myEmissionClassStrings
Mapping between emission class names and integer representations.
static HelpersHBEFA myHBEFA2Helper
Instance of HBEFA2Helper which gets cleaned up automatically.
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.
virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const
Returns the vehicle class described by this emission class as described in the Amitran interface (Pas...
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...
vehicles ignoring classes
void addAllClassesInto(std::vector< SUMOEmissionClass > &list) const
Add all known emission classes of this model to the given container.
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
void addScaled(const Emissions &a, const double scale=1.)
Add the values of the other struct to this one, scaling the values if needed.
static const HelpersEnergy & getEnergyHelper()
static HelpersEnergy myEnergyHelper
Instance of EnergyHelper which gets cleaned up automatically.
Helper methods for PHEMlight-based emission computation.
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...