-
Notifications
You must be signed in to change notification settings - Fork 0
/
varistorGeneralModel.py
445 lines (354 loc) · 14 KB
/
varistorGeneralModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
'''
Varistor - Transmission Line Time Domain
This code uses the Transmission Line Modelling Method to analyse two-wire
transmission lines, any frequency. It includes also source models,
load models, linear and non-linear devices models.
The user input parameters and choose the node to get results in the time domain.
Model developed by Mauro Fazion Filho. Code Copyright: Mauro Fazion Filho.
****************************************************************
Definitions:
K - number os instants - iterations - from 1 to KT
KT - total number of instants - iterations
j - Node number
N - total number of Nodes (transmission line nodes)
RD - Transmission line distributed Resistance
LD - Transmission line distributed Inductance
CD - Transmission line distributed Capacitance
GD - Transmission line distributed Conductance
C - Capacitance by line segment
L - Inductance by line segment
G - Conductance by line segment
R - Resistance by line segment
RL - Load Resistance
RS - Source Resistance
ZL - Load Impedance
Z0 - Characteristic Impedance of line segment
IL[K] - Load Current at instant K
VRL[K] - Voltage reflected for the Load Inductance
VS[K] - Source Voltage at instant K
VL[K] - Voltage at Load Inductance, instant K
VIL[K] - Incident Voltage at Load Inductance, instant K
I[j][K] - Current at node j, instant K
V[j][K] - Voltage at node j, instant K
VD[j][K] - Voltage at node j, Right side, instant K
VE[j][K] - Voltage at node j, Left side, instant K
VID[j][K] - Right side Incident Voltage at node j, instant K
VIE[j][K] - Left side Incident Voltage at node j, instant K
VRD[j][K] - Right side Reflected Voltage from node j, instant K
VRE[j][K] - Left side Reflected Voltage from node j, instant K
W - Source sine Angular frequency
FREQ - Source sine frequency
Deltat - Time step
Deltax - transmission line segment length
COMP - total transmission line length
Tempo - Time
CAP - Capacitance Filter (on the load)
ZC - Filter Impedance
****************************************************************
'''
import time
from math import *
startTime = time.clock()
def fileOut (V, I, NO, K, Tempo, file):
inFile = open(file +'.txt', 'r')
contents = inFile.read()
cont = contents
outFile = open(file +'.txt', 'w')
outFile.write(str(cont)+'\n'+str(Tempo)+','+str(V[NO-1][K])+','+str(V[NO][K])) #writing 'cont' as a string
outFile.close()
def procuraVAR(ZC, CONST, ALFA,V1,VRES):
# procuraVAR calculates the value of reflected voltage VRES from the Varistor
V2 = [0.0]*1500
ERRO = [0.0]*1500
i=0
BAUX = log10(ZC*CONST)
V2[1]= V1-1.
OP=1
ERRO[0]=1.
SUP=V1
INF=V2[1]
if V1==0.0:
V2[0]=0.0
elif V1 < 4.0:
V2[i]=V1
else:
while ERRO[i] > 1e-5:
i=i+1
A = log10(V1 - V2[i])
B = BAUX + ALFA*(log10(V1 + V2[i]))
ERRO[i] = fabs(A-B)
# print (ERRO[i], V1, V2[i])
if ((ERRO[i] > ERRO[i-1]) and (i == 2)):
OP=3
if OP == 1:
if fabs(A) < fabs(B):
V2[i+1]=V2[i] - 1.
OP=1
else:
SUP=V2[i-1]
INF=V2[i]
V2[i+1]=(SUP+INF)/2
OP=2
elif OP == 2:
if fabs(A) < fabs(B):
SUP=V2[i]
INF = INF
else:
SUP = SUP
INF = V2[i]
V2[i+1]=(SUP+INF)/2
elif OP == 3:
if fabs(A) < fabs(B):
SUP=SUP
INF = V2[i]
else:
SUP = V2[i]
INF = V2[i-1]
V2[i+1]=(SUP+INF)/2
if V2[i] == V2[i-1]:
ERRO[i] = 1e-6
VRES = V2[i]
return VRES
def sourceVoltage(KT, OP, Deltat, VS):
# defines the Source Voltage
if OP == 1:
VSO = float(input('What is the Boost Voltage (V)? '))
VS[0]=VSO
elif OP == 2:
VSO = float(input('What is the Maximum Pulse Voltage (V)? '))
LARG = float(input('What is the Pulse width (seconds) ?'))
for K in range(KT):
ONDA = K*Deltat
if ONDA < LARG:
VS[K]=VSO
else:
VS[K] = 0
elif OP ==3:
VSO = float(input('What is the Maximum Surge Voltage (V)? '))
for K in range(KT):
TAUX = K*Deltat
if TAUX < 1.2e-6:
VS[K] = (VSO/1.2e-6)*TAUX
elif TAUX < 100e-6:
VS[K] = (VSO*((100e-6)-TAUX))/98.8e-6
else:
VS[K] = 0
elif OP ==4:
VSO = float(input('What is the Maximum Surge Voltage (V)? '))
for K in range(KT):
TAUX = K*Deltat
if TAUX < 250e-6:
VS[K] = (VSO/250e-6)*TAUX
elif TAUX < 2500e-6:
VS[K] = (VSO*((2500e-6)-TAUX))/2500e-6
else:
VS[K] = 0
elif OP ==5:
VSO = float(input('What is the Maximum Sine Voltage (V)? '))
FREQ = float(input('What is the Sine Frequency (Hz)? '))
W = 2*FREQ*pi
for K in range(KT):
TAUX = K*Deltat
VS[K]=VSO*sin(W*TAUX)
return VS
def main():
print('')
print('Inputting data: Transmission line parameters')
KT = int(input('Number of iterations: ',))
COMP = 400. #float(input('Line length (meters): ', ))
N = 51 #int(input('Number of Nodes (transmission line nodes): ',))
RD = 1.0e-5 #float(input('Transmission line distributed Resistance (ohm/m): ',))
GD = 0.0 #float(input('Transmission line distributed Conductance (siemen/m): ',))
CD = 1.0e-10 #float(input('Transmission line distributed Capacitance (farad/m): ',))
LD = 2.5e-7 #float(input('Transmission line distributed Inductance (henry/m): ',))
print('')
print('Inputting data: Load and source parameters')
RL = 50. #float(input('Load Resistance (ohm): ',))
RS = 0.0 #float(input('Source Resistance (ohm): ',))
# varistor parameters
print('')
print('Inputting data: Varistor parameters (non linear device) ')
CAP = 5.2e-9 #float(input('Varistor Capacitance (farad): ',))
RON = 10. # float(input('Varistor Resistance - online - conducting (ohm): ',))
ROFF = 1.e9 #float(input('Varistor Resistance - offline (ohm): ',))
Vlim1 = 22.0 #float(input('Voltage at I = 1 mA (V): ',))
Ilim1 = 1.e-6
Va = 28. #36.0 #float(input('Va to calculate Varistor parameters (V)): ',))
Ia = 0.01 # 1.0 # float(input('Ia to calculate Varistor parameters (A): ',))
Vb = 36. #36.0 #float(input('Vb to calculate Varistor parameters (V): ',))
Ib = 0.5 # 1.0 # float(input('Ib to calculate Varistor parameters (A): ',))
ALFA = (log10(Ib) - log10(Ia))/(log10(Vb) - log10(Va))
CONST =(Ib/(Vb**ALFA))
print(ALFA,' ',CONST)
#ALFA = 11.55 #float(input('Varistor Alpha: ',)) << S05K11 Siemens >>
#CONST = 6.58e-18 #float(input('Varistor K constant: ',))
# transmission line parameters
Deltax = COMP/(N-1)
L = LD*Deltax
C = CD*Deltax
R = RD*Deltax
G = GD*Deltax
Z0 = sqrt(L/C)
Deltat = sqrt(L*C)
ZC = Deltat/(2*CAP)
# selecting the input voltage signal
# selecting the node to get results
print('Select the input voltage signal from the following:')
print('')
print(' 1 - Boost (voltage of just one time step)')
print(' 2 - Square pulse')
print(' 3 - Atmospheric Surge (1.2 x 50 microseconds)')
print(' 4 - Switching Surge (250 x 2500 microseconds)')
print(' 5 - Sine wave')
OP = int(input('What is the option ? 1/2/3/4 or 5 ? '))
while OP != 1 and OP != 2 and OP != 3 and OP != 4 and OP != 5:
print ('Incorreto valor de OP')
OP = int(input('What is the option ? 1/2/3/4 or 5 ?'))
VS = [0.]*(KT)
sourceVoltage(KT, OP, Deltat, VS)
NO = 50 #int(input('What is the node to get results of Voltage and Current? '))
fileName = input("Enter the name of the results file: ")
file = str(fileName) #transform the name in string
outFile = open(file +'.txt', 'w') # creates the file for results
# Iterative process.
# Constituted by incidence and reflection (scattering) computation for each time
# step, and connection to the following time step.
# References: see Mauro Faccioni Filho Thesis.
# At first instant, K=0, all currents and incident voltages are equal Zero
IL = [0.]*(KT)
VIC = [0.]*(KT)
VRC = [0.]*(KT)
VC = [0.]*(KT)
IVAR = [0.]*(KT)
VID = []
VIE = []
I = []
V = []
VD = []
VE = []
VRD = []
VRE = []
for j in range(N):
line1 = [] # creates a list
for K in range (KT):
line1.append(0.0) # building the matrix: zero in all nodes
VID.append(line1)
for j in range(N):
line2 = []
for K in range (KT):
line2.append(0.0)
VIE.append(line2)
for j in range(N):
line3 = []
for K in range (KT):
line3.append(0.0)
I.append(line3)
for j in range(N):
line4 = []
for K in range (KT):
line4.append(0.0)
V.append(line4)
for j in range(N):
line5 = []
for K in range (KT):
line5.append(0.0)
VD.append(line5)
for j in range(N):
line6 = []
for K in range (KT):
line6.append(0.0)
VE.append(line6)
for j in range(N):
line7 = []
for K in range (KT):
line7.append(0.0)
VRD.append(line7)
for j in range(N):
line8 = []
for K in range (KT):
line8.append(0.0)
VRE.append(line8)
VRES=0.0
Tempo = 0.0
#### START TIME ITERATION
for K in range(KT):
for j in range(N):
if j == 0:
## excites first node
if RS == 0.0:
V[j][K]= VS[K]
else:
V[j][K] = ((VS[K]/RS) + (2*VID[j][K]/(R+Z0)))/(1/RS + 1/(R+Z0))
I[j][K] = (V[j][K] - 2*VID[j][K])/(R+Z0)
VE[j][K] = V[j][K] #### MAYBE NOT NECESSARY
VD[j][K] = 2*VID[j][K] + I[j][K]*Z0
## first node replies
VRD[j][K] = VD[j][K] - VID[j][K]
VRE[j][K] = VE[j][K] - VIE[j][K] #### MAYBE NOT NECESSARY
## connection to the next timestep
if (K+1) != KT:
VIE[j][K+1] = 0.0
VID[j][K+1] = VRE[j+1][K]
elif j == (N-1):
## region =1, V[j-1][K] <= Vlim1
## region =2, Vlim1 < V[j-1][K] < Vlim2
## region =3, Vlim2 <= V[j-1][K]
## excites last node with VARISTOR
if V[j-1][K] <= Vlim1:
V[j][K] = ((2*VIE[j][K])/Z0 + (2*VIC[K])/ZC)/(1/Z0 + 1/RL + 1/ZC)
IL[K] = V[j][K]/RL
VC[K]=V[j][K]
elif V[j-1][K] > Vlim1: # and V[j-1][K] < Vlim2: # testing with no RON
V[j][K] = ((2*VIE[j][K])/Z0 + (2*VIC[K])/ZC)/(1/Z0 + 1/RL + 1/ZC)
IL[K] = V[j][K]/RL
# I[j][K] = V[j][K]/RL # must be the IL
VC[K]=V[j][K]
IVAR[K]=(V[j][K]-2*VIC[K])/ZC
else:
V[j][K] = (2*VIE[j][K]/Z0)/(1/Z0 + 1/RL + 1/RON)
IL[K] = V[j][K]/RL
# I[j][K] = V[j][K]/RL # must be the IL
IVAR[K]= V[j][K]/RON
VC[K]= 0.0
## last node replies
if V[j-1][K] <= Vlim1:
VRC[K] = VC[K] - VIC[K]
VRE[j][K] = V[j][K] - VIE[j][K]
elif V[j-1][K] > Vlim1: # and V[j-1][K] < Vlim2: #testing with no RON
VRE[j][K] = V[j][K] - VIE[j][K]
VRC[K] = VC[K] - VIC[K]
else:
VRE[j][K] = V[j][K] - VIE[j][K]
VRC[K] = 0.0
## last node connects to the next timestep
if (K+1) != KT:
if V[j-1][K] <= Vlim1:
VIC[K+1] = VRC[K]
VIE[j][K+1] = VRD[j-1][K]
elif V[j-1][K] > Vlim1: # and V[j-1][K] < Vlim2: #testing with no RON
VIE[j][K+1] = VRD[j-1][K]
V1=VRC[K]
VIC[K+1]= procuraVAR(ZC, CONST, ALFA,V1,VRES)
else:
VIE[j][K+1] = VRD[j-1][K]
VIC[K+1]= -VRC[K]
else:
## excites each node
V[j][K] = (2*VIE[j][K]/Z0 + 2*VID[j][K]/(R+Z0))/(1/Z0 + 1/(R+Z0) + G)
I[j][K] = (V[j][K] - (2*VID[j][K]))/(R+Z0)
VE[j][K] = V[j][K]
VD[j][K] = 2*VID[j][K] + I[j][K]*Z0
## each node replies
VRD[j][K] = VD[j][K] - VID[j][K]
VRE[j][K] = VE[j][K] - VIE[j][K]
## connection to the next timestep
if (K+1) != KT:
VIE[j][K+1] = VRD[j-1][K]
VID[j][K+1] = VRE[j+1][K]
Tempo= K*Deltat
###### # write the results in a txt file
fileOut (V, I, NO, K, Tempo, file)
## testing
## print(Tempo,' ',V[0][K],' ',V[NO][K])
main()
print (time.clock() - startTime, "seconds")