Eclipse 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-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 #ifndef PollutantsInterface_h
19 #define PollutantsInterface_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <limits>
29 #include <cmath>
30 #include <algorithm>
31 #include <utils/common/StdDefs.h>
33 #include "PHEMCEP.h"
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class HelpersHBEFA;
40 class HelpersHBEFA3;
41 class HelpersPHEMlight;
42 class HelpersEnergy;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
53 
54 public:
56  enum EmissionType { CO2, CO, HC, FUEL, NO_X, PM_X, ELEC };
57 
62  struct Emissions {
63  double CO2;
64  double CO;
65  double HC;
66  double fuel;
67  double NOx;
68  double PMx;
69  double electricity;
70 
80  Emissions(double co2 = 0, double co = 0, double hc = 0, double f = 0, double nox = 0, double pmx = 0, double elec = 0)
81  : CO2(co2), CO(co), HC(hc), fuel(f), NOx(nox), PMx(pmx), electricity(elec) {
82  }
83 
88  void addScaled(const Emissions& a, const double scale = 1.) {
89  CO2 += scale * a.CO2;
90  CO += scale * a.CO;
91  HC += scale * a.HC;
92  fuel += scale * a.fuel;
93  NOx += scale * a.NOx;
94  PMx += scale * a.PMx;
95  electricity += scale * a.electricity;
96  }
97  };
98 
103  class Helper {
104  public:
108  Helper(std::string name) : myName(name) {}
109 
113  const std::string& getName() const {
114  return myName;
115  }
116 
126  virtual SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
127  UNUSED_PARAMETER(vc);
128  if (myEmissionClassStrings.hasString(eClass)) {
129  return myEmissionClassStrings.get(eClass);
130  }
131  std::string eclower = eClass;
132  std::transform(eclower.begin(), eclower.end(), eclower.begin(), tolower);
133  return myEmissionClassStrings.get(eclower);
134  }
135 
140  const std::string getClassName(const SUMOEmissionClass c) const {
141  return myName + "/" + myEmissionClassStrings.getString(c);
142  }
143 
149  virtual bool isSilent(const SUMOEmissionClass c) {
150  return (c & 0xffffffff & ~HEAVY_BIT) == 0;
151  }
152 
155 
166  virtual SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass,
167  const std::string& fuel, const std::string& eClass, const double weight) const {
168  UNUSED_PARAMETER(vClass);
169  UNUSED_PARAMETER(fuel);
170  UNUSED_PARAMETER(eClass);
171  UNUSED_PARAMETER(weight);
172  return base;
173  }
174 
180  virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const {
181  UNUSED_PARAMETER(c);
182  return "Passenger";
183  }
184 
190  virtual std::string getFuel(const SUMOEmissionClass c) const {
191  UNUSED_PARAMETER(c);
192  return "Gasoline";
193  }
194 
200  virtual int getEuroClass(const SUMOEmissionClass c) const {
201  UNUSED_PARAMETER(c);
202  return 0;
203  }
204 
211  virtual double getWeight(const SUMOEmissionClass c) const {
212  UNUSED_PARAMETER(c);
213  return -1.;
214  }
216 
225  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;
226 
235  virtual double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) const {
236  UNUSED_PARAMETER(c);
237  UNUSED_PARAMETER(v);
238  UNUSED_PARAMETER(slope);
239  return a;
240  }
241 
245  void addAllClassesInto(std::vector<SUMOEmissionClass>& list) const {
246  myEmissionClassStrings.addKeysInto(list);
247  }
248 
249  protected:
251  const std::string myName;
252 
255 
256  private:
258  Helper& operator=(const Helper&) = delete;
259  };
260 
262  static const int ZERO_EMISSIONS = 0;
263 
265  static const int HEAVY_BIT = 1 << 15;
266 
271  static SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc = SVC_IGNORING);
272 
277  static const std::vector<SUMOEmissionClass> getAllClasses();
278 
280  static const std::vector<std::string>& getAllClassesStr();
281 
286  static std::string getName(const SUMOEmissionClass c);
287 
292  static bool isHeavy(const SUMOEmissionClass c);
293 
298  static bool isSilent(const SUMOEmissionClass c);
299 
308  static SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight);
309 
314  static std::string getAmitranVehicleClass(const SUMOEmissionClass c);
315 
320  static std::string getFuel(const SUMOEmissionClass c);
321 
326  static int getEuroClass(const SUMOEmissionClass c);
327 
333  static double getWeight(const SUMOEmissionClass c);
334 
343  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);
344 
352  static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param = 0);
353 
363  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);
364 
372  static double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope);
373 
375  static const HelpersEnergy& getEnergyHelper() {
376  return myEnergyHelper;
377  }
378 
379 private:
382 
385 
388 
391 
393  static Helper* myHelpers[];
394 
396  static std::vector<std::string> myAllClassesStr;
397 };
398 
399 
400 #endif
401 
402 /****************************************************************************/
static std::vector< std::string > myAllClassesStr
get all emission classes in strin format
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:32
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:43
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:47
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:47
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()
get energy helper
static HelpersEnergy myEnergyHelper
Instance of EnergyHelper which gets cleaned up automatically.
static const std::vector< std::string > & getAllClassesStr()
Get all SUMOEmissionClass in string format.
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...