GithubHelp home page GithubHelp logo

spicesharp / spicesharp Goto Github PK

View Code? Open in Web Editor NEW
215.0 13.0 49.0 14.71 MB

Spice# is a cross-platform electronic circuit simulator based on Berkeley Spice - the mother of commercial industry-standard circuit simulators.

License: MIT License

C# 99.61% Smalltalk 0.18% CSS 0.21%
circuit electronics spice simulator csharp net-framework net-core net-standard cross-platform berkeley-spice simulators nuget

spicesharp's Introduction

Spice# (SpiceSharp)

Spice# is a Spice circuit simulator written in C#. The framework is made to be compatible with the original Berkeley Spice simulator, but bugs have been squashed and features can and will probably will be added.

Documentation

You can find documentation at https://spicesharp.github.io/SpiceSharp/. There you can find a guide for getting started, as well as more information about:

  • Supported types of analysis.
  • The general structure of Spice#.
  • A tutorial on how to implement your own custom model equations (prerequisite knowledge needed).
  • An example of changing parameters during simulation.
  • etc.

Quickstart

Simulating a circuit is relatively straightforward. For example:

using System;
using SpiceSharp;
using SpiceSharp.Components;
using SpiceSharp.Simulations;

namespace SpiceSimulation
{
    class Program
    {
        static void Main(string[] args)
        {
            // Build the circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0.0),
                new Resistor("R1", "in", "out", 1.0e3),
                new Resistor("R2", "out", "0", 2.0e3)
                );

            // Create a DC sweep and register to the event for exporting simulation data
            var dc = new DC("dc", "V1", 0.0, 5.0, 0.001);
            dc.ExportSimulationData += (sender, exportDataEventArgs) =>
            {
                Console.WriteLine(exportDataEventArgs.GetVoltage("out"));
            };

            // Run the simulation
            dc.Run(ckt);
        }
    }
}

Most standard Spice-components are available, and building your own custom components is also possible!

Installation

Spice# is available as a NuGet Package.

NuGet Badge SpiceSharp

Current build status

Status
Windows Windows Tests
MacOS MacOS Tests
Linux/Ubuntu Linux Tests

Aim of Spice#?

Spice# aims to be:

  • A Library rather than a standalone piece of software like most simulators currently are.
  • Accessible for both the amateur and advanced electronics enthusiast (and perhaps professional designer). In order to decrease the hurdle, a Spice# parser is also being developed. This also includes it being cross-platform (.NET and Mono).
  • Compatible with the original Spice 3f5 software (without the bugs). There's a reason why this has become the industry standard.
  • Customizable with custom simulations, custom models, integration methods, solver, etc.
  • Performance, but still completely managed code. Nobody wants a slow simulator.

What Spice# is not

Having been implemented in the .NET framework does have some limitations:

  • Unmanaged C/C++ code can often be optimized more than managed code.
  • Spice# uses Reflection to give you a better experience. However if you decide to use reflection, you may feel some performance hit.

spicesharp's People

Contributors

katzb123 avatar marcin-golebiowski avatar sodalom avatar svenboulanger 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

spicesharp's Issues

ECS

Hi, I'd like to use this software in an Entity-Component-System environment. Would this require modification of any core code or can I simply use what is available as lego pieces to adapt this to fit ECS architecture?

No convergence with extremely tight tolerances

The following netlist converges to the wrong value for convergence ABSTOL=1e-20 and RELTOL=1e-16.

.MODEL mjd44h11 npn
+ IS = 1.45468e-14 BF = 135.617 NF = 0.85 VAF = 10
+ IKF = 5.15565 ISE = 2.02483e-13 NE = 3.99964 BR = 13.5617
+ NR = 0.847424 VAR = 100 IKR = 8.44427 ISC = 1.86663e-13
+ NC = 1.00046 RB = 1.35729 IRB = 0.1 RBM = 0.1
+ RE = 0.0001 RC = 0.037687 XTB = 0.90331 XTI = 1
+ EG = 1.20459 CJE = 3.02297e-09 VJE = 0.649408 MJE = 0.351062
+ TF = 2.93022e-09 XTF = 1.5 VTF = 1.00001 ITF = 0.999997
+ CJC = 3.0004e-10 VJC = 0.600008 MJC = 0.409966 XCJC = 0.8
+ FC = 0.533878 CJS = 0 VJS = 0.75 MJS = 0.5
+ TR = 2.73328e-08 PTF = 0 KF = 0 AF = 1

V1 V_B 0 10
V2 V_C 0 100
R1 V_E 0 1000
Q1 V_C V_B V_E 0 mjd44h11

The expected reference voltage V(V_E) = 9.452632245345402 (Spice 3f5)
The actual voltage V(V_E) = 2.46037709194741 (Spice#)
Note that it converges to the right value for less strict tolerances.

Missing 'Diode power'

Sorry for so many questions, but it seems to be a bug:

In Development branch, there is a attribute indicating 'Diode power' but the function related is missing.

Circuit Validation Results

Similarly to the Parser.ParseNetlist() being able to return error results rather than exceptions, it would be nice to be able to obtain the full set of Circuit Validation issues. This would allow the end-user to have greater detail on what needs to be corrected before running simulations. See issue SpiceSharp/SpiceSharpParser#142

ArgumentException When Adding Diode to Circuit

Using the latest 3.0.1 release, I get the following exception when trying to add a diode to a circuit:

ArgumentException: The parameter or property 'cd' points to both Current and Capacitance.

Note that I'm not even setting a parameter called 'cd'.

TC1,TC2 for capacitor

I've found some netlist where you can specify TC1, TC2 for capacitor.
Can I implement it in the core library? It will work similar to resistor TC1, TC2.

Singular matrix exception in MarkowitzEntireMatrix.FindPivot when DC simulating simple circuit

Hello Sven,

I am trying to run a simple dc simulation with the following code which is pretty similar to the examples from the getting started page.

`
Circuit ckt = new Circuit();

    ckt.Objects.Add(new Resistor("R1", "1", "2", 100.0));
    ckt.Objects.Add(new Resistor("R2", "2", "3", 100.0));
    ckt.Objects.Add(new Resistor("R3", "2", "3", 100.0));
    ckt.Objects.Add(new VoltageSource("V1", "3", "1", 5));
    DC dc = new DC("DC sim", "V1", 4, 5, 1);

    dc.OnExportSimulationData += (sender, args) =>
    {
        for (int i = 1; i < 4; i++)
        {
              Debug.Log(args.GetVoltage(i.ToString()));
        }
    };
    dc.Run(ckt);

`

But the following exception is thrown in the MarkowitzEntireMatrix.FindPivot function. I don't really what the function does so its hard for me to debug what's wrong. Just wondering if I set up the circuit wrong or is there something else which could be wrong?


Exception thrown: 'SpiceSharp.Algebra.SingularException' in SpiceSharp.dll
'ar-spicybread.exe' (CoreCLR: CoreCLR_UWP_Domain): 

Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\ARSpicyBreadVS.Debug_x86.Pat\System.Diagnostics.StackTrace.dll'. Cannot find or open the PDB file.
SingularException: Singular matrix

   at SpiceSharp.Algebra.Solve.MarkowitzEntireMatrix1.FindPivot(Markowitz1 markowitz, SparseMatrix1 matrix, Int32 eliminationStep)

   at SpiceSharp.Algebra.Solve.Markowitz1.FindPivot(SparseMatrix1 matrix, Int32 eliminationStep)

   at SpiceSharp.Algebra.RealSolver.OrderAndFactor()

   at SpiceSharp.Simulations.BaseSimulation.Iterate(Int32 maxIterations)

   at SpiceSharp.Simulations.DC.Execute()

   at SpiceSharp.Simulations.Simulation.Run(Circuit circuit, SimulationFlowController controller)

   at SpiceSharp.Simulations.Simulation.Run(Circuit circuit)


Thanks for the help :)

Voltage controlled current soure behavior

Following test fails. Why ?

       var ckt = new Circuit(
            new VoltageSource("V1", "1", "0", 200),
            new Resistor("R1", "1", "0", 10),
            new VoltageControlledCurrentSource("G1", "2", "0", "1", "0", 1.5),
            new Resistor("R2", "2", "0", 100));

        double current = 0.0;
        var op = new OP("op1");
        var exporter = new CurrentRealExport("I(G1)", op, "G1");
        op.ExportSimulationData += (sender, args) => { current = exporter.Extract(); };
        op.Run(ckt);
        Assert.Equal(300, current);

However following is passing:

  var ckt = new Circuit(
            new VoltageSource("V1", "1", "0", 200),
            new Resistor("R1", "1", "0", 10),
            new VoltageControlledCurrentSource("G1", "2", "0", "1", "0", 1.5),
            new Resistor("R2", "2", "0", 100));

        double current = 0.0;
        var op = new OP("op1");
        var exporter = new CurrentRealExport("I(R2)", op, "R2");
        op.ExportSimulationData += (sender, args) => { current = exporter.Extract(); };
        op.Run(ckt);
        Assert.Equal(-300, current);

Question: How to do a single-step simulation? (DC Solver)

Hi There,

Thanks for you great library, it's really easy to use. One thing troubles me is I couldn't find a way to do a simple DC solver.

According to the tutorial: "A DC simulation will (by default) sweep a voltage or current source value. The result is a DC transfer curve in function of the swept parameter." - is there anyway to do NOT sweep, but instead just give the steady state voltage values at the nodes?

For instance, for this circuit:

var ckt = new Circuit(
    new VoltageSource("V1", "in", "0", 5.0),
    new Resistor("R1", "in", "out", 1.0e4),
    new Resistor("R2", "out", "0", 2.0e4)
    );

What I could do is to initialize the simulation like this var dc = new DC("DC 1", "V1", 4.0, 5.0, 1.0); and take the last value as my result, but it just feels so weird. what I want to do is to just get the value at out when voltage is 5V.

I couldn't find out how to do that in the API manual, and I am wondering is this available?

Thanks!

Resistor enhancement

Please consider adding parameter to constructor of Resistor that specifies that _temp.Temperature(simulation) is executed in LoadBehavior of the resistor.
In other words: temperature behavior can be optionally executed on load.

Oh one more thing: K value of mutual inductance seems to be wrong

Hi Sven,

I've noticed another problem which troubles me a little :) That's the K(MUTcoupling) value of mutual inductance. Right now (using Development branch) it behaves as if MUTcoupling = 0.5 equals to K = 1.0 while MUTcoupling = 1.0 causes unpredictable behavior. I have no ability to investigate it more deeply, and therefore can only submit an issue here.

Thank for your great work again.
Best Regards

Problem about voltage loop

Hi Sven,
I've tried your spice# and find a problem which I don't know whether belongs to mine or your library.

Circuit ckt = new Circuit();
ckt.Objects.Add(
new Voltagesource("V1", "6", "gnd", 1),
new Resistor("V1-R", "gnd", "1", 1),
new Voltagesource("V2", "1", "2", 1),
new Resistor("V2-R", "2", "3", 1),
new Voltagesource("V3", "3", "4", 1),
new Resistor("V3-R", "4", "5", 1),
new Resistor("R", "1", "6", 1)
);

It shall throw an exception notifying 'voltage loop found' when performing checks.

But it's just imitating 3 non-ideal voltage source in series, along with another resistor. It is also worthy mention that 2 sources don't produce such result.

Question: How to calculate amount of current between pins?

Hi Sven,

Thank you for your hard work first - that's the cornerstone of anything grown out of it.

And here is my trivial question: how can I calculate amount of current between two connected pins without adding a trivial resistor between them (to simulate the wire between)? I know it works but wonder if Spice or Spice# has already provided some better approaches since every extra components cost performance.

PS when will the next release become available or can I use any branch beyond master for now?

Current Source - simulations

Hey there, it's me again.

I'm enjoying using your library. Could you please explain me, what am I doing wrong.

I've got two different circuits:

  1. var ckt = new Circuit(
    new CurrentSource("I1", "in", "0", 0.1),
    new Resistor("R1", "in", "out", 1.0e3),
    new Resistor("R2", "out", "0", 2.0e3)
    );
  2. var ckt2 = new Circuit(
    new CurrentSource("I1", "in", "0", 0.1),
    new Capacitor("C1", "in", "out", 1.0e-6),
    new Resistor("R2", "out", "0", 2.0e3)
    );

For the first one I've got a DC Simulation :
var dc = new DC("dc", "I1", 0.0, 5.0, 0.1);
dc.Run(ckt);
And for the second, the same simulation:
var dc2 = new DC("dc", "I1", 0.0, 5.0, 0.1);
dc2.Run(ckt2);

The second simulation returns an error :
SingularException: Singular matrix
SpiceSharp.Algebra.Solve.MarkowitzEntireMatrix1[T].FindPivot (SpiceSharp.Algebra.Solve.Markowitz1[T] markowitz, SpiceSharp.Algebra.SparseMatrix1[T] matrix, System.Int32 eliminationStep) (at <4b44f102b9d74f26b64afbe3a4e65f45>:0) SpiceSharp.Algebra.Solve.Markowitz1[T].FindPivot (SpiceSharp.Algebra.SparseMatrix`1[T] matrix, System.Int32 eliminationStep) (at <4b44f102b9d74f26b64afbe3a4e65f45>:0)
SpiceSharp.Algebra.RealSolver.OrderAndFactor () (at <4b44f102b9d74f26b64afbe3a4e65f45>:0)
SpiceSharp.Simulations.BaseSimulation.Iterate (System.Int32 maxIterations) (at <4b44f102b9d74f26b64afbe3a4e65f45>:0)
SpiceSharp.Simulations.DC.Execute () (at <4b44f102b9d74f26b64afbe3a4e65f45>:0)
SpiceSharp.Simulations.Simulation.Run (SpiceSharp.Circuit circuit) (at <4b44f102b9d74f26b64afbe3a4e65f45>:0)

Could you please explain, if I'm doing something wrong or it's a bug.

One more question from my side - am I possible to include Sin and Pulse in Current Source as in Voltage Source?

Thank you for your answer in advance.
Regards,
Simon

Add PSpice specific Evaluator

Please PSpice specific evaluator / decoder
If you add PSpice specific code, it will result in an error, e.g.:

V_V1 N14847 0
+PULSE 0V 5V 3.67us 40ns 40ns 3.255us 6.51us
V_V2 N14651 0 5Vdc
R_R1 N18055 N14538 2.2k TC=0,0
R_R2 N17129 N14555 2.2k TC=0,0
C_C1 N14538 N14569 1n TC=0,0
C_C2 N14555 N14581 330p TC=0,0
R_R3 N14677 N14651 1k TC=0,0
R_R4 N14677 0 1k TC=0,0
R_R5 N14538 N14569 68k TC=0,0
R_R6 N14555 N14581 120k TC=0,0
C_C3 N14569 N17129 10n TC=0,0
X_U6 N14677 N14538 N14651 0 N14569 MCP651
X_U7 N14677 N14555 N14651 0 N14581 MCP651
C_C4 N14847 N18055 100n TC=0,0
V_V3 M_UN0001 0 AC 0
+SIN 2.5V 2.06V 153600 0 0 0
...
MCP651.txt

Many methods are too long and need refactoring

Examples:

  • SpiceSharp.Components.BipolarBehaviors.TransientBehavior.Load()
  • SpiceSharp.Components.MosfetBehaviors.Level2.LoadBehavior.Load()
  • SpiceSharp.Components.MosfetBehaviors.Level3.LoadBehavior.Load()
  • SpiceSharp.Sparse.SparseOutput.Print()
  • SpiceSharp.Simulations.BaseSimulation.Iterate()
  • etc.

We need to be careful not to break the models! For the first 4 methods, the number of local variables exceed 64, which makes the methods slower (ref. Code Analysis CA1809).

Unable to use Inductor

Hello,
first of all thank you very much for your work. It's a pleasure to work with!

However I encountered a problem I cannot deal with. Whenever I use an inductor and check the circuit a null reference exception is thrown.

I cannot simulate or check even this simple circuit using your 1.1.0 release:

Circuit ckt = new Circuit();
      var src = new Voltagesource("V1", "A", "GND", 0);
      src.VSRCacMag.Set(12);
      ckt.Objects.Add(
        src,
        new Resistor("R1", "A", "B", 10),
        new Inductor("L1", "B", "GND", 0.000018));

      ckt.Check();

System.NullReferenceException
HResult=0x80004003
Source=SpiceSharp
StackTrace:
at SpiceSharp.Components.Inductor.Setup(Circuit ckt)
at SpiceSharp.Circuit.Setup()
at SpiceSharp.Circuits.CircuitCheck.Check(Circuit ckt)
at SpiceSharp.Circuit.Check()
at test.Program.Main(String[] args) in G:\Můj disk\schu\c#\2\test\Program.cs:line 166

What am I doing wrong? Thank you very much.

Enhancing RealPropertyExport

Is RealPropertyExport able to extract parameters from model of component ?
If it's not able, could you please add it?

FrequencyBehavior for VoltageSource

The AC excitation vector is computed in Setup. That prevents the parser from updating acmagnitude or acphase. Please consider moving following code to Load of the FrequencyBehavior:

        var radians = _ap.AcPhase * Math.PI / 180.0;
        Ac = new Complex(_ap.AcMagnitude * Math.Cos(radians), _ap.AcMagnitude * Math.Sin(radians));

Noise analysis input source is not doing anything

The input source parameter does not have any effect on the simulation output.

Double checking with Spice 3f5 confirms that the input source parameter is only used for checking that there is a non-zero AC magnitude. Afterwards, the input parameter seems to be ignored.
Reference in Spice 3f5: Libraries/CKT/noisean.c at line 52

The input equivalent noise is calculated by doing an AC analysis, and dividing the output noise by the AC output. When multiple sources have AC parameters, the AC output will be a superposition of all input contributions. This makes the input equivalent noise calculation wrong.

In order to solve this, I see the following options:

  • We can remove the input parameter and check the whole circuit that there is only one AC source available.
  • We can remove AC sources other than the input source such that the transfer function is correct.

The downside is that in the case outlined above, the simulator will not generate the same results. Although one can argue that it would lead to erroneous results anyway.

Netlist representation for debugging

Hello, how feasible is it to generate a netlist from a SpiceSharp Circuit? Is this already implemented? It would seem to be just a matter of iterating through all the Entities of the circuit and printing each. Thanks!

Inductor current

Could you please verify if an inductor current getter is properly implemented ?
I think that maybe instead of flux name there should be there i.

image

Allow lazy initialization of exporters

Exporters have to be created before running a simulation. However, many applications may require creating and removing exporters while the simulation is running.

Adding L,W parameter for MOSFET model

Is that ok to add l, w parameters to mosfet model?

Take a look at following part of netlist:

M14 12 2 15 15 NMI 
.MODEL NMI NMOS(L=2.00U W=42.0U KP=20.0U LEVEL=1 )

I could try to implement it.

Question: Issue with modeling

I am trying to model following test circuit and I am confused what would be the way of programming it in SpiceSharp specially values and function that are used here: Exm , Guv.
Please advice

I_M 0 N1 {0.02}
X_TEST N1 0 N2 M_TEST params: factor={4}

.subckt M_TEST m_in m_out v_Out params: factor=2

.func transf(m) {m*factor+3}

Vmas m_in msx {0}
Exm msx m_out value={V(v_Out)*V(v_Out)*3}
Hmss mss 0 Vmas 1

Guv 0 v_Out value={transf(V(mss))}
Ruv 0 v_Out 1

.ends

NotSupportedException: Matrices and vectors of type 'Complex' are not supported. Only Double, Single, Complex or Complex32 are supported at this point.

Hi, I'm fairly new to .net and coding in general. I am trying to build a circuit simplifer using unity and have been trying to use SpiceSharp to solve the circuits that I create. However, when I attempt to run the default dc simulation code from the wiki. I get the error: "NotSupportedException: Matrices and vectors of type 'Complex' are not supported. Only Double, Single, Complex or Complex32 are supported at this point."

The error seems to happen at runtime when the line "ckt.Simulate(dc);" is executed.

My scrpting runtime version is .Net 4.6 equivalent.

Any help would be much appreciated.

Documentation update

Hello,
could you please update the documentation file?
It would be useful for new users of your project.

Regards,
Simon

Two Capacitors in Series lead to a Rule Violation

Hello, first of all thank you for all the effort you are putting into this!

I have an issue with Capacitors:
In a simple Circuit (VoltageSource with Pulse, a Resistor and two Capacitor in Series) i get an "Floating Node Rule Violation". This only happens if i have two Capacitors. If i change the second Capacitor and replace it with a Resistor the error wont occur. Am i doing something wrong or is it a Bug?

Thank you!

The Circuit leading to the error:
CircuitTwoCapacitors

The RuleViolation:
CircuitTwoCapacitorsRuleViolations

Tickable Transient Simulation

I'd like to simulate a circuit at specified millisecond intervals to use this in a project. I've done this manually with an old version of SpiceSharp, but things are changing too much for my old TransientTickable class to work any more. Is there any way we could get a Transient.Tick(milliseconds) function?

Capacitor in Series leads to a Rule Violation

Hello, first of all thank you for all the effort you are putting into this!

I have an issue with Capacitors:
In a simple Circuit (VoltageSource with Pulse, a Resistor and two Capacitor in Series) i get an "Floating Node Rule Violation". This only happens if i have two Capacitors. If i change the second Capacitor and replace it with a Resistor the error wont occur. Am i doing something wrong or is it a Bug?

Thank you!

The Circuit leading to the error:
CircuitTwoCapacitors

The RuleViolation:
CircuitTwoCapacitorsRuleViolations

SpiceSharp.CircuitException: Non-convergence error message

Hi,
Im learning SpiceSharp + SpiceSharpBehavioral, I created simple parallel circuit without using behavioral elements and it is working fine, when I use some of the elements from SpiceSharpBehavioral like BehavioralCurrentSource I get error "SpiceSharp.CircuitException: 'Non-convergence, node Node m_in (Voltage) is not a number.'", any ideas how to solve this?

Question: Maximum reasonable circuit size

Hi,

I am currently working on a project using Spice#. My goal is to make a DC simulation of some big circuits (hundreds of resistors + hundreds of diodes + tenths of transistors + a couple of sources to drive a transistor). I would like to obtain a couple of operating points. After creating and validating a circuit with the previous characteristics, the simulations returns the "Could not determine operating point" exception. After increasing the number of iterations the result was the same and, when I lowered the Gmin parameter to 1e-18, the simulation returned the "Singular matrix" exception. Now I am wondering if there are any other parameters I can tweak to make it converge (like tolerances), or if the circuit is just too big to be handled by the library. In the latter case, do you have an idea of the maximum number of components it is reasonable to simulate?

Thank you in advance.

Regards,

Ricardo

Export methods and AC analysis do not use latest iteration

Most devices will use state.OldSolution or the last state variable in state.States[0] (which are solutions to the previous iteration) as opposed tostate. Solution (the solution of the current iteration) to calculate small-signal parameters for AC analysis. I believe this is not logical, as the most recent iteration should be a better approximation to the real solution.
The same happens for a lot of extract methods of devices.

Note that changing this breaks tests, because Spice 3f5, which is used as a reference, does this as well. I do not think other Spice-derivatives will have changed this (from what I could see ngSpice didn't).

Postprocessing data (Alternative to .MEASURE)

Hi, this is not really an issue, just the easiest way to contact you (hope that's ok).

I have tools to post process simulation results, if you need them:

  • Read in SPICE data files.
  • Collect data from multi-dimensional parametric sweeps into single variable.
  • Operate on multi-dim data using simple expressions.
  • Use expressions that are easier to write than Matlab code.
  • Automatic interpolation: Operate seamlessly on results from 2 different simulation runs (different time steps).
  • Look at results with a fast, interactive plotting tool.
    • Add H/V, and "Delta" markers to mark/measure points of interest.
    • Create high-quality .SVG/PNG/... outputs for design reviews.

Links

NOTE: These tools are written in Julia. Julia is a FREE, MIT-conceived language that is fast, and EXTREMELY mathematically oriented. It has the ease of use of MATLAB & Python, speeds approaching C, and many LISP influences. Julia is very well constructed: it does NOT have the unpolished feel of most open-source tools I have used (ex: gnu-octave).

Comparison to .MEASURE

Most simulators require you to re-simulate if you decide to modify .MEASURE statements (part of the netlist).

Instead, with MDDatasets, you should save all nodes of interest and POST-process the simulation results. This allows you to only re-run derived calculations instead of having to re-simulate the circuit itself.

Use in Conjunction with .MEASURE

Note that you could still compute results of interest using .MEASURE statements, then load/plot them with MDDatasets.jl/InspectDR.jl if you prefer.

Running a Simulation with an Invalid Circuit

I haven't fully worked my way through Circuit construction, Circuit validation and Circuit simulation, but I am not clear on why a Circuit does not have an IsValid property. The Circuit class does have a Validate() method, but all it does is return a CircuitException if a validation rule fails ( #96 ).
Perhaps the Circuit class could contain an IsValid property that calls the Validate() method when the circuit entity items have changed ( a needs validation flag ). This could then be used by the Simulation.Run( entities ) method to check if a circuit is valid before running simulations.

Separating DC, AC and Transient behaviors

Right now all calculations for DC, AC and Transient analysis are combined into one behavior ("Load" behavior). It might be more logical to separate them into separate behaviors. One for each type of analysis.

Proposition:

  • DC behavior will calculate all DC currents and load the Y-matrix and Rhs-vector
  • Transient behaviors will integrate using the current integration method and add contributions to the Y-matrix and Rhs-vector
  • AC behavior will extract simulation parameters for small-signal analysis, and a second method for loading the Y-matrix and Rhs-vector

Missing convergence tests

Device-specific convergence tests are missing.
Load behaviors often contain parts of convergence tests, and probably became separated later. This can be removed as well.

Changing circuit topology during simulation

The circuit topology can't be changed once a simulation has been started. We could include the feature of adding and removing components during the simulation (mainly transient simulations).

I foresee the following difficulties:

  • Adding/removing a component mid-simulation can cause convergence problems and a severe timestep truncation in transient analysis.
  • Adding/removing a component in a time analysis would need to be timestamped. If the timestep is truncated to a moment before the component is added. The component should be temporarily removed then. Can be avoided when not using timestep truncation.
  • Columns and rows need to be added/removed during simulation. This is not part of the current framework. This should be done carefully to avoid creating singular matrices.
  • Integration states need to be added/removed during simulation. This is not part of the current framework.
  • An added element would need some kind of initial condition.

Allowing dynamic behaviour executing during transient simulation

We're currently trying to use Spice# for some interactive circuit simulation, which requires to slightly modify components' parameters during simulation loop (we use event to intercept iteration and inject modification). In current release we can call temperature function, yet after switching to development branch the function has been moved; we therefore create a ResistorTemperatureBehavior and call it instead.

I'm not so familiar with this kind of Spice usage before (since this is the first thing that can work as a library), and I don't know whether my current method will cause some unknown problems. If that's really possible (in our test cases that really works, but I am not sure about its theoretical certainty), maybe you can allow your main library do it without hijacking.

Question: Do I have any way to change some parameters in-simulation?

Dear developer of Spice#,

It's a question which can be solved by 2 ways, while I know neither of them.

  1. Can I pause a transient simulation (or stop it) and resume it with some parameters changed, while others remain the same? (e.g the capacitor has the same voltage as initial condition, the AC source has the same phase, etc.) What if new elements are added or removed?
  2. Can I modify some parameters in a transient simulation on-the-fly (not pausing or stopping the simulation, e.g I can inject something when exporting), like the voltage of a capacitor, resistance of a resistor, and so on?

It's late now and sorry for my chaotic expression yet I believe that I stated the problem clearly enough lol.

Best Regards

Voltage source & inductor bug

Hi sven,

I noticed a strange behaviour where in transient simulation:

  1. Connect a voltage source, an inductor and a resistor;
  2. Give the voltage source an initial voltage;
  3. Start the simulation, and the resistor has a burst in power & current as if the inductor is releasing energy;
  4. If we give the voltage source initially zero voltage and something after 1 export, the resistor slowly grows its power as if the inductor is accumulating energy.

I don't know whether it's an Spice-defined behaviour or not so what I can do is to report it here.

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.