SUMO - Simulation of Urban MObility
PollutantsInterface.h
Go to the documentation of this file.
1 /****************************************************************************/
8 // Interface to capsulate different emission models
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2013-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 #ifndef PollutantsInterface_h
22 #define PollutantsInterface_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <limits>
36 #include <cmath>
37 #include <algorithm>
38 #include <utils/common/StdDefs.h>
40 #include "PHEMCEP.h"
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
46 class HelpersHBEFA;
47 class HelpersHBEFA3;
48 class HelpersPHEMlight;
49 class HelpersEnergy;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
60 public:
61 
63  enum EmissionType { CO2, CO, HC, FUEL, NO_X, PM_X, ELEC };
64 
65 
70  struct Emissions {
71  double CO2;
72  double CO;
73  double HC;
74  double fuel;
75  double NOx;
76  double PMx;
77  double electricity;
78 
88  Emissions(double co2 = 0, double co = 0, double hc = 0, double f = 0, double nox = 0, double pmx = 0, double elec = 0)
89  : CO2(co2), CO(co), HC(hc), fuel(f), NOx(nox), PMx(pmx), electricity(elec) {
90  }
91 
96  void addScaled(const Emissions& a, const double scale = 1.) {
97  CO2 += scale * a.CO2;
98  CO += scale * a.CO;
99  HC += scale * a.HC;
100  fuel += scale * a.fuel;
101  NOx += scale * a.NOx;
102  PMx += scale * a.PMx;
103  electricity += scale * a.electricity;
104  }
105  };
106 
107 
112  class Helper {
113  public:
117  Helper(std::string name) : myName(name) {}
118 
122  const std::string& getName() const {
123  return myName;
124  }
125 
135  virtual SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
136  UNUSED_PARAMETER(vc);
137  if (myEmissionClassStrings.hasString(eClass)) {
138  return myEmissionClassStrings.get(eClass);
139  }
140  std::string eclower = eClass;
141  std::transform(eclower.begin(), eclower.end(), eclower.begin(), tolower);
142  return myEmissionClassStrings.get(eclower);
143  }
144 
149  const std::string getClassName(const SUMOEmissionClass c) const {
150  return myName + "/" + myEmissionClassStrings.getString(c);
151  }
152 
158  virtual bool isSilent(const SUMOEmissionClass c) {
159  return (c & 0xffffffff & ~HEAVY_BIT) == 0;
160  }
161 
164 
175  virtual SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass,
176  const std::string& fuel, const std::string& eClass, const double weight) const {
177  UNUSED_PARAMETER(vClass);
178  UNUSED_PARAMETER(fuel);
179  UNUSED_PARAMETER(eClass);
180  UNUSED_PARAMETER(weight);
181  return base;
182  }
183 
189  virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const {
190  UNUSED_PARAMETER(c);
191  return "Passenger";
192  }
193 
199  virtual std::string getFuel(const SUMOEmissionClass c) const {
200  UNUSED_PARAMETER(c);
201  return "Gasoline";
202  }
203 
209  virtual int getEuroClass(const SUMOEmissionClass c) const {
210  UNUSED_PARAMETER(c);
211  return 0;
212  }
213 
220  virtual double getWeight(const SUMOEmissionClass c) const {
221  UNUSED_PARAMETER(c);
222  return -1.;
223  }
225 
234  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;
235 
239  void addAllClassesInto(std::vector<SUMOEmissionClass>& list) const {
240  myEmissionClassStrings.addKeysInto(list);
241  }
242 
243 
244  protected:
246  const std::string myName;
247 
250 
251  private:
252  Helper& operator=(const Helper&); // just to avoid a compiler warning
253 
254 
255  };
256 
257 
259  static const int ZERO_EMISSIONS = 0;
260 
262  static const int HEAVY_BIT = 1 << 15;
263 
268  static SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc = SVC_IGNORING);
269 
270 
275  static const std::vector<SUMOEmissionClass> getAllClasses();
276 
277 
282  static std::string getName(const SUMOEmissionClass c);
283 
284 
289  static bool isHeavy(const SUMOEmissionClass c);
290 
291 
296  static bool isSilent(const SUMOEmissionClass c);
297 
298 
307  static SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight);
308 
309 
314  static std::string getAmitranVehicleClass(const SUMOEmissionClass c);
315 
316 
321  static std::string getFuel(const SUMOEmissionClass c);
322 
323 
328  static int getEuroClass(const SUMOEmissionClass c);
329 
330 
336  static double getWeight(const SUMOEmissionClass c);
337 
338 
347  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);
348 
349 
357  static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param = 0);
358 
359 
369  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);
370 
371  static const HelpersEnergy& getEnergyHelper() {
372  return myEnergyHelper;
373  }
374 
375 private:
385  static Helper* myHelpers[];
386 
387 };
388 
389 
390 #endif
391 
392 /****************************************************************************/
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
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:38
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:50
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:54
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:54
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.
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...