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

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2012-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    MSElecHybridExport.cpp
      15              : /// @author  Jakub Sevcik (RICE)
      16              : /// @author  Jan Prikryl (RICE)
      17              : /// @date    2019-11-25
      18              : ///
      19              : // Realises dumping Electric hybrid vehicle data
      20              : /****************************************************************************/
      21              : #include <config.h>
      22              : 
      23              : #include <microsim/MSEdgeControl.h>
      24              : #include <microsim/MSEdge.h>
      25              : #include <microsim/MSLane.h>
      26              : #include <microsim/MSGlobals.h>
      27              : #include <utils/iodevices/OutputDevice.h>
      28              : #include <microsim/MSNet.h>
      29              : #include <microsim/MSVehicle.h>
      30              : #include <microsim/MSVehicleControl.h>
      31              : #include <microsim/devices/MSDevice_ElecHybrid.h>
      32              : #include "MSElecHybridExport.h"
      33              : 
      34              : 
      35              : // ===========================================================================
      36              : // method definitions
      37              : // ===========================================================================
      38              : void
      39          300 : MSElecHybridExport::writeAggregated(OutputDevice& of, SUMOTime timestep, int precision) {
      40          300 :     of.openTag(SUMO_TAG_TIMESTEP).writeAttr(SUMO_ATTR_TIME, time2string(timestep));
      41          300 :     of.setPrecision(precision);
      42              : 
      43          300 :     MSVehicleControl& vc = MSNet::getInstance()->getVehicleControl();
      44          806 :     for (MSVehicleControl::constVehIt it = vc.loadedVehBegin(); it != vc.loadedVehEnd(); ++it) {
      45              : 
      46          506 :         const SUMOVehicle* veh = it->second;
      47          506 :         const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
      48              : 
      49          506 :         if (!veh->isOnRoad()) {
      50            0 :             continue;
      51              :         }
      52              : 
      53          506 :         if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != 0) {
      54          331 :             MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
      55          331 :             if (elecHybridToExport->getMaximumBatteryCapacity() > 0) {
      56              :                 // Open Row
      57          331 :                 of.openTag(SUMO_TAG_VEHICLE);
      58              :                 // Write ID
      59              :                 of.writeAttr(SUMO_ATTR_ID, veh->getID());
      60              : 
      61              :                 // Write Maximum battery capacity
      62          331 :                 of.writeAttr(SUMO_ATTR_MAXIMUMBATTERYCAPACITY, elecHybridToExport->getMaximumBatteryCapacity());
      63              :                 // Write Actual battery capacity
      64          331 :                 of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, elecHybridToExport->getActualBatteryCapacity());
      65              : 
      66              :                 // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
      67          331 :                 of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
      68              :                 // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
      69          331 :                 of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
      70              :                 // Write Power demand (requsted from overhed wire) [W]
      71          331 :                 of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
      72              : 
      73              :                 // Write OverheadWire Segment ID
      74          331 :                 of.writeAttr(SUMO_ATTR_OVERHEADWIREID, elecHybridToExport->getOverheadWireSegmentID());
      75              :                 // Write Traction Substation ID
      76          331 :                 of.writeAttr(SUMO_ATTR_TRACTIONSUBSTATIONID, elecHybridToExport->getTractionSubstationID());
      77              : 
      78              :                 // Write current from overheadwire
      79          331 :                 of.writeAttr(SUMO_ATTR_CURRENTFROMOVERHEADWIRE, elecHybridToExport->getCurrentFromOverheadWire());
      80              :                 // Write voltage of overheadwire
      81          331 :                 of.writeAttr(SUMO_ATTR_VOLTAGEOFOVERHEADWIRE, elecHybridToExport->getVoltageOfOverheadWire());
      82              :                 // Write circuit alpha best (1 if the traction substation is not overloaded, number from interval [0,1) if the traction substation is overloaded, NAN if it is not applicable)
      83          331 :                 of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha());
      84              : 
      85              :                 // Write Speed
      86          331 :                 of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
      87              :                 // Write Acceleration
      88          331 :                 of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration());
      89              :                 // Write Distance
      90          331 :                 of.writeAttr(SUMO_ATTR_DISTANCE, veh->getOdometer());
      91              :                 // Write pos x
      92          331 :                 of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
      93              :                 // Write pos y
      94          331 :                 of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
      95              :                 // Write pos z
      96          331 :                 of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
      97              :                 // Write slope
      98          331 :                 of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
      99          331 :                 if (microVeh != nullptr) {
     100              :                     // Write Lane ID
     101          331 :                     of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
     102              :                 }
     103              :                 // Write vehicle position in the lane
     104          331 :                 of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane());
     105              :                 // Close Row
     106          662 :                 of.closeTag();
     107              :             }
     108              :         }
     109              :     }
     110          300 :     of.closeTag();
     111          300 : }
     112              : 
     113              : 
     114              : void
     115           54 : MSElecHybridExport::write(OutputDevice& of, const SUMOVehicle* veh, SUMOTime timestep, int precision) {
     116           54 :     of.openTag(SUMO_TAG_TIMESTEP).writeAttr(SUMO_ATTR_TIME, time2string(timestep));
     117           54 :     of.setPrecision(precision);
     118              : 
     119           54 :     if (!veh->isOnRoad()) {
     120              :         return;
     121              :     }
     122              : 
     123           54 :     const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh);
     124              : 
     125           54 :     if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) {
     126           54 :         MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid)));
     127              :         // Write Actual battery capacity
     128           54 :         of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, elecHybridToExport->getActualBatteryCapacity());
     129              : 
     130              :         // Write consumed energy [Wh] (computed by HelpersEnergy::compute)
     131           54 :         of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum());
     132              :         // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy)
     133           54 :         of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged());
     134              :         // Write Power demand (requsted from overhed wire) [W]
     135           54 :         of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted());
     136              : 
     137              :         // Write OverheadWire Segment ID
     138           54 :         of.writeAttr(SUMO_ATTR_OVERHEADWIREID, elecHybridToExport->getOverheadWireSegmentID());
     139              :         // Write Traction Substation ID
     140           54 :         of.writeAttr(SUMO_ATTR_TRACTIONSUBSTATIONID, elecHybridToExport->getTractionSubstationID());
     141              : 
     142              :         // Write current from overheadwire
     143           54 :         of.writeAttr(SUMO_ATTR_CURRENTFROMOVERHEADWIRE, elecHybridToExport->getCurrentFromOverheadWire());
     144              :         // Write voltage of overheadwire
     145           54 :         of.writeAttr(SUMO_ATTR_VOLTAGEOFOVERHEADWIRE, elecHybridToExport->getVoltageOfOverheadWire());
     146              :         // Write circuit alpha best (1 if the traction substation is not overloaded, number from interval [0,1) if the traction substation is overloaded, NAN if it is not applicable)
     147           54 :         of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha());
     148              : 
     149              :         // Write Speed
     150           54 :         of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed());
     151              :         // Write Acceleration
     152           54 :         of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration());
     153              :         // Write Distance
     154           54 :         of.writeAttr(SUMO_ATTR_DISTANCE, veh->getOdometer());
     155              :         // Write pos x
     156           54 :         of.writeAttr(SUMO_ATTR_X, veh->getPosition().x());
     157              :         // Write pos y
     158           54 :         of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y());
     159              :         // Write pos z
     160           54 :         of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z());
     161              :         // Write slope
     162           54 :         of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope());
     163              :         // Write Lane ID
     164           54 :         if (microVeh != 0) {
     165           34 :             of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID());
     166              :         }
     167              :         // Write vehicle position in the lane
     168          108 :         of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane());
     169              :     }
     170          108 :     of.closeTag();
     171              : }
        

Generated by: LCOV version 2.0-1