SUMO - Simulation of Urban MObility
PollutantsInterface.cpp
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-2015 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 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <limits>
33 #include <cmath>
35 #include "PollutantsInterface.h"
36 #include "HelpersHBEFA.h"
37 #include "HelpersHBEFA3.h"
38 #include "HelpersPHEMlight.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // static definitions
47 // ===========================================================================
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58 PollutantsInterface::getClassByName(const std::string& eClass, const SUMOVehicleClass vc) {
59  size_t sep = eClass.find("/");
60  if (sep != std::string::npos) {
61  const std::string model = eClass.substr(0, sep);
62  const std::string subClass = eClass.substr(sep + 1);
63  for (int i = 0; i < 3; i++) {
64  if (myHelpers[i]->getName() == model) {
65  return myHelpers[i]->getClassByName(subClass, vc);
66  }
67  }
68  } else {
69  // default HBEFA2
70  return myHelpers[0]->getClassByName(eClass, vc);
71  }
72  throw InvalidArgument("Unknown emission class '" + eClass + "'.");
73 }
74 
75 
76 const std::vector<SUMOEmissionClass>
78  std::vector<SUMOEmissionClass> result;
79  for (int i = 0; i < 3; i++) {
80  myHelpers[i]->addAllClassesInto(result);
81  }
82  return result;
83 }
84 
85 
86 std::string
88  return myHelpers[c >> 16]->getClassName(c);
89 }
90 
91 
92 bool
94  return (c & HEAVY_BIT) != 0;
95 }
96 
97 
98 bool
100  return myHelpers[c >> 16]->isSilent(c);
101 }
102 
103 
104 SUMOReal
105 PollutantsInterface::getMaxAccel(SUMOEmissionClass c, double v, double a, double slope) {
106  return myHelpers[c >> 16]->getMaxAccel(c, v, a, slope);
107 }
108 
109 
111 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
112  const std::string& fuel, const std::string& eClass, const double weight) {
113  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
114 }
115 
116 
117 std::string
119  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
120 }
121 
122 
123 std::string
125  return myHelpers[c >> 16]->getFuel(c);
126 }
127 
128 
129 int
131  return myHelpers[c >> 16]->getEuroClass(c);
132 }
133 
134 
135 SUMOReal
137  return myHelpers[c >> 16]->getWeight(c);
138 }
139 
140 
141 SUMOReal
142 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope) {
143  return myHelpers[c >> 16]->compute(c, e, v, a, slope);
144 }
145 
146 
148 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope) {
149  const Helper* const h = myHelpers[c >> 16];
150  return Emissions(h->compute(c, CO2, v, a, slope), h->compute(c, CO, v, a, slope), h->compute(c, HC, v, a, slope),
151  h->compute(c, FUEL, v, a, slope), h->compute(c, NO_X, v, a, slope), h->compute(c, PM_X, v, a, slope));
152 }
153 
154 
155 SUMOReal
156 PollutantsInterface::computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const SUMOReal tt) {
157  const Helper* const h = myHelpers[c >> 16];
158  return (h->compute(c, e, v, 0, slope) + h->compute(c, e, v - a, a, slope)) * tt / 2.;
159 }
160 
161 
162 /****************************************************************************/
163 
virtual int getEuroClass(const SUMOEmissionClass c) const
Returns the Euro emission class described by this emission class as described in the Amitran interfac...
static SUMOReal 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.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
virtual SUMOReal compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope) const =0
Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fue...
void addAllClassesInto(std::vector< SUMOEmissionClass > &list) const
Add all known emission classes of this model to the given container.
static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope)
Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fu...
virtual SUMOReal getMaxAccel(SUMOEmissionClass c, double v, double a, double slope) const
Returns the maximum possible acceleration or -1. if the model cannot determine the maximum accelerati...
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.
virtual SUMOReal getWeight(const SUMOEmissionClass c) const
Returns a reference weight in kg described by this emission class as described in the Amitran interfa...
Storage for collected values of all emission types.
const std::string getClassName(const SUMOEmissionClass c) const
Returns the complete name of the emission class including the model.
static const int HEAVY_BIT
the bit to set for denoting heavy vehicles
Helper methods for PHEMlight-based emission computation.
static Helper * myHelpers[]
the known model helpers
static std::string getAmitranVehicleClass(const SUMOEmissionClass c)
Returns the vehicle class described by the given emission class.
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 HelpersPHEMlight myPHEMlightHelper
Instance of PHEMlightHelper which gets cleaned up automatically.
abstract superclass for the model helpers
int SUMOEmissionClass
static SUMOReal computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const SUMOReal tt)
Returns the amount of emitted pollutant given the vehicle type and default values for the state (in m...
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.
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:54
static SUMOReal compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope)
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 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.
static SUMOReal getMaxAccel(SUMOEmissionClass c, double v, double a, double slope)
Returns the maximum possible acceleration.
#define SUMOReal
Definition: config.h:218
static std::string getFuel(const SUMOEmissionClass c)
Returns the fuel type of the given emission class.
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 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...