Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file PollutantsInterface.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date Mon, 19.08.2013
18 : ///
19 : // Interface to capsulate different emission models
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include <vector>
25 : #include <limits>
26 : #include <cmath>
27 : #include <algorithm>
28 : #include <utils/common/StdDefs.h>
29 : #include <utils/common/SUMOVehicleClass.h>
30 :
31 :
32 : // ===========================================================================
33 : // class declarations
34 : // ===========================================================================
35 : class EnergyParams;
36 : class HelpersHBEFA;
37 : class HelpersHBEFA3;
38 : class HelpersHBEFA4;
39 : class HelpersEnergy;
40 : class HelpersMMPEVEM;
41 : class HelpersPHEMlight;
42 : class HelpersPHEMlight5;
43 :
44 :
45 : // ===========================================================================
46 : // class definitions
47 : // ===========================================================================
48 : /**
49 : * @class PollutantsInterface
50 : * @brief Helper methods for PHEMlight-based emission computation
51 : */
52 : class PollutantsInterface {
53 :
54 : public:
55 : /// @brief Enumerating all emission types, including fuel
56 : enum EmissionType { CO2, CO, HC, FUEL, NO_X, PM_X, ELEC };
57 :
58 : /**
59 : * @struct Emissions
60 : * @brief Storage for collected values of all emission types
61 : */
62 : struct Emissions {
63 : /** @brief Constructor, intializes all members
64 : * @param[in] co2 initial value for CO2, defaults to 0
65 : * @param[in] co initial value for CO, defaults to 0
66 : * @param[in] hc initial value for HC, defaults to 0
67 : * @param[in] f initial value for fuel, defaults to 0
68 : * @param[in] nox initial value for NOx, defaults to 0
69 : * @param[in] pmx initial value for PMx, defaults to 0
70 : * @param[in] elec initial value for electricity, defaults to 0
71 : */
72 : Emissions(double co2 = 0, double co = 0, double hc = 0, double f = 0, double nox = 0, double pmx = 0, double elec = 0);
73 :
74 : /** @brief Add the values of the other struct to this one, scaling the values if needed
75 : * @param[in] a the other emission valuess
76 : * @param[in] scale scaling factor, defaulting to 1 (no scaling)
77 : */
78 : void addScaled(const Emissions& a, const double scale = 1.);
79 :
80 : /// @brief emission types
81 : /// @{
82 : double CO2;
83 : double CO;
84 : double HC;
85 : double fuel;
86 : double NOx;
87 : double PMx;
88 : double electricity;
89 : /// @}
90 : };
91 :
92 : /**
93 : * @class Helper
94 : * @brief zero emission model, used as superclass for the other model helpers
95 : */
96 : class Helper {
97 : public:
98 : /** @brief Constructor, intializes the name
99 : * @param[in] name the name of the model (string before the '/' in the emission class attribute)
100 : */
101 : Helper(std::string name, const int baseIndex, const int defaultClass);
102 :
103 : /// @brief empty destructor
104 168534 : virtual ~Helper() {}
105 :
106 : /** @brief Returns the name of the model
107 : * @return the name of the model (string before the '/' in the emission class attribute)
108 : */
109 : const std::string& getName() const;
110 :
111 : /** @brief Returns the emission class associated with the given name, aliases are possible
112 : * If this method is asked for the "unknown" class it should return the default
113 : * (possibly depending on the given vehicle class).
114 : * The class name is case insensitive.
115 : *
116 : * @param[in] eClass the name of the emission class (string after the '/' in the emission class attribute)
117 : * @param[in] vc the vehicle class to use when determining default class
118 : * @return the name of the model (string before the '/' in the emission class)
119 : */
120 : virtual SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc);
121 :
122 : /** @brief Returns the complete name of the emission class including the model
123 : * @param[in] c the emission class
124 : * @return the name of the class (the complete emission class attribute)
125 : */
126 : const std::string getClassName(const SUMOEmissionClass c) const;
127 :
128 : /** @brief Returns whether the class denotes a silent vehicle for interfacing with the noise model.
129 : * By default the first class in each model is the silent class.
130 : * @param[in] c the emission class
131 : * @return whether the class denotes a silent vehicle
132 : */
133 : virtual bool isSilent(const SUMOEmissionClass c);
134 :
135 : /// @name Methods for Amitran interfaces
136 : /// @{
137 :
138 : /** @brief Returns the emission class described by the given parameters.
139 : * The base is used to determine the model to use and as default return values.
140 : * Default implementation returns always base.
141 : * @param[in] base the base class giving the model and the default
142 : * @param[in] vClass the vehicle class as described in the Amitran interface (Passenger, ...)
143 : * @param[in] fuel the fuel type as described in the Amitran interface (Gasoline, Diesel, ...)
144 : * @param[in] eClass the emission class as described in the Amitran interface (Euro0, ...)
145 : * @param[in] weight the vehicle weight in kg as described in the Amitran interface
146 : * @return the class described by the parameters
147 : */
148 : virtual SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel,
149 : const std::string& eClass, const double weight) const;
150 :
151 : /** @brief Returns the vehicle class described by this emission class as described in the Amitran interface (Passenger, ...)
152 : * Default implementation returns always "Passenger".
153 : * @param[in] c the emission class
154 : * @return the name of the vehicle class
155 : */
156 : virtual std::string getAmitranVehicleClass(const SUMOEmissionClass c) const;
157 :
158 : /** @brief Returns the fuel type described by this emission class as described in the Amitran interface (Gasoline, Diesel, ...)
159 : * Default implementation returns always "Gasoline".
160 : * @param[in] c the emission class
161 : * @return the fuel type
162 : */
163 : virtual std::string getFuel(const SUMOEmissionClass c) const;
164 :
165 : /** @brief Returns the Euro emission class described by this emission class as described in the Amitran interface (0, ..., 6)
166 : * Default implementation returns always 0.
167 : * @param[in] c the emission class
168 : * @return the Euro class
169 : */
170 : virtual int getEuroClass(const SUMOEmissionClass c) const;
171 :
172 : /** @brief Returns a reference weight in kg described by this emission class as described in the Amitran interface
173 : * It might return -1, if the weight is not important to distinguish different emission classes.
174 : * Default implementation returns always -1.
175 : * @param[in] c the emission class
176 : * @return a reference weight
177 : */
178 : virtual double getWeight(const SUMOEmissionClass c) const;
179 : /// @}
180 :
181 : /** @brief Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fuel)
182 : * @param[in] c The vehicle emission class
183 : * @param[in] e the type of emission (CO, CO2, ...)
184 : * @param[in] v The vehicle's current velocity
185 : * @param[in] a The vehicle's current acceleration
186 : * @param[in] slope The road's slope at vehicle's position [deg]
187 : * @param[in] param parameter of the emission model affecting the computation
188 : * @return The amount emitted by the given emission class when moving with the given velocity and acceleration [mg/s or ml/s]
189 : */
190 : virtual double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const EnergyParams* param) const;
191 :
192 : /** @brief Returns the adapted acceleration value, useful for comparing with external PHEMlight references.
193 : * Default implementation returns always the input accel.
194 : * @param[in] c the emission class
195 : * @param[in] v the speed value
196 : * @param[in] a the acceleration value
197 : * @param[in] slope The road's slope at vehicle's position [deg]
198 : * @return the modified acceleration
199 : */
200 : virtual double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param) const;
201 :
202 : /** @brief Returns the maximum deceleration value (as a negative number), which can still be considered as non-braking.
203 : * Default implementation returns always zero.
204 : * @param[in] c the emission class
205 : * @param[in] v the speed value
206 : * @param[in] a the acceleration value
207 : * @param[in] slope The road's slope at vehicle's position [deg]
208 : * @param[in] param parameter of the emission model affecting the computation
209 : * @return the coasting deceleration
210 : */
211 : virtual double getCoastingDecel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param) const;
212 :
213 : /** @brief Add all known emission classes of this model to the given container
214 : * @param[in] list the vector to add to
215 : */
216 : void addAllClassesInto(std::vector<SUMOEmissionClass>& list) const;
217 :
218 : bool includesClass(const SUMOEmissionClass c) const;
219 :
220 : protected:
221 : /// @brief the lowest speed which allows reliable coasting calculations
222 : static const double ZERO_SPEED_ACCURACY;
223 :
224 : /// @brief the name of the model
225 : const std::string myName;
226 :
227 : /// @brief the starting index for classes of this model
228 : const int myBaseIndex;
229 :
230 : /// @brief return fuel consumption in l instead of mg
231 : bool myVolumetricFuel;
232 :
233 : /// @brief Mapping between emission class names and integer representations
234 : StringBijection<SUMOEmissionClass> myEmissionClassStrings;
235 :
236 : private:
237 : /// @brief invalidate copy constructor
238 : Helper& operator=(const Helper&) = delete;
239 : };
240 :
241 : /// @brief the first class in each model representing a zero emission vehicle
242 : static const int ZERO_EMISSIONS = 0;
243 :
244 : /// @brief the bit to set for denoting heavy vehicles
245 : static const int HEAVY_BIT = 1 << 15;
246 :
247 : /** @brief Checks whether the string describes a known vehicle class
248 : * @param[in] eClass The string describing the vehicle emission class
249 : * @return whether it describes a valid emission class
250 : */
251 : static SUMOEmissionClass getClassByName(const std::string& eClass, const SUMOVehicleClass vc = SVC_IGNORING);
252 :
253 : /** @brief Checks whether the string describes a known vehicle class
254 : * @param[in] eClass The string describing the vehicle emission class
255 : * @return whether it describes a valid emission class
256 : */
257 : static const std::vector<SUMOEmissionClass> getAllClasses();
258 :
259 : /// @brief Get all SUMOEmissionClass in string format
260 : static const std::vector<std::string>& getAllClassesStr();
261 :
262 : /** @brief Checks whether the string describes a known vehicle class
263 : * @param[in] eClass The string describing the vehicle emission class
264 : * @return whether it describes a valid emission class
265 : */
266 : static std::string getName(const SUMOEmissionClass c);
267 :
268 : /// @brief return the name for the given emission type
269 : static std::string getPollutantName(const EmissionType e);
270 :
271 : /** @brief Checks whether the emission class describes a bus, truck or similar vehicle
272 : * @param[in] c The vehicle emission class
273 : * @return whether it describes a heavy vehicle
274 : */
275 : static bool isHeavy(const SUMOEmissionClass c);
276 :
277 : /** @brief Checks whether the emission class describes an electric or similar silent vehicle
278 : * @param[in] c The vehicle emission class
279 : * @return whether it describes a silent vehicle
280 : */
281 : static bool isSilent(const SUMOEmissionClass c);
282 :
283 : /** @brief Returns the emission class fittig the given parameters
284 : * @param[in] base The base emission class to derive from
285 : * @param[in] vClass The vehicle class description (like "truck")
286 : * @param[in] eClass The emission class description (like "Euro5")
287 : * @param[in] fuel The fuel type (like "Diesel")
288 : * @param[in] weight The weight in kg
289 : * @return The best fitting emission class related to the base
290 : */
291 : static SUMOEmissionClass getClass(const SUMOEmissionClass base, const std::string& vClass, const std::string& fuel, const std::string& eClass, const double weight);
292 :
293 : /** @brief Returns the vehicle class described by the given emission class
294 : * @param[in] c The vehicle emission class
295 : * @return The Amitran string describing the vehicle class
296 : */
297 : static std::string getAmitranVehicleClass(const SUMOEmissionClass c);
298 :
299 : /** @brief Returns the fuel type of the given emission class
300 : * @param[in] c The vehicle emission class
301 : * @return "Diesel", "Gasoline", "HybridDiesel", "HybridGasoline", or "Electricity"
302 : */
303 : static std::string getFuel(const SUMOEmissionClass c);
304 :
305 : /** @brief Returns the Euro norm described by the given emission class
306 : * @param[in] c The vehicle emission class
307 : * @return A value between 0 and 6 (inclusive)
308 : */
309 : static int getEuroClass(const SUMOEmissionClass c);
310 :
311 : /** @brief Returns a representative weight for the given emission class
312 : * see http://colombo-fp7.eu/deliverables/COLOMBO_D4.2_ExtendedPHEMSUMO_v1.7.pdf
313 : * @param[in] c The vehicle emission class
314 : * @return the weight in kg if it matters, -1 otherwise
315 : */
316 : static double getWeight(const SUMOEmissionClass c);
317 :
318 : /** @brief Returns the amount of the emitted pollutant given the vehicle type and state (in mg/s or ml/s for fuel)
319 : * @param[in] c The vehicle emission class
320 : * @param[in] e the type of emission (CO, CO2, ...)
321 : * @param[in] v The vehicle's current velocity
322 : * @param[in] a The vehicle's current acceleration
323 : * @param[in] slope The road's slope at vehicle's position [deg]
324 : * @return The amount emitted by the given vehicle class when moving with the given velocity and acceleration [mg/s]
325 : */
326 : static double compute(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const EnergyParams* param);
327 :
328 : /** @brief Returns the amount of all emitted pollutants given the vehicle type and state (in mg/s or ml/s for fuel)
329 : * @param[in] c The vehicle emission class
330 : * @param[in] v The vehicle's current velocity
331 : * @param[in] a The vehicle's current acceleration
332 : * @param[in] slope The road's slope at vehicle's position [deg]
333 : * @return The amount emitted by the given vehicle class when moving with the given velocity and acceleration [mg/s]
334 : */
335 : static Emissions computeAll(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param);
336 :
337 : /** @brief Returns the amount of emitted pollutant given the vehicle type and default values for the state (in mg)
338 : * @param[in] c The vehicle emission class
339 : * @param[in] e the type of emission (CO, CO2, ...)
340 : * @param[in] v The vehicle's average velocity
341 : * @param[in] a The vehicle's average acceleration
342 : * @param[in] slope The road's slope at vehicle's position [deg]
343 : * @param{in] tt the time the vehicle travels
344 : * @param[in] param parameter of the emission model affecting the computation
345 : * @return The amount emitted by the given vehicle class [mg]
346 : */
347 : static double computeDefault(const SUMOEmissionClass c, const EmissionType e, const double v, const double a, const double slope, const double tt, const EnergyParams* param);
348 :
349 : /** @brief Returns the adapted acceleration value, useful for comparing with external PHEMlight references.
350 : * @param[in] c the emission class
351 : * @param[in] v the speed value
352 : * @param[in] a the acceleration value
353 : * @param[in] slope The road's slope at vehicle's position [deg]
354 : * @return the modified acceleration
355 : */
356 : static double getModifiedAccel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param);
357 :
358 : /** @brief Returns the coasting deceleration value, useful for comparing with external PHEMlight references.
359 : * @param[in] c the emission class
360 : * @param[in] v the speed value
361 : * @param[in] a the acceleration value
362 : * @param[in] slope The road's slope at vehicle's position [deg]
363 : * @param[in] param parameter of the emission model affecting the computation
364 : * @return the coasting deceleration
365 : */
366 : static double getCoastingDecel(const SUMOEmissionClass c, const double v, const double a, const double slope, const EnergyParams* param);
367 :
368 : /// @brief get energy helper
369 : static const HelpersEnergy& getEnergyHelper();
370 :
371 : private:
372 : /// @brief Instance of Helper which gets cleaned up automatically
373 : static Helper myZeroHelper;
374 :
375 : /// @brief Instance of HBEFA2Helper which gets cleaned up automatically
376 : static HelpersHBEFA myHBEFA2Helper;
377 :
378 : /// @brief Instance of HBEFA3Helper which gets cleaned up automatically
379 : static HelpersHBEFA3 myHBEFA3Helper;
380 :
381 : /// @brief Instance of PHEMlightHelper which gets cleaned up automatically
382 : static HelpersPHEMlight myPHEMlightHelper;
383 :
384 : /// @brief Instance of EnergyHelper which gets cleaned up automatically
385 : static HelpersEnergy myEnergyHelper;
386 :
387 : /// @brief Instance of HelpersMMPEVEM which gets cleaned up automatically
388 : static HelpersMMPEVEM myMMPEVEMHelper;
389 :
390 : /// @brief Instance of PHEMlight5Helper which gets cleaned up automatically
391 : static HelpersPHEMlight5 myPHEMlight5Helper;
392 :
393 : /// @brief Instance of HBEFA4Helper which gets cleaned up automatically
394 : static HelpersHBEFA4 myHBEFA4Helper;
395 :
396 : /// @brief the known model helpers
397 : static Helper* myHelpers[];
398 :
399 : /// @brief get all emission classes in string format
400 : static std::vector<std::string> myAllClassesStr;
401 : };
|