Closed dlee267 closed 4 months ago
There seems to be two independent circuits. You can see this with cct.cg.draw()
Thank you for the suggestion @mph ! I knew that I could draw the circuit on latex, but i didn't know you could draw the nodes programmatically! I made an algorithm that creates random circuits for a project, and it accidentally made two disconnected loops.
So, I added this code snippet I just made to only keep the loop that contains the voltage source:
main_graph = set(cct.super_nodes[0])
main_graph_has_changed = True
cct_other = Circuit(str(cct))
cct_main = Circuit()
while main_graph_has_changed:
print(main_graph)
cct_other_new = Circuit()
graph_new = main_graph.copy()
# print(main_graph)
main_graph_has_changed = False
for netlist_line in str(cct_other).split("\n"):
# print(netlist_line)
netlist_split = netlist_line.strip().split(" ")
for i in main_graph:
# print(i, netlist_split, i == netlist_split[1], netlist_split[2] not in graph_new)
if (i == netlist_split[1]) and (netlist_split[2] not in graph_new):
graph_new.add(netlist_split[2])
cct_main.add(netlist_line)
main_graph_has_changed = True
# print(main_graph_has_changed)
break
elif (i == netlist_split[2]) and (netlist_split[1] not in graph_new):
graph_new.add(netlist_split[1])
cct_main.add(netlist_line)
main_graph_has_changed = True
break
elif netlist_split[1] in graph_new and netlist_split[2] in graph_new:
cct_main.add(netlist_line)
break
else:
cct_other_new.add(netlist_line)
# print(main_graph_has_changed)
main_graph = graph_new
cct_other = cct_other_new
print(cct_main)
# cct_main.cg.draw()
cct_main["R_ref"].v.evaluate()
I am going to put this in my codebase real quick to see if it works out; if so, I will close the comment. Thank you for the help!
On a similar note, I couldn't find a method that removes unnecessary loops given only one voltage source in the Circuit
class. I don't want to make a pull request right away in case it is not in the scope of the library, but do you think it is possible to add something like my code snippet as a method, or is it too niche of a method to add to the lcapy library?
There is no Lcapy method to do this. It would be useful to add if it was generic. Another useful method would prune any component from the netlist that doesn't have a path to the ground node.
Python 3.12.2, with lcapy 1.23
Problem
I may not see a voltage source that is short-circuited or all other concerns regarding this error, but I cannot figure out why this configuration is not solvable. Is there any reason why the matrix is not invertible, or is my formatting of my netlist giving the parser trouble? Any help will be appreciated.
Code to Run:
Output:
Edit
Since my post, I tried debugging with nodal analysis. Here are the results:
Output:
They seem to only be dependent on each other, at least according to the nodal analysis. However, the netlist shows that there are other dependencies that affect voltage of
n_r
andt2
; am I wrong in this assessment?