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 : std::string fclass = veh->getVehicleType().getID(); 54 506 : fclass = fclass.substr(0, fclass.find_first_of("@")); 55 : 56 506 : if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != 0) { 57 331 : MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))); 58 331 : if (elecHybridToExport->getMaximumBatteryCapacity() > 0) { 59 : // Open Row 60 331 : of.openTag(SUMO_TAG_VEHICLE); 61 : // Write ID 62 : of.writeAttr(SUMO_ATTR_ID, veh->getID()); 63 : 64 : // Write Maximum battery capacity 65 331 : of.writeAttr(SUMO_ATTR_MAXIMUMBATTERYCAPACITY, elecHybridToExport->getMaximumBatteryCapacity()); 66 : // Write Actual battery capacity 67 331 : of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, elecHybridToExport->getActualBatteryCapacity()); 68 : 69 : // Write consumed energy [Wh] (computed by HelpersEnergy::compute) 70 331 : of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum()); 71 : // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy) 72 331 : of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged()); 73 : // Write Power demand (requsted from overhed wire) [W] 74 331 : of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted()); 75 : 76 : // Write OverheadWire Segment ID 77 331 : of.writeAttr(SUMO_ATTR_OVERHEADWIREID, elecHybridToExport->getOverheadWireSegmentID()); 78 : // Write Traction Substation ID 79 331 : of.writeAttr(SUMO_ATTR_TRACTIONSUBSTATIONID, elecHybridToExport->getTractionSubstationID()); 80 : 81 : // Write current from overheadwire 82 331 : of.writeAttr(SUMO_ATTR_CURRENTFROMOVERHEADWIRE, elecHybridToExport->getCurrentFromOverheadWire()); 83 : // Write voltage of overheadwire 84 331 : of.writeAttr(SUMO_ATTR_VOLTAGEOFOVERHEADWIRE, elecHybridToExport->getVoltageOfOverheadWire()); 85 : // 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) 86 331 : of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha()); 87 : 88 : // Write Speed 89 331 : of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed()); 90 : // Write Acceleration 91 331 : of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration()); 92 : // Write Distance 93 331 : of.writeAttr(SUMO_ATTR_DISTANCE, veh->getOdometer()); 94 : // Write pos x 95 662 : of.writeAttr(SUMO_ATTR_X, veh->getPosition().x()); 96 : // Write pos y 97 662 : of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y()); 98 : // Write pos z 99 662 : of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z()); 100 : // Write slope 101 331 : of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope()); 102 331 : if (microVeh != nullptr) { 103 : // Write Lane ID 104 331 : of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID()); 105 : } 106 : // Write vehicle position in the lane 107 331 : of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane()); 108 : // Close Row 109 662 : of.closeTag(); 110 : } 111 : } 112 : } 113 300 : of.closeTag(); 114 300 : } 115 : 116 : 117 : void 118 54 : MSElecHybridExport::write(OutputDevice& of, const SUMOVehicle* veh, SUMOTime timestep, int precision) { 119 54 : of.openTag(SUMO_TAG_TIMESTEP).writeAttr(SUMO_ATTR_TIME, time2string(timestep)); 120 54 : of.setPrecision(precision); 121 : 122 54 : if (!veh->isOnRoad()) { 123 : return; 124 : } 125 : 126 54 : const MSVehicle* microVeh = dynamic_cast<const MSVehicle*>(veh); 127 : 128 54 : if (static_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))) != nullptr) { 129 54 : MSDevice_ElecHybrid* elecHybridToExport = dynamic_cast<MSDevice_ElecHybrid*>(veh->getDevice(typeid(MSDevice_ElecHybrid))); 130 : // Write Actual battery capacity 131 54 : of.writeAttr(SUMO_ATTR_ACTUALBATTERYCAPACITY, elecHybridToExport->getActualBatteryCapacity()); 132 : 133 : // Write consumed energy [Wh] (computed by HelpersEnergy::compute) 134 54 : of.writeAttr(SUMO_ATTR_ENERGYCONSUMED, elecHybridToExport->getConsum()); 135 : // Write Energy charged in the Battery [Wh] (drawn energy from overhead wire minus consumed energy) 136 54 : of.writeAttr(SUMO_ATTR_ENERGYCHARGED, elecHybridToExport->getEnergyCharged()); 137 : // Write Power demand (requsted from overhed wire) [W] 138 54 : of.writeAttr(SUMO_ATTR_CHARGINGPOWER, elecHybridToExport->getPowerWanted()); 139 : 140 : // Write OverheadWire Segment ID 141 54 : of.writeAttr(SUMO_ATTR_OVERHEADWIREID, elecHybridToExport->getOverheadWireSegmentID()); 142 : // Write Traction Substation ID 143 54 : of.writeAttr(SUMO_ATTR_TRACTIONSUBSTATIONID, elecHybridToExport->getTractionSubstationID()); 144 : 145 : // Write current from overheadwire 146 54 : of.writeAttr(SUMO_ATTR_CURRENTFROMOVERHEADWIRE, elecHybridToExport->getCurrentFromOverheadWire()); 147 : // Write voltage of overheadwire 148 54 : of.writeAttr(SUMO_ATTR_VOLTAGEOFOVERHEADWIRE, elecHybridToExport->getVoltageOfOverheadWire()); 149 : // 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) 150 54 : of.writeAttr(SUMO_ATTR_ALPHACIRCUITSOLVER, elecHybridToExport->getCircuitAlpha()); 151 : 152 : // Write Speed 153 54 : of.writeAttr(SUMO_ATTR_SPEED, veh->getSpeed()); 154 : // Write Acceleration 155 54 : of.writeAttr(SUMO_ATTR_ACCELERATION, veh->getAcceleration()); 156 : // Write Distance 157 54 : of.writeAttr(SUMO_ATTR_DISTANCE, veh->getOdometer()); 158 : // Write pos x 159 108 : of.writeAttr(SUMO_ATTR_X, veh->getPosition().x()); 160 : // Write pos y 161 108 : of.writeAttr(SUMO_ATTR_Y, veh->getPosition().y()); 162 : // Write pos z 163 108 : of.writeAttr(SUMO_ATTR_Z, veh->getPosition().z()); 164 : // Write slope 165 54 : of.writeAttr(SUMO_ATTR_SLOPE, veh->getSlope()); 166 : // Write Lane ID 167 54 : if (microVeh != 0) { 168 34 : of.writeAttr(SUMO_ATTR_LANE, microVeh->getLane()->getID()); 169 : } 170 : // Write vehicle position in the lane 171 108 : of.writeAttr(SUMO_ATTR_POSONLANE, veh->getPositionOnLane()); 172 : } 173 108 : of.closeTag(); 174 : }