Advertisement
Rujeerat

Untitled

Nov 4th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.01 KB | None | 0 0
  1. # f2py -h only: Pre_xt1 Pre_vc Pre_PM duringpost : n.f95
  2. # f2py -c n.f95 -m calcu n.o
  3. import calcul
  4. import openpyxl
  5. import time
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8. start_time = time.time()
  9. book = openpyxl.load_workbook('data.xlsx')
  10. sheet = book.active
  11. data = []
  12. for ro in range(2,6):
  13.     for co in range(1,8):
  14.         #print('co =%d ro =%d' % (co, ro))
  15.         a3 = sheet.cell(row=ro, column=co)
  16.         data.append(a3.value)
  17.  
  18.  
  19.  
  20.     #รับค่าจาก excel และเปลี่ยนชนิดตัวแปร
  21.     v1, v2, P, x1o, x2o, x3o, xgo = data
  22.     x1 = complex(x1o)
  23.     x2 = complex(x2o)
  24.     x3 = complex(x3o)
  25.     xg = complex(xgo)
  26.  
  27.  
  28.     # ฟังชั่นการคำนวณจากฟอร์แทรน
  29.     x12 = calcul.pre_xt1(x1, x2, x3)
  30.     Vcurrent = calcul.pre_vc (v1, v2, P, x12)  # <class 'tuple'>((0.9+0.3j), (1+0.1j))
  31.     Voltage = Vcurrent[0]
  32.     Curr = Vcurrent[1]
  33.     PmEg = calcul.pre_pm(Voltage, v2, xg, x12, Curr)  # <class 'tuple'>
  34.     Pemax = PmEg[0]
  35.     Eg = PmEg[1]
  36.     ceta = np.arctan(Eg.imag/Eg.real)
  37.     Pt = calcul.duringpost(x1,x2,x3,xg,Eg,v2)
  38.  
  39.     # แสดงผลการคำนวณและกราฟ
  40.     print('Voltage Bus 1 = %.4f +%.4fi' % (Voltage.real, Voltage.imag))
  41.     print('Current in transmission lines = %.4f +%.4fi' % (Curr.real, Curr.imag))
  42.     print('Eg = %.4f +%.4fi' % (Eg.real, Eg.imag))
  43.     print('----- Power angle equation -----')
  44.     print('Pre fault P = %.3fsin(δ)' %(abs(Pemax)))
  45.     print('During fault P = %.3fsin(δ)' %(abs(Pt[0])))
  46.     print('Post fault P = %.3fsin(δ)' %(abs(Pt[1])))
  47.     print('--------------------------------')
  48.     x = np.linspace(0, np.pi, 200 )
  49.     plt.plot(x,abs(Pemax)*np.sin(x),label = "Pre fault")
  50.     plt.plot(x,(abs(Pt[0]))*np.sin(x),label = "During fault")
  51.     plt.plot(x, (abs(Pt[1]))*np.sin(x), label = "Post fault")
  52.     plt.xlabel('δ [rad]')
  53.     plt.ylabel('Power [pu]')
  54.     plt.legend()
  55.     plt.show()
  56.  
  57.     data = []
  58. print("finish")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement