Eclipse SUMO - Simulation of Urban MObility
MSOverheadWire.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2002-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 /****************************************************************************/
19 // Overhead wires for Electric (equipped with elecHybrid device) vehicles (Overhead wire segments, overhead wire sections, traction substations)
20 /****************************************************************************/
21 #pragma once
22 #include <config.h>
23 
24 #include <list>
25 #include <string>
26 #include <iostream>
27 #include <fstream>
28 #include <sstream>
30 #include <utils/common/Named.h>
34 
35 // Resistivity of Cu is 1.69*10^-8 Ohm*m. A cross-section S of the overhead wire used in Pilsen is 150 mm^2. So the "resistivity/S" is 0.000113 Ohm/m.
36 const double WIRE_RESISTIVITY = (double)2 * 0.000113;
37 
38 // Conversion macros
39 #define WATTHR2JOULE(_x) ((_x)*3600.0)
40 #define JOULE2WATTHR(_x) ((_x)/3600.0)
41 #define WATTHR2WATT(_x) ((_x)*3600.0/TS)
42 #define WATT2WATTHR(_x) ((_x)*TS/3600.0)
43 
44 // ===========================================================================
45 // class declarations
46 // ===========================================================================
47 class MSLane;
48 class MSBusStop;
49 class OptionsCont;
52 class Named;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
64 public:
65 
67  MSOverheadWire(const std::string& overheadWireSegmentID, MSLane& lane, double startPos, double endPos,
68  bool voltageSource);
69 
72 
74  double getVoltage() const;
75 
77  void setVoltage(double voltage);
78 
80  void setChargingVehicle(bool value);
81 
86  bool vehicleIsInside(const double position) const;
87 
89  bool isCharging() const;
90 
91  void addVehicle(SUMOVehicle& veh);
92 
93  void eraseVehicle(SUMOVehicle& veh);
94 
95  int getElecHybridCount() const {
96  return (int)myChargingVehicles.size();
97  }
98 
99  const std::vector<SUMOVehicle*>& getChargingVehicles() const {
100  return myChargingVehicles;
101  }
102 
103  double getTotalCharged() const {
104  return myTotalCharge;
105  }
106 
108  void addChargeValueForOutput(double WCharged, MSDevice_ElecHybrid* elecHybrid, bool ischarging = 1);
109 
112 
113  std::string getOverheadWireSegmentName();
114 
116  return myTractionSubstation;
117  }
118 
120  myTractionSubstation = substation;
121  }
122 
123  Circuit* getCircuit() const;
124 
126  myCircuitStartNodePos = node;
127  }
128 
130  myCircuitEndNodePos = node;
131  }
132 
133  void setCircuitElementPos(Element* element) {
134  myCircuitElementPos = element;
135  }
136 
138  return myCircuitStartNodePos;
139  }
140 
142  return myCircuitEndNodePos;
143  }
144 
146  return myCircuitElementPos;
147  }
148 
149  bool isThereVoltageSource() const {
150  return myVoltageSource;
151  }
152 
153  void lock() const;
154  void unlock() const;
155 
156 protected:
157 
159  struct Charge {
161  Charge(SUMOTime _timeStep, std::string _vehicleID, std::string _vehicleType, std::string _status,
162  double _WCharged, double _actualBatteryCapacity, double _maxBatteryCapacity, double _voltage,
163  double _totalEnergyCharged) :
164  timeStep(_timeStep),
165  vehicleID(_vehicleID),
166  vehicleType(_vehicleType),
167  status(_status),
168  WCharged(_WCharged),
169  actualBatteryCapacity(_actualBatteryCapacity),
170  maxBatteryCapacity(_maxBatteryCapacity),
171  voltage(_voltage),
172  totalEnergyCharged(_totalEnergyCharged) {}
173 
174  // @brief vehicle TimeStep
176  // @brief vehicle ID
177  std::string vehicleID;
178  // @brief vehicle Type
179  std::string vehicleType;
181  std::string status;
182  // @brief W charged
183  double WCharged;
184  // @brief actual battery capacity AFTER charging
186  // @brief battery max capacity
188  // @brief current charging power of charging station
189  double voltage;
190  // @brief current efficiency of charging station
192  // @brief current energy charged by charging stations AFTER charging
194  };
195 
198  public:
200  explicit vehicle_position_sorter() { }
201 
204  return v1->getPositionOnLane() > v2->getPositionOnLane();
205  }
206  };
207 
208  void static writeVehicle(OutputDevice& out, const std::vector<Charge>& chargeSteps, int iStart, int iEnd, double charged);
209 
211  double myVoltage;
212 
215 
218 
220  std::map<std::string, std::vector<Charge> > myChargeValues;
222  std::vector<std::string> myChargedVehicles;
223 
224  std::vector<SUMOVehicle*> myChargingVehicles;
225 
228 
230 
234 
235 private:
238 
241 };
242 
243 
248 class MSTractionSubstation : public Named {
249 public:
250 
252  MSTractionSubstation(const std::string& substationId, double voltage, double currentLimit);
253 
256 
257  Circuit* getCircuit() const {
258  return myCircuit;
259  }
260  void addOverheadWireSegmentToCircuit(MSOverheadWire* newOverheadWireSegment);
261 
262  void addOverheadWireClampToCircuit(const std::string id, MSOverheadWire* startSegment, MSOverheadWire* endSegment);
263 
265 
266  void writeOut();
267  std::size_t numberOfOverheadSegments() const {
268  return myOverheadWireSegments.size();
269  }
270 
272  void setChargingVehicle(bool value);
273 
275  bool isCharging() const;
276 
278 
280 
281  void addForbiddenLane(MSLane* lane);
282 
283  bool isForbidden(const MSLane* lane);
284 
285  void addClamp(const std::string& id, MSOverheadWire* startPos, MSOverheadWire* endPos);
286 
287  int getElecHybridCount() const {
288  return myElecHybridCount;
289  }
290 
291  void addVehicle(MSDevice_ElecHybrid* elecHybrid);
292 
293  void eraseVehicle(MSDevice_ElecHybrid* elecHybrid);
294 
295  double getSubstationVoltage() const {
296  return mySubstationVoltage;
297  }
298 
300 
302  SUMOTime solveCircuit(SUMOTime currentTime);
303 
305  void addChargeValueForOutput(double energy, double current, double alpha, Circuit::alphaFlag alphaReason);
306 
309 
310 protected:
312  struct chargeTS {
314  chargeTS(SUMOTime _timeStep, std::string _substationID, std::string _vehicleIDs, double _energy,
315  double _current, std::string _currentsString, double _voltage, std::string _status,
316  int _numVehicle, int _numVoltageSources, double _alpha, Circuit::alphaFlag _alphaReason) :
317  timeStep(_timeStep),
318  substationID(_substationID),
319  vehicleIDs(_vehicleIDs),
320  energy(_energy),
321  current(_current),
322  currentsString(_currentsString),
323  voltage(_voltage),
324  status(_status),
325  numVehicles(_numVehicle),
326  numVoltageSources(_numVoltageSources),
327  alpha(_alpha),
328  alphaReason(_alphaReason) {}
329 
330  // @brief vehicle TimeStep
332  // @brief substation ID
333  std::string substationID;
334  // @brief vehicle IDs
335  std::string vehicleIDs;
336  // @brief total power from voltage sources
337  double energy;
338  //@brief total current through voltage sources
339  double current;
340  // @brief list of all voltage currents
341  std::string currentsString;
342  //@brief voltage of voltage sources
343  double voltage;
345  std::string status;
346  //@brief number of vehicles connected to the circuit
348  //@brief number of votlage sources connected to the section
350  //@brief best alpha scaling value
351  double alpha;
353  };
354  std::vector<chargeTS> myChargeValues;
355 
356 public:
357  //preparation of overhead wire clamp
359  // @todo: 'MSTractionSubstation::overheadWireClamp' : no appropriate default constructor available
360  // provide default constructor for vector construction below
362  id("undefined"),
363  start(nullptr),
364  end(nullptr),
365  usage(false) {}
366 
367  OverheadWireClamp(const std::string _id, MSOverheadWire* _start, MSOverheadWire* _end, bool _usage):
368  id(_id),
369  start(_start),
370  end(_end),
371  usage(_usage) {}
372 
373  const std::string id;
376  bool usage;
377  };
378 
380  OverheadWireClamp* findClamp(std::string id);
381 
382 private:
383  void addOverheadWireInnerSegmentToCircuit(MSOverheadWire* incomingSegment, MSOverheadWire* outgoingSegment,
384  const MSLane* connection, const MSLane* frontConnection, const MSLane* behindConnection);
385 
386 protected:
390 
391 private:
394  std::vector<MSOverheadWire*> myOverheadWireSegments;
395  std::vector<MSDevice_ElecHybrid*> myElecHybrid;
396  std::vector<MSLane*> myForbiddenLanes;
399 
400  // RICE_TODO: Does this cause the "'MSTractionSubstation::overheadWireClamp' : no appropriate default
401  // constructor available" error in MSVC2013?
402  // This is probably an issue with gitHub build chain
403  std::vector<OverheadWireClamp> myOverheadWireClamps;
404 
405 };
long long int SUMOTime
Definition: GUI.h:35
const double WIRE_RESISTIVITY
alphaFlag
Flag of alpha scaling parameter.
Definition: Circuit.h:96
Base (microsim) event class.
Definition: Command.h:50
A device which collects info on the vehicle trip (mainly on departure and arrival)
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
A class for sorting vehicle on lane under the overhead wire segment.
int operator()(SUMOVehicle *v1, SUMOVehicle *v2)
Sorting function; compares RODFRouteDesc::distance2Last.
Definition of overhead wire segment.
std::map< std::string, std::vector< Charge > > myChargeValues
map with the charges of this charging station (key = vehicleID)
void unlock() const
void setCircuitEndNodePos(Node *node)
bool myChargingVehicle
Check if in the current TimeStep overheadWireSegment is charging a vehicle.
Element * myCircuitElementPos
Node * myCircuitEndNodePos
void setCircuitElementPos(Element *element)
Node * getCircuitEndNodePos() const
static void writeVehicle(OutputDevice &out, const std::vector< Charge > &chargeSteps, int iStart, int iEnd, double charged)
void writeOverheadWireSegmentOutput(OutputDevice &output)
write overhead wire segment values
Element * getCircuitElementPos() const
void setChargingVehicle(bool value)
enable or disable charging vehicle
bool vehicleIsInside(const double position) const
Check if a vehicle is inside in the Charge Station.
const std::vector< SUMOVehicle * > & getChargingVehicles() const
MSOverheadWire & operator=(const MSOverheadWire &)
Invalidated assignment operator.
double getTotalCharged() const
MSOverheadWire(const std::string &overheadWireSegmentID, MSLane &lane, double startPos, double endPos, bool voltageSource)
constructor
void setCircuitStartNodePos(Node *node)
std::string getOverheadWireSegmentName()
int getElecHybridCount() const
double myTotalCharge
total energy charged by this charging station
Node * myCircuitStartNodePos
void lock() const
void setVoltage(double voltage)
Set overhead wire's voltage.
std::vector< std::string > myChargedVehicles
order vehicles by time of first charge
bool isThereVoltageSource() const
bool isCharging() const
Return true if in the current time step charging station is charging a vehicle.
Circuit * getCircuit() const
double getVoltage() const
Get overhead wire's voltage.
Node * getCircuitStartNodePos() const
void addChargeValueForOutput(double WCharged, MSDevice_ElecHybrid *elecHybrid, bool ischarging=1)
add charge value for output
MSTractionSubstation * getTractionSubstation() const
void eraseVehicle(SUMOVehicle &veh)
void setTractionSubstation(MSTractionSubstation *substation)
MSTractionSubstation * myTractionSubstation
Parameter, Pointer to the electrical substation (by default is nullptr)
std::vector< SUMOVehicle * > myChargingVehicles
void addVehicle(SUMOVehicle &veh)
~MSOverheadWire()
destructor
MSOverheadWire(const MSOverheadWire &)
Invalidated copy constructor.
double myVoltage
Overhead wire's voltage.
A lane area vehicles can halt at.
Traction substaction powering one or more overhead wire sections.
bool myChargingVehicle
Check if in the current TimeStep substation (overhead wire section) is charging a vehicle.
void eraseVehicle(MSDevice_ElecHybrid *elecHybrid)
void addOverheadWireInnerSegmentToCircuit(MSOverheadWire *incomingSegment, MSOverheadWire *outgoingSegment, const MSLane *connection, const MSLane *frontConnection, const MSLane *behindConnection)
std::size_t numberOfOverheadSegments() const
double getSubstationVoltage() const
~MSTractionSubstation()
destructor
void eraseOverheadWireSegmentFromCircuit(MSOverheadWire *oldWireSegment)
std::vector< OverheadWireClamp > myOverheadWireClamps
std::vector< MSOverheadWire * > myOverheadWireSegments
void addOverheadWireClampToCircuit(const std::string id, MSOverheadWire *startSegment, MSOverheadWire *endSegment)
void addClamp(const std::string &id, MSOverheadWire *startPos, MSOverheadWire *endPos)
Circuit * getCircuit() const
void addSolvingCirucitToEndOfTimestepEvents()
bool isCharging() const
Return true if in the current time step the substation (overhead wire section) is charging a vehicle.
void writeTractionSubstationOutput(OutputDevice &output)
write traction substation values
std::vector< MSDevice_ElecHybrid * > myElecHybrid
bool isForbidden(const MSLane *lane)
std::vector< MSLane * > myForbiddenLanes
void addVehicle(MSDevice_ElecHybrid *elecHybrid)
std::vector< chargeTS > myChargeValues
SUMOTime solveCircuit(SUMOTime currentTime)
void addOverheadWireSegmentToCircuit(MSOverheadWire *newOverheadWireSegment)
MSTractionSubstation(const std::string &substationId, double voltage, double currentLimit)
Constructor instantiates a substation providing certain voltage and a maximum current.
int getElecHybridCount() const
OverheadWireClamp * findClamp(std::string id)
Find an overhead wire clamp by its ID.
static Command * myCommandForSolvingCircuit
void addForbiddenLane(MSLane *lane)
void setChargingVehicle(bool value)
enable or disable charging vehicle
void addChargeValueForOutput(double energy, double current, double alpha, Circuit::alphaFlag alphaReason)
add charge value for output
Base class for objects which have an id.
Definition: Named.h:54
Definition: Node.h:39
A storage for options typed value containers)
Definition: OptionsCont.h:89
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
struct to save information for the overhead wire segment output
Charge(SUMOTime _timeStep, std::string _vehicleID, std::string _vehicleType, std::string _status, double _WCharged, double _actualBatteryCapacity, double _maxBatteryCapacity, double _voltage, double _totalEnergyCharged)
constructor
std::string status
status
OverheadWireClamp(const std::string _id, MSOverheadWire *_start, MSOverheadWire *_end, bool _usage)
struct to save information for the traction substation output
Circuit::alphaFlag alphaReason
chargeTS(SUMOTime _timeStep, std::string _substationID, std::string _vehicleIDs, double _energy, double _current, std::string _currentsString, double _voltage, std::string _status, int _numVehicle, int _numVoltageSources, double _alpha, Circuit::alphaFlag _alphaReason)
constructor