Take this sample circuit:
The large resistors are Resistor_V2 (at 4D and of 500000.0 ohm) and Resistor_V1 (at 12 J and of 10000000.0 ohm).
The matrices turned out to be:
-----------------------------------------------------------------------------------------------------------
500000.0 500000.0 0.0 500000.0 500000.0
500000.0 500010.1 0.0 -500000.1 500000.1
0.0 0.0 10000010.0 0.0 -10000000.0
500000.0 -500000.1 0.0 500020.1 -499990.1
500000.0 500000.1 -10000000.0 -499990.1 10500010.1
0.0 0.0 0.0 0.0 0.0
0.0 0.0001 0.0 -0.0001 0.0001
0.0 0.0 0.1 0.0 0.0
0.0 -0.0001 0.0 0.2001 0.0999
0.0 0.0001 0.0 0.0999 0.1001
1.0
0.0
0.0
0.0
0.0
-----------------------------------------------------------------------------------------------------------
For loops defined as:
-----------------------------------------------------------------------------------------------------------
1D 2D 3D 4D 5D 6D 6C 6B 6A 5A 4A 3A 2A 1A 1B 1C 1D
1H 1G 1F 1E 1D 2D 3D 4D 5D 6D 6E 6F 6G 6H 5H 4H 3H 2H 1H
9L 10L 11L 12L 12K 12J 12I 12H 11H 10H 9H 9I 9J 9K 9L
1H 1G 1F 1E 1D 2D 3D 4D 5D 6D 6E 6F 6G 6H 6I 6J 6K 6L 5L 4L 3L 2L 1L 1K 1J 1I 1H
1H 1G 1F 1E 1D 2D 3D 4D 5D 6D 6E 6F 6G 6H 7H 8H 9H 10H 11H 12H 12I 12J 12K 12L 11L 10L 9L 8L 7L 6L 5L 4L 3L 2L 1L 1K 1J 1I 1H
-----------------------------------------------------------------------------------------------------------
Which is wrong. Because, the interaction between loop 2 and loop 4 is -500000.1 in the matrix A but should be positive from the sense of the loops above. The problem is in the code that defines the "forward" and "reverse" directions.
This is the new code (click on "view raw" to see the code in a new window):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A temporary list that stores the nodes | |
# common to two loops | |
nodes_in_loop=[] | |
# A array of all the loops of the system | |
# including common branches between loops. | |
system_loops=[] | |
for c1 in range(loop_count): | |
row_vector=[] | |
for c2 in range(loop_count): | |
row_vector.append([]) | |
system_loops.append(row_vector) | |
for c1 in range(len(loop_branches)): | |
# The diagonal elements of system_loops | |
# will be the loops themselves. | |
for c2 in range(len(loop_branches[c1])): | |
system_loops[c1][c1].append(loop_branches[c1][c2]) | |
# The system_loops array will be symmetric | |
for c2 in range(c1+1, len(loop_branches)): | |
# Find the nodes in loop1 | |
for c3 in range(len(node_list)): | |
if node_list[c3] in loop_branches[c1]: | |
nodes_in_loop.append(node_list[c3]) | |
# Find out the nodes common to loop1 | |
# and loop2. | |
for c3 in range(len(nodes_in_loop)-1, -1, -1): | |
if nodes_in_loop[c3] not in loop_branches[c2]: | |
del nodes_in_loop[c3] | |
# If there are two or more nodes common | |
# between loop1 and loop2, there are | |
# common elements. | |
if len(nodes_in_loop)>1: | |
comm_seg_in_loop=comm_elem_in_loop(loop_branches[c1], loop_branches[c2]) | |
# The list of common branches between | |
# loop c1 and loop c2 | |
sys_loop_off_diag=comm_branch_in_loop(comm_seg_in_loop, loop_branches[c1]) | |
for c3 in range(len(sys_loop_off_diag)): | |
#for c4 in range(len(sys_loop_off_diag[c3])): | |
system_loops[c1][c2].append(sys_loop_off_diag[c3]) | |
system_loops[c2][c1].append(sys_loop_off_diag[c3]) | |
# Determining the direction of common | |
# branches between loops c1 and c2 | |
for c3 in range(len(sys_loop_off_diag)): | |
st_node=sys_loop_off_diag[c3][0] | |
end_node=sys_loop_off_diag[c3][-1] | |
# Map the start and end nodes of common | |
# branch c3 to loops c1 and c2 | |
loop1_st_node=loop_branches[c1].index(st_node) | |
loop1_end_node=loop_branches[c1].index(end_node) | |
loop2_st_node=loop_branches[c2].index(st_node) | |
loop2_end_node=loop_branches[c2].index(end_node) | |
# This check is because the first node of a | |
# loop is the same as the last node. | |
# So this is to make sure, the correct start | |
# and end nodes are mapped, the difference between | |
# the indices is compared to the length of the common | |
# branch. If not equal, this means, the last node of | |
# a loop needs to be taken instead of the first node. | |
if (abs(loop1_end_node-loop1_st_node)!= (len(sys_loop_off_diag[c3])-1)): | |
if (len(loop_branches[c1])-1-loop1_st_node==(len(sys_loop_off_diag[c3])-1)): | |
loop1_end_node=len(loop_branches[c1])-1 | |
if (len(loop_branches[c1])-1-loop1_end_node==(len(sys_loop_off_diag[c3])-1)): | |
loop1_st_node=len(loop_branches[c1])-1 | |
if (abs(loop2_end_node-loop2_st_node)!= (len(sys_loop_off_diag[c3])-1)): | |
if (len(loop_branches[c2])-1-loop2_st_node==(len(sys_loop_off_diag[c3])-1)): | |
loop2_end_node=len(loop_branches[c2])-1 | |
if (len(loop_branches[c2])-1-loop2_end_node==(len(sys_loop_off_diag[c3])-1)): | |
loop2_st_node=len(loop_branches[c2])-1 | |
if (loop1_st_node<loop1_end_node): | |
loop1_dir="ahead" | |
else: | |
loop1_dir="back" | |
if (loop2_st_node<loop2_end_node): | |
loop2_dir="ahead" | |
else: | |
loop2_dir="back" | |
if loop1_dir=="ahead" and loop2_dir=="ahead": | |
sys_loop_off_diag[c3].append("forward") | |
if loop1_dir=="back" and loop2_dir=="back": | |
sys_loop_off_diag[c3].append("forward") | |
if loop1_dir=="ahead" and loop2_dir=="back": | |
sys_loop_off_diag[c3].append("reverse") | |
if loop1_dir=="back" and loop2_dir=="ahead": | |
sys_loop_off_diag[c3].append("reverse") | |
nodes_in_loop=[] |
The problem is with the judgement of length of branch with respect to the start and end nodes. The length of the branch will the number of elements in the branch. Which will be (end_node_st_node+1). This is exact block where there was the error:
-----------------------------------------------------------------------------------------------------------
if (abs(loop1_end_node-loop1_st_node)!= (len(sys_loop_off_diag[c3])-1)):
if (len(loop_branches[c1])-1-loop1_st_node==(len(sys_loop_off_diag[c3])-1)):
loop1_end_node=len(loop_branches[c1])-1
if (len(loop_branches[c1])-1-loop1_end_node==(len(sys_loop_off_diag[c3])-1)):
loop1_st_node=len(loop_branches[c1])-1
if (abs(loop2_end_node-loop2_st_node)!= (len(sys_loop_off_diag[c3])-1)):
if (len(loop_branches[c2])-1-loop2_st_node==(len(sys_loop_off_diag[c3])-1)):
loop2_end_node=len(loop_branches[c2])-1
if (len(loop_branches[c2])-1-loop2_end_node==(len(sys_loop_off_diag[c3])-1)):
loop2_st_node=len(loop_branches[c2])-1
-----------------------------------------------------------------------------------------------------------
So, the row manipulations to remove the stiff elements from the matrix produce the following matrices:
-----------------------------------------------------------------------------------------------------------
a=
500000.0 0.0 0.0 0.0 0.0
0.0 10.1 0.0 0.0999999999767 0.0999999999767
0.0 0.0 10500010.0 0.0 0.0
0.0 0.0999999999767 0.0 20.1 10.1
0.0 0.0999999999767 10.0 10.1 10.0999999996
e=
0.0 0.0 0.0 0.0 0.0
0.0 0.0001 0.0 0.0001 0.0001
0.0 0.0 0.0 0.0 0.0
0.0 0.0001 0.0 0.2001 0.1001
0.0 0.0001 0.1 0.1001 0.1001
b=
1.0
-1.0
1.0
-1.0
-1.0
-----------------------------------------------------------------------------------------------------------
The isolation has taken place. Because the two large resistors have been isolated to two separate rows. But the loop resistance between the 10000000.0 ohm resistor and the source is wrong. It should be 10000010.1 instead of 10500010.0.
Well, it doesn't blow up like before. So an improvement.
Releasing this as a new patch anyway (v0.1.2). Check on the SourceForge site soon.
No comments:
Post a Comment