Code Monkey home page Code Monkey logo

circuit-simulator's Introduction

circuit-simulator

This is a version of Paul Falstad's circuit simulator (original available at http://www.falstad.com/circuit/) with the following improvements:

  • fixed import/export when running as an applet
  • it is now possible to save/load to/from a file when running as an application
  • the circuits that appear in the "Circuit" menu may now be bundled with the jar file.
  • many interface improvements: double click to edit, Delete key to delete a component, cursor changes to crosshairs when in place mode, Esc goes back to move/interact mode, ...
  • separated keyboard shortcuts from dump types (this makes it easier to configure shortcuts without changing the file format)
  • WireElm is now a subclass of ResistorElm (without this change, whenever you use two switches in parallel, you get the error "voltage source/wire loop with no resistance")
  • some cosmetic improvements (like starting with a white background as default)

compiling and building

If you have make installed, just cd to the src directory and run make, followed by a make jar

If not, compile with javac *.java and build the jar file with jar cfm circuit.jar Manifest.txt *.class *.txt circuits/

running

As an application: java -jar circuit.jar

If you want to use the circuit simulator as an applet, create an html file and load the applet with:

<applet code=Circuit.class archive=circuit.jar width=600 height=50>
    Sorry, you need a Java-enabled browser to see the simulation.
    <param name=pause value=20>
</applet>

If you want to enable import/export of circuit files, you must define two javascript helper functions in the same page:

  • exportCircuit(dump), whose first parameter is a string describing the circuit in the same format used for the circuit file.

  • importCircuit(), which must return a string describing the circuit in the same format used for the circuit file.

The definition of those functions is up to you (for instance, you may copy the string to/from a textarea).

terms and conditions

The terms and conditions for the original code still apply. Check http://www.falstad.com/licensing.html before redistributing or modifying the code. You must always consult the original licensing information but, in case the link is unavailable, here is a copy of the original license (as of 2013-05-08):

You have permission to use these applets in a classroom setting or take
screenshots as long as the applets are unmodified. Modification or
redistribution for non-commercial purposes is allowed, as long as you
credit me (Paul Falstad) and provide a link to my page (the page you
found the applet(s) on, or http://www.falstad.com/mathphysics.html).

Contact me for any other uses. The source code for each applet is
generally available on that applet's web page, but some of the applets
use third-party source code that has restrictions.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Rodrigo Hausen's changes are in the public domain (but it would be nice if you credited me alongside Paul if you use this version).

circuit-simulator's People

Contributors

hausen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

circuit-simulator's Issues

Non-ideal Wires cause Singular Matrix error

I think Non-ideal Wires in your version are causing some strange Singular Matrix errors.
It does not happen in Falstad's original version.
Two wires NOT in circuit, but connected to each other, will cause error.
Like this one.
$ 1 5.0E-6 382.76258214399064 43 5.0 43
v 80 240 176 240 0 0 40.0 10.0 0.0 0.0 0.5
s 64 128 144 128 0 0 false
s 176 112 256 112 0 0 false
s 176 240 272 240 0 0 false
r 496 272 576 272 0 100.0
r 496 192 576 192 0 100.0
w 80 240 112 352 0
w 336 192 416 272 0
w 272 240 336 192 0
w 416 192 496 192 0
w 416 272 496 272 0
w 336 192 416 192 0
w 496 192 496 144 0
w 384 64 464 64 0
w 576 144 576 192 0
w 576 192 576 272 0
w 576 272 576 336 0
w 112 352 576 336 0
w 496 272 496 224 0
w 464 64 576 64 0
w 608 224 608 272 0
w 608 272 576 272 0

And this one too.
$ 1 5.0E-6 382.76258214399064 43 5.0 43
v 48 144 144 144 0 0 40.0 10.0 0.0 0.0 0.5
s 176 96 240 96 0 1 false
s 272 128 352 128 0 1 false
s 272 48 352 48 0 1 false
w 528 192 624 192 0
w 240 96 272 128 0
w 480 96 464 160 0
w 176 96 144 144 0
w 448 272 80 256 0
r 384 160 464 160 0 100.0
r 400 96 480 96 0 100.0
w 48 144 80 256 0
w 448 272 464 160 0
w 80 416 224 480 0
w 272 48 240 96 0

Please help if you could, I am trying to use this simulator in an educational product.
Thanks.
Bin

Doesn't seem to work in macOS

I have downloaded the last .dmg and tried it on my MacBook Pro ....

Model Name: MacBook Pro
Processor Name: Dual-Core Intel Core i5
Processor Speed: 2.8 GHz
Number of Processors: 1
Total Number of Cores: 2
L2 Cache (per Core): 256 KB
L3 Cache: 3 MB
Hyper-Threading Technology: Enabled
Memory: 8 GB
OS: Big Sur 11.5.2

The nwjs.app just doesn't open any windows when run.

Any guidance anyone?
2021-09-13_19-47-37

Incompatibility with previous export lists

Just built this yesterday and tried to import a saved filed from Falstad's original. The circuit shows up, even functions correctly, but the scope displays don't work properly. I can click any point in the circuit that clearly has a changing voltage and the scope displays no voltage change at all, just a flat 0 line.

Something changed with the format for file importing in this version??

In the picture below, my mouse is hovered over the scope, highlighting the wire to left in blue that is is currently displaying. It's clearly green in the picture, and the text display on the scope even says 15V, but no waveform appears.

falstad_update_error

Non-Ideal Wires Causing Errors

Unfortunately I think the sections of code written to use realistic wires are still causing quite a few errors.

I noticed this problem when one of my circuits ran fine on Falstad's original, but yet fails to converge in this version. Setting the boolean ideal to true inside WireElm allows the circuit to run properly on this version.

Rather difficult to debug, but so far I have traced the error to the program attempting to set one of the nodes to a voltage of 2.6 billion volts.

hausen_error_1

The value of 2.6 billion volts is inserted into the array called "volts". Inside of MosfetElm, this causes execution to run inside one of these if-statements, replacing the value with lastv2 + 0.5.

hausen_error_2

After that, the convergence is set to false, here:

hausen_error_3

This repeats until it has looped the maximum of 5,000 times, where it then fails. Each time the large value of 2.6 billion alternates between being in volts[1] or volts[2]

Now trying to trace this backwards, that result of 2.6 Billion is computed inside lu_solve in the matrix called b. Harder to trace at this point because I don't know which value is incorrect.

It comes from the statement:

b[i] = tot / a[i][i]

tot = -2.6*10^21

hausen_error_4

And a[i][i] = -1*10^12, (in this case i=29)

hausen_error_5

This may or may not be of any help. At this point it becomes much harder because this is getting into all of the matrix calculations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.