LCOV - code coverage report
Current view: top level - src/microsim/output - MSMeanData_Harmonoise.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 53 53
Test Date: 2024-12-21 15:45:41 Functions: 100.0 % 13 13

            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    MSMeanData_Harmonoise.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @date    Mon, 10.05.2004
      18              : ///
      19              : // Redirector for mean data output (net->edgecontrol)
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <microsim/MSLane.h>
      24              : #include <microsim/MSVehicle.h>
      25              : #include <microsim/output/MSDetectorControl.h>
      26              : #include <utils/common/SUMOTime.h>
      27              : #include <utils/common/ToString.h>
      28              : #include <utils/iodevices/OutputDevice.h>
      29              : #include "MSMeanData_Harmonoise.h"
      30              : #include <utils/emissions/HelpersHarmonoise.h>
      31              : #include <limits>
      32              : 
      33              : 
      34              : // ===========================================================================
      35              : // method definitions
      36              : // ===========================================================================
      37              : // ---------------------------------------------------------------------------
      38              : // MSMeanData_Harmonoise::MSLaneMeanDataValues - methods
      39              : // ---------------------------------------------------------------------------
      40       381040 : MSMeanData_Harmonoise::MSLaneMeanDataValues::MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
      41       381040 :         const MSMeanData_Harmonoise* parent)
      42              :     : MSMeanData::MeanDataValues(lane, length, doAdd, parent),
      43       381040 :       currentTimeN(0), meanNTemp(0), myParent(parent) {}
      44              : 
      45              : 
      46       762080 : MSMeanData_Harmonoise::MSLaneMeanDataValues::~MSLaneMeanDataValues() {
      47       762080 : }
      48              : 
      49              : 
      50              : void
      51      1154560 : MSMeanData_Harmonoise::MSLaneMeanDataValues::reset(bool) {
      52      1154560 :     sampleSeconds = 0;
      53      1154560 :     currentTimeN = 0;
      54      1154560 :     meanNTemp = 0;
      55      1154560 :     travelledDistance = 0;
      56      1154560 :     resetTime = SIMSTEP;
      57      1154560 : }
      58              : 
      59              : 
      60              : void
      61       363088 : MSMeanData_Harmonoise::MSLaneMeanDataValues::addTo(MSMeanData::MeanDataValues& val) const {
      62              :     MSLaneMeanDataValues& v = (MSLaneMeanDataValues&) val;
      63       363088 :     v.sampleSeconds += sampleSeconds;
      64       363088 :     v.meanNTemp += meanNTemp;
      65       363088 :     v.travelledDistance += travelledDistance;
      66       363088 : }
      67              : 
      68              : 
      69              : void
      70      7454304 : MSMeanData_Harmonoise::MSLaneMeanDataValues::update() {
      71      7454304 :     meanNTemp += currentTimeN;
      72      7454304 :     currentTimeN = 0;
      73      7454304 : }
      74              : 
      75              : 
      76              : void
      77       759176 : MSMeanData_Harmonoise::MSLaneMeanDataValues::notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double /*travelledDistanceFrontOnLane*/, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */) {
      78       759176 :     const double sn = HelpersHarmonoise::computeNoise(veh.getVehicleType().getEmissionClass(),
      79              :                       // XXX: recheck, which value to use here for the speed. (Leo) Refs. #2579
      80       759176 :                       (double) meanSpeedVehicleOnLane, veh.getAcceleration());
      81       759176 :     currentTimeN += (double) pow(10., (sn / 10.));
      82       759176 :     sampleSeconds += timeOnLane;
      83       759176 :     travelledDistance += travelledDistanceVehicleOnLane;
      84       759176 : }
      85              : 
      86              : 
      87              : void
      88        27596 : MSMeanData_Harmonoise::MSLaneMeanDataValues::write(OutputDevice& dev, long long int attributeMask, const SUMOTime period,
      89              :         const int /*numLanes*/, const double /*speedLimit*/, const double defaultTravelTime, const int /*numVehicles*/) const {
      90        27596 :     const double noise = meanNTemp != 0 ? (double)(10. * log10(meanNTemp * TS / STEPS2TIME(period))) : (double) 0.;
      91        27596 :     dev.writeOptionalAttr(SUMO_ATTR_NOISE, noise, attributeMask);
      92        27596 :     if (sampleSeconds > myParent->myMinSamples) {
      93        25484 :         double traveltime = myParent->myMaxTravelTime;
      94        25484 :         if (travelledDistance > 0.f) {
      95        50728 :             traveltime = MIN2(traveltime, myLaneLength * sampleSeconds / travelledDistance);
      96              :         }
      97        25484 :         dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, traveltime, attributeMask);
      98         2112 :     } else if (defaultTravelTime >= 0.) {
      99              :         // @todo default value for noise
     100         1056 :         dev.writeOptionalAttr(SUMO_ATTR_TRAVELTIME, defaultTravelTime, attributeMask);
     101              :     }
     102        27596 :     dev.closeTag();
     103        27596 : }
     104              : 
     105              : 
     106              : 
     107              : // ---------------------------------------------------------------------------
     108              : // MSMeanData_Harmonoise - methods
     109              : // ---------------------------------------------------------------------------
     110          408 : MSMeanData_Harmonoise::MSMeanData_Harmonoise(const std::string& id,
     111              :         const SUMOTime dumpBegin, const SUMOTime dumpEnd,
     112              :         const bool useLanes, const bool withEmpty,
     113              :         const bool printDefaults, const bool withInternal,
     114              :         const bool trackVehicles,
     115              :         const double maxTravelTime, const double minSamples,
     116              :         const std::string& vTypes,
     117              :         const std::string& writeAttributes,
     118              :         const std::vector<MSEdge*>& edges,
     119          408 :         bool aggregate) :
     120              :     MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, printDefaults,
     121          408 :                withInternal, trackVehicles, 0, maxTravelTime, minSamples, vTypes, writeAttributes, edges, aggregate) {
     122          408 : }
     123              : 
     124              : 
     125          816 : MSMeanData_Harmonoise::~MSMeanData_Harmonoise() {}
     126              : 
     127              : 
     128              : MSMeanData::MeanDataValues*
     129       381040 : MSMeanData_Harmonoise::createValues(MSLane* const lane, const double length, const bool doAdd) const {
     130       381040 :     return new MSLaneMeanDataValues(lane, length, doAdd, this);
     131              : }
     132              : 
     133              : 
     134              : void
     135       199200 : MSMeanData_Harmonoise::detectorUpdate(const SUMOTime step) {
     136       199200 :     MSMeanData::detectorUpdate(step);
     137      7653504 :     for (std::vector<std::vector<MeanDataValues*> >::const_iterator i = myMeasures.begin(); i != myMeasures.end(); ++i) {
     138              :         const std::vector<MeanDataValues*>& lm = *i;
     139     14908608 :         for (std::vector<MeanDataValues*>::const_iterator j = lm.begin(); j != lm.end(); ++j) {
     140      7454304 :             (*j)->update();
     141              :         }
     142              :     }
     143       199200 : }
     144              : 
     145              : 
     146              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1