LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_Emissions.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 33.3 % 3 1
Test Date: 2025-07-30 21:30:17 Functions: 0.0 % 1 0

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2025 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.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Fri, 30.01.2009
      18              : ///
      19              : // A device which collects vehicular emissions
      20              : /****************************************************************************/
      21              : #pragma once
      22              : #include <config.h>
      23              : 
      24              : #include <set>
      25              : #include <vector>
      26              : #include <map>
      27              : #include <utils/common/SUMOTime.h>
      28              : #include <utils/common/WrappingCommand.h>
      29              : #include <utils/emissions/PollutantsInterface.h>
      30              : #include <utils/emissions/EnergyParams.h>
      31              : #include <microsim/MSVehicle.h>
      32              : #include "MSVehicleDevice.h"
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // class declarations
      37              : // ===========================================================================
      38              : class MSLane;
      39              : 
      40              : 
      41              : // ===========================================================================
      42              : // class definitions
      43              : // ===========================================================================
      44              : /**
      45              :  * @class MSDevice_Emissions
      46              :  * @brief A device which collects vehicular emissions
      47              :  *
      48              :  * Each device collects the vehicular emissions / fuel consumption by being
      49              :  *  called each time step, computing the current values using
      50              :  *  PollutantsInterface, and aggregating them into internal storages over
      51              :  *  the complete journey.
      52              :  *
      53              :  * @see MSDevice
      54              :  * @see PollutantsInterface
      55              :  */
      56              : class MSDevice_Emissions : public MSVehicleDevice {
      57              : public:
      58              :     /** @brief Inserts MSDevice_Emissions-options
      59              :      */
      60              :     static void insertOptions(OptionsCont& oc);
      61              : 
      62              : 
      63              :     /** @brief Build devices for the given vehicle, if needed
      64              :      *
      65              :      * The options are read and evaluated whether emissions-devices shall be built
      66              :      *  for the given vehicle.
      67              :      *
      68              :      * For each seen vehicle, the global vehicle index is increased.
      69              :      *
      70              :      * The built device is stored in the given vector.
      71              :      *
      72              :      * @param[in] v The vehicle for which a device may be built
      73              :      * @param[in, filled] into The vector to store the built device in
      74              :      */
      75              :     static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
      76              : 
      77              : public:
      78              :     /** @brief Constructor
      79              :      *
      80              :      * @param[in] holder The vehicle that holds this device
      81              :      */
      82              :     MSDevice_Emissions(SUMOVehicle& holder);
      83              : 
      84              :     /// @brief Destructor.
      85              :     ~MSDevice_Emissions();
      86              : 
      87              :     /// @name Methods called on vehicle movement / state change, overwriting MSDevice
      88              :     /// @{
      89              : 
      90              :     /** @brief Computes current emission values and adds them to their sums
      91              :         *
      92              :         * The vehicle's current emission values
      93              :         *  are computed using the current velocity and acceleration.
      94              :         *
      95              :         * @param[in] veh The regarded vehicle
      96              :         * @param[in] oldPos Position before the move-micro-timestep.
      97              :         * @param[in] newPos Position after the move-micro-timestep.
      98              :         * @param[in] newSpeed The vehicle's current speed
      99              :         * @return false, if the vehicle is beyond the lane, true otherwise
     100              :         * @see MSMoveReminder
     101              :         * @see MSMoveReminder::notifyMove
     102              :         * @see PollutantsInterface
     103              :         */
     104              :     bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
     105              : 
     106              :     /** @brief Computes idling emission values and adds them to the emission sums
     107              :         *
     108              :         * Idling implied by zero velocity, acceleration and slope
     109              :         *
     110              :         * @param[in] veh The vehicle
     111              :         *
     112              :         * @see MSMoveReminder::notifyMove
     113              :         * @see PollutantsInterface
     114              :         */
     115              :     bool notifyIdle(SUMOTrafficObject& veh);
     116              : 
     117              :     /// @}
     118              : 
     119              :     /// @brief return the name for this type of device
     120            0 :     const std::string deviceName() const {
     121            0 :         return "emissions";
     122              :     }
     123              : 
     124              :     /** @brief Called on writing tripinfo output
     125              :      *
     126              :      * @param[in] os The stream to write the information into
     127              :      * @exception IOError not yet implemented
     128              :      * @see MSDevice::tripInfoOutput
     129              :      */
     130              :     void generateOutput(OutputDevice* tripinfoOut) const;
     131              : 
     132              :     static SumoXMLAttrMask getWrittenAttributes() {
     133        44376 :         return myWrittenAttributes;
     134              :     }
     135              : 
     136              :     /// @brief initialize attribute mask (once)
     137              :     static void initOnce();
     138              : 
     139              :     /// @brief resets the attribute mask
     140              :     static void cleanup();
     141              : 
     142              : 
     143              : protected:
     144              :     /** @brief Internal notification about the vehicle moves, see MSMoveReminder::notifyMoveInternal()
     145              :      *
     146              :      */
     147              :     void notifyMoveInternal(const SUMOTrafficObject& veh,
     148              :                             const double frontOnLane,
     149              :                             const double timeOnLane,
     150              :                             const double meanSpeedFrontOnLane,
     151              :                             const double meanSpeedVehicleOnLane,
     152              :                             const double travelledDistanceFrontOnLane,
     153              :                             const double travelledDistanceVehicleOnLane,
     154              :                             const double meanLengthOnLane);
     155              : 
     156              : private:
     157              :     /// @brief Internal storages for pollutant/fuel sum in mg or ml
     158              :     PollutantsInterface::Emissions myEmissions;
     159              : 
     160              :     /// @brief bit mask for checking attributes to be written
     161              :     static SumoXMLAttrMask myWrittenAttributes;
     162              :     static SumoXMLAttrMask getDefaultMask();
     163              :     static bool myAmInitialized;
     164              : 
     165              : private:
     166              :     /// @brief Invalidated copy constructor.
     167              :     MSDevice_Emissions(const MSDevice_Emissions&);
     168              : 
     169              :     /// @brief Invalidated assignment operator.
     170              :     MSDevice_Emissions& operator=(const MSDevice_Emissions&);
     171              : 
     172              : };
        

Generated by: LCOV version 2.0-1