SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_HBEFA.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A device which collects vehicular emissions (using HBEFA-reformulation)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 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 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include "MSDevice_HBEFA.h"
33 #include <microsim/MSNet.h>
34 #include <microsim/MSLane.h>
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // static initialisation methods
50 // ---------------------------------------------------------------------------
51 void
53  insertDefaultAssignmentOptions("hbefa", "Emissions", oc);
54 }
55 
56 
57 void
58 MSDevice_HBEFA::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
60  // route computation is enabled
61  if (equippedByDefaultAssignmentOptions(oc, "hbefa", v)) {
62  // build the device
63  MSDevice_HBEFA* device = new MSDevice_HBEFA(v, "hbefa_" + v.getID());
64  into.push_back(device);
65  }
66 }
67 
68 
69 // ---------------------------------------------------------------------------
70 // MSDevice_HBEFA-methods
71 // ---------------------------------------------------------------------------
72 MSDevice_HBEFA::MSDevice_HBEFA(SUMOVehicle& holder, const std::string& id)
73  : MSDevice(holder, id),
74  myCO2(0), myCO(0), myHC(0), myPMx(0), myNOx(0), myFuel(0) {
75 }
76 
77 
79 }
80 
81 
82 bool
83 MSDevice_HBEFA::notifyMove(SUMOVehicle& veh, SUMOReal /*oldPos*/, SUMOReal /*newPos*/, SUMOReal newSpeed) {
85  const SUMOReal a = veh.getAcceleration();
86  myCO2 += TS * HelpersHBEFA::computeCO2(c, newSpeed, a);
87  myCO += TS * HelpersHBEFA::computeCO(c, newSpeed, a);
88  myHC += TS * HelpersHBEFA::computeHC(c, newSpeed, a);
89  myPMx += TS * HelpersHBEFA::computePMx(c, newSpeed, a);
90  myNOx += TS * HelpersHBEFA::computeNOx(c, newSpeed, a);
91  myFuel += TS * HelpersHBEFA::computeFuel(c, newSpeed, a);
92  return true;
93 }
94 
95 
96 void
98  if (OptionsCont::getOptions().isSet("tripinfo-output")) {
99  OutputDevice& os = OutputDevice::getDeviceByOption("tripinfo-output");
100  (os.openTag("emissions") <<
101  " CO_abs=\"" << OutputDevice::realString(myCO, 6) <<
102  "\" CO2_abs=\"" << OutputDevice::realString(myCO2, 6) <<
103  "\" HC_abs=\"" << OutputDevice::realString(myHC, 6) <<
104  "\" PMx_abs=\"" << OutputDevice::realString(myPMx, 6) <<
105  "\" NOx_abs=\"" << OutputDevice::realString(myNOx, 6) <<
106  "\" fuel_abs=\"" << OutputDevice::realString(myFuel, 6) <<
107  "\"").closeTag();
108  }
109 }
110 
111 
112 
113 /****************************************************************************/
114 
static SUMOReal computeCO(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted CO given the vehicle type and state (in mg/s)
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_HBEFA-options.
MSDevice_HBEFA(SUMOVehicle &holder, const std::string &id)
Constructor.
static SUMOReal computeHC(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted HC given the vehicle type and state (in mg/s)
~MSDevice_HBEFA()
Destructor.
#define TS
Definition: SUMOTime.h:52
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
SUMOEmissionClass
Definition of vehicle emission classes.
Representation of a vehicle.
Definition: SUMOVehicle.h:63
static SUMOReal computeCO2(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted CO2 given the vehicle type and state (in mg/s)
void generateOutput() const
Called on writing tripinfo output.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:76
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
Abstract in-vehicle device.
Definition: MSDevice.h:68
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:90
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
A storage for options typed value containers)
Definition: OptionsCont.h:108
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Computes current emission values and adds them to their sums.
virtual SUMOReal getAcceleration() const =0
Returns the vehicle&#39;s acceleration.
static std::string realString(const SUMOReal v, const int precision=OUTPUT_ACCURACY)
Helper method for string formatting.
static SUMOReal computeNOx(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted NOx given the vehicle type and state (in mg/s)
static SUMOReal computeFuel(SUMOEmissionClass c, double v, double a)
Returns the amount of consumed fuel given the vehicle type and state (in ml/s)
static SUMOReal computePMx(SUMOEmissionClass c, double v, double a)
Returns the amount of emitted PMx given the vehicle type and state (in mg/s)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
#define SUMOReal
Definition: config.h:221
SUMOEmissionClass getEmissionClass() const
Get this vehicle type&#39;s emission class.
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
virtual const MSVehicleType & getVehicleType() const =0
Returns the vehicle&#39;s type.
A device which collects vehicular emissions (using HBEFA-reformulation)