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-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 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <limits>
32 #include <cmath>
34 #include "HelpersHBEFA.h"
35 #include "HelpersHBEFA3.h"
36 #include "HelpersPHEMlight.h"
37 #include "HelpersEnergy.h"
38 #include "PollutantsInterface.h"
39 
40 
41 // ===========================================================================
42 // static definitions
43 // ===========================================================================
49  &PollutantsInterface::myPHEMlightHelper, &PollutantsInterface::myEnergyHelper
50  };
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57 PollutantsInterface::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
58  const std::string::size_type sep = eClass.find("/");
59  if (sep != std::string::npos) {
60  const std::string model = eClass.substr(0, sep);
61  const std::string subClass = eClass.substr(sep + 1);
62  for (int i = 0; i < 4; i++) {
63  if (myHelpers[i]->getName() == model) {
64  return myHelpers[i]->getClassByName(subClass, vc);
65  }
66  }
67  } else {
68  // default HBEFA2
69  return myHelpers[0]->getClassByName(eClass, vc);
70  }
71  throw InvalidArgument("Unknown emission class '" + eClass + "'.");
72 }
73 
74 
75 const std::vector<SUMOEmissionClass>
77  std::vector<SUMOEmissionClass> result;
78  for (int i = 0; i < 3; i++) {
79  myHelpers[i]->addAllClassesInto(result);
80  }
81  return result;
82 }
83 
84 
85 std::string
87  return myHelpers[c >> 16]->getClassName(c);
88 }
89 
90 
91 bool
93  return (c & HEAVY_BIT) != 0;
94 }
95 
96 
97 bool
99  return myHelpers[c >> 16]->isSilent(c);
100 }
101 
102 
104 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
105  const std::string& fuel, const std::string& eClass, const double weight) {
106  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
107 }
108 
109 
110 std::string
112  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
113 }
114 
115 
116 std::string
118  return myHelpers[c >> 16]->getFuel(c);
119 }
120 
121 
122 int
124  return myHelpers[c >> 16]->getEuroClass(c);
125 }
126 
127 
128 double
130  return myHelpers[c >> 16]->getWeight(c);
131 }
132 
133 
134 double
135 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map<int, double>* param) {
136  return myHelpers[c >> 16]->compute(c, e, v, a, slope, param);
137 }
138 
139 
141 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param) {
142  const Helper* const h = myHelpers[c >> 16];
143  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),
144  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),
145  h->compute(c, ELEC, v, a, slope, param));
146 }
147 
148 
149 double
150 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) {
151  const Helper* const h = myHelpers[c >> 16];
152  return (h->compute(c, e, v, 0, slope, param) + h->compute(c, e, v - a, a, slope, param)) * tt / 2.;
153 }
154 
155 
156 double
157 PollutantsInterface::getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) {
158  return myHelpers[c >> 16]->getModifiedAccel(c, v, a, slope);
159 }
160 
161 
162 /****************************************************************************/
163 
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.
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 const int HEAVY_BIT
the bit to set for denoting heavy vehicles
Helper methods for PHEMlight-based emission computation.
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 methods for HBEFA-based emission computation.
Definition: HelpersHBEFA.h:53
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.
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...
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...
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...
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.
static HelpersEnergy myEnergyHelper
Instance of EnergyHelper which gets cleaned up automatically.
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...