SpiceSharp / SpiceSharpBehavioral

This library extends Spice# components with behavioral sources for modelling electronics circuits.
MIT License
6 stars 5 forks source link

SpiceSharpBehavioral

This library extends Spice# components with behavioral sources for modelling electronics circuits.

Documentation

The API can be found here

Quickstart

Including this library allows you to use two extra components:

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

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0.0),
                new BehavioralVoltageSource("A1", "out", "0", "V(in)^2+2"));

            var dc = new DC("dc", "V1", -1, 1, 0.1);
            dc.ExportSimulationData += (sender, e) =>
            {
                Console.WriteLine(e.GetVoltage("out"));
            };
            dc.Run(ckt);
            Console.ReadKey();
        }
    }
}

Installation

Spice#.Behavioral is available as a NuGet package.

NuGet Badge Spice#.Behavioral

How does it work?

The parser parses expressions into functions. It automatically constructs derivatives to other unknown variables (eg. "V(in)"), to be able to correctly load the Y-matrix and Rhs-vector each iteration. Still, there are some things it cannot do:

Please use the library with care.

Current build status

Platform Status
Windows Windows Tests
Linux (Mono) Linux Tests
MacOS (Mono) MacOS Tests

Aim of Spice#.Behavioral?

The aim is to provide an easier way of prototyping models in the Spice# simulator. While it is technically possible for anyone to extend Spice# with custom models and components to have full control over its behaviors, Spice#.Behavioral takes away a lot of that work.

Advantages:

Disadvantages: