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-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 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <limits>
26 #include <cmath>
28 #include "HelpersHBEFA.h"
29 #include "HelpersHBEFA3.h"
30 #include "HelpersPHEMlight.h"
31 #include "HelpersEnergy.h"
32 #include "PollutantsInterface.h"
33 
34 
35 // ===========================================================================
36 // static definitions
37 // ===========================================================================
38 
45  &PollutantsInterface::myPHEMlightHelper, &PollutantsInterface::myEnergyHelper
46 };
47 std::vector<std::string> PollutantsInterface::myAllClassesStr;
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 
54 PollutantsInterface::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
55  const std::string::size_type sep = eClass.find("/");
56  if (sep != std::string::npos) {
57  const std::string model = eClass.substr(0, sep);
58  const std::string subClass = eClass.substr(sep + 1);
59  for (int i = 0; i < 4; i++) {
60  if (myHelpers[i]->getName() == model) {
61  return myHelpers[i]->getClassByName(subClass, vc);
62  }
63  }
64  } else {
65  // default HBEFA2
66  return myHelpers[0]->getClassByName(eClass, vc);
67  }
68  throw InvalidArgument("Unknown emission class '" + eClass + "'.");
69 }
70 
71 
72 const std::vector<SUMOEmissionClass>
74  std::vector<SUMOEmissionClass> result;
75  for (int i = 0; i < 3; i++) {
76  myHelpers[i]->addAllClassesInto(result);
77  }
78  return result;
79 }
80 
81 
82 const std::vector<std::string>&
84  // first check if myAllClassesStr has to be filled
85  if (myAllClassesStr.empty()) {
86  // first obtain all emissionClasses
87  std::vector<SUMOEmissionClass> emissionClasses;
88  for (int i = 0; i < 3; i++) {
89  myHelpers[i]->addAllClassesInto(emissionClasses);
90  }
91  // now write all emissionClasses in myAllClassesStr
92  for (const auto& i : emissionClasses) {
93  myAllClassesStr.push_back(getName(i));
94  }
95  }
96  return myAllClassesStr;
97 }
98 
99 std::string
101  return myHelpers[c >> 16]->getClassName(c);
102 }
103 
104 
105 bool
107  return (c & HEAVY_BIT) != 0;
108 }
109 
110 
111 bool
113  return myHelpers[c >> 16]->isSilent(c);
114 }
115 
116 
118 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
119  const std::string& fuel, const std::string& eClass, const double weight) {
120  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
121 }
122 
123 
124 std::string
126  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
127 }
128 
129 
130 std::string
132  return myHelpers[c >> 16]->getFuel(c);
133 }
134 
135 
136 int
138  return myHelpers[c >> 16]->getEuroClass(c);
139 }
140 
141 
142 double
144  return myHelpers[c >> 16]->getWeight(c);
145 }
146 
147 
148 double
149 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const std::map<int, double>* param) {
150  return myHelpers[c >> 16]->compute(c, e, v, a, slope, param);
151 }
152 
153 
155 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const std::map<int, double>* param) {
156  const Helper* const h = myHelpers[c >> 16];
157  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),
158  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),
159  h->compute(c, ELEC, v, a, slope, param));
160 }
161 
162 
163 double
164 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) {
165  const Helper* const h = myHelpers[c >> 16];
166  return (h->compute(c, e, v, 0, slope, param) + h->compute(c, e, v - a, a, slope, param)) * tt / 2.;
167 }
168 
169 
170 double
171 PollutantsInterface::getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope) {
172  return myHelpers[c >> 16]->getModifiedAccel(c, v, a, slope);
173 }
174 
175 /****************************************************************************/
176 
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.
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: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 methods for HBEFA-based emission computation.
Definition: HelpersHBEFA.h:47
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.
static const std::vector< std::string > & getAllClassesStr()
Get all SUMOEmissionClass in string format.
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...