How to get the element matrix from a schematic?

Where in the documentation can I find the schematics file format.

https://dev-docs.kicad.org/en/file-formats/

1 Like

Be aware that the schematic file format will change drastically with version 6

1 Like

is there a way to export the elemental matrix from the schematics? API, through the GUI, or any other way?

I did a search on this term because I have no idea what that means in this context. The files are text based so nothing is actually hidden. A bit of code? SED?

1 Like

I’d like to test an in-house solver. The idea is to be able to export the “Elemental Matrix” meaning the matrix that contains my RL components. Generally the equation will be of the form Ax’ + Bx = f, where A and B are matrices populated with the components (R L or C) and the x’ the derivative of the unknowns and x unknowns and unknowns in terms of currents and voltages. The right-hand side f the definition of the source. I’d like to know if I can somehow obtain A and B from KiCad. If so, what would be the suggested/easiest way. If further explanation is needed please let me know. Thanks in advance.

Can you provide example of such matrixes ?

Generally kicad has no idea what R, L, C or any other component means or does, it just captures which pins of the symbols you placed are connected to which other pins (and a bit of metadata which is not relevant here).
So unless what you need can be extracted from that information (it’s called netlist and can be exported in number of formats from tools menu) then the answer is no.

1 Like

I’ve got a three phase system that reads:

Ldt iA + RiA = Voltage_A

Ldt iB + RiB = Voltage_B

Ldt iC + RiC = Voltage_C

so at the moment I populate my matrix manually to ensure KVL/KCL. This case is simple but tedious. I am connecting my circuit in Delta and the DoF vector component contains the voltage and currents across each component.

I add the resistance some other way but this is more or less the concept. I want to know if there’s a way to get matrices A or B or both.

Thanks

It appears that you are doing circuit analysis or simulation. Those are much different topics from what KiCAD is intended for. The information you are seeking is probably more easily extracted from the KiCAD “Netlist” file, or a SPICE netlist.

For several years, the KiCAD project has put time and effort into interfacing KiCAD with the NgSPICE circuit simulation tool. I have not paid attention to that effort, nor used the NgSPICE interface because I am satisfied by my current (no-charge) circuit simulation tool.

Users, or developers, in the NgSPICE Sub-Forum may be helpful to you.

Dale

2 Likes

I was wondering if this might be something more up @holger 's alley.

1 Like

Indeed ngspice offers the commands ‘mdump’ and ‘mrdump’ to dump the matrix and RHS matrix contens to the console or into a file (see ngspice manual chapt. 17.5.44).

The usage of these commands in conjuction with the KiCad/ngspice interface is somewhat tricky though.

To figure that out, could you please provide a (simple) KiCad project here with a circuit ready for simulation? I will then check how to add the two commands.

5 Likes

@holger. Since I’m a new user it won’t let me share a simple kicad project as an attachment. Hence, I’ll just copy the .sch file onto here. It’s just a dummy circuit with a resistor and an inductor connected in series.

/----------------------------------/

EESchema Schematic File Version 4
EELAYER 30 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title “”
Date “”
Rev “”
Comp “”
Comment1 “”
Comment2 “”
Comment3 “”
Comment4 “”
$EndDescr
$Comp
L pspice:0 #GND?
U 1 1 60C09794
P 3500 3450
F 0 “#GND?” H 3500 3350 50 0001 C CNN
F 1 “0” H 3600 3400 50 0000 C CNN
F 2 “” H 3500 3450 50 0001 C CNN
F 3 “~” H 3500 3450 50 0001 C CNN
1 3500 3450
1 0 0 -1
$EndComp
$Comp
L pspice:R Rst
U 1 1 60C09EC1
P 4450 2100
F 0 “Rst” V 4245 2100 50 0000 C CNN
F 1 “10k” V 4336 2100 50 0000 C CNN
F 2 “” H 4450 2100 50 0001 C CNN
F 3 “~” H 4450 2100 50 0001 C CNN
1 4450 2100
0 1 1 0
$EndComp
$Comp
L pspice:VSOURCE Vs
U 1 1 60C0B774
P 3500 2650
F 0 “Vs” H 3728 2696 50 0000 L CNN
F 1 “dc 0 ac 1” H 3728 2605 50 0000 L CNN
F 2 “” H 3500 2650 50 0001 C CNN
F 3 “~” H 3500 2650 50 0001 C CNN
1 3500 2650
1 0 0 -1
$EndComp
Wire Wire Line
3500 2350 3500 2100
Wire Wire Line
3500 2100 4200 2100
Wire Wire Line
4700 2100 5450 2100
Wire Wire Line
3500 3450 3500 2950
$Comp
L pspice:0 #GND?
U 1 1 60C10F17
P 5450 3450
F 0 “#GND?” H 5450 3350 50 0001 C CNN
F 1 “0” H 5450 3539 50 0000 C CNN
F 2 “” H 5450 3450 50 0001 C CNN
F 3 “~” H 5450 3450 50 0001 C CNN
1 5450 3450
1 0 0 -1
$EndComp
$Comp
L pspice:INDUCTOR Lew
U 1 1 60C11C37
P 5450 2700
F 0 “Lew” V 5404 2778 50 0000 L CNN
F 1 “1m” V 5495 2778 50 0000 L CNN
F 2 “” H 5450 2700 50 0001 C CNN
F 3 “~” H 5450 2700 50 0001 C CNN
1 5450 2700
0 1 1 0
$EndComp
Wire Wire Line
5450 3450 5450 2950
Wire Wire Line
5450 2450 5450 2100
$EndSCHEMATC

/---------/

Any pointers are appreciated

Quite fun & creative solution around this automated anti-spam feature.
Somewhere in the copy / paste / translation however, the “normal double quotes” got replaced by “upquotes” and “downquotes” (or whatever their official names are.) and therefore it did not work at the first try.
But a bit of search & replace in a text editor solved it quickly.
I do not know much of ngSpice, so can’t help there.

The schematic looks like:
image

The zipped project (KiCad added a project file):

2021-06-09_ckts_Schematics_Format.zip (1.3 KB)

1 Like

If you paste source code to the text editor, mark it and choose “preformatted Text” to avoid mangling the double quiotes (and may be other special characters).

Attached you will find the Eeschema file with my enhancements.

Basically it is annotating the devices (add numbers to their names) to enable simulation and then a ngspice script in a text box by using the “Place Text” command.

.ac dec 10 100 1Meg
.control
set controlswait
mdump D:\Spice_general\kicad\ckts\mmat.txt
mrdump D:\Spice_general\kicad\ckts\mrmat.txt
.endc

What does this script do? It adds the simulation command (.ac …).
Then it adds a control section (containing the ngspice script).
By selecting ‘Simulator’ and pushing the 'Run Simulation" button, this script will prepare an ac simulation. Eeschema adds this text to the generated ngspice netlist, sends it to ngspice and starts the simulation. Further processing (setting up the matrix, simulation) is exclusively done by ngspice, only the output data will get back to Eeschema for plotting.
Command ‘set controlswait’ cares for delaying all following commands until the simulation has finished, then ‘mdump’ and ‘mrdump’ will print the matrix and right hand side. You will have to modify the path and filename in the textbox for the output files according to your setup.

There is a small caveat in that mrdump opens its output file in an append mode (I will change that), so you have to delete the previous file before getting a new output.

ckts.sch (1.9 KB)

2 Likes

Software shows you are now a ‘basic’ user. If you have problems uploading just send me a private message.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.