-
Notifications
You must be signed in to change notification settings - Fork 0
/
solver_test.py
34 lines (25 loc) · 3.63 KB
/
solver_test.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
import unittest
from solver import *
from test import test_support
class SolverTest(unittest.TestCase):
# Only use setUp() and tearDown() if necessary
def setUp(self):
#... code to execute in preparation for tests ...
pass
def tearDown(self):
#... code to execute to clean up after tests ...
pass
def test_jacobian_calculation(self):
y = array([[0.0000 -17.3611j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 +17.3611j,0.0000 + 0.0000j,0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j ], [0.0000 + 0.0000j,0.0000 -16.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j, 0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 +16.0000j,0.0000 + 0.0000j ], [0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 -17.0648j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 +17.0648j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j ], [0.0000 +17.3611j,0.0000 + 0.0000j,0.0000 + 0.0000j,3.3074 -39.3089j,1.9422 +10.5107j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,1.3652 +11.6041j ], [0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,1.9422 +10.5107j,3.2242 -15.8409j,1.2820 + 5.5882j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j ], [0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 +17.0648j,0.0000 + 0.0000j,1.2820 + 5.5882j,2.4371 -32.1539j,1.1551 + 9.7843j,0.0000 + 0.0000j,0.0000 + 0.0000j ], [0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,1.1551 + 9.7843j,2.7722 -23.3032j,1.6171 +13.6980j,0.0000 + 0.0000j ], [0.0000 + 0.0000j,0.0000 +16.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j, 0.0000 + 0.0000j,1.6171 +13.6980j,2.8047 -35.4456j,1.1876 + 5.9751j ], [0.0000 + 0.0000j,0.0000 + 0.0000j,0.0000 + 0.0000j,1.3652 +11.6041j,0.0000 + 0.0000j, 0.0000 + 0.0000j,0.0000 + 0.0000j,1.1876 + 5.9751j,2.5528 -17.3382j]])
v = ones(9)
pv = [1,2]
pq = [3,4,5,6,7,8]
pvpq= [1,2,3,4,5,6,7,8]
j = calculateJacobian(y, v, pv, pq, pvpq)
j_correct = [[-16,0,0,0,0,0,16,0,0,0,0,0,0,0],[0,-17.0648464163823,0,0,17.0648464163823,0,0,0,0,0,0,0,0,0],[0,0,-39.9953822108554,10.8695652173913,0,0,0,11.7647058823529,3.30737896202531,-1.94219124871473,0,0,0,-1.36518771331058],[0,0,10.8695652173913,-16.7519181585678,5.88235294117647,0,0,0,-1.94219124871473,3.22420038713884,-1.28200913842411,0,0,0],[0,17.0648464163823,0,5.88235294117647,-32.8678342781936,9.92063492063492,0,0,0,-1.28200913842411,2.43709661931421,-1.15508748089010,0,0],[0,0,0,0,9.92063492063492,-23.8095238095238,13.8888888888889,0,0,0,-1.15508748089010,2.77220995413623,-1.61712247324614,0],[16,0,0,0,0,13.8888888888889,-36.1000690131125,6.21118012422360,0,0,0,-1.61712247324614,2.80472685253729,-1.18760437929115],[0,0,11.7647058823529,0,0,0,6.21118012422360,-17.9758860065765,-1.36518771331058,0,0,0,-1.18760437929115,2.55279209260173],[0,0,3.30737896202531,1.94219124871473,0,0,0,1.36518771331058,38.6223952413826,10.8695652173913,0,0,0,11.7647058823529],[0,0,1.94219124871473,3.22420038713884,1.28200913842411,0,0,0,10.8695652173913,14.9299358698911,5.88235294117647,0,0,0],[0,0,0,1.28200913842411,2.43709661931421,1.15508748089010,0,0,0,5.88235294117647,31.4398893320203,9.92063492063492,0,0],[0,0,0,0,1.15508748089010,2.77220995413623,1.61712247324614,0,0,0,9.92063492063492,22.7969742370194,13.8888888888889,0],[0,0,0,0,0,1.61712247324614,2.80472685253728,1.18760437929115,0,0,0,13.8888888888889,34.7911572473216,6.21118012422360],[0,0,1.36518771331058,0,0,0,1.18760437929115,2.55279209260173,11.7647058823529,0,0,0,6.21118012422360,16.7005741863205]]
print j
print j_correct
def test_main():
test_support.run_unittest(SolverTest)
if __name__ == '__main__':
test_main()