MatyasVasek / SymCirc

This project aims to be a light-weight comprehensive tool for symbolic circuit analysis. It is primarily developed for the web-based simulator GEEC.
https://matyasvasek.github.io/SymCirc/
MIT License
2 stars 0 forks source link

Controlled sources results #8

Open OndrejBukovsky opened 1 month ago

OndrejBukovsky commented 1 month ago

Describe the bug I'm not sure if controlled sources are fully supported already. If they are, the semi-symbolic DC analysis returns strange results. The values aren't fully evaluated, and there are odd keys like "'v(*shortVsense)': -100.000".

To Reproduce

from symcirc import *

netlist = """
*GEEC circuit number #1850
V1 ctrl1 0 DC 500m AC 0 0
Vsense 2 1 DC 0 AC 0 0
R1 1 0 1k 
R2 3 0 1k 
E1 ctrl2 0 ctrl1 0 2 
G1 2 0 ctrl2 0 100m 
F1 3 0 Vsense -5 
H1 7 0 Vsense 100 
"""
circuit = AnalyseCircuit(netlist, "DC", symbolic=False, method="tableau")
results = circuit.node_voltages()
results.update(circuit.component_values("all"))

print(results)

Output

{'v(ctrl1)': 0.500000, 'v(2)': -100.000, 'v(1)': -100.000, 'v(3)': -50.0*v(7) - 500.0, 'v(ctrl2)': 1.00000, 'v(7)': None, 'v(*shortVsense)': -100.000, 'v(V1)': 0.500000, 'i(V1)': 0, 'v(Vsense)': 0, 'i(Vsense)': -0.100000, 'v(R1)': -100.000, 'i(R1)': -0.100000, 'v(R2)': -50.0*v(7) - 500.0, 'i(R2)': -0.05*v(7) - 0.5, 'v(E1)': 1.00000, 'i(E1)': 0, 'v(G1)': -100.000, 'i(G1)': 0.100000, 'v(F1)': -50.0*v(7) - 500.0, 
'i(F1)': 0.05*v(7) + 0.5, 'v(H1)': v(7), 'i(H1)': 0}
MatyasVasek commented 1 month ago

Sorry for the long delay. I'm working on identifying the source of this issue, it's probably an error in the CCVS implementation.

MatyasVasek commented 1 month ago

Ok, so I think I've located two issue sources: 1) *short is a virtual node generated for the tableau method matrix, it is supposed to be filtered out of the results after analysis, this will be fixed soon 2) There's a bug which happens when multiple current controlled sources are assigned the same Vsense. The results are correct after adding a second Vsense. This bug should therefore affect only circuits where multiple current controlled sources (CCVS, CCCS) have the same Vsense.

Workaround before fix:

netlist = """
*GEEC circuit number #1850
G1 2 0 ctrl2 0 100m
F2 3 0 Vsense1 -5
E1 ctrl2 0 ctrl1 0 2
H2 7 0 Vsense2 100
V1 ctrl1 0 dc 500m
R1 1 0 1k
R2 3 0 1k
Vsense2 2 4 dc 0
Vsense1 4 1 dc 0
"""
MatyasVasek commented 1 week ago

@OndrejBukovsky Update: I've finally managed to solve this issue, it took more time than I initially expected. I will run some more tests and then publish a new version of SymCirc on PyPi. (v0.1.3)