circuitjs1 icon indicating copy to clipboard operation
circuitjs1 copied to clipboard

Using Sparse Matrix LU to Decompose and Solve Equations

Open H-Dynamite opened this issue 6 months ago • 9 comments

The use of sparse matrices can greatly improve simulation speed. This sparse matrix and sparse matrix LU decomposition are extracted from the EJML project and can be compatible with the GWT project. We hope to merge them into the project and make a contribution to open source development。

H-Dynamite avatar Dec 17 '23 09:12 H-Dynamite

Maybe that's a good idea. Such global implementations should be offered to the main repository: https://github.com/pfalstad/circuitjs1. Then I would still take this code to this repository.

@pfalstad look at this. Patch for your project: 17.patch.zip

SEVA77 avatar Dec 20 '23 23:12 SEVA77

Maybe that's a good idea. Such global implementations should be offered to the main repository: https://github.com/pfalstad/circuitjs1. Then I would still take this code to this repository.

@pfalstad look at this. Patch for your project: 17.patch.zip

Well, I tested the performance and it's much faster than before. It can support circuits with at least a few thousand nodes. If this project is used for large-scale circuit simulation, there is still a lot of room for optimization. The main branch of this project was originally this https://github.com/pfalstad/circuitjs1 I always thought it was https://github.com/sharpie7 . Do I need to create another dropdown request for the main warehouse? I'm not very good at playing Git

H-Dynamite avatar Dec 23 '23 07:12 H-Dynamite

Wow that sounds great, I’ll definitely take a look! Thanks!

pfalstad avatar Dec 24 '23 08:12 pfalstad

Wow that sounds great, I’ll definitely take a look! Thanks!

Should li-zhenhai create pull request for your repository?

SEVA77 avatar Dec 24 '23 16:12 SEVA77

Yes, that would be easiest for me.

pfalstad avatar Dec 24 '23 17:12 pfalstad

that would be easiest for me

If you're trying to embed parts of his code in your project, you can just apply my patch:

cat 17.patch | patch -p1

for test this patch:

cat 17.patch | patch -p1 --dry-run

These patches are extracted from any pull requests ("Add .patch or .diff to the end of URLs") but I modified this patch because we have different paths to the source code.

SEVA77 avatar Dec 24 '23 19:12 SEVA77

Ok I finally took a look at this and it seems slower, at least on the circuits I tested it on. I tested it with the circuit examples Op Amps->741 Internals and Analog/Digital->QAM-256, and they both seemed a bit slower. Maybe it's only better with some types of circuits, like very large ones? I don't have any circuits with a few thousand nodes to try it on.

pfalstad avatar Jan 23 '24 07:01 pfalstad

Analog/Digital->QAM-256 I used the file "Prova8. circuitjs. txt" from the questioner of this issue for testing,For large circuits, use the default step size of 5 μ s. The calculation is slow, even if the step size is adjusted to 500 μ s. Still slow, use sparse matrix and adjust step size to 500 μ s. The performance improvement for large circuits is very obvious, and I may have forgotten to tell you that large circuits need to adjust the step size to 500 μ s. Even larger step sizes can be adjusted according to the size of the circuit,

A set of test results Refresh Time (Normal LU Decomposition) Refresh Time (Sparse Matrix LU Decomposition) Matrix Size


2167 milliseconds 414.0 milliseconds 1232 7324 milliseconds 532 milliseconds 1592 32102 milliseconds 618 milliseconds 2352 No test 1441 milliseconds 3511

Using a better sparse matrix structure can be faster and support larger matrices. Below are the test results: Refresh Time (Sparse Matrix LU Decomposition) Matrix Size


400ms 24470/22100 430ms 48870/44200 460ms 73270/66300 550ms 122070/110500

H-Dynamite avatar Jan 26 '24 04:01 H-Dynamite

Well, I can see why making a pull request from the master branch is a bad idea. @H-Dynamite Transfer your development to a clone of Falstad’s repository but make sure that you create a separate branch for each of your ideas. Mixing your commits that add sparse matrix LU with commits that fix code style into one pull request is a bad idea for me: This will make it much more difficult to add changes from the Falstad’s repository.

It should also be recognized that my repository is not yet suitable for third-party developers. I need to do a lot of work to automate the application build at all stages. Additionally, there will be many other changes on my part, including updating the license to GPL v3.

SEVA77 avatar Mar 04 '24 20:03 SEVA77