I love tinkering with circuit simulators - this one seems really cool too, great work! Just wondering, from a programmer perspective: how do you simulate electricity? If you model a circuit in CircuitVerse, how similar would the results be to a real-world version?
This one doesn't "simulate electricity" per se; it's a digital simulator, which means it evaluates the output of each node based on its inputs, and propagates the changes as necessary. The core principle is a discrete event simulator:
If you model a circuit in CircuitVerse, how similar would the results be to a real-world version?
As long as the gate delays and fanin/fanout are considered, the results would be logically valid. For simulation of more analogue effects (e.g. what happens if you connect the outputs of two gates together, and one tries to pull it high and the other low?) something like SPICE is necessary:
It's possible to combine event-driven simulation (for digital) and nonlinear differential equation based simulation (for analog) within the same simulator. The simulation engine can be smart enough to mix the two efficiently. As a toy model, consider this 4-bit counter plus DAC (click "Simulate" at the bottom):
The simulation loop is both event driven (when CLK1 flips state every 0.5 seconds), propagating those changes through combinatorial gates, and analog, simulating the op-amp to create a simple digital-to-analog converter (DAC). Bridging the analog and digital sides within the simulator is tricky, but not impossible.
You are correct that if there were not both event-driven and analog simulation intermixed, and we simply simulated all the digital gates with their analog implementations in MOSFETs, that simulation would be at least an order of magnitude slower -- probably far worse!
(Disclosure: I built CircuitLab's simulation engine.)
Your analysis is correct with respect to circuitverse. This is just to test the logic correctness of your design after abstracting away the analog and real world nature of electricity.
When you model by hand you typically use ideal models. SPICE models can be vastly more complex. A good example is a diode which is harder to model as it's a non-linear device.
Simulated "electricity" (voltage and current) is reduced to a set of differential equations, which the program then uses to plot charts.
Electricity is not the phenomenon being simulated. The circuit and its component is. For example in SPICE, there is no electromagnetic wave, and you need additional software packages for antenna and EMI/EMC analyze.