SUMO - Simulation of Urban MObility
HelpersPHEMlight.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Helper methods for PHEMlight-based emission computation
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2013-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
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 "HelpersPHEMlight.h"
34 #include "PHEMCEPHandler.h"
35 #include "PHEMConstants.h"
36 #include <limits>
37 #include <cmath>
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 HelpersPHEMlight::HelpersPHEMlight() : PollutantsInterface::Helper("PHEMlight"), myIndex(PHEMLIGHT_BASE) {
49 }
50 
51 
53 HelpersPHEMlight::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
54  if (eClass == "unknown" && !myEmissionClassStrings.hasString("unknown")) {
55  myEmissionClassStrings.addAlias("unknown", getClassByName("PKW_G_EU4", vc));
56  }
57  if (myEmissionClassStrings.hasString(eClass)) {
58  return myEmissionClassStrings.get(eClass);
59  }
60  if (eClass.size() < 8 || (eClass.find("_D_EU") == std::string::npos && eClass.find("_G_EU") == std::string::npos)) {
61  return false;
62  }
63  int index = myIndex++;
64  const std::string type = eClass.substr(0, 3);
65  if (type == "LB_" || type == "RB_" || type == "LSZ" || eClass.find("LKW") != std::string::npos) {
67  }
68  myEmissionClassStrings.insert(eClass, index);
69  if (!PHEMCEPHandler::getHandlerInstance().Load(index, eClass)) {
70  myEmissionClassStrings.remove(eClass, index);
71  myIndex--;
72  throw InvalidArgument("File for PHEM emission class " + eClass + " not found.");
73  }
74  std::string eclower = eClass;
75  std::transform(eclower.begin(), eclower.end(), eclower.begin(), tolower);
76  myEmissionClassStrings.addAlias(eclower, index);
77  return index;
78 }
79 
80 
82 HelpersPHEMlight::getMaxAccel(SUMOEmissionClass c, double v, double a, double slope) const {
84  if (currCep == 0) {
85  return -1.;
86  }
87  return currCep->GetMaxAccel(v, a, slope);
88 }
89 
90 
92 HelpersPHEMlight::getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight) const {
93  std::string eClassOffset = "0";
94  if (eClass.length() == 5 && eClass.substr(0, 4) == "Euro") {
95  if (eClass[4] >= '0' && eClass[4] <= '6') {
96  eClassOffset = eClass.substr(4, 1);
97  }
98  }
99  std::string desc;
100  if (vClass == "Passenger") {
101  desc = "PKW_";
102  if (fuel == "Gasoline") {
103  desc += "G_";
104  } else if (fuel == "Diesel") {
105  desc += "D_";
106  } else if (fuel == "HybridGasoline") {
107  desc = "H_" + desc + "G_";
108  } else if (fuel == "HybridDiesel") {
109  desc = "H_" + desc + "G_";
110  }
111  desc += "EU" + eClassOffset;
112  } else if (vClass == "Moped") {
113  desc = "KKR_G_EU" + eClassOffset;
114  } else if (vClass == "Motorcycle") {
115  desc = "MR_G_EU" + eClassOffset;
116  if (fuel == "Gasoline2S") {
117  desc += "_2T";
118  } else {
119  desc += "_4T";
120  }
121  } else if (vClass == "Delivery") {
122  desc = "LNF_";
123  if (fuel == "Gasoline") {
124  desc += "G_";
125  } else if (fuel == "Diesel") {
126  desc += "D_";
127  }
128  desc += "EU" + eClassOffset + "_I";
129  if (weight > 1305.) {
130  desc += "I";
131  if (weight > 1760.) {
132  desc += "I";
133  }
134  }
135  } else if (vClass == "UrbanBus") {
136  desc = "LB_D_EU" + eClassOffset;
137  } else if (vClass == "Coach") {
138  desc = "RB_D_EU" + eClassOffset;
139  } else if (vClass == "Truck") {
140  desc = "Solo_LKW_D_EU" + eClassOffset + "_I";
141  if (weight > 1305.) {
142  desc += "I";
143  }
144  } else if (vClass == "Trailer") {
145  desc = "LSZ_D_EU" + eClassOffset;
146  }
147  if (myEmissionClassStrings.hasString(desc)) {
148  return myEmissionClassStrings.get(desc);
149  }
150  return base;
151 }
152 
153 
154 std::string
156  const std::string name = myEmissionClassStrings.getString(c);
157  if (name.find("KKR_") != std::string::npos) {
158  return "Moped";
159  } else if (name.find("RB_") != std::string::npos) {
160  return "Coach";
161  } else if (name.find("LB_") != std::string::npos) {
162  return "UrbanBus";
163  } else if (name.find("LNF_") != std::string::npos) {
164  return "Delivery";
165  } else if (name.find("LSZ_") != std::string::npos) {
166  return "Trailer";
167  } else if (name.find("MR_") != std::string::npos) {
168  return "Motorcycle";
169  } else if (name.find("LKW_") != std::string::npos) {
170  return "Truck";
171  }
172  return "Passenger";
173 }
174 
175 
176 std::string
178  const std::string name = myEmissionClassStrings.getString(c);
179  std::string fuel = "Gasoline";
180  if (name.find("_D_") != std::string::npos) {
181  fuel = "Diesel";
182  }
183  if (name.find("H_") != std::string::npos) {
184  fuel = "Hybrid" + fuel;
185  }
186  return fuel;
187 }
188 
189 
190 int
192  const std::string name = myEmissionClassStrings.getString(c);
193  if (name.find("_EU1") != std::string::npos) {
194  return 1;
195  } else if (name.find("_EU2") != std::string::npos) {
196  return 2;
197  } else if (name.find("_EU3") != std::string::npos) {
198  return 3;
199  } else if (name.find("_EU4") != std::string::npos) {
200  return 4;
201  } else if (name.find("_EU5") != std::string::npos) {
202  return 5;
203  } else if (name.find("_EU6") != std::string::npos) {
204  return 6;
205  }
206  return 0;
207 }
208 
209 
210 SUMOReal
212  const std::string name = myEmissionClassStrings.getString(c);
213  if (name.find("LNF_") != std::string::npos) {
214  if (name.find("_III") != std::string::npos) {
215  return 2630.;
216  } else if (name.find("_II") != std::string::npos) {
217  return 1532.;
218  } else if (name.find("_I") != std::string::npos) {
219  return 652.;
220  }
221  }
222  if (name.find("Solo_LKW_") != std::string::npos) {
223  if (name.find("_II") != std::string::npos) {
224  return 8398.;
225  } else if (name.find("_I") != std::string::npos) {
226  return 18702.;
227  }
228  }
229  return -1.;
230 }
231 
232 
233 SUMOReal
234 HelpersPHEMlight::compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope) const {
235  if (c == PHEMLIGHT_BASE) { // zero emission class
236  return 0.;
237  }
238  const PHEMCEP* const currCep = PHEMCEPHandler::getHandlerInstance().GetCep(c);
239  const double corrSpeed = MAX2((double) 0.0, v);
240  const double decelCoast = currCep->GetDecelCoast(corrSpeed, a, slope, 0);
241  if (a < decelCoast) {
242  return 0;
243  }
244  double power = currCep->CalcPower(corrSpeed, a, slope);
245  switch (e) {
247  return currCep->GetEmission("CO", power, corrSpeed) / SECONDS_PER_HOUR * 1000.;
249  return currCep->GetEmission("FC", power, corrSpeed) * 3.15 / SECONDS_PER_HOUR * 1000.;
251  return currCep->GetEmission("HC", power, corrSpeed) / SECONDS_PER_HOUR * 1000.;
253  return currCep->GetEmission("NOx", power, corrSpeed) / SECONDS_PER_HOUR * 1000.;
255  return currCep->GetEmission("PM", power, corrSpeed) / SECONDS_PER_HOUR * 1000.;
257  std::string fuelType = currCep->GetVehicleFuelType();
258  if (fuelType == "D") { // divide by average diesel density of 836 g/l
259  return currCep->GetEmission("FC", power, corrSpeed) / 836. / SECONDS_PER_HOUR * 1000.;
260  } else if (fuelType == "G") { // divide by average gasoline density of 742 g/l
261  return currCep->GetEmission("FC", power, corrSpeed) / 742. / SECONDS_PER_HOUR * 1000.;
262  } else {
263  return currCep->GetEmission("FC", power, corrSpeed) / SECONDS_PER_HOUR * 1000.; // surely false, but at least not additionally modified
264  }
265  }
266  }
267  // should never get here
268  return 0.;
269 }
270 
271 
272 /****************************************************************************/
273 
Data Handler for a single CEP emission data set.
Definition: PHEMCEP.h:59
void remove(const std::string str, const T key)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool hasString(const std::string &str) const
int myIndex
the index of the next class
HelpersPHEMlight()
Constructor.
int getEuroClass(const SUMOEmissionClass c) const
Returns the Euro emission class described by this emission class as described in the Amitran interfac...
EmissionType
Enumerating all emission types, including fuel.
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string GetVehicleFuelType() const
Getter function to recieve vehicle data from CEP.
Definition: PHEMCEP.h:230
SUMOReal compute(const SUMOEmissionClass c, const PollutantsInterface::EmissionType e, const double v, const double a, const double slope) const
Returns the amount of emitted pollutant given the vehicle type and state (in mg/s or in ml/s for fuel...
SUMOReal getWeight(const SUMOEmissionClass c) const
Returns a reference weight in kg described by this emission class as described in the Amitran interfa...
static const int HEAVY_BIT
the bit to set for denoting heavy vehicles
static PHEMCEPHandler & getHandlerInstance()
Implementatio of Singelton pattern.
void insert(const std::string str, const T key, bool checkDuplicates=true)
void addAlias(const std::string str, const T key)
std::string getFuel(const SUMOEmissionClass c) const
Returns the fuel type described by this emission class as described in the Amitran interface (Gasolin...
int SUMOEmissionClass
const std::string & getString(const T key) const
const double SECONDS_PER_HOUR
Definition: PHEMConstants.h:27
static const int PHEMLIGHT_BASE
double GetMaxAccel(double v, double a, double gradient, double vehicleLoading=0) const
Returns the maximum accelaration for a vehicle at state v,a, slope and loading.
Definition: PHEMCEP.cpp:422
StringBijection< SUMOEmissionClass > myEmissionClassStrings
Mapping between emission class names and integer representations.
SUMOReal getMaxAccel(SUMOEmissionClass c, double v, double a, double slope) const
Returns the maximum possible acceleration.
std::string getAmitranVehicleClass(const SUMOEmissionClass c) const
Returns the vehicle class described by this emission class as described in the Amitran interface (Pas...
double CalcPower(double v, double a, double slope, double vehicleLoading=0) const
Returns the power of used for a vehicle at state v,a, slope and loading.
Definition: PHEMCEP.cpp:411
SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc)
Checks whether the string describes a known vehicle class.
T get(const std::string &str) const
PHEMCEP * GetCep(SUMOEmissionClass emissionClass)
Returns the CEP data for a PHEM emission class.
#define SUMOReal
Definition: config.h:214
double GetDecelCoast(double speed, double acc, double gradient, double vehicleLoading) const
Definition: PHEMCEP.cpp:290
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.
double GetEmission(const std::string &pollutantIdentifier, double power, double speed, bool normalized=false) const
Returns a emission measure for power[kW] level.
Definition: PHEMCEP.cpp:208
Helper methods for PHEMlight-based emission computation.