Skip to main content

Spice model generator for Kicad's NGSpice solver

Generates a Kicad model and corresponding ngspice model from the provided ordinary differential equation (ODE) to be solved by NGspice. Considered ODEs are defined in this general form.

$$\dot{x}=Ax+Bu+f(x,u)$$

$$y=Cx+Du+g(x,u)$$

where

  • $x\in\mathbb{R}^n$ is the $n$ dimensional state vector
  • $u\in\mathbb{R}^m$ is the $m$ dimensional input vector
  • $y\in\mathbb{R}^r$ is the $r$ dimensional output vector
  • $A\in\mathbb{R}^{n \times n}$ is the state matrix
  • $B\in\mathbb{R}^{n \times m}$ is the input matrix
  • $C\in\mathbb{R}^{r \times n}$ is the output matrix
  • $D\in\mathbb{R}^{r \times m}$ is the input-to-output matrix
  • $f(x,u)$ vector of functions of state and input vectors
  • $g(x,u)$ vector of functions of state and input vectors

Example

Let us define an ODE where $n=2$, $m=1$, $r=2$.

import kicadODE

data = {
    'A': [
        [ -0.1, 1 ],
        [ 0, -0.1 ],
    ],
    'B': [
        [ 1 ],
        [ 0 ],
    ],
    'C': [
        [ 1e-2, 0 ],
        [ 0, 1e-2 ],
    ],
    'D': [
        [ 0 ],
        [ 0 ],
    ],
    'f': [
        '-0.01*x1^3-x2^3/33',
        'exp(-u1)',
    ],
    'g': [
        'sin(x1*x2)',
        'x1/(x2^2+1)',
    ],
    "x0": [ 1.0, -0.3 ], # Initial conditions
    "name": "test_model", # Name of Kicad model
    "to_file": True, # Exports 'test_model.lib' and 'test_model.kicad_sym'
}

kicadODE.generate(data)
print(data["lib"])
print(data["sym"])

Parameters A, B, C, D are required. If your model does not need the linear part, set A,B,C,D zero matrices with appropriate dimensions.

Parameters f and g can contain math terms which are supported by ngspice. Please, visit this page for a list of all supported functions.

Metadata

Release files for kicadODE 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kicadODE 0.1.0
File Size Uploaded
kicadODE-0.1.0.tar.gz 44.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kicadODE 0.1.0
File Interpreter ABI Platform
kicadODE-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 74.4 kB

Release files / kicadODE-0.1.0.tar.gz

Download URL kicadODE-0.1.0.tar.gz
Size 44.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e70e200bd51136055d7a8ecac54f91fa7250faa81f838cf2b32ac4debdaca28d
BLAKE2b-256 checksum
How to use checksums
eae9dc1d603959a2146bee953d8659d1ff7f0a7624389fc0237b0a30e5882947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / kicadODE-0.1.0-py3-none-any.whl

Download URL kicadODE-0.1.0-py3-none-any.whl
Size 30.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b46888fe531e1db0c701549bdae43bdc35816fc101ca020058c1566d4874098
BLAKE2b-256 checksum
How to use checksums
da06a0a2b036aff9f77e4e21c4890024677dc5bce172135879e2c7f3b30710ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page