66import numpy as np
77from VeraGridEngine .Devices .admittance_matrix import AdmittanceMatrix
88from VeraGridEngine .Devices .Parents .editable_device import EditableDevice , DeviceType
9-
10-
11- def get_line_impedances_with_c (r_ohm : float , x_ohm : float , c_nf : float ,
12- length : float , Imax : float ,
13- freq : float , Sbase : float , Vnom : float ) -> Tuple [float , float , float , float ]:
9+ from VeraGridEngine .basic_structures import Logger
10+
11+
12+ def get_line_impedances_with_c (r_ohm : float ,
13+ x_ohm : float ,
14+ c_nf : float ,
15+ length : float ,
16+ Imax : float ,
17+ freq : float ,
18+ Sbase : float ,
19+ Vnom : float ,
20+ logger : Logger = Logger ()) -> Tuple [float , float , float , float ]:
1421 """
1522 Fill R, X, B from not-in-per-unit parameters
1623 :param r_ohm: Resistance per km in OHM/km
@@ -21,26 +28,31 @@ def get_line_impedances_with_c(r_ohm: float, x_ohm: float, c_nf: float,
2128 :param freq: System frequency in Hz
2229 :param Sbase: Base power in MVA (take always 100 MVA)
2330 :param Vnom: nominal voltage (kV)
31+ :param logger: logger
2432 :return R, X, B, rate
2533 """
2634 r_ohm_total = r_ohm * length
2735 x_ohm_total = x_ohm * length
2836 b_siemens_total = (2 * np .pi * freq * c_nf * 1e-9 ) * length
2937
30- Zbase = (Vnom * Vnom ) / Sbase
31- Ybase = 1.0 / Zbase
32-
33- R = np .round (r_ohm_total / Zbase , 6 )
34- X = np .round (x_ohm_total / Zbase , 6 )
35- B = np .round (b_siemens_total / Ybase , 6 )
38+ if Vnom > 0.0 :
39+ Zbase = (Vnom * Vnom ) / Sbase
40+ Ybase = 1.0 / Zbase
3641
37- rate = np .round (Imax * Vnom * 1.73205080757 , 6 ) # nominal power in MVA = kA * kV * sqrt(3)
42+ R : float = np .round (r_ohm_total / Zbase , 6 )
43+ X : float = np .round (x_ohm_total / Zbase , 6 )
44+ B : float = np .round (b_siemens_total / Ybase , 6 )
45+ rate : float = np .round (Imax * Vnom * 1.73205080757 , 6 ) # nominal power in MVA = kA * kV * sqrt(3)
3846
39- return R , X , B , rate
47+ return R , X , B , rate
48+ else :
49+ logger .add_error ("Nominal voltage is zero" , device_class = "SequenceLineType" )
50+ return 1e-20 , 1e-20 , 0 , 1e-20
4051
4152
4253def get_line_impedances_with_b (r_ohm : float , x_ohm : float , b_us : float , length : float ,
43- Imax : float , Sbase : float , Vnom : float ) -> Tuple [float , float , float , float ]:
54+ Imax : float , Sbase : float , Vnom : float ,
55+ logger : Logger = Logger ()) -> Tuple [float , float , float , float ]:
4456 """
4557 Fill R, X, B from not-in-per-unit parameters
4658 :param r_ohm: Resistance per km in OHM/km
@@ -56,16 +68,20 @@ def get_line_impedances_with_b(r_ohm: float, x_ohm: float, b_us: float, length:
5668 x_ohm_total = x_ohm * length
5769 b_siemens_total = (b_us * 1e-6 ) * length
5870
59- Zbase = (Vnom * Vnom ) / Sbase
60- Ybase = 1.0 / Zbase
71+ if Vnom > 0 :
72+ Zbase = (Vnom * Vnom ) / Sbase
73+ Ybase = 1.0 / Zbase
6174
62- R = np .round (r_ohm_total / Zbase , 6 )
63- X = np .round (x_ohm_total / Zbase , 6 )
64- B = np .round (b_siemens_total / Ybase , 6 )
75+ R : float = np .round (r_ohm_total / Zbase , 6 )
76+ X : float = np .round (x_ohm_total / Zbase , 6 )
77+ B : float = np .round (b_siemens_total / Ybase , 6 )
78+ rate : float = np .round (Imax * Vnom * 1.73205080757 , 6 ) # nominal power in MVA = kA * kV * sqrt(3)
6579
66- rate = np .round (Imax * Vnom * 1.73205080757 , 6 ) # nominal power in MVA = kA * kV * sqrt(3)
80+ return R , X , B , rate
81+ else :
82+ logger .add_error ("Nominal voltage is zero" , device_class = "SequenceLineType" )
6783
68- return R , X , B , rate
84+ return 1e-20 , 1e-20 , 0 , 1e-20
6985
7086
7187class SequenceLineType (EditableDevice ):
@@ -139,7 +155,8 @@ def __init__(self, name='SequenceLine', idtag=None, Imax=1, Vnom=1,
139155 definition = 'Use conductance? else the susceptance is used' )
140156 self .register (key = 'n_circuits' , units = '' , tpe = int , definition = 'number of circuits' )
141157
142- def get_values (self , Sbase : float , freq : float , length : float , line_Vnom : float , ):
158+ def get_values (self , Sbase : float , freq : float , length : float , line_Vnom : float ,
159+ logger : Logger = Logger ()):
143160 """
144161 Get the per-unit values
145162 :param Sbase: Base power (MVA, always use 100MVA)
@@ -153,24 +170,38 @@ def get_values(self, Sbase: float, freq: float, length: float, line_Vnom: float,
153170 R , X , B , rate = get_line_impedances_with_c (r_ohm = self .R ,
154171 x_ohm = self .X ,
155172 c_nf = self .Cnf ,
156- length = length , Imax = self .Imax ,
157- freq = freq , Sbase = Sbase , Vnom = line_Vnom )
173+ length = length ,
174+ Imax = self .Imax ,
175+ freq = freq ,
176+ Sbase = Sbase ,
177+ Vnom = line_Vnom ,
178+ logger = logger )
179+
158180 R0 , X0 , B0 , _ = get_line_impedances_with_c (r_ohm = self .R0 ,
159181 x_ohm = self .X0 ,
160182 c_nf = self .Cnf0 ,
161- length = length , Imax = self .Imax ,
162- freq = freq , Sbase = Sbase , Vnom = line_Vnom )
183+ length = length ,
184+ Imax = self .Imax ,
185+ freq = freq ,
186+ Sbase = Sbase ,
187+ Vnom = line_Vnom ,
188+ logger = logger )
163189 else :
164190 R , X , B , rate = get_line_impedances_with_b (r_ohm = self .R ,
165191 x_ohm = self .X ,
166192 b_us = self .B ,
167- length = length , Imax = self .Imax ,
168- Sbase = Sbase , Vnom = line_Vnom )
193+ length = length ,
194+ Imax = self .Imax ,
195+ Sbase = Sbase ,
196+ Vnom = line_Vnom )
197+
169198 R0 , X0 , B0 , _ = get_line_impedances_with_b (r_ohm = self .R0 ,
170199 x_ohm = self .X0 ,
171200 b_us = self .B0 ,
172- length = length , Imax = self .Imax ,
173- Sbase = Sbase , Vnom = line_Vnom )
201+ length = length ,
202+ Imax = self .Imax ,
203+ Sbase = Sbase ,
204+ Vnom = line_Vnom )
174205
175206 return R , X , B , R0 , X0 , B0 , rate
176207
@@ -227,4 +258,4 @@ def get_ysh_nabc(self) -> AdmittanceMatrix:
227258 adm .phB = 1
228259 adm .phC = 1
229260
230- return adm
261+ return adm
0 commit comments