LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Emissions.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 44 44 100.0 %
Date: 2024-04-30 15:40:33 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2001-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    MSDevice_Emissions.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Laura Bieker
      17             : /// @author  Michael Behrisch
      18             : /// @date    Fri, 30.01.2009
      19             : ///
      20             : // A device which collects vehicular emissions
      21             : /****************************************************************************/
      22             : #include <config.h>
      23             : 
      24             : #include <microsim/MSNet.h>
      25             : #include <microsim/MSLane.h>
      26             : #include <microsim/MSStop.h>
      27             : #include <microsim/MSVehicleControl.h>
      28             : #include <microsim/output/MSDetectorControl.h>
      29             : #include <utils/options/OptionsCont.h>
      30             : #include <utils/emissions/PollutantsInterface.h>
      31             : #include <utils/emissions/HelpersEnergy.h>
      32             : #include <utils/iodevices/OutputDevice.h>
      33             : #include "MSDevice_Emissions.h"
      34             : 
      35             : 
      36             : // ===========================================================================
      37             : // method definitions
      38             : // ===========================================================================
      39             : // ---------------------------------------------------------------------------
      40             : // static initialisation methods
      41             : // ---------------------------------------------------------------------------
      42             : void
      43       36322 : MSDevice_Emissions::insertOptions(OptionsCont& oc) {
      44       72644 :     insertDefaultAssignmentOptions("emissions", "Emissions", oc);
      45             : 
      46       72644 :     oc.doRegister("device.emissions.begin", new Option_String("-1"));
      47       72644 :     oc.addDescription("device.emissions.begin", "Emissions", TL("Recording begin time for emission-data"));
      48             : 
      49       72644 :     oc.doRegister("device.emissions.period", new Option_String("0"));
      50       72644 :     oc.addDescription("device.emissions.period", "Emissions", TL("Recording period for emission-output"));
      51       36322 : }
      52             : 
      53             : 
      54             : void
      55     4655777 : MSDevice_Emissions::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
      56     4655777 :     OptionsCont& oc = OptionsCont::getOptions();
      57     9311554 :     if (equippedByDefaultAssignmentOptions(oc, "emissions", v, oc.isSet("emission-output"))) {
      58      187196 :         into.push_back(new MSDevice_Emissions(v));
      59             :     }
      60     4655777 : }
      61             : 
      62             : 
      63             : // ---------------------------------------------------------------------------
      64             : // MSDevice_Emissions-methods
      65             : // ---------------------------------------------------------------------------
      66      187196 : MSDevice_Emissions::MSDevice_Emissions(SUMOVehicle& holder)
      67      374392 :     : MSVehicleDevice(holder, "emissions_" + holder.getID()), myEmissions() {
      68      187196 : }
      69             : 
      70             : 
      71      374392 : MSDevice_Emissions::~MSDevice_Emissions() {
      72      374392 : }
      73             : 
      74             : 
      75             : bool
      76    62496500 : MSDevice_Emissions::notifyMove(SUMOTrafficObject& veh, double /*oldPos*/, double /*newPos*/, double newSpeed) {
      77    62496500 :     const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
      78    62496500 :     myEmissions.addScaled(PollutantsInterface::computeAll(c, newSpeed, veh.getAcceleration(), veh.getSlope(), myHolder.getEmissionParameters()), TS);
      79    62496500 :     return true;
      80             : }
      81             : 
      82             : 
      83             : bool
      84         308 : MSDevice_Emissions::notifyIdle(SUMOTrafficObject& veh) {
      85         308 :     const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
      86         308 :     myEmissions.addScaled(PollutantsInterface::computeAll(c, 0., 0., 0., myHolder.getEmissionParameters()), TS);
      87         308 :     return true;
      88             : }
      89             : 
      90             : 
      91             : void
      92       10756 : MSDevice_Emissions::notifyMoveInternal(const SUMOTrafficObject& veh,
      93             :                                        const double /* frontOnLane */,
      94             :                                        const double timeOnLane,
      95             :                                        const double /* meanSpeedFrontOnLane */,
      96             :                                        const double meanSpeedVehicleOnLane,
      97             :                                        const double /* travelledDistanceFrontOnLane */,
      98             :                                        const double /* travelledDistanceVehicleOnLane */,
      99             :                                        const double /* meanLengthOnLane */) {
     100             : 
     101             :     // called by meso (see MSMeanData_Emissions::MSLaneMeanDataValues::notifyMoveInternal)
     102       10756 :     const SUMOEmissionClass c = veh.getVehicleType().getEmissionClass();
     103       10756 :     myEmissions.addScaled(PollutantsInterface::computeAll(c, meanSpeedVehicleOnLane, veh.getAcceleration(), veh.getSlope(), myHolder.getEmissionParameters()), timeOnLane);
     104       10756 : }
     105             : 
     106             : 
     107             : 
     108             : void
     109      187076 : MSDevice_Emissions::generateOutput(OutputDevice* tripinfoOut) const {
     110      187076 :     if (tripinfoOut != nullptr) {
     111      186586 :         const OptionsCont& oc = OptionsCont::getOptions();
     112      186586 :         const int precision = MAX2(
     113      373190 :                                   oc.isDefault("emission-output.precision") ? 6 : oc.getInt("emission-output.precision"),
     114             :                                   gPrecision);
     115      186586 :         tripinfoOut->openTag("emissions");
     116      373172 :         tripinfoOut->writeAttr("CO_abs", OutputDevice::realString(myEmissions.CO, precision));
     117      373172 :         tripinfoOut->writeAttr("CO2_abs", OutputDevice::realString(myEmissions.CO2, precision));
     118      373172 :         tripinfoOut->writeAttr("HC_abs", OutputDevice::realString(myEmissions.HC, precision));
     119      373172 :         tripinfoOut->writeAttr("PMx_abs", OutputDevice::realString(myEmissions.PMx, precision));
     120      373172 :         tripinfoOut->writeAttr("NOx_abs", OutputDevice::realString(myEmissions.NOx, precision));
     121      373172 :         tripinfoOut->writeAttr("fuel_abs", OutputDevice::realString(myEmissions.fuel, precision));
     122      373172 :         tripinfoOut->writeAttr("electricity_abs", OutputDevice::realString(myEmissions.electricity, precision));
     123      373172 :         tripinfoOut->closeTag();
     124             :     }
     125      187076 : }
     126             : 
     127             : 
     128             : /****************************************************************************/

Generated by: LCOV version 1.14