Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 MSChargingStation.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Tamas Kurczveil
17 : /// @author Pablo Alvarez Lopez
18 : /// @author Mirko Barthauer
19 : /// @date 20-12-13
20 : ///
21 : // Charging Station for Electric vehicles
22 : /****************************************************************************/
23 : #pragma once
24 : #include <config.h>
25 :
26 : #include <list>
27 : #include <string>
28 : #include <iostream>
29 : #include <fstream>
30 : #include <sstream>
31 : #include <microsim/MSStoppingPlace.h>
32 :
33 :
34 : // ===========================================================================
35 : // class declarations
36 : // ===========================================================================
37 : class MSLane;
38 : class MSBusStop;
39 : class OptionsCont;
40 : class MSDevice_Battery;
41 : class Command;
42 :
43 : // ===========================================================================
44 : // class definitions
45 : // ===========================================================================
46 : /**
47 : * @class ChargingStation
48 : * @brief Definition of charging stations
49 : */
50 : class MSChargingStation : public MSStoppingPlace {
51 :
52 : public:
53 : enum ChargeType {
54 : CHARGETYPE_NORMAL = 0,
55 : CHARGETYPE_BATTERYEXCHANGE,
56 : CHARGETYPE_FUEL
57 : };
58 :
59 : /** @brief Get the string representation of a charge type
60 : * @param[in] type The charge type to represent
61 : */
62 0 : static inline std::string chargeTypeToString(ChargeType type) {
63 0 : if (type == CHARGETYPE_NORMAL) {
64 0 : return "normal";
65 0 : } else if (type == CHARGETYPE_BATTERYEXCHANGE) {
66 0 : return "battery-exchange";
67 0 : } else if (type == CHARGETYPE_FUEL) {
68 0 : return "fuel";
69 : } else {
70 0 : WRITE_WARNING(TL("Encountered an unknown charge type. Assuming charge type 'normal'."));
71 0 : return "normal";
72 : }
73 : }
74 :
75 : /** @brief Get the charge type from its string representation
76 : * @param[in] repr The string to convert into charge type
77 : */
78 15235 : static inline ChargeType stringToChargeType(const std::string& repr) {
79 15235 : if (repr == "normal") {
80 : return ChargeType::CHARGETYPE_NORMAL;
81 101 : } else if (repr == "battery-exchange") {
82 : return ChargeType::CHARGETYPE_BATTERYEXCHANGE;
83 89 : } else if (repr == "fuel") {
84 : return ChargeType::CHARGETYPE_FUEL;
85 : } else {
86 0 : WRITE_WARNINGF("Encountered an unknown charge type string '%'. Assuming charge type 'normal'.", repr);
87 0 : return ChargeType::CHARGETYPE_NORMAL;
88 : }
89 : }
90 :
91 : public:
92 :
93 : /// @brief constructor
94 : MSChargingStation(const std::string& chargingStationID, MSLane& lane, double startPos, double endPos,
95 : const std::string& name, double chargingPower, double totalPower, double efficency, bool chargeInTransit,
96 : SUMOTime chargeDelay, const std::string& chargeType, SUMOTime waitingTime);
97 :
98 : MSChargingStation(const std::string& chargingStationID, const MSParkingArea* parkingArea, const std::string& name, double chargingPower,
99 : double totalPower, double efficency, bool chargeInTransit, SUMOTime chargeDelay, const std::string& chargeType,
100 : SUMOTime waitingTime);
101 :
102 : /// @brief destructor
103 : ~MSChargingStation();
104 :
105 : /// @brief Get charging station's charging power
106 : double getChargingPower(bool usingFuel) const;
107 :
108 : /// @brief Get efficiency of the charging station
109 : double getEfficency() const;
110 :
111 : /// @brief Get chargeInTransit
112 : bool getChargeInTransit() const;
113 :
114 : /// @brief Get Charge Delay
115 : SUMOTime getChargeDelay() const;
116 :
117 : /// @brief Get charge type
118 : ChargeType getChargeType() const;
119 :
120 : /// @brief Get waiting time
121 : SUMOTime getWaitingTime() const;
122 :
123 : /** @brief Get the parking area the charging station is placed on
124 : * @return pointer to the parking area or nullptr
125 : */
126 : const MSParkingArea* getParkingArea() const;
127 :
128 : /// @brief set charging station's charging power
129 : void setChargingPower(double chargingPower);
130 :
131 : /// @brief set efficiency of the charging station
132 : void setEfficiency(double efficiency);
133 :
134 : /// @brief set charging delay of the charging station
135 : void setChargeDelay(SUMOTime delay);
136 :
137 : /// @brief set charging in transit
138 : void setChargeInTransit(bool value);
139 :
140 : /// @brief Get charging station's total power
141 : double getTotalChargingPower() const;
142 :
143 : /// @brief set charging station's total power
144 : void setTotalChargingPower(double totalPower);
145 :
146 : /// @brief enable or disable charging vehicle
147 : void setChargingVehicle(bool value);
148 :
149 : /// @brief update the delivered power to all charging vehicles after all requests are known
150 : SUMOTime checkTotalPower(SUMOTime currentTime);
151 :
152 : /** @brief Check if a vehicle is inside in the Charge Station
153 : * @param[in] position Position of vehicle in the LANE
154 : * @return true if is between StartPostion and EndPostion
155 : */
156 : bool vehicleIsInside(const double position) const;
157 :
158 : /// @brief Return true if in the current time step charging station is charging a vehicle
159 : bool isCharging() const;
160 :
161 : double getTotalCharged() const {
162 5 : return myTotalCharge;
163 : }
164 :
165 : /// @brief add charge value for output
166 : void addChargeValueForOutput(double WCharged, MSDevice_Battery* battery);
167 :
168 : /// @brief write charging station values
169 : void writeChargingStationOutput(OutputDevice& output);
170 :
171 : /// @brief write ungrouped output (flush data after writing)
172 : void writeAggregatedChargingStationOutput(OutputDevice& output, bool includeUnfinished = false);
173 :
174 : protected:
175 :
176 : /// @brief struct to save information for the chargingStation output
177 : struct Charge {
178 : /// @brief constructor
179 99605 : Charge(SUMOTime _timeStep, std::string _vehicleID, std::string _vehicleType, std::string _status,
180 : double _WCharged, double _actualBatteryCapacity, double _maxBatteryCapacity, double _chargingPower,
181 99605 : double _chargingEfficiency, double _totalEnergyCharged) :
182 99605 : timeStep(_timeStep),
183 99605 : vehicleID(_vehicleID),
184 99605 : vehicleType(_vehicleType),
185 99605 : status(_status),
186 99605 : WCharged(_WCharged),
187 99605 : actualBatteryCapacity(_actualBatteryCapacity),
188 99605 : maxBatteryCapacity(_maxBatteryCapacity),
189 99605 : chargingPower(_chargingPower),
190 99605 : chargingEfficiency(_chargingEfficiency),
191 99605 : totalEnergyCharged(_totalEnergyCharged) {}
192 :
193 : // @brief vehicle TimeStep
194 : SUMOTime timeStep;
195 : // @brief vehicle ID
196 : std::string vehicleID;
197 : // @brief vehicle Type
198 : std::string vehicleType;
199 : /// @brief status
200 : std::string status;
201 : // @brief W charged
202 : double WCharged;
203 : // @brief actual battery capacity AFTER charging
204 : double actualBatteryCapacity;
205 : // @brief battery max capacity
206 : double maxBatteryCapacity;
207 : // @brief current charging power of charging station
208 : double chargingPower;
209 : // @brief current efficiency of charging station
210 : double chargingEfficiency;
211 : // @brief current energy charged by charging stations AFTER charging
212 : double totalEnergyCharged;
213 : };
214 :
215 : static void writeVehicle(OutputDevice& out, const std::vector<Charge>& chargeSteps, int iStart, int iEnd, double charged);
216 :
217 : /// @brief Charging station's nominal charging power per vehicle
218 : double myNominalChargingPower = 0;
219 :
220 : /// @brief The maximal charging power available to serve all charging vehicles (value <= 0 take no effect)
221 : double myTotalChargingPower = 0;
222 :
223 : /// @brief Efficiency of the charging station
224 : double myEfficiency = 0;
225 :
226 : /// @brief Allow charge in transit
227 : bool myChargeInTransit;
228 :
229 : /// @brief Charge Delay
230 : SUMOTime myChargeDelay = 0;
231 :
232 : /// @brief charge type
233 : const ChargeType myChargeType;
234 :
235 : /// @brief waiting time
236 : SUMOTime myWaitingTime = 0;
237 :
238 : /// @brief Check if in the current TimeStep chargingStation is charging a vehicle
239 : bool myChargingVehicle = false;
240 :
241 : /// @brief total energy charged by this charging station
242 : double myTotalCharge = 0;
243 :
244 : /// @brief parkingArea the charging station is placed on
245 : const MSParkingArea* myParkingArea = nullptr;
246 :
247 : /// @brief map with the charges of this charging station (key = vehicleID)
248 : std::map<std::string, std::vector<Charge> > myChargeValues;
249 : /// @brief order vehicles by time of first charge
250 : std::vector<std::string> myChargedVehicles;
251 :
252 : /// @brief map with the Batteries charged by this charging station (key = vehicleID)
253 : std::map<std::string, MSDevice_Battery*> myChargedBatteries;
254 :
255 : /// @brief Event for checking at every time-step if myTotalPower has been exceeded
256 : Command* myTotalPowerCheckEvent;
257 :
258 :
259 : private:
260 : /// @brief Invalidated copy constructor.
261 : MSChargingStation(const MSChargingStation&) = delete;
262 :
263 : /// @brief Invalidated assignment operator.
264 : MSChargingStation& operator=(const MSChargingStation&) = delete;
265 : };
|