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-2016 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  const std::string::size_type 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 
105 PollutantsInterface::getClass(const SUMOEmissionClass base, const std::string& vClass,
106  const std::string& fuel, const std::string& eClass, const double weight) {
107  return myHelpers[base >> 16]->getClass(base, vClass, fuel, eClass, weight);
108 }
109 
110 
111 std::string
113  return myHelpers[c >> 16]->getAmitranVehicleClass(c);
114 }
115 
116 
117 std::string
119  return myHelpers[c >> 16]->getFuel(c);
120 }
121 
122 
123 int
125  return myHelpers[c >> 16]->getEuroClass(c);
126 }
127 
128 
129 SUMOReal
131  return myHelpers[c >> 16]->getWeight(c);
132 }
133 
134 
135 SUMOReal
136 PollutantsInterface::compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope) {
137  return myHelpers[c >> 16]->compute(c, e, v, a, slope);
138 }
139 
140 
142 PollutantsInterface::computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope) {
143  const Helper* const h = myHelpers[c >> 16];
144  return Emissions(h->compute(c, CO2, v, a, slope), h->compute(c, CO, v, a, slope), h->compute(c, HC, v, a, slope),
145  h->compute(c, FUEL, v, a, slope), h->compute(c, NO_X, v, a, slope), h->compute(c, PM_X, v, a, slope),
146  h->compute(c, ELEC, v, a, slope));
147 }
148 
149 
150 SUMOReal
151 PollutantsInterface::computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const SUMOReal tt) {
152  const Helper* const h = myHelpers[c >> 16];
153  return (h->compute(c, e, v, 0, slope) + h->compute(c, e, v - a, a, slope)) * tt / 2.;
154 }
155 
156 
157 /****************************************************************************/
158 
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...
virtual std::string getFuel(const SUMOEmissionClass c) const
Returns the fuel type described by this emission class as described in the Amitran interface (Gasolin...
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 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 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 SUMOReal getWeight(const SUMOEmissionClass c) const
Returns a reference weight in kg described by this emission class as described in the Amitran interfa...
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.
virtual int getEuroClass(const SUMOEmissionClass c) const
Returns the Euro emission class described by this emission class as described in the Amitran interfac...
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
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 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...
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.
#define SUMOReal
Definition: config.h:213
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...
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.
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...