This library extends Spice# components with behavioral sources for modelling electronics circuits.
The API can be found here
Including this library allows you to use two extra components:
BehavioralVoltageSource
BehavioralCurrentSource
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();
}
}
}
Spice#.Behavioral is available as a NuGet package.
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.
Platform | Status |
---|---|
Windows | |
Linux (Mono) | |
MacOS (Mono) |
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: