@@ -104,7 +104,7 @@ def __init__(self, **kwargs):
104
104
self .feeders_redirect = {}
105
105
self .mv_load_voltage_dict = {}
106
106
self .feeder_head_line = None
107
- self .model_dtrans = False
107
+ self .model_dtrans = True # this will decide if model secondary / dtrans
108
108
109
109
self .write_distribution_transformers = True
110
110
self .write_taps = False
@@ -372,8 +372,8 @@ def write_bus_coordinates(self, model, delimiter=","):
372
372
373
373
txt += "{name}{delimiter}{X}{delimiter}{Y}\n " .format (
374
374
name = re .sub ("[^0-9a-zA-Z]+" , "_" , i .name .lower ()),
375
- X = i .positions [0 ].long ,
376
- Y = i .positions [0 ].lat ,
375
+ X = i .positions [0 ].lat ,
376
+ Y = i .positions [0 ].long ,
377
377
delimiter = delimiter ,
378
378
)
379
379
feeder_text_map [substation_name + "_" + feeder_name ] = txt
@@ -1141,23 +1141,28 @@ def write_dtransformers(self, model):
1141
1141
# if hasattr(i, "bus2") and i.bus2 is not None:
1142
1142
# txt += i.bus2 + ")"
1143
1143
if hasattr (i , "conn" ) and i .conn is not None :
1144
- txt += f" conn = ({ i .conn [0 ]} , { i .conn [1 ]} )"
1144
+ txt += f" conns = ({ i .conn [0 ]} , { i .conn [1 ]} )"
1145
1145
1146
1146
if hasattr (i , "nominal_voltage" ) and i .nominal_voltage is not None :
1147
1147
#txt += f" kvs = ({i.nominal_voltage/1000}, 0.24)"
1148
1148
if hasattr (i , "phase_loads" ) and i .phase_loads is not None and len (i .phase_loads )== 1 :
1149
1149
try :
1150
- kv1 = self .mv_load_voltage_dict [i .name .split ('DTran_ ' )[1 ]]
1150
+ kv1 = self .mv_load_voltage_dict [i .name .split ('_ ' )[1 ]]
1151
1151
except :
1152
+
1152
1153
kv1 = 0
1153
-
1154
+ logger .warning ('WARNING: There is kv1=0 in dtrans object!' )
1155
+
1156
+
1154
1157
txt += f" kvs = ({ kv1 } , 0.24)"
1155
1158
else :
1156
1159
try :
1157
- kv1 = self .mv_load_voltage_dict [i .name .split ('DTran_ ' )[1 ]]
1160
+ kv1 = self .mv_load_voltage_dict [i .name .split ('_ ' )[1 ]]
1158
1161
except :
1159
- kv1 = 0
1160
- txt += f" kvs = ({ kv1 } , 0.208)"
1162
+ kv1 = 0
1163
+ logger .warning ('WARNING: There is kv1=0 in dtrans object!' )
1164
+
1165
+ txt += f" kvs = ({ kv1 } , 0.416)"
1161
1166
1162
1167
1163
1168
if hasattr (i , "kvas" ) and i .kvas is not None :
@@ -1495,35 +1500,50 @@ def write_PVs(self, model):
1495
1500
1496
1501
# nominal voltage
1497
1502
if hasattr (i , "nominal_voltage" ) and i .nominal_voltage is not None :
1498
- if i .nominal_voltage < 300 :
1499
- if hasattr (i , "phases" ) and i .phases is not None :
1500
- txt += " phases=1"
1501
- txt += " kV={kV}" .format (
1502
- kV = i .nominal_voltage * 10 ** - 3
1503
- ) # DiTTo in volts
1504
- else :
1505
- if hasattr (i , "phases" ) and i .phases is not None :
1506
- txt += " phases=3"
1507
- txt += " kV={kV}" .format (
1508
- kV = i .nominal_voltage * 10 ** - 3
1509
- ) # DiTTo in volts
1503
+ if hasattr (i , "phases" ) and i .phases is not None :
1504
+ txt += f" phases={ len (i .phases )} "
1505
+ if len (i .phases ) == 1 :
1506
+ txt += f" kV={ round (i .nominal_voltage * 10 ** - 3 / 1.732 ,2 )} "
1507
+ else :
1508
+ txt += f" kV={ i .nominal_voltage * 10 ** - 3 } " # DiTTo in volts
1509
+
1510
+ # if i.nominal_voltage < 300:
1511
+ # if hasattr(i, "phases") and i.phases is not None:
1512
+ # txt += " phases=1"
1513
+ # txt += " kV={kV}".format(
1514
+ # kV=i.nominal_voltage * 10**-3
1515
+ # ) # DiTTo in volts
1516
+ # else:
1517
+ # if hasattr(i, "phases") and i.phases is not None:
1518
+ # txt += " phases=3"
1519
+ # txt += " kV={kV}".format(
1520
+ # kV=i.nominal_voltage * 10**-3
1521
+ # ) # DiTTo in volts
1510
1522
if not substation_name + "_" + feeder_name in self ._baseKV_feeders_ :
1511
1523
self ._baseKV_feeders_ [
1512
1524
substation_name + "_" + feeder_name
1513
1525
] = set ()
1514
- if (
1515
- i .nominal_voltage < 300
1516
- ): # Line-Neutral voltage for 120 V (i.e. 240V)
1517
- self ._baseKV_ .add (i .nominal_voltage * 10 ** - 3 )
1518
- self ._baseKV_feeders_ [substation_name + "_" + feeder_name ].add (
1519
- i .nominal_voltage * 2 * 10 ** - 3
1520
- )
1521
- else :
1522
- self ._baseKV_ .add (i .nominal_voltage * 10 ** - 3 )
1523
- self ._baseKV_feeders_ [substation_name + "_" + feeder_name ].add (
1524
- i .nominal_voltage * 10 ** - 3
1525
- )
1526
+ # if (
1527
+ # i.nominal_voltage < 300
1528
+ # ): # Line-Neutral voltage for 120 V (i.e. 240V)
1529
+ # self._baseKV_.add(i.nominal_voltage * 10**-3)
1530
+ # self._baseKV_feeders_[substation_name + "_" + feeder_name].add(
1531
+ # i.nominal_voltage * 2 * 10**-3
1532
+ # )
1533
+ # else:
1534
+ # self._baseKV_.add(i.nominal_voltage * 10**-3)
1535
+ # self._baseKV_feeders_[substation_name + "_" + feeder_name].add(
1536
+ # i.nominal_voltage * 10**-3
1537
+ # )
1538
+ self ._baseKV_ .add (i .nominal_voltage * 10 ** - 3 )
1539
+ self ._baseKV_feeders_ [substation_name + "_" + feeder_name ].add (
1540
+ i .nominal_voltage * 10 ** - 3
1541
+ )
1542
+
1526
1543
else :
1544
+ logger .warning (
1545
+ "Warning - check PV definition, possible no kv defined."
1546
+ )
1527
1547
parent = model [i .connecting_element ]
1528
1548
if (
1529
1549
hasattr (parent , "nominal_voltage" )
@@ -1563,7 +1583,7 @@ def write_PVs(self, model):
1563
1583
1564
1584
if hasattr (i , "active_rating" ) and i .active_rating is not None :
1565
1585
pf_local = 1.0
1566
- if i .power_factor is not None :
1586
+ if i .power_factor is not None and i . power_factor > 0 :
1567
1587
pf_local = abs (i .power_factor )
1568
1588
txt += " kVA={kva}" .format (
1569
1589
kva = i .active_rating / pf_local * 10 ** - 3
@@ -1578,23 +1598,30 @@ def write_PVs(self, model):
1578
1598
** - 3 # Set the inverter to be oversized by 10% if active rating not specified
1579
1599
) # DiTTo in watts
1580
1600
1601
+ else :
1602
+ # wenbo note: if no active rating, kva need to be defined still.
1603
+ pf_local = 1.0
1604
+ txt += " kVA={kva}" .format (
1605
+ kva = i .rated_power / pf_local * 10 ** - 3
1606
+ ) # DiTTo in watts
1607
+
1581
1608
if hasattr (i , "rated_power" ) and i .rated_power is not None :
1582
1609
txt += " Pmpp={kw}" .format (
1583
1610
kw = i .rated_power
1584
1611
* 10
1585
1612
** - 3 # Set the inverter to be oversized by 10% if active rating not specified
1586
1613
) # DiTTo in watts
1587
1614
1588
- if hasattr (i , "reactive_rating" ) and i .reactive_rating is not None :
1589
- if self .opendss_version >= 9 :
1590
- kvarlimit_key = " kvarMax="
1591
- else :
1592
- kvarlimit_key = " kvarlimit="
1593
- txt += kvarlimit_key + "{kvar}" .format (
1594
- kvar = i .reactive_rating
1595
- * 10
1596
- ** - 3 # Set the inverter to be oversized by 10% if active rating not specified
1597
- ) # DiTTo in watts
1615
+ # if hasattr(i, "reactive_rating") and i.reactive_rating is not None:
1616
+ # if self.opendss_version >= 9:
1617
+ # kvarlimit_key = " kvarMax="
1618
+ # else:
1619
+ # kvarlimit_key = " kvarlimit="
1620
+ # txt += kvarlimit_key + "{kvar}".format(
1621
+ # kvar=i.reactive_rating
1622
+ # * 10
1623
+ # ** -3 # Set the inverter to be oversized by 10% if active rating not specified
1624
+ # ) # DiTTo in watts
1598
1625
1599
1626
# connection type
1600
1627
if hasattr (i , "connection_type" ) and i .connection_type is not None :
@@ -1636,7 +1663,7 @@ def write_PVs(self, model):
1636
1663
if hasattr (i , "control_type" ) and (
1637
1664
i .control_type is None or i .control_type == "powerfactor"
1638
1665
): # use powerfactor as default mode
1639
- if hasattr (i , "power_factor" ) and i .power_factor is not None :
1666
+ if hasattr (i , "power_factor" ) and i .power_factor is not None and i . power_factor > 0 :
1640
1667
txt += " Model=1 pf={power_factor}" .format (
1641
1668
power_factor = i .power_factor
1642
1669
)
@@ -2086,11 +2113,14 @@ def write_loads(self, model):
2086
2113
2087
2114
# Name
2088
2115
if hasattr (i , "name" ) and i .name is not None :
2116
+
2117
+
2089
2118
if i .name not in load_list :
2090
2119
2091
2120
txt += "New Load." + i .name
2092
2121
load_list .append (i .name )
2093
2122
else :
2123
+ continue
2094
2124
txt += "New Load." + i .name + '_dup'
2095
2125
#print(f"i.name = {i.name}")
2096
2126
else :
@@ -2145,22 +2175,23 @@ def write_loads(self, model):
2145
2175
#print(f"i.phase_loads length = {len(i.phase_loads)}")
2146
2176
if self .model_dtrans :
2147
2177
if i .nominal_voltage < 300 :
2178
+
2148
2179
txt += " kV={volt}" .format (volt = i .nominal_voltage * 10 ** - 3 )
2149
2180
# Wenbo: This is added because single phase load should be L-N, not L-L
2150
2181
elif hasattr (i , "phase_loads" ) and i .phase_loads is not None and len (i .phase_loads )== 1 :
2151
2182
#txt += " kV={volt}".format(volt=round(i.nominal_voltage * 10**-3/math.sqrt(3),2))
2152
2183
txt += " kV=0.24"
2153
2184
self .mv_load_voltage_dict [i .name .split ('Load_' )[1 ]] = round (i .nominal_voltage * 10 ** - 3 / 1.732 ,2 )
2154
2185
elif hasattr (i , "phase_loads" ) and i .phase_loads is not None and len (i .phase_loads )> 1 :
2155
- txt += " kV=0.208 "
2186
+ txt += " kV=0.416 "
2156
2187
self .mv_load_voltage_dict [i .name .split ('Load_' )[1 ]] = round (i .nominal_voltage * 10 ** - 3 ,2 )
2157
2188
#txt += " kV={volt}".format(volt=i.nominal_voltage * 10**-3)
2158
2189
else :
2159
2190
if i .nominal_voltage < 300 :
2160
2191
txt += " kV={volt}" .format (volt = i .nominal_voltage * 10 ** - 3 )
2161
2192
# Wenbo: This is added because single phase load should be L-N, not L-L
2162
2193
elif hasattr (i , "phase_loads" ) and i .phase_loads is not None and len (i .phase_loads )== 1 :
2163
- txt += " kV={volt}" .format (volt = round (i .nominal_voltage * 10 ** - 3 / math .sqrt (3 ),2 ))
2194
+ txt += " kV={volt}" .format (volt = round (i .nominal_voltage * 10 ** - 3 / math .sqrt (3 ),2 ))
2164
2195
else :
2165
2196
txt += " kV={volt}" .format (volt = i .nominal_voltage * 10 ** - 3 )
2166
2197
@@ -4277,7 +4308,7 @@ def write_master_file(self, model):
4277
4308
):
4278
4309
fp .write ("Redirect {file}\n " .format (file = file ))
4279
4310
4280
- _baseKV_list_ = list (self ._baseKV_ ) + [0.208 , 0.416 ]
4311
+ _baseKV_list_ = list (self ._baseKV_ ) + [0.24 , 0.416 ]
4281
4312
_baseKV_list_ = sorted (_baseKV_list_ )
4282
4313
fp .write ("\n Set Voltagebases={}\n " .format (_baseKV_list_ ))
4283
4314
0 commit comments