├── PySpice ├── Doc │ ├── __init__.py │ └── ExampleTools.py ├── Config │ ├── __init__.py │ ├── logging.yml │ └── ConfigInstall.py ├── Logging │ └── __init__.py ├── Physics │ ├── __init__.py │ ├── Resistor.py │ └── MaterialProperties.py ├── Plot │ └── __init__.py ├── Probe │ ├── __init__.py │ └── Plot.py ├── Scripts │ └── __init__.py ├── Tools │ ├── __init__.py │ └── Path.py ├── Spice │ ├── Xyce │ │ └── __init__.py │ ├── Expression │ │ └── __init__.py │ └── NgSpice │ │ ├── __init__.py │ │ └── api.h ├── __init__.py └── Math │ └── __init__.py ├── anaconda-recipe ├── bld.bat ├── README.md └── build.sh ├── doc ├── pelican │ ├── theme │ │ ├── templates │ │ │ ├── src │ │ │ ├── index.html │ │ │ ├── 404.html │ │ │ ├── tag.html │ │ │ ├── author.html │ │ │ ├── category.html │ │ │ ├── tags.html │ │ │ ├── archives.html │ │ │ ├── authors.html │ │ │ ├── categories.html │ │ │ ├── pagination.html │ │ │ ├── period_archives.html │ │ │ ├── translations.html │ │ │ ├── gosquared.html │ │ │ ├── page.html │ │ │ └── articles.html │ │ ├── scss │ │ │ ├── libs │ │ │ │ ├── bootstrap │ │ │ │ ├── fontawesome │ │ │ │ └── _all.scss │ │ │ ├── settings │ │ │ │ ├── _fontawesome_v5.scss │ │ │ │ ├── _pre_bootstrap.scss │ │ │ │ ├── _bootstrap4.scss │ │ │ │ ├── _all.scss │ │ │ │ └── _custom.scss │ │ │ ├── mixins │ │ │ │ ├── _material_design.scss │ │ │ │ ├── _colours.scss │ │ │ │ ├── _functions.scss │ │ │ │ ├── _all.scss │ │ │ │ ├── _other.scss │ │ │ │ └── _zindex.scss │ │ │ ├── layout │ │ │ │ ├── _gabriela.scss │ │ │ │ ├── _codes.scss │ │ │ │ ├── _images.scss │ │ │ │ ├── _footer.scss │ │ │ │ ├── _content.scss │ │ │ │ ├── _all.scss │ │ │ │ └── _header.scss │ │ │ ├── addons │ │ │ │ ├── _all.scss │ │ │ │ └── _browser.scss │ │ │ ├── base.scss │ │ │ └── sites │ │ │ │ └── _all.scss │ │ ├── static │ │ │ ├── js │ │ │ │ └── libs │ │ │ │ │ ├── jquery.min.js │ │ │ │ │ ├── jquery.slim.min.js │ │ │ │ │ ├── bootstrap.min.js │ │ │ │ │ ├── bootstrap.bundle.min.js │ │ │ │ │ └── outdatedbrowser.min.js │ │ │ └── webfonts │ │ │ │ ├── fa-brands-400.eot │ │ │ │ ├── fa-brands-400.svg │ │ │ │ ├── fa-brands-400.ttf │ │ │ │ ├── fa-brands-400.woff │ │ │ │ ├── fa-regular-400.eot │ │ │ │ ├── fa-regular-400.svg │ │ │ │ ├── fa-regular-400.ttf │ │ │ │ ├── fa-solid-900.eot │ │ │ │ ├── fa-solid-900.svg │ │ │ │ ├── fa-solid-900.ttf │ │ │ │ ├── fa-solid-900.woff │ │ │ │ ├── fa-solid-900.woff2 │ │ │ │ ├── fa-brands-400.woff2 │ │ │ │ ├── fa-regular-400.woff │ │ │ │ ├── fa-regular-400.woff2 │ │ │ │ └── setup.sh │ │ ├── browserslist │ │ └── package.json │ ├── content │ │ ├── images │ │ │ ├── favicon.png │ │ │ ├── favicon.svg │ │ │ ├── logo.png │ │ │ └── logo.svg │ │ └── pages │ │ │ ├── page-404.md │ │ │ └── legal_notice.md │ ├── src │ │ ├── contact.html │ │ ├── get-help.html │ │ └── documentation.html │ └── publishconf.py ├── sphinx │ ├── source │ │ ├── _static │ │ │ └── logo.png │ │ ├── news.rst │ │ ├── design-notes.rst │ │ ├── themes │ │ │ └── PySpiceRtd │ │ │ │ ├── theme.conf │ │ │ │ ├── static │ │ │ │ └── getthecode.js │ │ │ │ └── layout.html │ │ ├── reference-manual.rst │ │ ├── on-the-web.rst │ │ ├── how-to-refer.rst │ │ ├── abbreviation.txt │ │ ├── development.rst │ │ ├── donate.rst │ │ ├── bibliography.rst │ │ ├── roadmap.rst │ │ ├── project-links.txt │ │ └── example-whish-list.rst │ └── make-html ├── datasheets │ ├── BAV20.pdf │ ├── 1N5919B.pdf │ ├── 2N2222A.pdf │ └── 1N4148_1N4448.pdf └── logo │ └── make-logo-png ├── examples ├── power-supplies │ ├── rectification.py │ ├── m4 │ │ ├── capacitive-half-wave-rectification-post-zener-circuit.m4 │ │ └── capacitive-half-wave-rectification-pre-zener-circuit.m4 │ └── HP54501A.py ├── .travis │ └── travis.py ├── spice-parser │ ├── index.rst │ ├── kicad-spice-example │ │ ├── spice │ │ │ ├── run.sh │ │ │ ├── example.cir │ │ │ └── components.cir │ │ ├── README.txt │ │ ├── netlist │ │ │ ├── kicad-spice-example.number-node.cir │ │ │ ├── kicad-spice-example.default.cir │ │ │ └── kicad-spice-example.using-X.cir │ │ ├── kicad-spice-example-rescue.lib │ │ └── kicad-spice-example.pro │ └── kicad-pyspice-example │ │ ├── kicad-pyspice-example.cir │ │ ├── kicad-pyspice-example-rescue.lib │ │ └── kicad-pyspice-example.pro ├── diode │ ├── notes │ │ ├── schema1.png │ │ ├── schema2.png │ │ └── rectification1.png │ ├── index.rst │ ├── m4 │ │ ├── diode-characteristic-curve-circuit.m4 │ │ ├── diode-characteristic-curve-circuit-ac.m4 │ │ ├── diode-characteristic-curve-circuit-pulse.m4 │ │ ├── zener-diode-characteristic-curve-circuit.m4 │ │ ├── half-wave-rectification.m4 │ │ ├── voltage-multiplier-circuit.m4 │ │ └── full-wave-rectification.m4 │ └── RingModulator.py ├── c-examples │ ├── ngspice_cb │ │ ├── ng_shared_test │ │ │ └── compile.txt │ │ ├── compile-linux.txt │ │ └── ngspice_cb_contents.txt │ └── ngspice-shared │ │ ├── Makefile │ │ ├── sharedspice-essential.h │ │ └── test-module.py ├── spice-examples │ ├── voltage-divider.cir │ ├── transistor2.cir │ ├── diode-ac.cir │ ├── low-pass-rc-filter.cir │ ├── resistor-bridge.cir │ ├── transistor.cir │ ├── diode.cir │ ├── ac-coupled-amplifier.cir │ ├── small-signal-amplifier.cir │ ├── ac-coupled-transistor-amplifier.cir │ ├── small-signal-amplifier-with-diodes.cir │ ├── operational-amplifier-model-1.cir │ ├── operational-amplifier-model-2.cir │ ├── transform-less-power-supply.cir │ └── astable.cir ├── advanced-usages │ └── index.rst ├── basic-usages │ ├── index.rst │ ├── raw-spice.py │ ├── netlist-manipulations.py │ └── subcircuit.py ├── pyterate-templates │ └── document.jinja2 ├── index.rst ├── analyses │ ├── test_pole_zero.cir │ └── pole_zero_analysis.py ├── fundamental-laws │ └── m4 │ │ ├── voltage-divider.m4 │ │ ├── current-divider.m4 │ │ ├── millman-theorem.m4 │ │ ├── thevenin-norton-theorem.m4 │ │ └── millman-theorem-with-current-source.m4 ├── resistor │ ├── m4 │ │ ├── voltage-divider.m4 │ │ └── resistor-bridge.m4 │ ├── resistor-bridge.py │ └── voltage-divider.py ├── filter │ ├── m4 │ │ ├── low-pass-rc-filter.m4 │ │ ├── pass-band-rlc-filter.m4 │ │ └── low-pass-rlc-filter.m4 │ └── low-pass-rc-filter.py ├── Settings.py ├── transistor │ └── m4 │ │ ├── transistor.m4 │ │ └── ac-coupled-amplifier.m4 ├── ngspice-shared │ ├── index.rst │ └── ngspice-interpreter.py ├── passive │ └── m4 │ │ └── capacitor_and_inductor.m4 ├── libraries │ ├── diode │ │ ├── general-purpose │ │ │ ├── BAV21.lib │ │ │ └── BAV21.lib@xyce │ │ ├── schottky │ │ │ └── 1N5822.lib │ │ ├── switching │ │ │ └── 1N4148.lib │ │ └── zener │ │ │ └── 1N5919B.lib │ ├── transistor │ │ └── 2N2222A.lib │ └── mosfet │ │ └── irf150.lib ├── transmission-lines │ └── time-delay.py ├── run-examples ├── operational-amplifier │ ├── operational-amplifier.py │ └── OperationalAmplifier-api-brainstorming.py └── transformer │ └── transformer-example.py ├── tasks ├── cir2py-libraries ├── github.py ├── __init__.py └── anaconda.py ├── invoke.yaml ├── requirements.txt ├── gh-pages ├── html-rsync-filter.txt ├── README.rst ├── init-gh-pages └── update-gh-pages ├── .github ├── SUPPORT.md ├── ISSUE_TEMPLATE.md ├── CONTRIBUTING.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── pyspice-test.yml ├── .gitattributes ├── issues ├── issue-172.cir ├── two-stage-amp.cir ├── issue-130.py ├── issue-167.lib ├── issue-169.py ├── issue-11.py ├── issue-150.py ├── issue-6.py ├── issue-157-2.py ├── issue-182-lf411c.mod ├── issue-157.py ├── issue-172.py ├── issue-133.py └── issue-142.py ├── .gitmodules ├── tox.ini ├── CONTRIBUTORS.md ├── unit-test └── SpiceParser │ └── mosdriver.lib ├── unit-test-todo ├── test_file.py ├── test_pipe.py └── test_netlist.py ├── requirements-dev.txt ├── MANIFEST.in ├── bin ├── cir2py └── pyspice-post-installation └── setup.py /PySpice/Doc/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /anaconda-recipe/bld.bat: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Config/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Logging/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Physics/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Plot/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Probe/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Scripts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Tools/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /PySpice/Spice/Xyce/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/src: -------------------------------------------------------------------------------- 1 | ../../src/ -------------------------------------------------------------------------------- /doc/pelican/content/images/favicon.png: -------------------------------------------------------------------------------- 1 | logo.png -------------------------------------------------------------------------------- /doc/pelican/content/images/favicon.svg: -------------------------------------------------------------------------------- 1 | logo.svg -------------------------------------------------------------------------------- /doc/pelican/content/images/logo.png: -------------------------------------------------------------------------------- 1 | ../../../logo/logo.png -------------------------------------------------------------------------------- /doc/sphinx/source/_static/logo.png: -------------------------------------------------------------------------------- 1 | ../../../logo/logo.png -------------------------------------------------------------------------------- /doc/pelican/content/images/logo.svg: -------------------------------------------------------------------------------- 1 | ../../../logo/svg/logo-v1.svg -------------------------------------------------------------------------------- /examples/power-supplies/rectification.py: -------------------------------------------------------------------------------- 1 | ../diode/rectification.py -------------------------------------------------------------------------------- /doc/pelican/theme/scss/libs/bootstrap: -------------------------------------------------------------------------------- 1 | ../../node_modules/bootstrap/scss/ -------------------------------------------------------------------------------- /anaconda-recipe/README.md: -------------------------------------------------------------------------------- 1 | # Anaconda Recipe 2 | 3 | This recipe is used for test. 4 | -------------------------------------------------------------------------------- /doc/sphinx/make-html: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | make -f Makefile.sphinx html 4 | 5 | # End -------------------------------------------------------------------------------- /examples/.travis/travis.py: -------------------------------------------------------------------------------- 1 | # Travis test 2 | #skip# 3 | raise NameError('Failure') 4 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/libs/fontawesome: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/scss/ -------------------------------------------------------------------------------- /doc/pelican/theme/static/js/libs/jquery.min.js: -------------------------------------------------------------------------------- 1 | ../../../node_modules/jquery/dist/jquery.min.js -------------------------------------------------------------------------------- /tasks/cir2py-libraries: -------------------------------------------------------------------------------- 1 | find examples/libraries/ -name '*.lib' -exec ./bin/cir2py {} \; 2 | -------------------------------------------------------------------------------- /doc/datasheets/BAV20.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/doc/datasheets/BAV20.pdf -------------------------------------------------------------------------------- /doc/pelican/theme/static/js/libs/jquery.slim.min.js: -------------------------------------------------------------------------------- 1 | ../../../node_modules/jquery/dist/jquery.slim.min.js -------------------------------------------------------------------------------- /doc/datasheets/1N5919B.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/doc/datasheets/1N5919B.pdf -------------------------------------------------------------------------------- /doc/datasheets/2N2222A.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/doc/datasheets/2N2222A.pdf -------------------------------------------------------------------------------- /doc/pelican/theme/static/js/libs/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | ../../../node_modules/bootstrap/dist/js/bootstrap.min.js -------------------------------------------------------------------------------- /examples/spice-parser/index.rst: -------------------------------------------------------------------------------- 1 | This section shows how to use the Spice netlist parser. 2 | 3 | .. end 4 | -------------------------------------------------------------------------------- /doc/sphinx/source/news.rst: -------------------------------------------------------------------------------- 1 | .. _news-page: 2 | 3 | ====== 4 | News 5 | ====== 6 | 7 | .. include:: news.txt 8 | -------------------------------------------------------------------------------- /invoke.yaml: -------------------------------------------------------------------------------- 1 | Package: PySpice 2 | ngspice: 3 | directory: [ngspice-build, 'ngspice-{}'] 4 | version: 32 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML>=5.3 2 | cffi>=1.14 3 | matplotlib>=3.2 4 | numpy>=1.18 5 | ply>=3.11 6 | scipy>=1.4 7 | -------------------------------------------------------------------------------- /doc/datasheets/1N4148_1N4448.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/doc/datasheets/1N4148_1N4448.pdf -------------------------------------------------------------------------------- /doc/pelican/theme/static/js/libs/bootstrap.bundle.min.js: -------------------------------------------------------------------------------- 1 | ../../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js -------------------------------------------------------------------------------- /examples/diode/notes/schema1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/examples/diode/notes/schema1.png -------------------------------------------------------------------------------- /examples/diode/notes/schema2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/examples/diode/notes/schema2.png -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-brands-400.eot: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.eot -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-brands-400.svg: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.svg -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-brands-400.woff: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.woff -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-regular-400.eot: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.eot -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-regular-400.svg: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.svg -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-solid-900.eot: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.eot -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-solid-900.svg: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.svg -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-solid-900.woff: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.woff -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /doc/pelican/theme/static/js/libs/outdatedbrowser.min.js: -------------------------------------------------------------------------------- 1 | ../../../node_modules/outdatedbrowser/outdatedbrowser/outdatedbrowser.min.js -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-regular-400.woff: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.woff -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- 1 | ../../node_modules/@fortawesome/fontawesome-free/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /examples/diode/notes/rectification1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PySpice-org/PySpice/HEAD/examples/diode/notes/rectification1.png -------------------------------------------------------------------------------- /doc/pelican/theme/static/webfonts/setup.sh: -------------------------------------------------------------------------------- 1 | for i in ../../node_modules/@fortawesome/fontawesome-free/webfonts/* ; do ln -sf $i; done 2 | -------------------------------------------------------------------------------- /examples/c-examples/ngspice_cb/ng_shared_test/compile.txt: -------------------------------------------------------------------------------- 1 | g++-3.exe -o bin/Debug/ng_shared_test.exe obj/Debug/main.o -m32 -lpthread -------------------------------------------------------------------------------- /examples/diode/index.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Diode 3 | ======== 4 | 5 | This section contains examples based on diodes. 6 | 7 | .. end 8 | -------------------------------------------------------------------------------- /doc/sphinx/source/design-notes.rst: -------------------------------------------------------------------------------- 1 | .. _design-note-page: 2 | 3 | ============== 4 | Design Notes 5 | ============== 6 | 7 | To be written ... 8 | -------------------------------------------------------------------------------- /examples/spice-examples/voltage-divider.cir: -------------------------------------------------------------------------------- 1 | .title Voltage Divider 2 | Vinput in 0 DC 10V 3 | R1 in out 9k 4 | R2 out 0 1k 5 | .op 6 | .end 7 | 8 | -------------------------------------------------------------------------------- /gh-pages/html-rsync-filter.txt: -------------------------------------------------------------------------------- 1 | .buildinfo 2 | .git 3 | .gitignore 4 | README.rst 5 | push-to-github.sh 6 | html-rsync-filter.txt 7 | update.sh 8 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-spice-example/spice/run.sh: -------------------------------------------------------------------------------- 1 | echo 'Enter' 2 | echo '> tran 0.3m 3m' 3 | echo '> plot V(2) V(7)' 4 | ngspice example.cir 5 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/index.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block content %} 5 | 6 | {% endblock content %} 7 | -------------------------------------------------------------------------------- /examples/advanced-usages/index.rst: -------------------------------------------------------------------------------- 1 | ================= 2 | Advanced Usages 3 | ================= 4 | 5 | This section contains examples showing advanced usages. 6 | -------------------------------------------------------------------------------- /examples/basic-usages/index.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Basic Usages 3 | ============== 4 | 5 | This section contains examples showing basic usages. 6 | 7 | .. end 8 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-spice-example/README.txt: -------------------------------------------------------------------------------- 1 | This example comes from https://github.com/stffrdhrn/kicad-spice-demo 2 | 3 | Note: We have to prexix manually Ji by X. 4 | -------------------------------------------------------------------------------- /.github/SUPPORT.md: -------------------------------------------------------------------------------- 1 | There is no mailing list or forum actually, so you can either contact me or fill an issue on Github. 2 | 3 | If you encounter an issue, please fill an issue. 4 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/settings/_fontawesome_v5.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Place to override Font Awesome variables 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Environment (OS, Python version, PySpice version, simulator) 2 | 3 | ### Expected Behaviour 4 | 5 | ### Actual Behaviour 6 | 7 | ### Steps to reproduce the behaviour 8 | -------------------------------------------------------------------------------- /examples/pyterate-templates/document.jinja2: -------------------------------------------------------------------------------- 1 | {% extends "document_base.jinja2" %} 2 | 3 | {% block includes %} 4 | .. include:: /project-links.txt 5 | .. include:: /abbreviation.txt 6 | {% endblock %} 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://git-scm.com/docs/gitattributes 2 | 3 | # *.cir text eol=lf 4 | # *.lib text eol=lf 5 | # *.mod text eol=lf 6 | 7 | *.py text eol=lf 8 | *.rst text eol=lf 9 | *.yml text eol=lf 10 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | PySpice is an open-source project, and relies on its community of users to keep getting better. 2 | 3 | To read further, look at this page https://pyspice.fabrice-salvaire.fr/development.html 4 | -------------------------------------------------------------------------------- /issues/issue-172.cir: -------------------------------------------------------------------------------- 1 | .title Pulse 2 | Bsource in 0 v=time^4*exp(-1000*time) 3 | R1 in out 9kOhm 4 | R2 out 0 1kOhm 5 | .options TEMP = 27°C 6 | .options TNOM = 27°C 7 | .ic 8 | .tran 0.001ms 20ms 0s 9 | .end 10 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/404.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block content %} 5 |
6 | {{ page.content }} 7 |
8 | {% endblock content %} 9 | -------------------------------------------------------------------------------- /examples/index.rst: -------------------------------------------------------------------------------- 1 | .. -*- Mode: rst -*- 2 | 3 | .. _examples-page: 4 | 5 | ========== 6 | Examples 7 | ========== 8 | 9 | The examples are classified by topics. 10 | 11 | .. here comes examples/examples.rst 12 | -------------------------------------------------------------------------------- /examples/analyses/test_pole_zero.cir: -------------------------------------------------------------------------------- 1 | .title Pole Zero Test 2 | R1 1 2 10000 3 | C1 1 2 1e-6 4 | R2 2 0 1000 5 | C2 2 0 1e-6 6 | L1 2 0 1e-3 7 | * 8 | *.options noacct 9 | .control 10 | pz 1 0 2 0 vol pz 11 | print all 12 | -------------------------------------------------------------------------------- /doc/pelican/content/pages/page-404.md: -------------------------------------------------------------------------------- 1 | Title: Page Not Found 2 | Status: hidden 3 | Template: 404 4 | Save_as: 404.html 5 | 6 | # 404 — Page not found 7 | 8 | We are sorry, but the requested page could not be found. 9 | 10 | -------------------------------------------------------------------------------- /examples/spice-examples/transistor2.cir: -------------------------------------------------------------------------------- 1 | .title Transistor 2 | Q1 collector base 0 generic 3 | Vcollector collector 0 5 4 | Ibase 0 base 90m 5 | .model generic npn () 6 | .end 7 | .options TNOM = 25 8 | .options NOINIT 9 | .options TEMP = 25 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pyspice-feedstock"] 2 | path = pyspice-feedstock 3 | url = https://github.com/conda-forge/pyspice-feedstock 4 | [submodule "ngspice-feedstock"] 5 | path = ngspice-feedstock 6 | url = https://github.com/conda-forge/ngspice-feedstock.git 7 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/tag.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "articles.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - {{ tag }} tag{% endblock %} 5 | 6 | {% block content_title %} 7 |

Articles tagged with {{ tag }}

8 | {% endblock %} 9 | -------------------------------------------------------------------------------- /doc/pelican/src/contact.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block html_lang %}en{% endblock %} 5 | 6 | {% block title %}{{ SITENAME }} - Contact {%endblock%} 7 | 8 | {% block content %} 9 | Contact ... 10 | {% endblock %} 11 | -------------------------------------------------------------------------------- /examples/spice-examples/diode-ac.cir: -------------------------------------------------------------------------------- 1 | .title Diode 2 | .include examples/libraries/diode/BAV21.lib 3 | Vinput in 0 DC 5V AC SIN(5V 0.1V 1kHz) 4 | R1 in out 1k 5 | D1 out 0 BAV21 6 | .save V(in) V(out) 7 | .control 8 | op 9 | ac dec 10 10k 1G 10 | .endc 11 | .end 12 | -------------------------------------------------------------------------------- /examples/spice-examples/low-pass-rc-filter.cir: -------------------------------------------------------------------------------- 1 | .title Low Pass RC Filter 2 | Vinput in 0 DC 0V AC SIN(0V 10V 1kHz) 3 | R1 in out 1k 4 | C1 out 0 1u 5 | .ac dec 1 1 10k 6 | .save v(in) v(out) 7 | .control 8 | run 9 | * plot v(out) 10 | print v(out) 11 | .endc 12 | .end 13 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/mixins/_material_design.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Material Design 3 | 4 | @mixin rised-component() { 5 | box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12); 6 | } 7 | -------------------------------------------------------------------------------- /examples/spice-examples/resistor-bridge.cir: -------------------------------------------------------------------------------- 1 | .title Resistor Bridge 2 | Vinput 1 0 10V 3 | R1 1 2 2 4 | R2 1 3 1 5 | R3 2 0 1 6 | R4 3 0 2 7 | R5 3 2 2 8 | ** .op 9 | * analysis 1 10 | *.dc Vinput 10 20 1 11 | *.save v(2) v(1) 12 | * analysis 2 13 | .sens v(1) 14 | .end 15 | 16 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/author.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "articles.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - Articles by {{ author }}{% endblock %} 5 | 6 | {% block content_title %} 7 |

Articles by {{ author }}

8 | {% endblock %} 9 | 10 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/mixins/_colours.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Colours 3 | 4 | @mixin white_on_dark() { 5 | @extend .bg-dark; 6 | @extend .text-white; 7 | 8 | a { 9 | @extend .text-white; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /gh-pages/README.rst: -------------------------------------------------------------------------------- 1 | This branch contains the GitHub Pages for PySpice. 2 | 3 | These pages are generated by the Sphinx tool (http://sphinx-doc.org) using the 4 | tools/generate-rst-api.sh script from the sources and then the update.sh script to fix them suitable 5 | for github pages. 6 | 7 | .. End 8 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/category.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "articles.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - {{ category }} category{% endblock %} 5 | 6 | {% block content_title %} 7 |

Articles in the {{ category }} category

8 | {% endblock %} 9 | 10 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/layout/_gabriela.scss: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Gabriela'; 3 | font-style: normal; 4 | font-weight: 400; 5 | src: local('Gabriela'), local('Gabriela-Regular'), url(https://fonts.gstatic.com/l/font?kit=BEd5TJl5geC-G_qgmtkw3kO-NZ8T69qbbis4mE8I88g&skey=146d0218141ab9a9&v=v4) format('woff2'); 6 | } 7 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | To make it easier to merge your pull request, you should divide your PR into smaller and easier-to-verify units. 2 | 3 | Please do not make a pull requests with a lot of modifications which are difficult to check. If I merge 4 | pull requests blindly then there is a high risk this software will become a mess quickly for everybody. 5 | -------------------------------------------------------------------------------- /examples/spice-examples/transistor.cir: -------------------------------------------------------------------------------- 1 | .title Transistor 2 | Vcollector collector 0 dc 0V 3 | * Vcollector 1 0 dc 4 | * Vammeter 1 collector dc 0V 5 | Ibase 0 base dc 100u 6 | Q1 collector base 0 generic 7 | .control 8 | dc vcollector 0 5 10m 9 | * ibase 0 100m 10m 10 | * range 10 mA 11 | plot -vcollector#branch 12 | * plot i(Vammeter) 13 | .endc 14 | .end 15 | -------------------------------------------------------------------------------- /doc/pelican/theme/browserslist: -------------------------------------------------------------------------------- 1 | # Supported browsers 2 | # https://github.com/twbs/bootstrap/blob/v4.4.1/.browserslistrc 3 | # https://github.com/browserslist/browserslist#readme 4 | 5 | >= 1% 6 | last 1 major version 7 | not dead 8 | Chrome >= 45 9 | Firefox >= 38 10 | Edge >= 12 11 | Explorer >= 10 12 | iOS >= 9 13 | Safari >= 9 14 | Android >= 4.4 15 | Opera >= 30 16 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/layout/_codes.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Codes 3 | 4 | pre { 5 | @extend .p-2; 6 | // background-color: $gray-100; 7 | background-color: #f5f5f5; 8 | // border: 1px solid $gray-400; 9 | border: 1px solid #ccc; 10 | border-radius: $border-radius; 11 | } 12 | -------------------------------------------------------------------------------- /examples/fundamental-laws/m4/voltage-divider.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | Origin: Here 8 | dot; "in" above 9 | resistor(right_ elen,,E); llabel(,R_1,); dot; "out" above 10 | resistor(down_ elen,,E); llabel(,R_2,) 11 | line down epsilon then left_ elen; dot 12 | .PE 13 | -------------------------------------------------------------------------------- /examples/c-examples/ngspice-shared/Makefile: -------------------------------------------------------------------------------- 1 | all: test test-external-source 2 | 3 | FLAGS = -std=c99 -Wall -I /usr/local/stow/ngspice-26/share/ngspice/include -L /usr/local/stow/ngspice-26/lib -lngspice -lpthread -lgomp 4 | 5 | test: test.c 6 | ${CC} ${FLAGS} -o $@ $< 7 | 8 | test-external-source: test-external-source.c 9 | ${CC} ${FLAGS} -o $@ $< 10 | 11 | # End 12 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | # tox (https://tox.readthedocs.io/) is a tool for running tests 2 | # in multiple virtualenvs. This configuration file will run the 3 | # test suite on all supported python versions. To use it, "pip install tox" 4 | # and then run "tox" from this directory. 5 | 6 | [tox] 7 | envlist = py38 8 | 9 | [testenv] 10 | commands = pytest unit-test 11 | deps = pytest 12 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/mixins/_functions.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // FUNCTIONS 3 | 4 | // basic mathematical functions that are helpful 5 | 6 | // em calculation 7 | @function em($target, $context: $font-size) { 8 | @if $target == 0 { 9 | @return 0 10 | } 11 | @return $target / $context + em; 12 | } 13 | -------------------------------------------------------------------------------- /examples/spice-examples/diode.cir: -------------------------------------------------------------------------------- 1 | .title Diode 2 | * .include examples/libraries/diode/BAV21.lib 3 | .MODEL BAV21 D 4 | + IS=21.910E-9 5 | + N=2.2330 6 | + RS=1.0000E-3 7 | + IKF=19.230E-3 8 | + CJO=1.0300E-12 9 | + M=.1001 10 | + VJ=.75 11 | + BV=293.10 12 | + IBV=1.2930E-3 13 | + TT=51.940E-9 14 | * + ISR=10.010E-21 15 | Vinput in 0 0.9 16 | R1 in out 1k 17 | D1 out 0 BAV21 18 | .end 19 | -------------------------------------------------------------------------------- /examples/spice-examples/ac-coupled-amplifier.cir: -------------------------------------------------------------------------------- 1 | AC-coupled amplifier 2 | Vpwr 6 0 DC 15V 3 | Vin 1 0 AC 1V SIN(0V .5V 1KHz) 4 | C1 1 2 10u 5 | R1 6 2 100k 6 | R2 2 0 20k 7 | RC 6 4 10k 8 | Q1 4 2 3 bjt 9 | RE 3 0 2k 10 | C2 4 5 10u 11 | RL 5 0 1Meg 12 | .model bjt npn(bf=80 cjc=5p rb=100) 13 | .ac dec 5 10m 1G 14 | *.tran .02ms 2ms 0 .01ms 15 | .control 16 | run 17 | plot V(1) V(5) 18 | .end 19 | -------------------------------------------------------------------------------- /doc/logo/make-logo-png: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | options="--export-area-page --export-background=white --export-background-opacity=0" 4 | 5 | # --export-width= 6 | 7 | height=400 8 | 9 | for i in 1 2; do 10 | inkscape --export-png=logo-v$i.png ${options} --export-height=${height} svg/logo-v$i.svg 11 | inkscape --export-png=logo-v$i.png ${options} --export-height=${height} svg/logo-v$i.svg 12 | done 13 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributors 2 | 3 | In addition to https://github.com/FabriceSalvaire/PySpice/graphs/contributors, some contributors are lost due to git/github folks ... 4 | 5 | * **Peter Garrone** https://github.com/PeterGarrone 6 | 7 | Pole-zero, noise, distorsion, transfer-function analyses 8 | 9 | https://github.com/FabriceSalvaire/PySpice/pull/191 merged in 7aea62b (author lost in github) 10 | -------------------------------------------------------------------------------- /doc/sphinx/source/themes/PySpiceRtd/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = sphinx_rtd_theme 3 | stylesheet = css/PySpice.css 4 | # pygments_style = sphinx 5 | 6 | [options] 7 | typekit_id = hiw1hhg 8 | analytics_id = 9 | sticky_navigation = False 10 | logo_only = 11 | collapse_navigation = False 12 | display_version = True 13 | navigation_depth = 4 14 | prev_next_buttons_location = bottom 15 | canonical_url = 16 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/settings/_pre_bootstrap.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // These variables are used in _bootstrap_v3.scss 3 | 4 | $mytheme-dark-gray: #35363C; 5 | $mytheme-green: #a1c42c; 6 | 7 | $mytheme-highlighted-color: $mytheme-green; 8 | // $mytheme-rule-color: $gray-darker; 9 | -------------------------------------------------------------------------------- /examples/resistor/m4/voltage-divider.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | Origin: Here 8 | ground; dot; 9 | source(up_ elen, V); llabel(,V_{in},); dot; "in" rjust 10 | resistor(right_ elen); llabel(,R_1,) dot; "out" ljust 11 | resistor(down_ elen); llabel(,R_2,) 12 | line down epsilon then to Origin then up epsilon 13 | .PE 14 | -------------------------------------------------------------------------------- /examples/spice-examples/small-signal-amplifier.cir: -------------------------------------------------------------------------------- 1 | Small Signal Amplifier 2 | * 3 | * This circuit simulates a simple small signal amplifier. 4 | * 5 | Vin input 0 0V SIN(0V .1V 500Hz) 6 | Rsource input amp_in 100 7 | C1 amp_in 0 1uF 8 | R_amp_input amp_in 0 1Meg 9 | E1 (amp_out 0) (amp_in 0) -10 10 | Rload amp_out 0 1k 11 | .tran 1us 10ms 12 | .control 13 | run 14 | plot V(input) V(amp_out) 15 | .endc 16 | .end 17 | -------------------------------------------------------------------------------- /examples/filter/m4/low-pass-rc-filter.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | Origin: Here 8 | ground; dot; 9 | source(up_ elen, AC); llabel(,V_{in},); dot; "in" above 10 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 11 | capacitor(down_ elen); llabel(,C_1,) 12 | line down epsilon then to Origin then up epsilon 13 | .PE 14 | -------------------------------------------------------------------------------- /unit-test/SpiceParser/mosdriver.lib: -------------------------------------------------------------------------------- 1 | * Ideal mos driver 2 | .subckt mosdriver hb hi ho hs li lo vdd vss 3 | 4 | .model diode D (is=1.038e-15 n=1 tt=20e-9 cjo=5e-12 rs=0.50 bv=130) 5 | 6 | bhigh hoi hs v={if(v(hi, vss) > 0.5, 5, 0)} smoothbsrc=1 7 | rhoi hoi ho 1 8 | choi ho hs 1e-9 9 | blow loi vss v={if(v(li, vss) > 0.5, 5, 0)} smoothbsrc=1 10 | rloi loi lo 1 11 | cloi lo vss 1e-9 12 | dhb vdd hb diode 13 | 14 | .ENDS mosdriver -------------------------------------------------------------------------------- /doc/pelican/theme/templates/tags.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - Tags{% endblock %} 5 | 6 | {% block content %} 7 |

Tags for {{ SITENAME }}

8 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /unit-test-todo/test_file.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | from PySpice.Spice.Library import SpiceLibrary 3 | 4 | library_path = Path(__file__).resolve().parents[1].joinpath('examples', 'libraries') 5 | print(library_path) 6 | spice_library = SpiceLibrary(library_path) 7 | # print list(spice_library.iter_on_subcircuits()) 8 | # print list(spice_library.iter_on_models()) 9 | print(list(spice_library.subcircuits)) 10 | print(list(spice_library.models)) 11 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/archives.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - Archives{% endblock %} 5 | 6 | {% block content %} 7 |

Archives for {{ SITENAME }}

8 | 9 |
10 | {% for article in dates %} 11 |
{{ article.locale_date }}
12 |
{{ article.title }}
13 | {% endfor %} 14 |
15 | {% endblock %} 16 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/authors.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - Authors{% endblock %} 5 | 6 | {% block content %} 7 |

Authors on {{ SITENAME }}

8 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /examples/Settings.py: -------------------------------------------------------------------------------- 1 | #skip# 2 | 3 | #################################################################################################### 4 | 5 | from Pyterate.RstFactory.Settings import DefaultRstFactorySettings 6 | 7 | #################################################################################################### 8 | 9 | class RstFactorySettings(DefaultRstFactorySettings): 10 | 11 | # Flags 12 | show_counters = True # Show documents counters in toc 13 | -------------------------------------------------------------------------------- /examples/filter/m4/pass-band-rlc-filter.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | Origin: Here 8 | ground; dot; 9 | source(up_ elen, AC); llabel(,V_{in},); dot; "in" above 10 | inductor(right_ dimen_); llabel(,L_1,) 11 | capacitor(right_ dimen_); llabel(,C_1,) dot; "out" ljust 12 | resistor(down_ elen); llabel(,R_1,) 13 | line down epsilon then to Origin then up epsilon 14 | .PE 15 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/categories.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - Categories{% endblock %} 5 | 6 | {% block content %} 7 |

Categories on {{ SITENAME }}

8 | 13 | {% endblock %} 14 | -------------------------------------------------------------------------------- /examples/filter/m4/low-pass-rlc-filter.m4: -------------------------------------------------------------------------------- 1 | 2 | .PS 3 | cct_init(SIdefaults) 4 | linethick_(.5) 5 | define(`dimen_', 10) 6 | elen = dimen_*3/2 7 | epsilon = 1e-3 8 | Origin: Here 9 | ground; dot; 10 | source(up_ elen, AC); llabel(,V_{in},); dot; "in" above 11 | resistor(right_ dimen_); llabel(,R_1,) 12 | inductor(right_ dimen_); llabel(,L_1,) dot; "out" ljust 13 | capacitor(down_ elen); llabel(,C_1,) 14 | line down epsilon then to Origin then up epsilon 15 | .PE 16 | -------------------------------------------------------------------------------- /examples/diode/m4/diode-characteristic-curve-circuit.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | define(`bigdiode', 8 | `resized(2., `diode', $1)') 9 | Origin: Here 10 | ground; dot; 11 | source(up_ elen, V); llabel(,V_{in},); dot; "in" above 12 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 13 | bigdiode(down_ elen); llabel(,D_1,) 14 | line down epsilon then to Origin then up epsilon 15 | .PE 16 | -------------------------------------------------------------------------------- /examples/diode/m4/diode-characteristic-curve-circuit-ac.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | define(`bigdiode', 8 | `resized(2., `diode', $1)') 9 | Origin: Here 10 | ground; dot; 11 | source(up_ elen, AC); llabel(,V_{in},); dot; "in" above 12 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 13 | bigdiode(down_ elen); llabel(,D_1,) 14 | line down epsilon then to Origin then up epsilon 15 | .PE 16 | -------------------------------------------------------------------------------- /examples/diode/m4/diode-characteristic-curve-circuit-pulse.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | define(`bigdiode', 8 | `resized(2., `diode', $1)') 9 | Origin: Here 10 | ground; dot; 11 | source(up_ elen, P); llabel(,V_{in},); dot; "in" above 12 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 13 | bigdiode(down_ elen); llabel(,D_1,) 14 | line down epsilon then to Origin then up epsilon 15 | .PE 16 | -------------------------------------------------------------------------------- /examples/diode/m4/zener-diode-characteristic-curve-circuit.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | define(`bigdiode', 8 | `resized(2., `diode', $1, S)') 9 | Origin: Here 10 | ground; dot; 11 | source(up_ elen, V); llabel(,V_{in},); dot; "in" above 12 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 13 | bigdiode(down_ elen); llabel(,Dz_1,) 14 | line down epsilon then to Origin then up epsilon 15 | .PE 16 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/pagination.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% if DEFAULT_PAGINATION %} 3 |

4 | {% if articles_page.has_previous() %} 5 | « 6 | {% endif %} 7 | Page {{ articles_page.number }} / {{ articles_paginator.num_pages }} 8 | {% if articles_page.has_next() %} 9 | » 10 | {% endif %} 11 |

12 | {% endif %} 13 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/period_archives.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block title %}{{ SITENAME }} - {{ period | reverse | join(' ') }} archives{% endblock %} 5 | 6 | {% block content %} 7 |

Archives for {{ period | reverse | join(' ') }}

8 | 9 |
10 | {% for article in dates %} 11 |
{{ article.locale_date }}
12 |
{{ article.title }}
13 | {% endfor %} 14 |
15 | {% endblock %} 16 | -------------------------------------------------------------------------------- /anaconda-recipe/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # https://github.com/AnacondaRecipes/conda-feedstock/blob/master/recipe/build.sh 3 | 4 | # --record filename in which to record list of 5 | # installed files 6 | # --single-version-externally-managed used by system package builders to 7 | # create 'flat' eggs 8 | 9 | invoke release.update-git-sha 10 | $PYTHON setup.py install --single-version-externally-managed --record record.txt 11 | -------------------------------------------------------------------------------- /examples/diode/m4/half-wave-rectification.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | define(`bigdiode', 7 | `resized(2., `diode', $1)') 8 | Origin: Here 9 | ground; dot 10 | source(up_ elen, AC); llabel(,V_{in},); dot; "in" above 11 | bigdiode(right_ elen); llabel(,D,); dot 12 | { capacitor(down_ elen, C+); llabel(,C,) dot } 13 | line right_ dimen_; dot; "out" above 14 | resistor(down_ elen); llabel(,R,); b_current(i) 15 | line to Origin 16 | .PE 17 | -------------------------------------------------------------------------------- /examples/fundamental-laws/m4/current-divider.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | Origin: Here 8 | line right_ elen*1/2; 9 | { 10 | # simpler way ? 11 | arrow right arrowht from Origin + (elen*1/4,0) "$I_{in}$" above 12 | } 13 | { 14 | dot; 15 | resistor(down_ elen,,E); rlabel(,R_1,) 16 | dot; 17 | } 18 | line right_ elen*1/2 then down epsilon 19 | resistor(down_ elen,,E); llabel(,R_2,); b_current(I_{out}) 20 | line down epsilon then left_ elen 21 | .PE 22 | -------------------------------------------------------------------------------- /issues/two-stage-amp.cir: -------------------------------------------------------------------------------- 1 | *Sheet Name:/OPA_SR 2 | V1 vp GND dc 1.65 ac 0.5 3 | V2 vn GND dc 1.65 ac -0.5 4 | C2 Vout GND 4p 5 | C1 /3 Vout 6.9p 6 | M7 Vout /6 VDD VDD p_33 W=25.9u L=0.9u 7 | M6 Vout /3 GND GND n_33 W=92.04u L=1.4u 8 | M2 /3 vp /1 VDD p_33 W=51.78u L=0.9u 9 | M1 /2 vn /1 VDD p_33 W=51.78u L=0.9u 10 | M4 /3 /2 GND GND n_33 W=46.02u L=1.4u 11 | M3 /2 /2 GND GND n_33 W=46.02u L=1.4u 12 | M5 /1 /6 VDD VDD p_33 W=12.95u L=0.9u 13 | V0 VDD GND 3.3 14 | M8 /6 /6 VDD VDD p_33 W=1.3u L=0.9u 15 | I1 /6 GND 10u 16 | 17 | .lib CMOS_035_Spice_Model.lib tt 18 | 19 | .end 20 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | # Automate tasks 2 | # http://www.pyinvoke.org 3 | requests 4 | beautifulsoup4 5 | invoke 6 | PyGithub 7 | 8 | # Build documentation 9 | sphinx 10 | sphinxcontrib-getthecode 11 | pyterate 12 | pelican 13 | 14 | # Check code style, errors, etc 15 | pylint 16 | flake8 17 | 18 | # Test runners 19 | pytest 20 | tox 21 | 22 | # Check that MANIFEST.in matches Git repo contents before making a release 23 | # https://github.com/mgedmin/check-manifest 24 | check-manifest 25 | 26 | # To make wheel packages 27 | wheel 28 | 29 | # Securely upload packages to PyPI 30 | twine 31 | -------------------------------------------------------------------------------- /gh-pages/init-gh-pages: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | repository=$1 4 | 5 | if [ -z ${repository} ]; then 6 | echo Usage: init-gh-pages REPOSITORY 7 | exit 1 8 | fi 9 | 10 | tmp_dir=$(mktemp -d) 11 | pushd ${tmp_dir} 12 | 13 | git clone git@github.com:FabriceSalvaire/${repository}.git 14 | pushd ${repository} 15 | git checkout --orphan gh-pages 16 | git rm -rf . 17 | echo "My GitHub Page" > index.html 18 | git add index.html 19 | git commit -a -m "First pages commit" 20 | git push origin gh-pages 21 | 22 | popd -1 ; popd 23 | if [ -d ${tmp_dir} ]; then 24 | rm -rf ${tmp_dir} 25 | fi 26 | 27 | # End 28 | -------------------------------------------------------------------------------- /examples/transistor/m4/transistor.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init 3 | 4 | elen = 0.75 5 | epsilon = 1e-3 6 | 7 | G: ground; dot 8 | source(up_ elen,AC); llabel(,V_{base},) 9 | line up epsilon then right epsilon 10 | resistor(right_ elen); llabel(,R_{b},) 11 | 12 | Q1: bi_tr(up_,,,E) with .B at Here; llabel(,,Q_1) 13 | 14 | line down from Q1.E to (Q1.E, G) then right to G then up epsilon 15 | 16 | resistor(up_ 1.25*elen from Q1.C); rlabel(,R_{c}) 17 | Top: Here 18 | line up epsilon then left to (G,Top) then down epsilon 19 | reversed(`source', down_ elen,V); llabel(,V_{collector},) 20 | ground 21 | 22 | .PE 23 | -------------------------------------------------------------------------------- /issues/issue-130.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | from PySpice.Spice import Parser 4 | 5 | #################################################################################################### 6 | 7 | source = """ 8 | .title test 9 | Xld_D0 gnd:F12992 vdd:F3152 DNWPS AREA=16.072 PJ=20.54 10 | Xld_D0 gnd:F12992 vdd:F3152 11 | Xld_D0 gnd:F12992 vdd:F3152 DNWPS 12 | Xld_D0 gnd:F12992 vdd:F3152 AREA=16.072 PJ=20.54 13 | """ 14 | 15 | parser = Parser.SpiceParser(source=source) 16 | for statement in parser._statements: 17 | print(statement) 18 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/layout/_images.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Images 3 | 4 | // cf. addons/_rst.scss 5 | .container { 6 | img.left { 7 | clear: left; 8 | float: left; 9 | @extend .mr-3; 10 | // text-align: left; 11 | } 12 | 13 | img.right { 14 | clear: right; 15 | float: right; 16 | // @extend .ml-3; 17 | // text-align: right; 18 | } 19 | img.centered { 20 | margin-left: auto; 21 | margin-right: auto 22 | } 23 | } 24 | 25 | img { 26 | &.rotated-5-acw { 27 | @extend .p-3; 28 | transform: rotate(-5deg); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /issues/issue-167.lib: -------------------------------------------------------------------------------- 1 | .subckt test_netlist gate_drive1 sw_node_hs1 gate_drive2 sw_node_hs2 2 | 3 | * Test circuit 1 4 | V1 N200 0 100 5 | R1 N200 sw_node_hs1 1 6 | S1 sw_node_hs1 0 gate_drive1 0 myswitch 7 | V2 N102 0 PULSE(0 10 0 1n 1n 50u 100u 200) 8 | B2 gate_drive1 0 V=V(N102) 9 | *output load 10 | R23 0 sw_node_hs1 1 11 | 12 | * Test circuit 2 13 | V3 N201 0 100 14 | R3 N201 sw_node_hs2 1 15 | S5 sw_node_hs2 0 gate_drive2 0 myswitch 16 | V4 N101 0 PULSE(0 10 0 50u 50u 1n 100u 200) 17 | B1 gate_drive2 0 V=V(N101) 18 | *output load 19 | R26 0 sw_node_hs2 1 20 | .model myswitch SW(Ron=0.002 Roff=1000000 Vt=3.0) 21 | 22 | .ends test_netlist 23 | -------------------------------------------------------------------------------- /examples/spice-examples/ac-coupled-transistor-amplifier.cir: -------------------------------------------------------------------------------- 1 | A Berkeley SPICE3 compatible circuit 2 | * 3 | * This circuit contains only Berkeley SPICE3 components. 4 | * 5 | * The circuit is an AC coupled transistor amplifier with 6 | * a sine wave input at node "1", again of approximately -3.9, 7 | * and output on node "coll". 8 | * 9 | Vcc vcc 0 12V 10 | Vin 1 0 0V AC 1V SIN(0V 1V 1kHz) 11 | Ccouple 1 base 10uF 12 | Rbias1 vcc base 100k 13 | Rbias2 base 0 24k 14 | Q1 coll base emit generic 15 | Rcollector vcc coll 3.9k 16 | Remitter emit 0 1k 17 | * 18 | .model generic npn 19 | * 20 | .tran 1us 10ms 21 | .control 22 | run 23 | plot V(1) V(coll) 24 | .endc 25 | .end 26 | -------------------------------------------------------------------------------- /examples/ngspice-shared/index.rst: -------------------------------------------------------------------------------- 1 | This section shows how to use the NgSpice Shared Simulation Mode which permits to plug 2 | voltage/current sources from Python to NgSpice and vice versa. 3 | 4 | This NgSpice feature paves the way to advanced simulation use cases. For example we can perform a 5 | mixed level simulation of an analogic circuit connected to a microcontroller. We just need to 6 | implement an impedance model in Spice for input and output ports and implement the logic within 7 | Python. The NgSpice callbacks provide the interface to read and set current/voltage of the external 8 | nodes. 9 | 10 | See :mod:`PySpice.Spice.NgSpice.Shared` for more details. 11 | 12 | .. end 13 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-pyspice-example/kicad-pyspice-example.cir: -------------------------------------------------------------------------------- 1 | * /home/gv/fabrice/developpement/PySpice/examples/spice-parser/kicad-pyspice-example/kicad-pyspice-example.cir 2 | 3 | * EESchema Netlist Version 1.1 (Spice format) creation date: dim. 29 nov. 2015 18:04:33 CET 4 | 5 | * To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N 6 | * To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0 7 | 8 | * Sheet Name: / 9 | X3 7 6 5 4 1 Opamp 10 | X1 2 5 5 JackIn 11 | X4 7 3 5 JackOut 12 | R2 6 7 50K 13 | R1 2 6 2K 14 | R3 5 3 2K 15 | X2 4 5 1 PowerIn 16 | 17 | .end 18 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/translations.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | 3 | {% macro translations_for(article) %} 4 | {% if article.translations %} 5 | Translations: 6 | {% for translation in article.translations %} 7 | {{ translation.lang }} 8 | {% endfor %} 9 | {% endif %} 10 | {% endmacro %} 11 | 12 | {% macro entry_hreflang(entry) %} 13 | {% if entry.translations %} 14 | {% for translation in entry.translations %} 15 | 16 | {% endfor %} 17 | {% endif %} 18 | {% endmacro %} 19 | -------------------------------------------------------------------------------- /examples/spice-examples/small-signal-amplifier-with-diodes.cir: -------------------------------------------------------------------------------- 1 | Small Signal Amplifier 2 | * 3 | * This circuit simulates a small signal amplifier with a diode limiter. 4 | * 5 | Vin input 0 DC 0V 6 | Rsource input amp_in 100 7 | * 8 | Dneg 0 amp_in 1n4148 9 | Dpos amp_in 0 1n4148 10 | * 11 | C1 amp_in 0 1uF 12 | A1 amp_in 0 amp_out amplifier 13 | Rload amp_out 0 1000 14 | * 15 | .model 1n4148 D (is=2.495E-09 rs=4.755E-01 n=1.679E+00 16 | + tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 17 | + ibv=1.000E-04) 18 | * 19 | .model amplifier Amp (gain = -10 in_offset = 1e-3 rin = 1meg rout = 0.4) 20 | * 21 | .dc Vin -1V 1V .05V 22 | .control 23 | run 24 | plot V(input) V(amp_out) 25 | .endc 26 | .end 27 | -------------------------------------------------------------------------------- /doc/sphinx/source/reference-manual.rst: -------------------------------------------------------------------------------- 1 | .. include:: abbreviation.txt 2 | 3 | .. _reference-manual-page: 4 | 5 | =================== 6 | API Documentation 7 | =================== 8 | 9 | This is the API documentation for the PySpice library. 10 | 11 | .. warning:: The API documentation is automatically generated from the docstrings in the source 12 | using the |Sphinx| tool. This way to produce the documentation is know to be perfectible 13 | actually, but not too bad. 14 | 15 | Contents: 16 | 17 | .. toctree:: 18 | :maxdepth: 2 19 | 20 | api/PySpice 21 | 22 | Indexes 23 | ------- 24 | 25 | * :ref:`genindex` 26 | * :ref:`modindex` 27 | 28 | .. * :ref:`search` 29 | 30 | .. End 31 | 32 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/gosquared.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% if GOSQUARED_SITENAME %} 3 | 15 | {% endif %} 16 | -------------------------------------------------------------------------------- /examples/c-examples/ngspice_cb/compile-linux.txt: -------------------------------------------------------------------------------- 1 | ** compile with LINUX 2 | *create shared ngspice: 3 | 4 | cd ngspice 5 | ./autogen.sh 6 | mkdir debug-sh 7 | cd debug-sh 8 | ../configure --with-ngshared --enable-xspice --enable-cider --enable-openmp --enable-pss 9 | make 10 | sudo make install 11 | 12 | 13 | * create calling console executable 14 | cd ngspice_cb 15 | 16 | * static linking of ngspice 17 | cd ng_shared_test_sl 18 | 19 | gcc -g -Wall -lgomp -lngspice -o ./bin/Debug/ng_sh main.c 20 | 21 | * run example 22 | ./bin/Debug/ng_sh 23 | 24 | 25 | * dynamic linking ngspice during runtime 26 | cd ng_shared_test 27 | 28 | gcc -Wall -g -lgomp -ldl -o ./bin/Debug/ng_sh main.c 29 | 30 | * run example 31 | ./bin/Debug/ng_sh 32 | -------------------------------------------------------------------------------- /doc/pelican/content/pages/legal_notice.md: -------------------------------------------------------------------------------- 1 | Title: Legal Notice 2 | 3 | ## Copyright and Intellectual Property 4 | 5 | This website is protected by French and international legislation on royalties and intellectual property. 6 | 7 | Unless otherwise specified the content of this website is licensed under Creative Commons by-nc-sa. 8 | 9 | ## Personal Data and Privacy 10 | 11 | You can visit this site on Internet without providing your identity and personnal data about yourself. 12 | 13 | Apart from the use of a tracker to measure the site audience. 14 | 15 | ## Publisher 16 | 17 | **Fabrice SALVAIRE** pyspice AT fabrice-salvaire DOT fr 18 | 19 | ## Website Hosting 20 | 21 | This web site is hosted by the OVH SAS society in France. 22 | -------------------------------------------------------------------------------- /examples/passive/m4/capacitor_and_inductor.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | 4 | linethick_(.5) 5 | define(`dimen_', 10) 6 | elen = dimen_*3/2 7 | epsilon = 1e-3 8 | 9 | [ 10 | Origin: Here 11 | ground; dot; 12 | source(up_ elen, P); llabel(,V_{in},); dot; "in" above 13 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 14 | capacitor(down_ elen); llabel(,C_1,) 15 | line down epsilon then to Origin then up epsilon 16 | ] 17 | 18 | [ 19 | move right 1.5*elen 20 | Origin: Here 21 | ground; dot; 22 | source(up_ elen, P); llabel(,V_{in},); dot; "in" above 23 | resistor(right_ elen); llabel(,R_1,) dot; "out" above 24 | inductor(down_ elen); llabel(,L_1,) 25 | line down epsilon then to Origin then up epsilon 26 | ] 27 | 28 | .PE 29 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-spice-example/spice/example.cir: -------------------------------------------------------------------------------- 1 | * EESchema Netlist Version 1.1 (Spice format) creation date: Mon 27 Apr 2015 06:01:42 AM JST 2 | 3 | * To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N 4 | * To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0 5 | * Bring in subckts for power, jacks and opamp 6 | .include components.cir 7 | 8 | *Sheet Name:/ 9 | XU1 7 6 0 4 1 OPAMP 10 | XJ1 2 0 0 JACK_IN 11 | XJ2 7 3 0 JACK_OUT 12 | R2 6 7 50K 13 | R1 2 6 2K 14 | R3 0 3 2K 15 | XP1 4 0 1 PWR_IN 16 | 17 | .op 18 | 19 | .tran 0.1m 3m 20 | .plot tran V(7) V(2) 21 | 22 | .ac dec 10 1 100K 23 | .plot ac V(7) 24 | 25 | .end 26 | -------------------------------------------------------------------------------- /examples/fundamental-laws/m4/millman-theorem.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | dnl tsection(i, 1 to don't show dot, 1 to show A node) 8 | define(`tsection', ` 9 | ifelse(eval($2!=1), 1, `dot') 10 | ifelse(eval($3==1), 1, `dot; "A" above') 11 | resistor(down_ elen,,E); llabel(,R_`$1',) 12 | reversed(`source', down_ elen,V); llabel(,V_`$1',) 13 | ifelse(eval($2!=1), 1, `dot') 14 | ') 15 | 16 | Origin: Here 17 | for_(1, 3, 1, ` 18 | ifelse(eval(m4x!=1), 1, `line up epsilon then right_ elen') 19 | { tsection(m4x, m4x, 0) } 20 | ') 21 | line dotted right_ elen 22 | tsection(i, 1, 1) 23 | line down epsilon then to (Origin.x, Here.y) then up epsilon 24 | .PE 25 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-spice-example/spice/components.cir: -------------------------------------------------------------------------------- 1 | * Components and subcircuits for use in example.cir 2 | 3 | .INCLUDE LMV981.MOD 4 | 5 | * 4 0 1 PWR_IN 6 | * + g - 7 | .subckt PWR_IN 1 2 3 8 | Vneg 1 2 3.3V 9 | Vpos 2 3 3.3V 10 | .ends PWR_IN 11 | 12 | * 7 6 0 4 1 OPAMP 13 | * o - + p n 14 | .subckt OPAMP 1 2 3 4 5 15 | * PINOUT ORDER 1 3 6 2 4 5 16 | * PINOUT ORDER +IN -IN +V -V OUT NSD 17 | Xopamp 3 2 4 5 1 NSD LMV981 18 | .ends OPAMP 19 | 20 | * s x g 21 | .subckt JACK_IN 1 2 3 22 | *** Simulate mic input A-note 23 | Vmic 3 1 ac SIN(0 0.02 440) 24 | .ends JACK_IN 25 | 26 | * s x g 27 | .subckt JACK_OUT 1 2 3 28 | Rwire 1 2 10ohm 29 | .ends JACK_OUT 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/c-examples/ngspice_cb/ngspice_cb_contents.txt: -------------------------------------------------------------------------------- 1 | source code and project files (code::blocks nad MS Visual Studio 2008) 2 | for two console master programs to call ngspice.dll 3 | 4 | include 5 | contains common header sharedspice.h 6 | 7 | ng_shared_test 8 | contains source file main.c, compiles to console app which links to 9 | ngspice.dll dynamically during runtime 10 | 11 | ng_shared_test_v 12 | project files for MS Studio 2008 13 | 14 | ng_shared_test_sl 15 | contains source file main.c, compiles to console app which links 16 | ngspice.dll during the compile/link step 17 | You will need either ngspice.dll.a or ngspice.dll for linking. 18 | 19 | 20 | ng_shared_test_sl_v 21 | project files for MS Studio 2008 22 | You will need ngspice.lib for linking 23 | 24 | -------------------------------------------------------------------------------- /examples/diode/m4/voltage-multiplier-circuit.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | define(`bigdiode', 7 | `resized(2., `diode', $1)') 8 | Ground: Here 9 | ground; dot 10 | source(up_ elen, AC); llabel(,V_{in},); dot; "in" above 11 | capacitor(right_ elen); llabel(,C1,); dot; "1" above 12 | bigdiode(down_ elen); rlabel(,D1,) 13 | { line left_ elen } 14 | capacitor(right_ elen); rlabel(,C2,); dot; "2" below 15 | bigdiode(up_ elen); llabel(,D2,) 16 | { line left_ elen } 17 | capacitor(right_ elen); llabel(,C3,); dot; "3" above 18 | bigdiode(down_ elen); rlabel(,D3,) 19 | { line left_ elen } 20 | capacitor(right_ elen); rlabel(,C4,); dot; "4" below 21 | bigdiode(up_ elen); llabel(,D4,) 22 | { line left_ elen } 23 | .PE 24 | -------------------------------------------------------------------------------- /examples/fundamental-laws/m4/thevenin-norton-theorem.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | T: Here 8 | source(up_ elen, V); llabel(,V_{th},) 9 | line up_ epsilon then right_ epsilon 10 | resistor(right_ elen,,E); llabel(,R_{th},) 11 | dot; "A" above 12 | resistor(down_ elen,,E); llabel(,R_{load},) 13 | dot; "B" below 14 | Tse: Here 15 | line to T then up epsilon 16 | [ 17 | N: Here 18 | source(up_ elen, I); llabel(,I_{no},) 19 | line up_ epsilon then right_ elen/2 20 | {dot; resistor(down_ elen,,E); llabel(,R_{no},); dot} 21 | line right_ elen 22 | dot; "A" above 23 | resistor(down_ elen,,E); llabel(,R_{load},) 24 | dot; "B" below 25 | line to N then up epsilon 26 | ] with .sw at Tse + (elen*3/2,0) 27 | .PE 28 | -------------------------------------------------------------------------------- /examples/resistor/m4/resistor-bridge.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | 4 | linethick_(.5) 5 | define(`dimen_', 10) 6 | epsilon = 1e-3 7 | 8 | Left: dot; "2" rjust 9 | { 10 | Point_(45); resistor(,); dlabel(0,4,,,R_1) 11 | Top: dot; "1" rjust; Point_(-45); resistor(,); dlabel(0,4,,,R_2) 12 | Right: dot; "3" ljust; resistor(from Right to Left); llabel(,R_5,) 13 | } 14 | { 15 | Point_(-45); resistor(,); dlabel(0,-4,,,R_3) 16 | Bottom: dot; "0" rjust; Point_(45); resistor(,); dlabel(0,-4,,,R_4) 17 | } 18 | 19 | small_length = dimen_/4 20 | move to Top; line up small_length then left dimen_*2 then down epsilon 21 | STop: Here 22 | move to Bottom; line down small_length; dot; ground 23 | line to (STop, Here) then up epsilon 24 | SBot: Here 25 | source(from SBot to STop, V); dlabel(0,6,,,V_{in}) 26 | 27 | .PE 28 | -------------------------------------------------------------------------------- /examples/libraries/diode/general-purpose/BAV21.lib: -------------------------------------------------------------------------------- 1 | * -*- spice -*- 2 | * http://www.nxp.com/documents/spice_model/BAV21.prm 3 | * 4 | ******************************************* 5 | * 6 | * BAV21 7 | * 8 | * NXP Semiconductors 9 | * 10 | * General-purpose diode 11 | * 12 | * VRRM = 250V 13 | * IFRM = 625mA 14 | * trr = 50ns 15 | * 16 | * Package pinning does not match Spice model pinning. 17 | * Package: SOD27 18 | * 19 | * Package Pin 1: Cathode 20 | * Package Pin 2: Anode 21 | * 22 | * Simulator: PSPICE 23 | * 24 | ******************************************* 25 | * 26 | .MODEL BAV21 D 27 | + IS=21.910E-9 28 | + N=2.2330 29 | + RS=1.0000E-3 30 | + IKF=19.230E-3 31 | + CJO=1.0300E-12 32 | + M=.1001 33 | + VJ=.75 34 | * + ISR=10.010E-21 * not recognised 35 | + BV=293.10 36 | + IBV=1.2930E-3 37 | + TT=51.940E-9 38 | * 39 | -------------------------------------------------------------------------------- /examples/libraries/diode/general-purpose/BAV21.lib@xyce: -------------------------------------------------------------------------------- 1 | * -*- spice -*- 2 | * http://www.nxp.com/documents/spice_model/BAV21.prm 3 | * 4 | ******************************************* 5 | * 6 | * BAV21 7 | * 8 | * NXP Semiconductors 9 | * 10 | * General-purpose diode 11 | * 12 | * VRRM = 250V 13 | * IFRM = 625mA 14 | * trr = 50ns 15 | * 16 | * Package pinning does not match Spice model pinning. 17 | * Package: SOD27 18 | * 19 | * Package Pin 1: Cathode 20 | * Package Pin 2: Anode 21 | * 22 | * Simulator: PSPICE 23 | * 24 | ******************************************* 25 | * 26 | .MODEL BAV21 D 27 | + IS=21.910E-9 28 | + N=2.2330 29 | + RS=1.0000E-3 30 | * + IKF=19.230E-3 31 | + CJO=1.0300E-12 32 | + M=.1001 33 | + VJ=.75 34 | * + ISR=10.010E-21 * not recognised 35 | + BV=293.10 36 | + IBV=1.2930E-3 37 | + TT=51.940E-9 38 | * 39 | -------------------------------------------------------------------------------- /examples/libraries/diode/schottky/1N5822.lib: -------------------------------------------------------------------------------- 1 | * -*- spice -*- 2 | * https://www.vishay.com/docs/88003/1n5822.txt 3 | * 4 | ********************************** 5 | * Model created by * 6 | * Uni.Dipl.-Ing. Arpad Buermen * 7 | * arpad.burmen@ieee.org * 8 | * Copyright: * 9 | * Thomatronik GmbH, Germany * 10 | * info@thomatronik.de * 11 | ********************************** 12 | * April 2001 13 | * SPICE3 14 | .subckt 1N5822 1 2 15 | Ddio 1 2 legd 16 | Dgr 1 2 grd 17 | .model legd d is = 2.37487E-007 n = 1.98477 rs = 0.0171579 18 | + eg = 1.79999 xti = 3.99991 19 | + cjo = 5.47556E-010 vj = 1.64135 m = 0.603662 fc = 0.5 20 | + tt = 1.4427E-009 bv = 48.4 ibv = 3.5 af = 1 kf = 0 21 | .model grd d is = 1.27781E-005 n = 1.2149 rs = 0.0250254 22 | + eg = 0.55507 xti = 0.794212 23 | .ends 24 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/mixins/_all.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // 3 | // This folder is used to store additional functions or mixins which are 4 | // not part of the default bootstrap eco-system. 5 | // 6 | // We provide already some helper functions such as em(12px, 16px) 7 | // that calculates the pixel values from a given size in relation to 8 | // the parent size. 9 | // 10 | // Additionally we have mixins for managing z-index layers and 11 | // hide-content. 12 | // 13 | // this folder is for additional mixins 14 | // each mixin should be its own maintained file 15 | // 16 | // ############################################################################# 17 | 18 | @import "functions"; 19 | @import "zindex"; 20 | @import "other"; 21 | @import "material_design"; 22 | @import "colours"; 23 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/addons/_all.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // 3 | // If a component is plug-and-playable, it probably belongs in here. Good 4 | // examples are jQuery plugins or Aldryn addons. Sometimes larger 5 | // application such as a shop might also be pluggable. If this is not the 6 | // case, they belong in the /sass/sites directory. 7 | // 8 | // Warning 9 | // You will always encounter the question whether to place a component 10 | // within /sass/addons or /sass/sites. In case of doubts, use the sites 11 | // folder. 12 | // 13 | // this folder is for reusable addons / apps from a cms or alike 14 | // update this file accordingly to include new addons globally 15 | // 16 | // ############################################################################# 17 | 18 | @import "browser"; 19 | -------------------------------------------------------------------------------- /examples/spice-examples/operational-amplifier-model-1.cir: -------------------------------------------------------------------------------- 1 | OPMODEL1.CIR - OPAMP MODEL SINGLE-POLE 2 | * from http://www.ecircuitcenter.com/OpModels/OpampModels.htm 3 | * 4 | VS 1 0 AC 1 PWL(0US 0V 0.01US 1V) 5 | XOP 1 0 3 OPAMP1 6 | RL 3 0 1K 7 | * 8 | * OPAMP MACRO MODEL, SINGLE-POLE 9 | * connections: non-inverting input 10 | * | inverting input 11 | * | | output 12 | * | | | 13 | .SUBCKT OPAMP1 1 2 6 14 | * INPUT IMPEDANCE 15 | RIN 1 2 10MEG 16 | * DC GAIN=100K AND POLE1=100HZ 17 | * UNITY GAIN = DCGAIN X POLE1 = 10MHZ 18 | EGAIN 3 0 1 2 100K 19 | RP1 3 4 1K 20 | CP1 4 0 1.5915UF 21 | * OUTPUT BUFFER AND RESISTANCE 22 | EBUFFER 5 0 4 0 1 23 | ROUT 5 6 10 24 | .ENDS 25 | * 26 | * ANALYSIS 27 | .AC DEC 5 1 100MEG 28 | *.TRAN 0.05US 2US 29 | .PLOT AC VM(3) 30 | .PROBE 31 | .END 32 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-pyspice-example/kicad-pyspice-example-rescue.lib: -------------------------------------------------------------------------------- 1 | EESchema-LIBRARY Version 2.3 2 | #encoding utf-8 3 | # 4 | # LM193-RESCUE-kicad-pyspice-example 5 | # 6 | DEF LM193-RESCUE-kicad-pyspice-example U 0 20 Y Y 2 F N 7 | F0 "U" 150 150 60 H V C CNN 8 | F1 "LM193-RESCUE-kicad-pyspice-example" 200 -200 60 H V C CNN 9 | F2 "" 0 0 60 H V C CNN 10 | F3 "" 0 0 60 H V C CNN 11 | DRAW 12 | P 4 0 1 0 -200 200 200 0 -200 -200 -200 200 N 13 | X ~ 1 500 0 300 L 40 40 1 1 C 14 | X _ 2 -500 -100 300 R 40 40 1 1 I 15 | X + 3 -500 100 300 R 40 40 1 1 I 16 | X V- 4 -100 -400 250 U 40 40 1 1 W 17 | X V+ 8 -100 400 250 D 40 40 1 1 W 18 | X V- 4 -100 -400 250 U 40 40 2 1 W 19 | X + 5 -500 100 300 R 40 40 2 1 I 20 | X _ 6 -500 -100 300 R 40 40 2 1 I 21 | X ~ 7 500 0 300 L 40 40 2 1 C 22 | X V+ 8 -100 400 250 D 40 40 2 1 W 23 | ENDDRAW 24 | ENDDEF 25 | # 26 | #End Library 27 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/page.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block html_lang %}{{ page.lang }}{% endblock %} 5 | 6 | {% block title %}{{ SITENAME }} - {{ page.title }}{%endblock%} 7 | 8 | {% block head %} 9 | {{ super() }} 10 | 11 | {% import 'translations.html' as translations with context %} 12 | {% if translations.entry_hreflang(page) %} 13 | {{ translations.entry_hreflang(page) }} 14 | {% endif %} 15 | {% endblock %} 16 | 17 | {% block content %} 18 |

{{ page.title }}

19 | {% import 'translations.html' as translations with context %} 20 | {{ translations.translations_for(page) }} 21 | 22 | {{ page.content }} 23 | 24 | {% if page.modified %} 25 |

26 | Last updated: {{ page.locale_modified }} 27 |

28 | {% endif %} 29 | {% endblock %} 30 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/layout/_footer.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Footer 3 | 4 | // all styles related to the global footer should be declared within this file 5 | // apply the "sites/" nesting described within the documentation if the file is 6 | // getting to large 7 | 8 | // .page-footer 9 | footer { 10 | @extend .mt-3; 11 | @extend .py-3; 12 | @include rised-component(); 13 | @include white_on_dark(); 14 | } 15 | 16 | .footer-container { 17 | @extend .container; 18 | @extend .d-flex; 19 | 20 | #copyright-notice { 21 | } 22 | 23 | #page-top-link { 24 | @extend .ml-auto; 25 | } 26 | } 27 | 28 | @media(max-width: $grid-float-breakpoint) { 29 | .footer-container { 30 | // @extend .flex-column; // but don't work in media ... 31 | flex-direction: column; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-spice-example/netlist/kicad-spice-example.number-node.cir: -------------------------------------------------------------------------------- 1 | * /home/gv/fabrice/developpement/PySpice/examples/spice-parser/kicad-spice-example/kicad-spice-example-3.cir 2 | 3 | * EESchema Netlist Version 1.1 (Spice format) creation date: jeu. 26 nov. 2015 16:43:09 CET 4 | 5 | * To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N 6 | * To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0 7 | * 8 | * Bring in subckts for power, jacks and opamp 9 | .include components.cir 10 | 11 | * Sheet Name: / 12 | XU1 7 6 5 4 1 OPAMP 13 | J1 2 5 5 JACK_IN 14 | J2 7 3 5 JACK_OUT 15 | R2 6 7 50K 16 | R1 2 6 2K 17 | R3 5 3 2K 18 | P1 4 5 1 PWR_IN 19 | 20 | .op 21 | 22 | .tran 0.1m 3m 23 | .plot tran V(7) V(2) 24 | 25 | .ac dec 10 1 100K 26 | .plot ac V(7) 27 | 28 | .end 29 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/mixins/_other.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // OTHER 3 | 4 | // hides text in an element so you can see the background. 5 | // INFO: conflicts otherwise with hide-text from bootstrap 6 | @mixin hide-content() { 7 | $approximate-em-value: 12px / 1em; 8 | $wider-than-any-screen: -9999em; 9 | text-indent: $wider-than-any-screen * $approximate-em-value; 10 | overflow: hidden; 11 | text-align: left; 12 | } 13 | 14 | // outline button mixin which extends bootstrap button-variant 15 | @mixin button-variant-outline($color, $border, $color-hover: #fff) { 16 | @include button-variant($color, transparent, $border); 17 | &:hover, 18 | &:active, 19 | &.active, 20 | &:focus, 21 | .open > &.dropdown-toggle { 22 | color: $color-hover; 23 | background-color: $border; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /doc/sphinx/source/on-the-web.rst: -------------------------------------------------------------------------------- 1 | .. _on-the-web-page: 2 | 3 | ==================== 4 | PySpice on the Web 5 | ==================== 6 | 7 | *Don't hesitate to contact me to aggregate web content about PySpice.* 8 | 9 | Articles 10 | -------- 11 | 12 | You will find here a list of links to some articles talking about PySpice: 13 | 14 | * http://www.tazabekov.com/blog/2017/06/digital-to-analog-converter-modelling-with-pyspice 15 | * http://www.tazabekov.com/blog/2017/07/analog-to-digital-converter-modelling-with-pyspice 16 | 17 | On Github 18 | --------- 19 | 20 | You will find here a list of links to git repositories containing PySpice examples: 21 | 22 | * `https://github.com/OlzhasT/PySpiceCircuits- `_ 23 | cf. http://www.tazabekov.com/blog/2017/06/digital-to-analog-converter-modelling-with-pyspice 24 | * https://github.com/danielvilas/PySpice-Library 25 | -------------------------------------------------------------------------------- /examples/power-supplies/m4/capacitive-half-wave-rectification-post-zener-circuit.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | define(`bigdiode', 8 | `resized(2., `diode', $1)') 9 | define(`bigzenerdiode', 10 | `resized(2., `reversed', `diode', $1, S)') 11 | Neutral: Here 12 | dot; "N" below; 13 | source(up_ elen, AC); llabel(,V_{AC},); dot; "L" above; 14 | resistor(right_ elen); llabel(,R_{in},); dot; "1" above; 15 | capacitor(right_ elen); llabel(,C_{in},); dot; "2" above; 16 | { 17 | bigzenerdiode(down_ elen); rlabel(,Dz,); dot; 18 | } 19 | bigdiode(right_ elen); rlabel(,D,); dot; 20 | { 21 | capacitor(down_ elen, C+); llabel(,C,); dot; 22 | } 23 | line right_ elen then down epsilon; "out" above; 24 | resistor(down_ elen); llabel(,R_{load},); 25 | line down epsilon then to Neutral then up epsilon 26 | .PE 27 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/settings/_bootstrap4.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // Typography 3 | 4 | $font-family-sans-serif: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif; 5 | $font-family-serif: "Roboto Slab",Georgia, "Times New Roman", Times, serif; 6 | // Default monospace fonts for ``, ``, and `
`.
 7 | $font-family-monospace:   Menlo, Monaco, Consolas, "Courier New", monospace;
 8 | 
 9 | // #############################################################################
10 | // Grid system
11 | 
12 | // Point at which the navbar becomes uncollapsed.
13 | $grid-float-breakpoint: 768px; // medium
14 | 
15 | // #############################################################################
16 | // Code
17 | 
18 | // User in _getthecode.scss
19 | // $pre-color
20 | $pre-bg:                      #f5f5f5;
21 | $pre-border-color:            #ccc;
22 | 


--------------------------------------------------------------------------------
/doc/pelican/theme/scss/libs/_all.scss:
--------------------------------------------------------------------------------
 1 | // #############################################################################
 2 | //
 3 | // All independent files are placed within this folder. This implies that
 4 | // the order of inclusion does not matter within /sass/libs/_all.scss.
 5 | //
 6 | // Hint
 7 | // Libraries are, in their very core, plug-and-playable. The main
 8 | // difference between libraries and other plug-and-play components is,
 9 | // that if a library is removed, things will break.
10 | //
11 | // this folder is for additional independent libraries such as 960gs or
12 | // twitter bootstrap these libraries do not depend on other elements
13 | //
14 | // #############################################################################
15 | 
16 | @import "bootstrap/bootstrap";
17 | 
18 | @import "fontawesome/fontawesome";
19 | @import "fontawesome/brands";
20 | @import "fontawesome/solid";
21 | 
22 | // @import "iconfont"; uncomment to enable custom icons
23 | 


--------------------------------------------------------------------------------
/doc/pelican/theme/scss/mixins/_zindex.scss:
--------------------------------------------------------------------------------
 1 | // #############################################################################
 2 | // ZINDEX
 3 | 
 4 | // handle z-index mor easily
 5 | // DOCS: http://www.sitepoint.com/better-solution-managing-z-index-sass/
 6 | 
 7 | @function map-has-nested-keys($map, $keys...) {
 8 |     @each $key in $keys {
 9 |         @if not map-has-key($map, $key) {
10 |             @return false;
11 |         }
12 |         $map: map-get($map, $key);
13 |     }
14 | 
15 |     @return true;
16 | }
17 | @function map-deep-get($map, $keys...) {
18 |     @each $key in $keys {
19 |         $map: map-get($map, $key);
20 |     }
21 | 
22 |     @return $map;
23 | }
24 | @function z($layers...) {
25 |     @if not map-has-nested-keys($z-layers, $layers...) {
26 |         @error "No layer found for `#{inspect($layers...)}`
27 |                 in $z-layers map. Property omitted.";
28 |     }
29 | 
30 |     @return map-deep-get($z-layers, $layers...);
31 | }
32 | 


--------------------------------------------------------------------------------
/examples/spice-parser/kicad-spice-example/kicad-spice-example-rescue.lib:
--------------------------------------------------------------------------------
 1 | EESchema-LIBRARY Version 2.3
 2 | #encoding utf-8
 3 | #
 4 | # GND-RESCUE-kicad-spice-example
 5 | #
 6 | DEF ~GND-RESCUE-kicad-spice-example #PWR 0 0 Y Y 1 F P
 7 | F0 "#PWR" 0 0 30 H I C CNN
 8 | F1 "GND-RESCUE-kicad-spice-example" 0 -70 30 H I C CNN
 9 | F2 "" 0 0 60 H V C CNN
10 | F3 "" 0 0 60 H V C CNN
11 | DRAW
12 | P 4 0 1 0  -50 0  0 -50  50 0  -50 0 N
13 | X GND 1 0 0 0 U 30 30 1 1 W N
14 | ENDDRAW
15 | ENDDEF
16 | #
17 | # R-RESCUE-kicad-spice-example
18 | #
19 | DEF R-RESCUE-kicad-spice-example R 0 0 N Y 1 F N
20 | F0 "R" 80 0 40 V V C CNN
21 | F1 "R-RESCUE-kicad-spice-example" 7 1 40 V V C CNN
22 | F2 "" -70 0 30 V V C CNN
23 | F3 "" 0 0 30 H V C CNN
24 | $FPLIST
25 |  R?
26 |  SM0603
27 |  SM0805
28 |  R?-*
29 |  SM1206
30 | $ENDFPLIST
31 | DRAW
32 | S -40 150 40 -150 0 1 12 N
33 | X ~ 1 0 250 100 D 60 60 1 1 P
34 | X ~ 2 0 -250 100 U 60 60 1 1 P
35 | ENDDRAW
36 | ENDDEF
37 | #
38 | #End Library
39 | 


--------------------------------------------------------------------------------
/issues/issue-169.py:
--------------------------------------------------------------------------------
 1 | import PySpice.Logging.Logging as Logging
 2 | logger = Logging.setup_logging()
 3 | 
 4 | from PySpice.Spice.Netlist import Circuit
 5 | from PySpice.Unit import *
 6 | from PySpice.Spice.BasicElement import BehavioralSource
 7 | 
 8 | circuit = Circuit('test')
 9 | # circuit.LosslessTransmissionLine('line1', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50)
10 | circuit.LosslessTransmissionLine('line1', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50, TD=40e-9)
11 | circuit.LosslessTransmissionLine('line2', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50, time_delay=40@u_ns)
12 | # circuit.LosslessTransmissionLine('line3', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50, frequency=50@u_ns)
13 | circuit.LosslessTransmissionLine('line3', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50, frequency=50@u_Hz, normalized_length=10)
14 | circuit.LosslessTransmissionLine('line4', 'output', circuit.gnd, 'input', circuit.gnd, Z0=50, F=50@u_Hz, NL=10)
15 | 
16 | print(circuit)
17 | 


--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
 1 | include .gitignore
 2 | include .travis.yml
 3 | include CHANGES.txt
 4 | include GPL-V3.0.txt
 5 | include LICENSE.txt
 6 | include MANIFEST.in
 7 | include README.html
 8 | include README.rst
 9 | include README.txt
10 | include bower/bower.json
11 | include invoke.yaml
12 | include make-release.sh
13 | include requirements.txt requirements-dev.txt
14 | include setenv.sh start.sh
15 | include setup_data.py
16 | include tox.ini
17 | recursive-include PySpice *.py *.yml *.h
18 | recursive-include doc *
19 | recursive-include doc/sphinx/source/_static *
20 | recursive-include examples *
21 | recursive-include gh-pages *
22 | recursive-include tools *
23 | recursive-include unit-test *.py
24 | recursive-include spice-examples *
25 | recursive-include issues *.py *.lib
26 | global-exclude *~
27 | global-exclude *__pycache__*
28 | global-exclude *.pyc
29 | global-exclude *.pdf
30 | prune build
31 | prune doc/sphinx/build
32 | prune doc/sphinx/source/api
33 | prune doc/sphinx/source/examples
34 | prune doc/pelican


--------------------------------------------------------------------------------
/doc/pelican/theme/scss/settings/_all.scss:
--------------------------------------------------------------------------------
 1 | // #############################################################################
 2 | //
 3 | // It is very useful to store values, that are used more than twice,
 4 | // within their own variable. We even encourage storing all colour values
 5 | // within the settings. Don’t repeat yourself. Create a sub-structure,
 6 | // similar to /sites if the structure becomes more complex.
 7 | //
 8 | // Warning
 9 | // Do not add additional variables to
10 | // /private/sass/settings/_bootstrap.scss. This file is reserved for
11 | // Bootstrap-only variables. Use /private/sass/settings/_custom.scss
12 | // instead.
13 | //
14 | // this folder contains required variables for colors, sizes, styles and more
15 | // add additional files for encapsulated settings
16 | //
17 | // #############################################################################
18 | 
19 | @import "pre_bootstrap";
20 | @import "bootstrap4";
21 | 
22 | // @import "fontawesome_v5";
23 | 
24 | //! @import "custom";
25 | 


--------------------------------------------------------------------------------
/PySpice/Spice/Expression/__init__.py:
--------------------------------------------------------------------------------
 1 | ####################################################################################################
 2 | #
 3 | # PySpice - A Spice Package for Python
 4 | # Copyright (C) 2017 Fabrice Salvaire
 5 | #
 6 | # This program is free software: you can redistribute it and/or modify
 7 | # it under the terms of the GNU General Public License as published by
 8 | # the Free Software Foundation, either version 3 of the License, or
 9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program.  If not, see .
18 | #
19 | ####################################################################################################
20 | 


--------------------------------------------------------------------------------
/examples/libraries/diode/switching/1N4148.lib:
--------------------------------------------------------------------------------
 1 | * -*- spice -*-
 2 | * http://www.nxp.com/documents/spice_model/1N4148.prm
 3 | *
 4 | *******************************************
 5 | *
 6 | * 1N4148
 7 | * 
 8 | * NXP Semiconductors
 9 | * 
10 | * High-speed diodes
11 | * 
12 | * VRRM = 100V
13 | * IFRM = 450 mA 
14 | * trr  = 4ns
15 | * 
16 | * Package pinning does not match Spice model pinning.
17 | * Package: SOD 27
18 | * 
19 | * Package Pin 1 : Cathode
20 | * Package Pin 2 : Anode
21 | * 
22 | * Simulator: PSPICE
23 | *
24 | *******************************************
25 | *
26 | .SUBCKT 1N4148 1 2 
27 | *
28 | * The resistor R1 does not reflect 
29 | * a physical device. Instead it
30 | * improves modeling in the reverse 
31 | * mode of operation.
32 | *
33 | R1 1 2 5.827E+9 
34 | D1 1 2 1N4148
35 | *
36 | .MODEL 1N4148 D 
37 | + IS = 4.352E-9 
38 | + N = 1.906 
39 | + BV = 110 
40 | + IBV = 0.0001 
41 | + RS = 0.6458 
42 | + CJO = 7.048E-13 
43 | + VJ = 0.869 
44 | + M = 0.03 
45 | + FC = 0.5 
46 | + TT = 3.48E-9 
47 | .ENDS
48 | *
49 | 


--------------------------------------------------------------------------------
/examples/spice-parser/kicad-spice-example/netlist/kicad-spice-example.default.cir:
--------------------------------------------------------------------------------
 1 | * /home/gv/fabrice/developpement/PySpice/examples/spice-parser/kicad-spice-example/kicad-spice-example-0.cir
 2 | 
 3 | * EESchema Netlist Version 1.1 (Spice format) creation date: jeu. 26 nov. 2015 16:43:57 CET
 4 | 
 5 | * To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N
 6 | * To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0
 7 | * 
 8 | * Bring in subckts for power, jacks and opamp
 9 | .include components.cir
10 | 
11 | * Sheet Name: /
12 | U1  Net-_J2-Pad1_ Net-_R1-Pad2_ GND VSS VCC OPAMP		
13 | J1  Net-_J1-Pad1_ GND GND JACK_IN		
14 | J2  Net-_J2-Pad1_ Net-_J2-Pad2_ GND JACK_OUT		
15 | R2  Net-_R1-Pad2_ Net-_J2-Pad1_ 50K		
16 | R1  Net-_J1-Pad1_ Net-_R1-Pad2_ 2K		
17 | R3  GND Net-_J2-Pad2_ 2K		
18 | P1  VSS GND VCC PWR_IN		
19 | 
20 | .op
21 | 
22 | .tran 0.1m 3m
23 | .plot tran V(7) V(2)
24 | 
25 | .ac dec 10 1 100K
26 | .plot ac V(7)
27 | 
28 | .end
29 | 


--------------------------------------------------------------------------------
/examples/spice-parser/kicad-spice-example/netlist/kicad-spice-example.using-X.cir:
--------------------------------------------------------------------------------
 1 | * /home/gv/fabrice/developpement/PySpice/examples/spice-parser/kicad-spice-example/kicad-spice-example-2.cir
 2 | 
 3 | * EESchema Netlist Version 1.1 (Spice format) creation date: jeu. 26 nov. 2015 16:42:56 CET
 4 | 
 5 | * To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N
 6 | * To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0
 7 | * 
 8 | * Bring in subckts for power, jacks and opamp
 9 | .include components.cir
10 | 
11 | * Sheet Name: /
12 | XU1  Net-_J2-Pad1_ Net-_R1-Pad2_ GND VSS VCC OPAMP		
13 | J1  Net-_J1-Pad1_ GND GND JACK_IN		
14 | J2  Net-_J2-Pad1_ Net-_J2-Pad2_ GND JACK_OUT		
15 | R2  Net-_R1-Pad2_ Net-_J2-Pad1_ 50K		
16 | R1  Net-_J1-Pad1_ Net-_R1-Pad2_ 2K		
17 | R3  GND Net-_J2-Pad2_ 2K		
18 | P1  VSS GND VCC PWR_IN		
19 | 
20 | .op
21 | 
22 | .tran 0.1m 3m
23 | .plot tran V(7) V(2)
24 | 
25 | .ac dec 10 1 100K
26 | .plot ac V(7)
27 | 
28 | .end
29 | 


--------------------------------------------------------------------------------
/doc/pelican/theme/scss/layout/_content.scss:
--------------------------------------------------------------------------------
 1 | // #################################################################################################
 2 | // Content
 3 | 
 4 | // Sticky Footer
 5 | // https://css-tricks.com/couple-takes-sticky-footer/
 6 | 
 7 | // html, body {
 8 | //   height: 100%;
 9 | // }
10 | // body {
11 | //   display: flex;
12 | //   flex-direction: column;
13 | // }
14 | // .content {
15 | //   flex: 1 0 auto;
16 | // }
17 | // footer #page-footer {
18 | //     flex-shrink: 0;
19 | // }
20 | 
21 | html {
22 |   height: 100%;
23 | }
24 | 
25 | body {
26 |   min-height: 100%;
27 |   display: grid;
28 |   grid-template-rows: auto 1fr auto;
29 |   grid-template-areas:
30 |       "header"
31 |       "content"
32 |       "footer";
33 | }
34 | 
35 | header#page-header {
36 |     grid-area: header;
37 |     // grid-row-start: 1;
38 |     // grid-row-end: 2;
39 | }
40 | 
41 | div#page-content {
42 |     grid-area: content;
43 | }
44 | 
45 | footer#page-footer {
46 |     grid-area: footer;
47 |     // grid-row-start: 3;
48 |     // grid-row-end: 4;
49 | }
50 | 


--------------------------------------------------------------------------------
/examples/power-supplies/HP54501A.py:
--------------------------------------------------------------------------------
 1 | ####################################################################################################
 2 | 
 3 | from PySpice.Spice.Netlist import SubCircuitFactory
 4 | from PySpice.Unit import *
 5 | 
 6 | ####################################################################################################
 7 | 
 8 | class HP54501A(SubCircuitFactory):
 9 | 
10 |     NAME = 'HP54501A'
11 |     NODES = ('line_plus', 'line_minus')
12 | 
13 |     ##############################################
14 | 
15 |     def __init__(self, diode_model):
16 | 
17 |         super().__init__()
18 | 
19 |         self.C(1, 'line_plus', 'line_minus', 1@u_uF)
20 | 
21 |         self.X('D1', diode_model, 'top', 'line_plus')
22 |         self.X('D2', diode_model, 'line_plus', 'scope_ground')
23 |         self.X('D3', diode_model, 'top', 'line_minus')
24 |         self.X('D4', diode_model, 'line_minus', 'scope_ground')
25 | 
26 |         self.R(1, 'top', 'output', 10)
27 |         self.C(2, 'output', 'scope_ground', 50@u_uF)
28 |         self.R(2, 'output', 'scope_ground', 900@u_Ω)
29 | 


--------------------------------------------------------------------------------
/bin/cir2py:
--------------------------------------------------------------------------------
 1 | #! /usr/bin/env python3
 2 | 
 3 | ####################################################################################################
 4 | #
 5 | # PySpice - A Spice Package for Python
 6 | # Copyright (C) 2020 Fabrice Salvaire
 7 | #
 8 | # This program is free software: you can redistribute it and/or modify
 9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation, either version 3 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program.  If not, see .
20 | #
21 | ####################################################################################################
22 | 
23 | from PySpice.Scripts.cir2py import main
24 | main()
25 | 


--------------------------------------------------------------------------------
/doc/sphinx/source/how-to-refer.rst:
--------------------------------------------------------------------------------
 1 | .. _how-to-refer-page:
 2 | 
 3 | ===========================
 4 |  How to Refer to PySpice ?
 5 | ===========================
 6 | 
 7 | Up to now, the official url for PySpice is https://pyspice.fabrice-salvaire.fr
 8 | 
 9 | *A permanent redirection will be implemented if the domain change in the future.*
10 | 
11 | On Github, you can use the **pyspice** `topic `_ for repository related to PySpice.
12 | 
13 | A typical `BibTeX `_ citation would be, for example:
14 | 
15 | .. code:: bibtex
16 | 
17 |     @software{PySpice,
18 |       author = {Fabrice Salvaire}, % actual author and maintainer
19 |       title = {PySpice},
20 |       url = {https://pyspice.fabrice-salvaire.fr},
21 |       version = {x.y},
22 |       date = {yyyy-mm-dd}, % set to the release date
23 |     }
24 | 
25 |     @Misc{PySpice,
26 |       author = {Fabrice Salvaire},
27 |       title = {PySpice},
28 |       howpublished = {\url{https://pyspice.fabrice-salvaire.fr}},
29 |       year = {yyyy}
30 |     }
31 | 


--------------------------------------------------------------------------------
/examples/fundamental-laws/m4/millman-theorem-with-current-source.m4:
--------------------------------------------------------------------------------
 1 | .PS
 2 | cct_init(SIdefaults)
 3 | linethick_(.5)
 4 | define(`dimen_', 10)
 5 | elen = dimen_*3/2
 6 | epsilon = 1e-3
 7 | dnl Xsection(i, 1 to don't show dot, 1 to show A node)
 8 | define(`Vsection', `
 9 |   ifelse(eval($2!=1), 1, `dot')
10 |   ifelse(eval($3==1), 1, `dot; "A" above')
11 |   resistor(down_ elen,,E); llabel(,R_`$1',)
12 |   reversed(`source', down_ elen,V); llabel(,V_`$1',)
13 |   ifelse(eval($2!=1), 1, `dot')
14 |  ')
15 | define(`Isection', `
16 |   ifelse(eval($2!=1), 1, `dot')
17 |   ifelse(eval($3==1), 1, `dot; "A" above')
18 |   resistor(down_ elen,,E); llabel(,R_`$1',)
19 |   reversed(`source', down_ elen,I); llabel(,I_`$1',)
20 |   ifelse(eval($2!=1), 1, `dot')
21 |  ')
22 | 
23 | Origin: Here
24 |   for_(1, 3, 1, `
25 |     ifelse(eval(m4x!=1), 1, `line up epsilon then right_ elen')
26 |     { Vsection(m4x, m4x, 0) }
27 |   ')
28 |   line dotted right_ elen
29 |   { Vsection(i, 0, 0) }
30 |   line dotted right_ elen
31 |   Isection(k, 1, 1)
32 | line down epsilon then to (Origin.x, Here.y) then up epsilon
33 | .PE
34 | 


--------------------------------------------------------------------------------
/issues/issue-11.py:
--------------------------------------------------------------------------------
 1 | ####################################################################################################
 2 | 
 3 | import PySpice.Logging.Logging as Logging
 4 | logger = Logging.setup_logging()
 5 | 
 6 | ####################################################################################################
 7 | 
 8 | from PySpice.Spice.Netlist import Circuit, SubCircuit
 9 | from PySpice.Unit.Units import *
10 | 
11 | ####################################################################################################
12 | 
13 | circuit = Circuit('Test')
14 | 
15 | summer = SubCircuit('Sum', 1, 2, 3, K1=1.0, K2=1.0)
16 | summer.BehavorialSource(1, 3, summer.gnd, v='{K1}*V(1) + {K2}*V(2)')
17 | summer.BehavorialSource(2, 3, summer.gnd, voltage_expression='{K1}*V(1) + {K2}*V(2)')
18 | 
19 | print(summer.B1.v)
20 | print(summer.B1.voltage_expression)
21 | 
22 | print(str(summer))
23 | 
24 | ####################################################################################################
25 | #
26 | # End
27 | #
28 | ####################################################################################################
29 | 


--------------------------------------------------------------------------------
/bin/pyspice-post-installation:
--------------------------------------------------------------------------------
 1 | #! /usr/bin/env python3
 2 | 
 3 | ####################################################################################################
 4 | #
 5 | # PySpice - A Spice Package for Python
 6 | # Copyright (C) 2020 Fabrice Salvaire
 7 | #
 8 | # This program is free software: you can redistribute it and/or modify
 9 | # it under the terms of the GNU General Public License as published by
10 | # the Free Software Foundation, either version 3 of the License, or
11 | # (at your option) any later version.
12 | #
13 | # This program is distributed in the hope that it will be useful,
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 | # GNU General Public License for more details.
17 | #
18 | # You should have received a copy of the GNU General Public License
19 | # along with this program.  If not, see .
20 | #
21 | ####################################################################################################
22 | 
23 | from PySpice.Scripts.pyspice_post_installation import main
24 | main()


--------------------------------------------------------------------------------
/examples/diode/m4/full-wave-rectification.m4:
--------------------------------------------------------------------------------
 1 | .PS
 2 | cct_init(SIdefaults)
 3 | ifdef(`m4pco',`resetrgb')
 4 | 
 5 | linethick_(.5)
 6 | define(`dimen_', 10)
 7 | elen = dimen_*3/2
 8 | 
 9 | Origin: Here
10 |   T: source(up_ elen, AC) ; llabel(,V_{in},); "in" above
11 |   bridge_len = dimen_/2
12 |   W: T.centre + (dimen_/2,0)
13 |   N: W + (bridge_len,  bridge_len)
14 |   S: W + (bridge_len, -bridge_len)
15 |   E: S + (bridge_len,  bridge_len)
16 |     diode(from W to N)
17 |     diode(from S to E)
18 |   R: resistor(from E + (dimen_,0) down_ dimen_); llabel(+,R_{load},-) # ; "out" above
19 |   C: capacitor(down_ R.start.y - R.end.y from 0.5 between E and R.start, C+); rlabel(,C,)
20 | 
21 |   setrgb(1,0,0) # red
22 |     dot(at T.end)
23 |     dot(at C.start)
24 |     line from T.end to (N,T.end) then to N; dot
25 |     diode(to E); dot
26 |     line from E to R.start; dot
27 |   resetrgb
28 | 
29 |   setrgb(0,1,0) # green
30 |     dot(at C.end)
31 |     dot(at R.end)
32 |     ground
33 |     line to (W,Here) then to W; dot
34 |     diode(to S); dot
35 |     line to (Here,T.start) then to T.start; dot
36 |   resetrgb
37 | 
38 | .PE
39 | 


--------------------------------------------------------------------------------
/issues/issue-150.py:
--------------------------------------------------------------------------------
 1 | ####################################################################################################
 2 | 
 3 | import PySpice.Logging.Logging as Logging
 4 | logger = Logging.setup_logging()
 5 | 
 6 | ####################################################################################################
 7 | 
 8 | from PySpice.Spice.Netlist import Circuit
 9 | from PySpice.Unit import *
10 | 
11 | ####################################################################################################
12 | 
13 | thevenin_circuit = Circuit('Thevenin Representation')
14 | 
15 | thevenin_circuit.V('input', 1, thevenin_circuit.gnd, 10@u_V)
16 | thevenin_circuit.R('generator', 1, 'load', 10@u_Ω)
17 | thevenin_circuit.R('load', 'load', thevenin_circuit.gnd, 1@u_kΩ)
18 | 
19 | simulator = thevenin_circuit.simulator(simulator='xyce-serial', temperature=25, nominal_temperature=25)
20 | # simulator._spice_server._xyce_command = "C:\\Program Files\\Xyce 6.10 OPENSOURCE\\bin\\Xyce.exe"
21 | analysis = simulator.operating_point()
22 | 
23 | load_node = analysis.load
24 | print('Node {}: {:5.2f} V'.format(str(load_node), float(load_node)))
25 | #o#
26 | 


--------------------------------------------------------------------------------
/PySpice/Spice/NgSpice/__init__.py:
--------------------------------------------------------------------------------
 1 | ####################################################################################################
 2 | #
 3 | # PySpice - A Spice Package for Python
 4 | # Copyright (C) 2020 Fabrice Salvaire
 5 | #
 6 | # This program is free software: you can redistribute it and/or modify
 7 | # it under the terms of the GNU General Public License as published by
 8 | # the Free Software Foundation, either version 3 of the License, or
 9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program.  If not, see .
18 | #
19 | ####################################################################################################
20 | 
21 | __all__ = ['NGSPICE_SUPPORTED_VERSION']
22 | 
23 | from .SimulationType import LAST_VERSION as NGSPICE_SUPPORTED_VERSION
24 | 


--------------------------------------------------------------------------------
/examples/libraries/transistor/2N2222A.lib:
--------------------------------------------------------------------------------
 1 | * -*- spice -*-
 2 | *
 3 | * http://www.onsemi.com/pub_link/Collateral/2N2222A.SP3.TXT
 4 | *
 5 | **************************************
 6 | *      Model Generated by MODPEX     *
 7 | *Copyright(c) Symmetry Design Systems*
 8 | *         All Rights Reserved        *
 9 | *    UNPUBLISHED LICENSED SOFTWARE   *
10 | *   Contains Proprietary Information *
11 | *      Which is The Property of      *
12 | *     SYMMETRY OR ITS LICENSORS      *
13 | *Commercial Use or Resale Restricted *
14 | *   by Symmetry License Agreement    *
15 | **************************************
16 | * Model generated on Feb 28, 13
17 | * MODEL FORMAT: SPICE3
18 | .MODEL 2n2222a npn
19 | +IS=3.88184e-14 BF=929.846 NF=1.10496 VAF=16.5003
20 | +IKF=0.019539 ISE=1.0168e-11 NE=1.94752 BR=48.4545
21 | +NR=1.07004 VAR=40.538 IKR=0.19539 ISC=1.0168e-11
22 | +NC=4 RB=0.1 IRB=0.1 RBM=0.1
23 | +RE=0.0001 RC=0.426673 XTB=0.1 XTI=1
24 | +EG=1.05 CJE=2.23677e-11 VJE=0.582701 MJE=0.63466
25 | +TF=4.06711e-10 XTF=3.92912 VTF=17712.6 ITF=0.4334
26 | +CJC=2.23943e-11 VJC=0.576146 MJC=0.632796 XCJC=1
27 | +FC=0.170253 CJS=0 VJS=0.75 MJS=0.5
28 | +TR=1e-07 PTF=0 KF=0 AF=1
29 | 
30 | 


--------------------------------------------------------------------------------
/doc/sphinx/source/abbreviation.txt:
--------------------------------------------------------------------------------
 1 | .. -*- Mode: rst -*-
 2 | 
 3 | .. _CFFI: http://cffi.readthedocs.org/en/latest/
 4 | .. _Circuit_macros: http://ece.uwaterloo.ca/~aplevich/Circuit_macros
 5 | .. _IPython: http://ipython.org
 6 | .. _Kicad: http://www.kicad-pcb.org
 7 | .. _Matplotlib: http://matplotlib.org
 8 | .. _Modelica: http://www.modelica.org
 9 | .. _Ngspice: http://ngspice.sourceforge.net
10 | .. _Numpy: http://www.numpy.org
11 | .. _PyPI: https://pypi.python.org/pypi
12 | .. _Pyterate: https://github.com/FabriceSalvaire/Pyterate
13 | .. _Python: http://python.org
14 | .. _Sphinx: http://sphinx-doc.org
15 | .. _Tikz: http://www.texample.net/tikz
16 | .. _Xyce: https://xyce.sandia.gov
17 | 
18 | .. |CFFI| replace:: CFFI
19 | .. |Circuit_macros| replace:: Circuit_macros
20 | .. |IPython| replace:: IPython
21 | .. |Kicad| replace:: Kicad
22 | .. |Matplotlib| replace:: Matplotlib
23 | .. |Modelica| replace:: Modelica
24 | .. |Ngspice| replace:: Ngspice
25 | .. |Numpy| replace:: Numpy
26 | .. |PyPI| replace:: PyPI
27 | .. |Pyterate| replace:: Pyterate
28 | .. |Python| replace:: Python
29 | .. |Sphinx| replace:: Sphinx
30 | .. |Tikz| replace:: Tikz
31 | .. |Xyce| replace:: Xyce
32 | 


--------------------------------------------------------------------------------
/examples/transistor/m4/ac-coupled-amplifier.m4:
--------------------------------------------------------------------------------
 1 | .PS
 2 | 
 3 | cct_init
 4 | 
 5 | elen = 0.75
 6 | epsilon = 1e-3
 7 | 
 8 | G: ground; dot; "0" rjust
 9 |   source(up_ elen,AC); llabel(,V_{in},); dot; "in" rjust
10 |   capacitor(right_ elen); llabel(,C_{1},); dot; "2" rjust above
11 |   { resistor(down_ to (Here,G)); rlabel(,R_{2}) }
12 |   { R1: resistor(up_ elen_*1.5); llabel(,R_{1}); dot; "5" above }
13 | 
14 |   line right_ elen_/2; up_ # Q1 direction
15 | Q1: bi_tr(,,,E) with .B at Here; llabel(,,Q_1)
16 | 
17 | Q1E: Q1.E - (0,elen_/8) # shift a little bit
18 |   # resistor(down_ from Q1.E to (Q1.E,G)); rlabel(,R_{E})
19 |   line down from Q1.E to Q1E; dot; "3" ljust
20 |   resistor(down_ to (Q1.E,G)); rlabel(,R_{E})
21 | 
22 | Q1C: Q1.C + (0,elen_/8) # shift a little bit
23 |   dot(at Q1C); "4" ljust above
24 |   capacitor(right_ elen from Q1C); llabel(,C_{2})
25 |   dot; "out" ljust
26 |   resistor(down_ to (Here,G)); rlabel(,R_{L})
27 |   line down epsilon then to G
28 | 
29 |   resistor(up_ from Q1.C to (Q1.C,R1.end)); llabel(,R_{C})
30 |   line up epsilon then left to (G,R1.end) then down epsilon
31 |   reversed(`source', down_ elen,V); llabel(,V_{pwr},)
32 |   ground
33 | .PE
34 | 


--------------------------------------------------------------------------------
/issues/issue-6.py:
--------------------------------------------------------------------------------
 1 | ####################################################################################################
 2 | 
 3 | import PySpice.Logging.Logging as Logging
 4 | logger = Logging.setup_logging()
 5 | 
 6 | ####################################################################################################
 7 | 
 8 | from PySpice.Spice.Netlist import Circuit, SubCircuit
 9 | from PySpice.Unit.Units import *
10 | 
11 | ####################################################################################################
12 | 
13 | circuit = Circuit('Regulator')
14 | 
15 | # Netlist.TwoPortElement
16 | # .. warning:: As opposite to Spice, the input nodes are specified before the output nodes.
17 | # circuit.VCVS(1, 1, 0, 2, 0, , milli(50))
18 | 
19 | gain = SubCircuit('GAIN', 1, 2, K=milli(20))
20 | gain.VCVS(1, 1, 0, 2, 0, '{K}')
21 | 
22 | circuit.subcircuit(gain)
23 | circuit.X(2, 'GAIN', 7, 6, K=milli(50))
24 | 
25 | print(str(circuit))
26 | 
27 | ####################################################################################################
28 | #
29 | # End
30 | #
31 | ####################################################################################################
32 | 


--------------------------------------------------------------------------------
/doc/sphinx/source/development.rst:
--------------------------------------------------------------------------------
 1 | .. _development-page:
 2 | 
 3 | =========================
 4 |  Development & Community
 5 | =========================
 6 | 
 7 | PySpice is an open-source project, and relies on its community of users to keep getting better.
 8 | 
 9 | PySpice source code and issues are managed on `Github `_.
10 | 
11 | **Note to Packagers: Please don't create PySpice package (PiPY do the job)**
12 | 
13 | How you can help ?
14 | ------------------
15 | 
16 | As an open source project, anyone is welcome to contribute in whatever form they are able.
17 | 
18 | .. , which can include taking part in discussions, filing bug reports, proposing improvements,
19 |    contributing code or documentation, and testing it.
20 | 
21 | * Promote PySpice on the web and all around you
22 | * Fill bug reports
23 | * Test PySpice on Linux, Windows and OS X
24 | * Check for errors on the documentation
25 | * Propose improvements
26 | * Implement missing features
27 | * Provides additional examples
28 | 
29 | Contributors
30 | ------------
31 | 
32 | The list of contributors is available at https://github.com/FabriceSalvaire/PySpice/graphs/contributors
33 | 


--------------------------------------------------------------------------------
/doc/sphinx/source/donate.rst:
--------------------------------------------------------------------------------
 1 | .. _donate-page:
 2 | 
 3 | =======================
 4 |  How to Help Further ?
 5 | =======================
 6 | 
 7 | If you like PySpice, you can donate for its developement to my `PayPal account
 8 | `_.
 9 | 
10 | This budget could help me to mainly finance a domain, a vps to host a site, a forum (*) and also to
11 | participate to conference on open source Electronic Design Automation.
12 | 
13 | (*) This web site is actually hosted on my vps, which is quite loaded.  I don't use hosting site
14 | since it is easier to update the documentation using my own infrastructure.
15 | 
16 | Professional Support
17 | ====================
18 | 
19 | PySpice is provided as is and I don't provide extensive support.  I just solve issues and implement
20 | new features when I have time to do it, like usual for any open source projects.
21 | 
22 | If you are student, I will not help you to do your exercises.
23 | 
24 | If you work on a company, I will not help you to perform simulations.
25 | 
26 | However if you are interested by a professional support. You can contact my at the address *pyspice*
27 | at my domain name *fabrice-salvaire.fr*
28 | 


--------------------------------------------------------------------------------
/doc/pelican/theme/scss/base.scss:
--------------------------------------------------------------------------------
 1 | // #############################################################################
 2 | //
 3 | // Every folder within /private/sass has a file called _all.scss. This
 4 | // file ultimately gets imported by /private/sass/base.scss which gets
 5 | // compiled into /static/css/base.css. Update the _all.scss file to
 6 | // include additional modules. To keep the file simple, do not include
 7 | // files directly within base.scss.
 8 | //
 9 | // Copyright Fabrice Salvaire 2019
10 | // Copyright (c) 2013, Divio AG
11 | // Licensed under BSD
12 | // http://github.com/aldryn/aldryn-boilerplate-bootstrap3
13 | //
14 | // #############################################################################
15 | 
16 | @charset "utf-8";
17 | 
18 | // #############################################################################
19 | 
20 | @import "settings/all";
21 | 
22 | // importin mixins
23 | @import "mixins/all";
24 | 
25 | // importing frameworks
26 | @import "libs/all";
27 | 
28 | // @import "libs_tier2/all";
29 | 
30 | // importing modules
31 | @import "layout/all";
32 | 
33 | // importing addons
34 | @import "addons/all";
35 | 
36 | // importing sites
37 | @import "sites/all";
38 | 


--------------------------------------------------------------------------------
/doc/pelican/theme/package.json:
--------------------------------------------------------------------------------
 1 | {
 2 |     "name": "package",
 3 |     "private": true,
 4 |     "dependencies": {
 5 |         "@fortawesome/fontawesome-free": "^5.13.0",
 6 |         "bootstrap": "^4.5",
 7 |         "jquery": "3.5.1",
 8 |         "outdatedbrowser": "^1.1.5",
 9 |         "popper.js": "^1.16.0"
10 |     },
11 |     "devDependencies": {
12 |         "autoprefixer": "^9.7.3",
13 |         "bower-away": "^1.1.2",
14 |         "browser-sync": "^2.26.7",
15 |         "gulp": "^4.0.2",
16 |         "gulp-cached": "^1.1.1",
17 |         "gulp-clean-css": "^4.2.0",
18 |         "gulp-eslint": "^6.0.0",
19 |         "gulp-header": "^2.0.9",
20 |         "gulp-iconfont": "^10.0.3",
21 |         "gulp-iconfont-css": "^3.0.0",
22 |         "gulp-if": "^3.0.0",
23 |         "gulp-imagemin": "^6.2.0",
24 |         "gulp-plumber": "^1.2.1",
25 |         "gulp-postcss": "^8.0.0",
26 |         "gulp-sass": "^4.0.2",
27 |         "gulp-scss-lint": "^1.0.0",
28 |         "gulp-sourcemaps": "^2.6.5",
29 |         "gulp-util": "^3.0.8",
30 |         "minimist": "^1.2.0",
31 |         "package.json": "^2.0.1"
32 |     },
33 |     "engines": {
34 |         "yarn": ">= 1.0.0"
35 |     },
36 |     "scripts": {}
37 | }
38 | 


--------------------------------------------------------------------------------
/doc/sphinx/source/themes/PySpiceRtd/static/getthecode.js:
--------------------------------------------------------------------------------
 1 | // https://github.com/FabriceSalvaire/sphinx-getthecode
 2 | // Licensed under GPLv3
 3 | // Require http://fontawesome.io
 4 | $(document).ready(function() {
 5 |     // Add a button on the top-right corner of getthecode div to show the code
 6 |     $('.getthecode-header').each(function(index) {
 7 | 	var div = $(this);
 8 | 	var button = $('
  • '); 9 | button.attr('title', 'Show/Hide the code'); 10 | div.find('ul:first').append(button); 11 | div_highlight = div.parent().find('.highlight').parent(); 12 | if (div_highlight.hasClass('highlight-hidden')) { 13 | button.find('.fa-eye-slash').toggle(); 14 | div_highlight.toggle(); 15 | } else { 16 | button.find('.fa-eye').toggle(); 17 | } 18 | }); 19 | 20 | // define the behavior of the button when it's clicked 21 | $('.show-code-button').click(function() { 22 | var button = $(this); 23 | button.parents().eq(3).find('.highlight').parent().toggle(); 24 | button.find('.fa-eye').toggle(); 25 | button.find('.fa-eye-slash').toggle(); 26 | }); 27 | }); 28 | -------------------------------------------------------------------------------- /examples/resistor/resistor-bridge.py: -------------------------------------------------------------------------------- 1 | #r# This example shows the computation of the DC biases in a resistor bridge. 2 | 3 | #################################################################################################### 4 | 5 | import PySpice.Logging.Logging as Logging 6 | logger = Logging.setup_logging() 7 | 8 | #################################################################################################### 9 | 10 | from PySpice.Spice.Netlist import Circuit 11 | from PySpice.Unit import * 12 | 13 | #################################################################################################### 14 | 15 | #f# circuit_macros('resistor-bridge.m4') 16 | 17 | circuit = Circuit('Resistor Bridge') 18 | 19 | circuit.V('input', 1, circuit.gnd, 10@u_V) 20 | circuit.R(1, 1, 2, 2@u_kΩ) 21 | circuit.R(2, 1, 3, 1@u_kΩ) 22 | circuit.R(3, 2, circuit.gnd, 1@u_kΩ) 23 | circuit.R(4, 3, circuit.gnd, 2@u_kΩ) 24 | circuit.R(5, 3, 2, 2@u_kΩ) 25 | 26 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 27 | analysis = simulator.operating_point() 28 | 29 | for node in analysis.nodes.values(): 30 | print('Node {}: {:4.1f} V'.format(str(node), float(node))) # Fixme: format value + unit 31 | #o# 32 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/settings/_custom.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // 3 | // CUSTOM SETTINGS 4 | // 5 | // this setting file is intended for additional variables not defined within the bootstrap default 6 | // feel free to create additional files if settings get cluttered 7 | // 8 | // ############################################################################# 9 | 10 | // ############################################################################# 11 | 12 | $speed-base: 200ms; 13 | 14 | // ############################################################################# 15 | // Z-INDEX 16 | // DOCS: http://www.sitepoint.com/better-solution-managing-z-index-sass/ 17 | // http://sassmeister.com/gist/341c052928c956c1a751 18 | // use case: header { z-index: z("modal", "header"); } 19 | 20 | /* 21 | $z-layers: ( 22 | "goku": 9001, 23 | "shoryuken": 8000, 24 | "modal": ( 25 | "base": 500, 26 | "close": 100, 27 | "header": 50, 28 | "footer": 10 29 | ), 30 | "default": 1, 31 | "below": -1, 32 | "bottomless-pit": -9000 33 | ); 34 | */ 35 | -------------------------------------------------------------------------------- /examples/spice-examples/operational-amplifier-model-2.cir: -------------------------------------------------------------------------------- 1 | OPAMP2.CIR - OPAMP MODEL (LEVEL 2) 2 | * from http://www.ecircuitcenter.com/OpModels/OpampModels.htm 3 | * 4 | * SIGNAL SOURCE 5 | VS 1 0 AC 1 PWL(0US 0V 0.01US 1V 100US 1V) 6 | * 7 | * POWER SUPPLIES 8 | VCC 10 0 DC +15V 9 | VEE 11 0 DC -15V 10 | * 11 | R1 0 2 1 12 | *R2 2 3 1 13 | XOP 1 2 3 10 11 OPAMP2 14 | RL 3 0 100K 15 | * 16 | * 17 | * OPAMP MACRO MODEL (INTERMEDIATE LEVEL) 18 | * 19 | * IN+ IN- OUT VCC VEE 20 | .SUBCKT OPAMP2 1 2 81 101 102 21 | Q1 5 1 7 NPN 22 | Q2 6 2 8 NPN 23 | RC1 101 5 95.49 24 | RC2 101 6 95.49 25 | RE1 7 4 43.79 26 | RE2 8 4 43.79 27 | I1 4 102 0.001 28 | * 29 | * OPEN-LOOP GAIN, FIRST POLE AND SLEW RATE 30 | G1 100 10 6 5 0.0104719 31 | RP1 10 100 9.549MEG 32 | CP1 10 100 0.0016667UF 33 | * 34 | *OUTPUT STAGE 35 | EOUT 80 100 10 100 1 36 | RO 80 81 100 37 | * 38 | * INTERNAL REFERENCE 39 | RREF1 101 103 100K 40 | RREF2 103 102 100K 41 | EREF 100 0 103 0 1 42 | R100 100 0 1MEG 43 | * 44 | .model NPN NPN(BF=50000) 45 | * 46 | .ENDS 47 | * 48 | * ANALYSIS 49 | .TRAN 0.1US 5US 50 | .AC DEC 5 0.1HZ 10MEGHZ 51 | * 52 | * VIEW RESULTS 53 | .PRINT TRAN V(3) 54 | .PRINT AC V(3) 55 | .PROBE 56 | .END 57 | -------------------------------------------------------------------------------- /unit-test-todo/test_pipe.py: -------------------------------------------------------------------------------- 1 | from PySpice.Pipe import SpiceServer 2 | 3 | spice_server = SpiceServer() 4 | 5 | ngspice_input_template = """ 6 | .title Simple Rectifier 7 | .subckt 1N4148 1 2 8 | R1 1 2 5.827E+9 9 | D1 1 2 1N4148 10 | .model 1N4148 D IS = 4.352E-9 N = 1.906 BV = 110 IBV = 0.0001 RS = 0.6458 CJO = 7.048E-13 VJ = 0.869 M = 0.03 FC = 0.5 TT = 3.48E-9 11 | .ends 12 | Vinput in 0 DC 0V SIN(0V {line_peak_voltage}V {frequence}Hz) 13 | xD in out 1N4148 14 | Cload out 0 100uF 15 | Rload out 0 1k 16 | * 17 | .options TEMP=25 18 | .options TNOM=25 19 | *.options NODE 20 | .options NOINIT 21 | .options filetype = binary 22 | .save V(in) V(out) 23 | .tran {step_time} {end_time} 24 | .end 25 | """ 26 | 27 | frequence = 50 28 | perdiod = 1. / frequence 29 | 30 | ngspice_input = ngspice_input_template.format(line_peak_voltage=10, 31 | frequence=frequence, 32 | step_time=perdiod/200, 33 | end_time=perdiod*10 34 | ) 35 | 36 | raw_file = spice_server(ngspice_input) 37 | 38 | print(raw_file.data.dtype.fields) 39 | print(raw_file.data) 40 | -------------------------------------------------------------------------------- /doc/pelican/src/get-help.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block html_lang %}en{% endblock %} 5 | 6 | {% block title %}{{ SITENAME }} — Help{%endblock%} 7 | 8 | {% block content %} 9 | 10 |
    11 |

    PySpice Forum

    12 |

    A Discourse forum to discuss about PySpice and related topics

    13 | Go to Forum 14 |
    15 | 16 |
    17 |
    18 |
    19 |

    Documentation

    20 |

    To get the User manual, to lean more about the API

    21 | Go to Documentation Page 22 |
    23 |
    24 |
    25 |
    26 |

    Bug Tracker

    27 |

    Pyspice Bug Tracker is hosted on Github

    28 | Go to Bug Tracker 29 |
    30 |
    31 |
    32 | 33 | {% endblock %} 34 | -------------------------------------------------------------------------------- /PySpice/__init__.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice Package for Python 4 | # Copyright (C) 2014 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | 23 | __version__ = '1.5' 24 | GIT_TAG = 'v1.5' 25 | 26 | def show_version(): 27 | print('PySpice Version {}'.format(__version__)) 28 | -------------------------------------------------------------------------------- /examples/basic-usages/raw-spice.py: -------------------------------------------------------------------------------- 1 | #r# ========================================= 2 | #r# Pass Raw Spice Definitions to a Netlist 3 | #r# ========================================= 4 | 5 | #Fixme: to be documented, improved 6 | 7 | #r# This example shows how to pass raw spice definitions to a netlist. 8 | 9 | #################################################################################################### 10 | 11 | import PySpice.Logging.Logging as Logging 12 | logger = Logging.setup_logging() 13 | 14 | #################################################################################################### 15 | 16 | from PySpice.Spice.Netlist import Circuit 17 | from PySpice.Unit import * 18 | 19 | #################################################################################################### 20 | 21 | #r# Let define a circuit. 22 | 23 | circuit = Circuit('Test') 24 | 25 | #r# Pass raw Spice definitions to a circuit, aka netlist, content is inserted at the beginning of 26 | #r# the netlist. 27 | circuit.raw_spice = ''' 28 | Vinput in 0 10V 29 | R1 in out 9kOhm 30 | ''' 31 | 32 | #r# Pass element parameters as raw Spice, content is concatenated with `R2 out 0` 33 | circuit.R(2, 'out', 0, raw_spice='1k') 34 | 35 | print(circuit) 36 | #o# 37 | -------------------------------------------------------------------------------- /issues/issue-157-2.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | import PySpice.Logging.Logging as Logging 5 | logger = Logging.setup_logging() 6 | 7 | from PySpice.Probe.Plot import plot 8 | from PySpice.Spice.Netlist import Circuit 9 | from PySpice.Unit import * 10 | 11 | # Parameters 12 | frequency = 1e3 13 | period = 1 / frequency 14 | omega = 2 * np.pi * frequency 15 | 16 | I_P1 = 100 17 | L_P1 = 1e-6 18 | L_S1 = 10e-6 19 | K_P1S1 = 0.1 20 | 21 | circuit = Circuit('2CoupledInductors') 22 | 23 | #Primary Side 24 | circuit.I('I2', circuit.gnd, 'N1', 'AC ' + str(I_P1) + '') 25 | circuit.L('L_P1', circuit.gnd, 'N1', str(L_P1)) 26 | 27 | # Secondary Side 28 | circuit.L('L_S1', circuit.gnd, 'N2', str(L_S1) ) 29 | circuit.K('K_P1S1', 'LL_P1', 'LL_S1', K_P1S1) # NB, it adds an L to the name of the inductor ... 30 | 31 | print(circuit) 32 | 33 | # # Do the simulation 34 | # simulator = circuit.simulator(temperature=25, nominal_temperature=25) 35 | # analysis = simulator.ac(variation='lin', number_of_points=1, start_frequency=frequency, stop_frequency=frequency) 36 | 37 | # # Print the results 38 | # print('--- Results ---') 39 | # for node in analysis.nodes.values(): 40 | # print('Node {}: {:5.2f} V'.format(str(node), float(abs(node)))) 41 | -------------------------------------------------------------------------------- /issues/issue-182-lf411c.mod: -------------------------------------------------------------------------------- 1 | * LF411C operational amplifier "macromodel" subcircuit 2 | * created using Parts release 4.01 on 06/27/89 at 08:19 3 | * (REV N/A) 4 | * connections: non-inverting input 5 | * | inverting input 6 | * | | positive power supply 7 | * | | | negative power supply 8 | * | | | | output 9 | * | | | | | 10 | .subckt LF411C 1 2 3 4 5 11 | * 12 | c1 11 12 3.498E-12 13 | c2 6 7 15.00E-12 14 | dc 5 53 dx 15 | de 54 5 dx 16 | dlp 90 91 dx 17 | dln 92 90 dx 18 | dp 4 3 dx 19 | egnd 99 0 poly(2) (3,0) (4,0) 0 .5 .5 20 | fb 7 99 poly(5) vb vc ve vlp vln 0 28.29E6 -30E6 30E6 30E6 -30E6 21 | ga 6 0 11 12 282.8E-6 22 | gcm 0 6 10 99 1.590E-9 23 | iss 3 10 dc 195.0E-6 24 | hlim 90 0 vlim 1K 25 | j1 11 2 10 jx 26 | j2 12 1 10 jx 27 | r2 6 9 100.0E3 28 | rd1 4 11 3.536E3 29 | rd2 4 12 3.536E3 30 | ro1 8 5 50 31 | ro2 7 99 25 32 | rp 3 4 15.00E3 33 | rss 10 99 1.026E6 34 | vb 9 0 dc 0 35 | vc 3 53 dc 2.200 36 | ve 54 4 dc 2.200 37 | vlim 7 8 dc 0 38 | vlp 91 0 dc 30 39 | vln 0 92 dc 30 40 | .model dx D(Is=800.0E-18) 41 | .model jx PJF(Is=12.50E-12 Beta=250.1E-6 Vto=-1) 42 | .ends 43 |  -------------------------------------------------------------------------------- /issues/issue-157.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | import PySpice.Logging.Logging as Logging 5 | logger = Logging.setup_logging() 6 | 7 | from PySpice.Probe.Plot import plot 8 | from PySpice.Spice.Netlist import Circuit 9 | from PySpice.Unit import * 10 | 11 | # Parameters 12 | frequency = 1e3 13 | period = 1 / frequency 14 | omega = 2 * np.pi * frequency 15 | 16 | I_P1 = 100 17 | L_P1 = 1e-6 18 | L_S1 = 10e-6 19 | K_P1S1 = 0.1 20 | 21 | circuit = Circuit('2CoupledInductors') 22 | 23 | #Primary Side 24 | circuit.I('I2', circuit.gnd, 'N1', 'AC ' + str(I_P1) + '') 25 | circuit.L('L_P1', circuit.gnd, 'N1', str(L_P1)) 26 | 27 | # Secondary Side 28 | circuit.L('L_S1', circuit.gnd, 'N2', str(L_S1) ) 29 | circuit.K('K_P1S1', 'L_P1', 'L_S1', K_P1S1) 30 | # circuit.K('K_P1S1', 'L_P1', 'LL_S1', K_P1S1) 31 | # circuit.K('K_P1S1', 'LL_P1', 'LL_S1', K_P1S1) 32 | 33 | print(circuit) 34 | 35 | # Do the simulation 36 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 37 | analysis = simulator.ac(variation='lin', number_of_points=1, start_frequency=frequency, stop_frequency=frequency) 38 | 39 | # Print the results 40 | print('--- Results ---') 41 | for node in analysis.nodes.values(): 42 | print('Node {}: {:5.2f} V'.format(str(node), float(abs(node)))) 43 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/layout/_all.scss: -------------------------------------------------------------------------------- 1 | /* 2 | * We consider the general look and feel as the layout of a website or 3 | * application. This might include the typography, header and footer, 4 | * icons or the printable version. The layout can be broken down into 5 | * further parts if a website gets very large. We advise in general 6 | * against this strategy and rather prefer to use /sass/sites to create 7 | * specific layouts and derive from a global common style guide. 8 | * 9 | * Warning 10 | * Everything that targets a specific element, such as custom styles for 11 | * Bootstrap components or a specific form error, belongs in /sass/addons 12 | * or /sass/sites. 13 | */ 14 | 15 | // ############################################################################# 16 | // AUTOIMPORTS 17 | 18 | // this folder is for predefined parts of a website section like header/footer 19 | // or icons which are globally used there are very few occasions where 20 | // you want to add more files here 21 | 22 | // @import "fonts"; 23 | @import "roboto"; 24 | @import "gabriela"; 25 | 26 | // @import "iconography"; 27 | // @import "forms"; 28 | // @import "buttons"; 29 | @import "header"; 30 | @import "breadcrumb"; 31 | @import "footer"; 32 | @import "content"; 33 | @import "images"; 34 | @import "codes"; 35 | 36 | // @import "print"; 37 | -------------------------------------------------------------------------------- /issues/issue-172.py: -------------------------------------------------------------------------------- 1 | # from pylab import * 2 | import matplotlib.pyplot as plt 3 | 4 | import PySpice.Logging.Logging as Logging 5 | logger = Logging.setup_logging() 6 | 7 | from PySpice.Spice.Netlist import Circuit 8 | from PySpice.Unit import * 9 | from PySpice.Spice.BasicElement import BehavioralSource 10 | 11 | circuit = Circuit('Pulse') 12 | 13 | source = circuit.BehavioralSource('source', 'in', circuit.gnd, voltage_expression = 'time^4*exp(-1000*time)') 14 | # look like a " is simply discarded 15 | # source = circuit.BehavioralSource('source', 'in', circuit.gnd, voltage_expression = '"time^4*exp(-1000*time)') 16 | 17 | circuit.R(1, 'in', 'out', u_kOhm(9)) 18 | circuit.R(2, 'out', circuit.gnd, u_kOhm(1)) 19 | 20 | print(circuit) 21 | 22 | simulator = circuit.simulator(simulator='ngspice-shared') 23 | # the commented out version next line works 24 | #simulator = circuit.simulator(simulator='ngspice-subprocess') 25 | transient = simulator.transient(step_time=u_ms(1e-3), end_time=u_ms(20), log_desk=True) 26 | 27 | # print(type(simulator)) -> PySpice.Spice.NgSpice.Simulation.NgSpiceSharedCircuitSimulator 28 | # circuit must be loaded 29 | print('-'*100) 30 | print(simulator.ngspice.listing()) 31 | print('-'*100) 32 | 33 | # clf() 34 | plt.grid(True) 35 | plt.plot(transient['out'].abscissa, transient['out']) 36 | plt.show() 37 | -------------------------------------------------------------------------------- /examples/power-supplies/m4/capacitive-half-wave-rectification-pre-zener-circuit.m4: -------------------------------------------------------------------------------- 1 | .PS 2 | cct_init(SIdefaults) 3 | linethick_(.5) 4 | define(`dimen_', 10) 5 | elen = dimen_*3/2 6 | epsilon = 1e-3 7 | define(`bigdiode', 8 | `resized(2., `diode', $1)') 9 | define(`bigzenerdiode', 10 | `resized(2., `reversed', `diode', $1, S)') 11 | Neutral: Here 12 | dot; "N" below; 13 | source(up_ elen*2, AC); llabel(,V_{AC},); dot; "L" above; 14 | line right_ elen/2; dot; 15 | { 16 | line down_ elen/2; 17 | resistor(right_ elen); llabel(,R_{emi},); 18 | line up_ elen/2; 19 | } 20 | capacitor(right_ elen); llabel(,C_{in},); dot; "1" above; 21 | resistor(right_ elen); llabel(,R_{in},); dot; "2" above; 22 | bigdiode(right_ elen); rlabel(,D_{1},); dot; 23 | { 24 | C2: capacitor(down_ elen, C+); llabel(,C_{2},); dot; "3" at C2.end ljust; 25 | { bigdiode(left_ elen); llabel(,D_{2},); line up_ elen; } 26 | resistor(down_ elen); llabel(,R_{2},); dot; 27 | } 28 | line right_ elen; dot; 29 | { 30 | bigzenerdiode(down_ elen*2); llabel(,Dz,); dot; 31 | } 32 | line right_ elen; dot; 33 | { 34 | capacitor(down_ elen*2, C+); llabel(,C,); dot; 35 | } 36 | line right_ elen then down epsilon; "out" above; 37 | resistor(down_ elen*2); llabel(,R_{load},); 38 | line down epsilon then to Neutral then up epsilon 39 | .PE 40 | -------------------------------------------------------------------------------- /PySpice/Config/logging.yml: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | version: 1 4 | 5 | #################################################################################################### 6 | 7 | formatters: 8 | 9 | simple: 10 | format: '%(asctime)s - %(name)s - %(module)s.%(levelname)s - %(message)s' 11 | 12 | ansi: 13 | # RESET_SEQ = "\033[0m" 14 | # COLOR_SEQ = "\033[1;%dm" 15 | # BOLD_SEQ = "\033[1m" 16 | format: '[1;32m%(asctime)s[0m - [1;34m%(name)s.%(funcName)s[0m - [1;31m%(levelname)s[0m - %(message)s' 17 | 18 | #################################################################################################### 19 | 20 | handlers: 21 | 22 | console: 23 | class: logging.StreamHandler 24 | # level: INFO 25 | # formatter: ansi 26 | stream: ext://sys.stdout 27 | 28 | #################################################################################################### 29 | 30 | root: 31 | level: INFO 32 | # level: WARNING 33 | # level: DEBUG 34 | handlers: [console] 35 | 36 | #################################################################################################### 37 | 38 | # loggers: 39 | 40 | # PySpice: 41 | # level: DEBUG 42 | # #level: INFO 43 | # #level: WARNING 44 | # handlers: [console] 45 | -------------------------------------------------------------------------------- /examples/libraries/diode/zener/1N5919B.lib: -------------------------------------------------------------------------------- 1 | * -*- spice -*- 2 | * http://www.onsemi.com/pub_link/Collateral/1N5919BRL.SP3 3 | .SUBCKT d1n5919brl 2 1 4 | ************************************** 5 | * Model Generated by MODPEX * 6 | *Copyright(c) Symmetry Design Systems* 7 | * All Rights Reserved * 8 | * UNPUBLISHED LICENSED SOFTWARE * 9 | * Contains Proprietary Information * 10 | * Which is The Property of * 11 | * SYMMETRY OR ITS LICENSORS * 12 | * Modeling services provided by * 13 | * Interface Technologies www.i-t.com * 14 | ************************************** 15 | * Model generated on Jun 22, 2004 16 | * MODEL FORMAT: SPICE3 17 | * anode cathode 18 | *node: 2 1 19 | * Forward Section 20 | D1 2 1 MD1 21 | .MODEL MD1 D IS=1.33275e-21 N=1 XTI=1 RS=0.1 22 | + CJO=1e-11 TT=1e-08 23 | * Leakage Current 24 | R 1 2 600000 MDR 25 | .MODEL MDR R TC1=0 TC2=0 26 | * Breakdown 27 | RZ 2 3 0.520393 28 | IZG 4 3 0.3204 29 | R4 4 3 100 30 | D3 3 4 MD3 31 | .MODEL MD3 D IS=2.5e-12 N=2.40102 XTI=0 EG=0.1 32 | D2 5 4 MD2 33 | .MODEL MD2 D IS=2.5e-12 N=3.19856 XTI=0 EG=0.1 34 | EV1 1 5 6 0 1 35 | IBV 0 6 0.001 36 | RBV 6 0 5153.19 MDRBV 37 | .MODEL MDRBV R TC1=1.79e-08 38 | *-- SPICE3 DIODE MODEL DEFAULT PARAMETER 39 | * VALUES ARE ASSUMED 40 | *IS=1E-14 RS=0 N=1 TT=0 CJO=0 41 | *VJ=1 M=0.5 EG=1.11 XTI=3 FC=0.5 42 | *KF=0 AF=1 BV=inf IBV=1e-3 TNOM=27 43 | .ENDS d1n5919brl 44 | -------------------------------------------------------------------------------- /examples/resistor/voltage-divider.py: -------------------------------------------------------------------------------- 1 | #r# This example shows the computation of the DC bias and sensitivity in a voltage divider. 2 | 3 | #################################################################################################### 4 | 5 | import PySpice.Logging.Logging as Logging 6 | logger = Logging.setup_logging() 7 | 8 | #################################################################################################### 9 | 10 | from PySpice.Spice.Netlist import Circuit 11 | from PySpice.Unit import * 12 | 13 | #################################################################################################### 14 | 15 | #f# circuit_macros('voltage-divider.m4') 16 | 17 | circuit = Circuit('Voltage Divider') 18 | 19 | circuit.V('input', 'in', circuit.gnd, 10@u_V) 20 | circuit.R(1, 'in', 'out', 9@u_kΩ) 21 | circuit.R(2, 'out', circuit.gnd, 1@u_kΩ) 22 | 23 | #################################################################################################### 24 | 25 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 26 | 27 | analysis = simulator.operating_point() 28 | for node in (analysis['in'], analysis.out): # .in is invalid ! 29 | print('Node {}: {} V'.format(str(node), float(node))) 30 | #o# 31 | 32 | # Fixme: Xyce sensitivity analysis 33 | analysis = simulator.dc_sensitivity('v(out)') 34 | for element in analysis.elements.values(): 35 | print(element, float(element)) 36 | #o# 37 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-pyspice-example/kicad-pyspice-example.pro: -------------------------------------------------------------------------------- 1 | update=lun. 31 juil. 2017 15:10:40 CEST 2 | version=1 3 | last_client=kicad 4 | [pcbnew] 5 | version=1 6 | LastNetListRead= 7 | UseCmpFile=1 8 | PadDrill=0.600000000000 9 | PadDrillOvalY=0.600000000000 10 | PadSizeH=1.500000000000 11 | PadSizeV=1.500000000000 12 | PcbTextSizeV=1.500000000000 13 | PcbTextSizeH=1.500000000000 14 | PcbTextThickness=0.300000000000 15 | ModuleTextSizeV=1.000000000000 16 | ModuleTextSizeH=1.000000000000 17 | ModuleTextSizeThickness=0.150000000000 18 | SolderMaskClearance=0.000000000000 19 | SolderMaskMinWidth=0.000000000000 20 | DrawSegmentWidth=0.200000000000 21 | BoardOutlineThickness=0.100000000000 22 | ModuleOutlineThickness=0.150000000000 23 | [pcbnew/libraries] 24 | LibName1=connect 25 | LibName2=discret 26 | LibName3=pin_array 27 | LibName4=divers 28 | LibName5=smd_resistors 29 | LibName6=smd_crystal&oscillator 30 | LibName7=w_conn_av 31 | LibName8=libcms 32 | LibName9=dip_sockets 33 | LibDir= 34 | [cvpcb] 35 | version=1 36 | NetIExt=net 37 | [cvpcb/libraries] 38 | EquName1=devcms 39 | [general] 40 | version=1 41 | [eeschema] 42 | version=1 43 | LibDir= 44 | [eeschema/libraries] 45 | LibName1=kicad-pyspice-example-rescue 46 | LibName2=power 47 | LibName3=device 48 | LibName4=transistors 49 | LibName5=conn 50 | LibName6=linear 51 | LibName7=regul 52 | LibName8=74xx 53 | LibName9=cmos4000 54 | LibName10=adc-dac 55 | LibName11=memory 56 | LibName12=xilinx 57 | -------------------------------------------------------------------------------- /doc/pelican/theme/templates/articles.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | {% extends "base.html" %} 3 | 4 | {% block content %} 5 | 6 |
    7 | 8 | {% block content_title %} 9 |

    All articles

    10 | {% endblock %} 11 | 12 |
      13 | {% for article in articles_page.object_list %} 14 |
    1. 15 | {#
      #} 16 |

      17 | 18 | {{ article.title }} 19 | 20 |

      21 | {#
      #} 22 | {#
      #} 23 | 24 |
      By 25 | {% for author in article.authors %} 26 | {{ author }} 27 | {% endfor %} 28 |
      29 | {#
      #} 30 |
      {{ article.summary }}
      31 |
    2. 32 | {% endfor %} 33 |
    34 | 35 | {% if articles_page.has_other_pages() %} 36 | {% include 'pagination.html' %} 37 | {% endif %} 38 | 39 |
    40 | 41 | {% endblock content %} 42 | -------------------------------------------------------------------------------- /.github/workflows/pyspice-test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions 3 | 4 | name: Pyspice Test 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ${{ matrix.os }} 16 | strategy: 17 | matrix: 18 | os: [ubuntu-latest, macos-latest, windows-latest] 19 | python-version: [3.8] 20 | 21 | steps: 22 | - uses: actions/checkout@v2 23 | - name: Set up Python ${{ matrix.python-version }} 24 | uses: actions/setup-python@v2 25 | with: 26 | python-version: ${{ matrix.python-version }} 27 | - name: Install dependencies 28 | run: | 29 | python -m pip install --upgrade pip 30 | pip install -r requirements.txt 31 | pip install -r requirements-dev.txt 32 | - name: Install PySpice 33 | run: python setup.py install 34 | # - name: Run Tox 35 | # run: tox -e py 36 | - name: Run Unit-Tests 37 | run: pytest unit-test 38 | # - name: Run examples 39 | # run: pyterate --only-run 40 | # - name: Make examples RST 41 | # run: | 42 | # # --skip-rst --skip-external-figure --skip-notebook 43 | # pyterate --skip-external-figure --skip-notebook 44 | -------------------------------------------------------------------------------- /doc/sphinx/source/bibliography.rst: -------------------------------------------------------------------------------- 1 | .. _bibliography-page: 2 | 3 | ============== 4 | Bibliography 5 | ============== 6 | 7 | SPICE References 8 | ---------------- 9 | 10 | The `technical report No. UCB/ERL M520 `_ 11 | written by Nagel gives an interesting description of the algorithms involved in Spice. I recommend 12 | to read part 2 and 3 that explain the equation formulation. The next parts describes the 13 | numerical analysis. 14 | 15 | The relevant references on Spice are by date of publication: 16 | 17 | * `Technical Report No. UCB/ERL M382 `_; 18 | SPICE (Simulation Program with Integrated Circuit Emphasis); 19 | Nagel, Laurence W. and Pederson, D.O.; 20 | April 1973 21 | 22 | * `Technical Report No. UCB/ERL M520 `_; 23 | SPICE2: A Computer Program to Simulate Semiconductor Circuits; 24 | Nagel, Laurence W.; 25 | 1975 26 | 27 | * `Technical Report No. UCB/ERL M89/42 `_; 28 | Analysis of Performance and Convergence Issues for Circuit Simulation; 29 | Quarles, Thomas L.; 30 | 1989 31 | 32 | * `official spice3f5 source code `_ 33 | on eecs.berkeley.edu server, the page contains some links on Spice (historical notes). 34 | -------------------------------------------------------------------------------- /issues/issue-133.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | import matplotlib.pyplot as plt 4 | 5 | import PySpice.Logging.Logging as Logging 6 | logger = Logging.setup_logging() 7 | 8 | from PySpice.Doc.ExampleTools import find_libraries 9 | from PySpice.Spice.Library import SpiceLibrary 10 | from PySpice.Spice.Netlist import Circuit 11 | from PySpice.Unit import * 12 | 13 | #################################################################################################### 14 | 15 | libraries_path = find_libraries() 16 | spice_library = SpiceLibrary(libraries_path) 17 | 18 | #################################################################################################### 19 | 20 | circuit = Circuit('test') 21 | 22 | R1 = circuit.R(1, 'p1', 'p2', 4@u_kΩ) 23 | R2 = circuit.R(2, 'p2', 'p6', 1@u_kΩ) 24 | R3 = circuit.R(3, 'p1', 'p5', 1@u_kΩ) 25 | R4 = circuit.R(4, 'p5', 'p6', 1@u_kΩ) 26 | R5 = circuit.R(5, 'p6', 0, 1e-9@u_Ω) 27 | 28 | I1 = circuit.I(1, 0, 'p1', 1@u_A) 29 | 30 | V1 = circuit.V(1, 'p1', 'p4', -10@u_V) 31 | V2 = circuit.V(2, 'p2', 'p3', -10@u_V) 32 | 33 | print(str(circuit)) 34 | 35 | simulator = circuit.simulator(simulator='xyce-serial') 36 | analysis = simulator.operating_point() 37 | 38 | for node in analysis.nodes.values(): 39 | print('Node {}: {:5.2f} V'.format(str(node), float(node))) 40 | for node in analysis.branches.values(): 41 | print('Node {}: {:5.2f} A'.format(str(node), float(node))) 42 | -------------------------------------------------------------------------------- /PySpice/Physics/Resistor.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice Package for Python 4 | # Copyright (C) 2014 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | # 23 | # Notes: Drude model, Nernst-Einstein law 24 | # 25 | #################################################################################################### 26 | 27 | #################################################################################################### 28 | 29 | def conductor_resistance(resistivity, length, section): 30 | return resistivity * length / section 31 | -------------------------------------------------------------------------------- /doc/sphinx/source/roadmap.rst: -------------------------------------------------------------------------------- 1 | .. _roadmap-page: 2 | 3 | .. include:: abbreviation.txt 4 | .. include:: project-links.txt 5 | 6 | ========= 7 | Roadmap 8 | ========= 9 | 10 | `Roadmap @Github `_ 11 | 12 | V1.3 13 | ---- 14 | 15 | `V1.3 Roadmap @Github `_ 16 | 17 | * to be defined 18 | 19 | V2 20 | -- 21 | 22 | `V2 Roadmap @Github `_ 23 | 24 | * `Implement missing analyses `_ 25 | * `Implement missing devices `_ 26 | 27 | .. What are the planned features ? 28 | 29 | Some ideas for the future 30 | ------------------------- 31 | 32 | These features are planned in the future: 33 | 34 | * Improve the analyse experience 35 | * Complete Spice expression parser 36 | * Complete missing devices and simulations 37 | * Jupyter notebook examples 38 | 39 | Some other ideas are: 40 | 41 | * Implement a Modelica backend. |Modelica|_ is a very interesting solution for transient analysis. 42 | 43 | The implementation of a simulator in Python is not planned since it would be too challenging to 44 | release a full featured and proved simulator. However you could look at the project `Ahkab 45 | `_ which aims to implement such Python based simulator. Notice any 46 | of the projects like Ngspice or Ahkab are compliant with industrial quality assurance processes. 47 | -------------------------------------------------------------------------------- /unit-test-todo/test_netlist.py: -------------------------------------------------------------------------------- 1 | from PySpice.Netlist import SubCircuit, Circuit 2 | from PySpice.Units import * 3 | 4 | subcircuit_1N4148 = SubCircuit('1N4148', 1, 2) 5 | subcircuit_1N4148.R('1', 1, 2, 5.827E+9) 6 | subcircuit_1N4148.D('1', 1, 2, '1N4148') 7 | subcircuit_1N4148.model('1N4148', 'D', 8 | IS=4.352E-9, N=1.906, BV=110, IBV=0.0001, RS=0.6458, CJO=7.048E-13, 9 | VJ=0.869, M=0.03, FC=0.5, TT=3.48E-9) 10 | # print str(subcircuit_1N4148) 11 | 12 | frequence = 50 13 | perdiod = 1. / frequence 14 | step_time = perdiod/200 15 | end_time = perdiod*10 16 | 17 | line_peak_voltage = 10 18 | 19 | circuit = Circuit('Simple Rectifier', global_nodes=(0, 'out')) 20 | circuit.subcircuit(subcircuit_1N4148) 21 | circuit.V('input', 'in', circuit.gnd, 'DC 0V', 'SIN(0V {}V {}Hz)'.format(line_peak_voltage, frequence)) 22 | circuit.X('D', '1N4148', 'in', 'out') 23 | circuit.C('load', 'out', circuit.gnd, micro(100)) 24 | circuit.R('load', 'out', circuit.gnd, kilo(1), ac='1k') 25 | 26 | circuit.Cload.plus.add_current_probe(circuit) 27 | 28 | simulation = circuit.simulation(temperature=25, nominal_temperature=25, pipe=True) 29 | simulation.options(filetype='binary') 30 | simulation.save('V(in)', 'V(out)') 31 | simulation.tran(step_time, end_time) 32 | 33 | print(circuit.nodes) 34 | for node in circuit.nodes: 35 | print(repr(node), ':', ' '.join(element.name for element in node.elements)) 36 | print(circuit.Cload.plus) 37 | # print repr(circuit.Cload) 38 | # # print circuit.1N4148 39 | # print subcircuit_1N4148['1N4148'] 40 | # print circuit.out 41 | print('\n\n') 42 | 43 | print(str(simulation)) 44 | # python PySpice/test_netlist.py | ngspice -s > data 45 | -------------------------------------------------------------------------------- /PySpice/Physics/MaterialProperties.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | #################################################################################################### 4 | # 5 | # PySpice - A Spice Package for Python 6 | # Copyright (C) 2014 Fabrice Salvaire 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | # 21 | #################################################################################################### 22 | 23 | #################################################################################################### 24 | 25 | class Copper: 26 | 27 | atomic_number = 29 28 | 29 | atomic_mass = 63.546 * 1e-3 # kg 30 | density = 8.96 * 1e3 # kg·m−3 31 | thermal_conductivity = 401 # W·m−1·K−1 32 | electrical_resistivity = 16.78 * 1e-9 # Ω·m @20 °C 33 | electron_mobility = - 4.6 * 1e3 # m2·V−1·s−1 34 | 35 | ############################################## 36 | 37 | def electrical_resistance_for_conductor(self, degree): 38 | """ Used to compute conductor resistance. """ 39 | rho0 = 16e-3 # Ω·m·mm−2 40 | return rho0 * (1 + .00393 * degree) 41 | -------------------------------------------------------------------------------- /doc/sphinx/source/project-links.txt: -------------------------------------------------------------------------------- 1 | .. -*- Mode: rst -*- 2 | 3 | .. |PySpiceUrl| replace:: https://pyspice.fabrice-salvaire.fr 4 | 5 | .. |PySpiceHomePage| replace:: PySpice Home Page 6 | .. _PySpiceHomePage: https://pyspice.fabrice-salvaire.fr 7 | 8 | 9 | .. |PySpice@github| replace:: https://github.com/FabriceSalvaire/PySpice 10 | 11 | 12 | .. |PySpice@pypi| replace:: https://pypi.python.org/pypi/PySpice 13 | 14 | 15 | .. |PySpice@anaconda| replace:: https://anaconda.org/conda-forge/pyspice 16 | 17 | .. |PySpice@fs-anaconda| replace:: https://anaconda.org/fabricesalvaire/pyspice 18 | 19 | .. |Anaconda Version| image:: https://anaconda.org/conda-forge/pyspice/badges/version.svg 20 | :target: https://anaconda.org/conda-forge/pyspice/badges/version.svg 21 | :alt: Anaconda last version 22 | 23 | .. |Anaconda Downloads| image:: https://anaconda.org/conda-forge/pyspice/badges/downloads.svg 24 | :target: https://anaconda.org/conda-forge/pyspice/badges/downloads.svg 25 | :alt: Anaconda donwloads 26 | 27 | 28 | .. |Pypi Version| image:: https://img.shields.io/pypi/v/PySpice.svg 29 | :target: https://pypi.python.org/pypi/PySpice 30 | :alt: PySpice last version 31 | 32 | .. |Pypi License| image:: https://img.shields.io/pypi/l/PySpice.svg 33 | :target: https://pypi.python.org/pypi/PySpice 34 | :alt: PySpice license 35 | 36 | .. |Pypi Python Version| image:: https://img.shields.io/pypi/pyversions/PySpice.svg 37 | :target: https://pypi.python.org/pypi/PySpice 38 | :alt: PySpice python version 39 | 40 | 41 | .. |Tavis CI master| image:: https://travis-ci.com/FabriceSalvaire/PySpice.svg?branch=master 42 | :target: https://travis-ci.com/FabriceSalvaire/PySpice 43 | :alt: PySpice build status @travis-ci.org 44 | -------------------------------------------------------------------------------- /examples/spice-examples/transform-less-power-supply.cir: -------------------------------------------------------------------------------- 1 | * ************************************************************************************************** 2 | 3 | .title STM AN1476: LOW-COST POWER SUPPLY FOR HOME APPLIANCES 4 | 5 | * ************************************************************************************************** 6 | 7 | * 1N4148 8 | .include /home/gv/sys/fc14/fabrice/electronic-design-pattern/spice/libraries/diode/standard-rectifier/1N4148.lib 9 | 10 | * 1N5919B: 5.6 V, 3.0 W Zener Diode Voltage Regulator 11 | * d1n5919brl 12 | .include /home/gv/sys/fc14/fabrice/electronic-design-pattern/spice/libraries/diode/zener/1N5919B-spice3.lib 13 | 14 | * ************************************************************************************************** 15 | 16 | .param line_peak_voltage=220V 17 | .param freq=50Hz 18 | .param periode={1 / freq} 19 | 20 | Vinput1 out in DC 0V SIN(0V {line_peak_voltage} {freq}) 21 | Rload out 0 1k 22 | Cload out 0 220uF 23 | xD1 0 1 1N4148 24 | * xDz1 1 out d1n5919brl 25 | xDz1 1 out 1N4148 26 | Cac 1 2 470nF 27 | Rac 2 in 470 28 | 29 | * ************************************************************************************************** 30 | 31 | .op 32 | 33 | .param tran_step={periode / 200} 34 | * .tran 200us 2000ms 35 | .tran {tran_step} {periode * 50} 36 | 37 | * ************************************************************************************************** 38 | 39 | .control 40 | run 41 | plot .1*(V(out)-V(in)), V(out), v(out)-v(1), .1*(V(1)-V(2)) 42 | .endc 43 | 44 | * ************************************************************************************************** 45 | 46 | .end 47 | 48 | * ************************************************************************************************** 49 | -------------------------------------------------------------------------------- /doc/pelican/src/documentation.html: -------------------------------------------------------------------------------- 1 | 2 | {# -*- engine: jinja2 -*- #} 3 | {% extends "base.html" %} 4 | 5 | {% block html_lang %}en{% endblock %} 6 | 7 | {% block title %}{{ SITENAME }} — Documentation{%endblock%} 8 | 9 | {% block content %} 10 | 11 |

    PySpice User / API Documentation

    12 | 13 |

    14 | Note: if something looks wrong in the lastest documentation, it is advisable to check the older documentations. 15 |

    16 | 17 |
    18 |
    19 |
    20 |
    Last Release Documentation
    21 | Release {{ LAST_RELEASE }} 22 |
    23 |
    24 |
    25 |
    26 |
    Dev Release Documentation
    27 | Release {{ DEV_RELEASE }} 28 |
    29 |
    30 | 36 |
    37 | 38 |
    39 |

    Older Releases

    40 | {# {% for release in OLD_RELEASES[1:] %} #} 41 | {% for release in OLD_RELEASES %} 42 | {# flexbox ??? #} 43 | 46 | {% endfor %} 47 |
    48 | 49 | {% endblock %} 50 | -------------------------------------------------------------------------------- /issues/issue-142.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | import PySpice.Logging.Logging as Logging 4 | logger = Logging.setup_logging() 5 | 6 | from PySpice.Spice.Parser import SpiceParser 7 | 8 | #################################################################################################### 9 | 10 | # source = """ 11 | # .title Test 12 | # V1 vp GND dc 1.65 ac 0.5 13 | # V2 vn GND dc 1.65 ac -0.5 14 | # C2 Vout GND 4p 15 | # C1 /3 Vout 6.9p 16 | # M7 Vout /6 VDD VDD p_33 W=25.9u L=0.9u 17 | # M6 Vout /3 GND GND n_33 W=92.04u L=1.4u 18 | # M2 /3 vp /1 VDD p_33 W=51.78u L=0.9u 19 | # M1 /2 vn /1 VDD p_33 W=51.78u L=0.9u 20 | # M4 /3 /2 GND GND n_33 W=46.02u L=1.4u 21 | # M3 /2 /2 GND GND n_33 W=46.02u L=1.4u 22 | # M5 /1 /6 VDD VDD p_33 W=12.95u L=0.9u 23 | # V0 VDD GND 3.3 24 | # M8 /6 /6 VDD VDD p_33 W=1.3u L=0.9u 25 | # I1 /6 GND 10u 26 | # 27 | #.lib CMOS_035_Spice_Model.lib tt 28 | # 29 | #.end 30 | # """ 31 | 32 | source = """ 33 | .title Test 34 | V1 vp GND dc 1.65 ac 0.5 35 | M7 Vout /6 VDD VDD p_33 l=0.9u w=25.9u 36 | M6 Vout /3 GND GND n_33 l=1.4u w=92.04u 37 | M2 /3 vp /1 VDD p_33 l=0.9u w=51.78u 38 | M1 /2 vn /1 VDD p_33 l=0.9u w=51.78u 39 | M4 /3 /2 GND GND n_33 l=1.4u w=46.02u 40 | M3 /2 /2 GND GND n_33 l=1.4u w=46.02u 41 | M5 /1 /6 VDD VDD p_33 l=0.9u w=12.95u 42 | V0 VDD GND 3.3 43 | M8 /6 /6 VDD VDD p_33 l=0.9u w=1.3u 44 | I1 /6 GND 10u 45 | .lib CMOS_035_Spice_Model.lib tt 46 | """.strip() 47 | 48 | parser = SpiceParser(source=source) 49 | circuit = parser.build_circuit() 50 | source2 = str(circuit) 51 | for line1, line2 in zip(source.splitlines(), source2.splitlines()): 52 | print('-'*100) 53 | print(line1 + '|') 54 | print(line2 + '|') 55 | assert(line1 == line2) 56 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/sites/_all.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // 3 | // Besides /addons you will work mostly within the /private/sass/sites 4 | // folder. All custom elements that are in general not plug-and-playable, 5 | // fixed into the website somewhere or specific components, get thrown in 6 | // here. 7 | // 8 | // This will force you to devise and adhere to structure 9 | // patterns. Here are some examples depending on the requirements for 10 | // your project: 11 | // 12 | // Multisite Setup 13 | // Let’s assume you create one style guide sharing different marketing 14 | // websites or applications - your structure might look something 15 | // like: 16 | // 17 | // sites/ 18 | // ├─ application/ 19 | // │ ├─ _all.scss 20 | // │ ├─ _general.scss 21 | // │ └─ _wizard.scss 22 | // ├─ marketing/ 23 | // │ ├─ _all.scss 24 | // │ ├─ _layout.scss 25 | // │ └─ _addons.scss 26 | // ├─ _application.scss (imports application/_all.scss) 27 | // └─ _marketing.scss (imports marketing/_all.scss) 28 | // 29 | // Theme Setup 30 | // If you are using different themes for the same markup, your 31 | // structure might look something like: 32 | // 33 | // sites/ 34 | // ├─ dark_theme/ 35 | // │ ├─ _all.scss 36 | // │ ├─ _header.scss 37 | // │ └─ _footer.scss 38 | // ├─ white_theme/ 39 | // │ ├─ _all.scss 40 | // │ ├─ _header.scss 41 | // │ └─ _footer.scss 42 | // ├─ dark_theme.scss (imports dark_theme/_all.scss) 43 | // └─ white_theme.scss (imports white_theme/_all.scss) 44 | // 45 | // this folder contains overrides and additional css which cannot be categorised 46 | // files can be split and included here 47 | // 48 | // ############################################################################# 49 | 50 | //! @import "custom"; 51 | -------------------------------------------------------------------------------- /examples/spice-examples/astable.cir: -------------------------------------------------------------------------------- 1 | .title Astable Multivibrator 2 | * 3 | **************************************************************************************************** 4 | .subckt BasicComparator output voltage_minus non_inverting_input inverting_input 5 | E1 output voltage_minus TABLE {V(non_inverting_input, inverting_input)} = (-1uV, 0V) (1uV, 15V) 6 | * Error on line 0 : b.xcomparator.b*1 xcomparator.*1_int1 0 v= v(reference,comparator) , -1.0000000000e-06 , 0.0000000000e+00 , 1.0000000000e-06 , 1.5000000000e+01 7 | * unknown parameter (-1.0000000000e-06) 8 | .ends 9 | **************************************************************************************************** 10 | Vcc vcc 0 15 11 | **************************************************************************************************** 12 | * Time constant 13 | R1 output comparator 1k 14 | C1 comparator 0 100n 15 | * mandatory 16 | .IC V(comparator)=0 17 | **************************************************************************************************** 18 | * Reference 19 | R2 output reference 100k 20 | R3 Vcc reference 100k 21 | R4 reference 0 100k 22 | **************************************************************************************************** 23 | * Comparator 24 | * Xcomparator output 0 reference comparator BasicComparator 25 | E1 output 0 TABLE {V(reference, comparator)} = (-1uV, 0V) (1uV, 15V) 26 | **************************************************************************************************** 27 | .end 28 | **************************************************************************************************** 29 | .control 30 | tran 1u 500u 31 | plot V(output) V(reference) V(comparator) 32 | .endc 33 | **************************************************************************************************** 34 | -------------------------------------------------------------------------------- /PySpice/Math/__init__.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice Package for Python 4 | # Copyright (C) 2014 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | """This module implements mathematical functions. 22 | """ 23 | 24 | #################################################################################################### 25 | 26 | import math 27 | 28 | #################################################################################################### 29 | 30 | def odd(x): 31 | """Return True is *x* is odd""" 32 | return x & 1 33 | 34 | def even(x): 35 | """Return True is *x* is even""" 36 | return not(odd(x)) 37 | 38 | #################################################################################################### 39 | 40 | def rms_to_amplitude(x): 41 | """Return :math:`x \sqrt{2}`""" 42 | return x * math.sqrt(2) 43 | 44 | def amplitude_to_rms(x): 45 | """Return :math:`x / \sqrt{2}`""" 46 | return x / math.sqrt(2) 47 | -------------------------------------------------------------------------------- /examples/transmission-lines/time-delay.py: -------------------------------------------------------------------------------- 1 | #r# This example shows the simulation of a transmission line. 2 | 3 | #################################################################################################### 4 | 5 | import matplotlib.pyplot as plt 6 | 7 | #################################################################################################### 8 | 9 | import PySpice.Logging.Logging as Logging 10 | logger = Logging.setup_logging() 11 | 12 | #################################################################################################### 13 | 14 | from PySpice.Probe.Plot import plot 15 | from PySpice.Spice.Netlist import Circuit 16 | from PySpice.Unit import * 17 | 18 | #################################################################################################### 19 | 20 | #r# We will drive the transmission line with a pulse source and use a standard 50 Ω load. 21 | 22 | circuit = Circuit('Transmission Line') 23 | circuit.PulseVoltageSource('pulse', 'input', circuit.gnd, 0@u_V, 1@u_V, 1@u_ns, 1@u_us) 24 | circuit.LosslessTransmissionLine('delay', 'output', circuit.gnd, 'input', circuit.gnd, 25 | impedance=50, time_delay=40e-9) 26 | circuit.R('load', 'output', circuit.gnd, 50@u_Ω) 27 | 28 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 29 | analysis = simulator.transient(step_time=1e-11, end_time=100e-9) 30 | 31 | #################################################################################################### 32 | 33 | figure, ax = plt.subplots(figsize=(20, 6)) 34 | ax.plot(analysis['input']) 35 | ax.plot(analysis['output']) 36 | ax.set_xlabel('Time [s]') 37 | ax.set_ylabel('Voltage (V)') 38 | ax.grid() 39 | ax.legend(['input', 'output'], loc='upper right') 40 | 41 | plt.show() 42 | 43 | #f# save_figure('figure', 'time-delay.png') 44 | -------------------------------------------------------------------------------- /examples/run-examples: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | # -*- Python -*- 3 | 4 | #################################################################################################### 5 | # 6 | # PySpice - A Spice Package for Python 7 | # Copyright (C) 2014 Fabrice Salvaire 8 | # 9 | # This program is free software: you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | # 22 | #################################################################################################### 23 | 24 | #################################################################################################### 25 | 26 | from pathlib import Path 27 | import glob 28 | import os 29 | import subprocess 30 | import sys 31 | 32 | #################################################################################################### 33 | 34 | examples_path = Path(__file__).resolve().parent 35 | 36 | for topic in os.listdir(examples_path): 37 | python_files = glob.glob(str(examples_path.joinpath(topic, '*.py'))) 38 | for file_name in python_files: 39 | if file_name.islower(): 40 | print('Run {}'.format(file_name)) 41 | subprocess.call(('python', file_name)) 42 | print('To continue press Enter') 43 | rc = sys.stdin.readline().strip() 44 | -------------------------------------------------------------------------------- /examples/spice-parser/kicad-spice-example/kicad-spice-example.pro: -------------------------------------------------------------------------------- 1 | update=jeu. 26 nov. 2015 16:40:27 CET 2 | version=1 3 | last_client=kicad 4 | [pcbnew] 5 | version=1 6 | LastNetListRead= 7 | UseCmpFile=1 8 | PadDrill=0.600000000000 9 | PadDrillOvalY=0.600000000000 10 | PadSizeH=1.500000000000 11 | PadSizeV=1.500000000000 12 | PcbTextSizeV=1.500000000000 13 | PcbTextSizeH=1.500000000000 14 | PcbTextThickness=0.300000000000 15 | ModuleTextSizeV=1.000000000000 16 | ModuleTextSizeH=1.000000000000 17 | ModuleTextSizeThickness=0.150000000000 18 | SolderMaskClearance=0.000000000000 19 | SolderMaskMinWidth=0.000000000000 20 | DrawSegmentWidth=0.200000000000 21 | BoardOutlineThickness=0.100000000000 22 | ModuleOutlineThickness=0.150000000000 23 | [pcbnew/libraries] 24 | LibName1=connect 25 | LibName2=discret 26 | LibName3=pin_array 27 | LibName4=divers 28 | LibName5=smd_resistors 29 | LibName6=smd_crystal&oscillator 30 | LibName7=w_conn_av 31 | LibName8=libcms 32 | LibName9=dip_sockets 33 | LibDir= 34 | [cvpcb] 35 | version=1 36 | NetIExt=net 37 | [cvpcb/libraries] 38 | EquName1=devcms 39 | [eeschema] 40 | version=1 41 | LibDir= 42 | [eeschema/libraries] 43 | LibName1=kicad-spice-example-rescue 44 | LibName2=power 45 | LibName3=device 46 | LibName4=transistors 47 | LibName5=conn 48 | LibName6=linear 49 | LibName7=regul 50 | LibName8=74xx 51 | LibName9=cmos4000 52 | LibName10=adc-dac 53 | LibName11=memory 54 | LibName12=xilinx 55 | LibName14=microcontrollers 56 | LibName15=dsp 57 | LibName16=microchip 58 | LibName17=analog_switches 59 | LibName18=motorola 60 | LibName19=texas 61 | LibName20=intel 62 | LibName21=audio 63 | LibName22=interface 64 | LibName23=digital-audio 65 | LibName24=philips 66 | LibName25=display 67 | LibName26=cypress 68 | LibName27=siliconi 69 | LibName28=opto 70 | LibName29=atmel 71 | LibName30=contrib 72 | LibName31=valves 73 | [general] 74 | version=1 75 | -------------------------------------------------------------------------------- /gh-pages/update-gh-pages: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | #################################################################################################### 4 | 5 | root_dir=$(dirname $(dirname $(realpath $0))) 6 | html_build="${root_dir}/doc/sphinx/build/html" 7 | source_gh_pages=${root_dir}/gh-pages 8 | 9 | echo Source Path: ${root_dir} 10 | echo HTML Build Path: ${html_build} 11 | 12 | origin='git@github.com:FabriceSalvaire/PySpice.git' 13 | 14 | #################################################################################################### 15 | 16 | tmp_dir=$(mktemp -d) 17 | if [ -e ${tmp_dir} ]; then 18 | pushd ${tmp_dir} 19 | 20 | git clone ${origin} PySpice-gh-pages --branch gh-pages --single-branch 21 | pushd PySpice-gh-pages 22 | # sync with origin if already cloned 23 | # git fetch origin 24 | git checkout gh-pages 25 | 26 | rm -rf static images 27 | rsync --delete -av --exclude-from=${source_gh_pages}/html-rsync-filter.txt ${html_build}/ . 28 | cp ${source_gh_pages}/README.rst . 29 | if [ -e _images ]; then 30 | mv _images images 31 | find . -name "*.html" -exec sed -e 's/_images/images/g;' -i {} \; 32 | fi 33 | if [ -e _static ]; then 34 | mv _static static 35 | find . -name "*.html" -exec sed -e 's/_static/static/g;' -i {} \; 36 | fi 37 | if [ -e _downloads ]; then 38 | mv _downloads downloads 39 | find . -name "*.html" -exec sed -e 's/_downloads/downloads/g;' -i {} \; 40 | fi 41 | find . -name '.#*html' -exec rm {} \; 42 | 43 | git add --all * 44 | git commit -m 'update' 45 | git push -u origin gh-pages 46 | 47 | popd -1 ; popd 48 | rm -rf ${tmp_dir} 49 | fi 50 | 51 | #################################################################################################### 52 | # 53 | # End 54 | # 55 | #################################################################################################### 56 | -------------------------------------------------------------------------------- /PySpice/Probe/Plot.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice Package for Python 4 | # Copyright (C) 2014 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | # Fixme: versus PySpice.Plot ??? 22 | 23 | #################################################################################################### 24 | 25 | """This module implements plotting helper.""" 26 | 27 | #################################################################################################### 28 | 29 | import matplotlib.pyplot as plt 30 | 31 | #################################################################################################### 32 | 33 | def plot(waveform, *args, **kwargs): 34 | 35 | """Plot a waveform using the current Axes instance or the one specified by the *axis* key 36 | argument. Additional parameters are passed to the Matplotlib plot function. 37 | 38 | """ 39 | 40 | axis = kwargs.get('axis', plt.gca()) 41 | if 'axis' in kwargs: 42 | del kwargs['axis'] 43 | axis.plot(waveform.abscissa, waveform, *args, **kwargs) 44 | -------------------------------------------------------------------------------- /tasks/github.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice package for Python 4 | # Copyright (C) 2021 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | 23 | from invoke import task 24 | 25 | try: 26 | from github import Github 27 | except ImportError: 28 | pass 29 | 30 | #################################################################################################### 31 | 32 | REPOSITORY_NAME = "FabriceSalvaire/PySpice" 33 | 34 | #################################################################################################### 35 | 36 | def get_repo(): 37 | g = Github() 38 | repo = g.get_repo(REPOSITORY_NAME) 39 | return repo 40 | 41 | #################################################################################################### 42 | 43 | @task 44 | def labels(ctx): 45 | repo = get_repo() 46 | labels = repo.get_labels() 47 | for label in labels: 48 | print(f'{label.name}: {label.description}') 49 | -------------------------------------------------------------------------------- /doc/pelican/publishconf.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice package for Python 4 | # Copyright (C) 2020 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | 23 | # This file is only used if you use `make publish` or explicitly specify it as your config file. 24 | 25 | #################################################################################################### 26 | 27 | import os 28 | import sys 29 | sys.path.append(os.curdir) 30 | from pelicanconf import * 31 | 32 | #################################################################################################### 33 | 34 | # Delete the output directory, and all of its contents, before generating new files. 35 | DELETE_OUTPUT_DIRECTORY = True 36 | 37 | # If your site is available via HTTPS, make sure SITEURL begins with https:// 38 | SITEURL = 'https://pyspice.fabrice-salvaire.fr' 39 | RELATIVE_URLS = False 40 | 41 | # Atom 42 | FEED_DOMAIN = SITEURL 43 | FEED_ALL_ATOM = 'feeds/all.atom.xml' 44 | CATEGORY_FEED_ATOM = 'feeds/{slug}.atom.xml' 45 | -------------------------------------------------------------------------------- /examples/operational-amplifier/operational-amplifier.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | import numpy as np 4 | 5 | import matplotlib.pyplot as plt 6 | 7 | #################################################################################################### 8 | 9 | import PySpice.Logging.Logging as Logging 10 | logger = Logging.setup_logging() 11 | 12 | #################################################################################################### 13 | 14 | from PySpice.Plot.BodeDiagram import bode_diagram 15 | from PySpice.Probe.Plot import plot 16 | from PySpice.Spice.Netlist import Circuit 17 | from PySpice.Unit import * 18 | 19 | from OperationalAmplifier import BasicOperationalAmplifier 20 | 21 | #f# literal_include('OperationalAmplifier.py') 22 | 23 | #################################################################################################### 24 | 25 | circuit = Circuit('Operational Amplifier') 26 | 27 | # AC 1 PWL(0US 0V 0.01US 1V) 28 | circuit.SinusoidalVoltageSource('input', 'in', circuit.gnd, amplitude=1@u_V) 29 | circuit.subcircuit(BasicOperationalAmplifier()) 30 | circuit.X('op', 'BasicOperationalAmplifier', 'in', circuit.gnd, 'out') 31 | circuit.R('load', 'out', circuit.gnd, 470@u_Ω) 32 | 33 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 34 | analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=100@u_MHz, number_of_points=5, variation='dec') 35 | 36 | figure, (ax1, ax2) = plt.subplots(2, figsize=(20, 10)) 37 | 38 | plt.title("Bode Diagram of an Operational Amplifier") 39 | bode_diagram(axes=(ax1, ax2), 40 | frequency=analysis.frequency, 41 | gain=20*np.log10(np.absolute(analysis.out)), 42 | phase=np.angle(analysis.out, deg=False), 43 | marker='.', 44 | color='blue', 45 | linestyle='-', 46 | ) 47 | plt.tight_layout() 48 | plt.show() 49 | 50 | #f# save_figure('figure', 'operational-amplifier.png') 51 | -------------------------------------------------------------------------------- /examples/transformer/transformer-example.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | #r# 4 | #r# ============= 5 | #r# Transformer 6 | #r# ============= 7 | #r# 8 | #r# This examples shows how to simulate a transformer. 9 | #r# 10 | 11 | #################################################################################################### 12 | 13 | import matplotlib.pyplot as plt 14 | 15 | #################################################################################################### 16 | 17 | import PySpice.Logging.Logging as Logging 18 | logger = Logging.setup_logging() 19 | 20 | #################################################################################################### 21 | 22 | from PySpice.Probe.Plot import plot 23 | from PySpice.Spice.Netlist import Circuit 24 | from PySpice.Unit import * 25 | 26 | #################################################################################################### 27 | 28 | from Transformer import Transformer 29 | 30 | #f# literal_include('Transformer.py') 31 | 32 | #################################################################################################### 33 | 34 | circuit = Circuit('Transformer') 35 | 36 | ac_line = circuit.AcLine('input', 'input', circuit.gnd, rms_voltage=230@u_V, frequency=50@u_Hz) 37 | circuit.subcircuit(Transformer(turn_ratio=10)) 38 | circuit.X('transformer', 'Transformer', 'input', circuit.gnd, 'output', circuit.gnd) 39 | circuit.R('load', 'output', circuit.gnd, 1@u_kΩ) 40 | 41 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 42 | analysis = simulator.transient(step_time=ac_line.period/200, end_time=ac_line.period*3) 43 | 44 | figure, ax = plt.subplots(figsize=(20, 10)) 45 | ax.plot(analysis.input) 46 | ax.plot(analysis.output) 47 | ax.legend(('Vin [V]', 'Vout [V]'), loc=(.8,.8)) 48 | ax.grid() 49 | ax.set_xlabel('t [s]') 50 | ax.set_ylabel('[V]') 51 | 52 | plt.tight_layout() 53 | plt.show() 54 | 55 | #f# save_figure('figure', 'transformer.png') 56 | -------------------------------------------------------------------------------- /PySpice/Config/ConfigInstall.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | import os 4 | import sys 5 | 6 | #################################################################################################### 7 | 8 | import PySpice.Tools.Path as PathTools # Fixme: why ? 9 | 10 | #################################################################################################### 11 | 12 | class OsFactory: 13 | 14 | ############################################## 15 | 16 | def __init__(self): 17 | 18 | if sys.platform.startswith('linux'): 19 | self._name = 'linux' 20 | elif sys.platform.startswith('win'): 21 | self._name = 'windows' 22 | elif sys.platform.startswith('darwin'): 23 | self._name = 'osx' 24 | 25 | ############################################## 26 | 27 | @property 28 | def name(self): 29 | return self._name 30 | 31 | @property 32 | def on_linux(self): 33 | return self._name == 'linux' 34 | 35 | @property 36 | def on_windows(self): 37 | return self._name == 'windows' 38 | 39 | @property 40 | def on_osx(self): 41 | return self._name == 'osx' 42 | 43 | OS = OsFactory() 44 | 45 | #################################################################################################### 46 | 47 | _this_file = PathTools.to_absolute_path(__file__) 48 | 49 | class Path: 50 | 51 | pyspice_module_directory = PathTools.parent_directory_of(_this_file, step=2) 52 | config_directory = os.path.dirname(_this_file) 53 | 54 | #################################################################################################### 55 | 56 | class Logging: 57 | 58 | default_config_file = 'logging.yml' 59 | directories = (Path.config_directory,) 60 | 61 | ############################################## 62 | 63 | @staticmethod 64 | def find(config_file): 65 | return PathTools.find(config_file, Logging.directories) 66 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/layout/_header.scss: -------------------------------------------------------------------------------- 1 | //################################################################################################### 2 | // HEADER 3 | 4 | // all styles related to the global header should be declared within 5 | // this file apply the "sites/" nesting described within the 6 | // documentation if the file is getting to large 7 | 8 | header.page_header { 9 | // Add vertical space to the header 10 | @extend .mb-3; 11 | @include rised-component(); 12 | } 13 | 14 | #top-navbar { 15 | @extend .navbar-expand-lg; 16 | @extend .py-0; 17 | 18 | text-transform: uppercase; 19 | } 20 | 21 | // Show from small ≥576px device 22 | @media(min-width: $grid-float-breakpoint) { 23 | // Implement an horizontal line below menu item 24 | // Fixme: better ? 25 | #top-navbar { 26 | .nav-item:not(.dropdown) { // doesn't work with dropdown 27 | > a::after { 28 | // position: absolute; 29 | // left: 0; 30 | content: ""; 31 | display: block; 32 | height: 2px; 33 | bottom: 3px; 34 | background-color: #a1c42c; 35 | width: 0; 36 | transition: all .2s ease-out; 37 | } 38 | &.active > a::after, 39 | > a:hover::after { // :active::after, :focus::after 40 | width: 100%; 41 | } 42 | } 43 | } 44 | } 45 | 46 | //################################################################################################### 47 | 48 | header.page_header { 49 | @extend .bg-dark; 50 | } 51 | 52 | $logo-angle: 20deg; 53 | $logo-padding: 30px; 54 | 55 | #top-navbar { 56 | // @extend .navbar-light; 57 | // @extend .bg-light; 58 | 59 | @extend .navbar-dark; 60 | @extend .bg-dark; 61 | 62 | @include white_on_dark(); 63 | 64 | a.navbar-brand { 65 | transform: skew(-$logo-angle); 66 | background: white; 67 | padding-right: $logo-padding; 68 | padding-left: $logo-padding; 69 | img { 70 | transform: skew($logo-angle); 71 | } 72 | } 73 | 74 | // Fix dropdown menu text colour 75 | a.dropdown-item { 76 | @extend .text-dark; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /doc/sphinx/source/example-whish-list.rst: -------------------------------------------------------------------------------- 1 | .. _exemple-wish-list-page: 2 | 3 | =================== 4 | Example Wish List 5 | =================== 6 | 7 | Operational Points 8 | ------------------ 9 | 10 | * https://ahkab.readthedocs.io/en/latest/examples/Simple_OP.html 11 | * DAC using resistor network 12 | * Wheastone Bridge 13 | 14 | Amplifier 15 | --------- 16 | 17 | * AC Coupled Amplifier 18 | 19 | Diode 20 | ----- 21 | 22 | * Clampers 23 | * Restaurateur de niveau moyen 24 | * Detecteur d'enveloppe 25 | * Redresseur sans seuil 26 | 27 | Filters 28 | ------- 29 | 30 | * Wien filter 31 | * Tuinnenga p50 RLC 32 | * RC / RL Bridge 33 | * Butterworth 34 | * High Frequence Probe (Delacressonnière p57) 35 | * https://ahkab.readthedocs.io/en/latest/examples/PZ_Example.html 36 | 37 | Inductors 38 | ---------- 39 | 40 | * https://ahkab.readthedocs.io/en/latest/help/Mutual-Inductors.html 41 | 42 | Operational Amplifier 43 | --------------------- 44 | 45 | * Integrator / Derivative 46 | * Exponential / Logarithmic 47 | * Current Source 48 | * Astable 49 | * Active filter 50 | * Rauch 51 | * Thermal Probe (Delacressonnière p43) 52 | * Negative Impedance NIC (Delacressonnière p67) 53 | * Peak-to-Peak Detector 54 | 55 | Oscillators 56 | ----------- 57 | 58 | * Colpitts Oscillator 59 | https://ahkab.readthedocs.io/en/latest/examples/Transient-Example.html 60 | * Quartz oscillator 61 | 62 | Power Supplies 63 | -------------- 64 | 65 | * Zener Voltage Regulator 66 | 67 | Switching Power Supplies 68 | ------------------------ 69 | 70 | Telecommunication 71 | ----------------- 72 | 73 | * Simulate resistance using capacitive commutation (Delacressonnière p27) 74 | 75 | Transistor 76 | ---------- 77 | 78 | * All configurations (Bolyestad p293) 79 | * Cascode 80 | * Darlington 81 | * Feedback Pair 82 | * Relay Driver 83 | * Constant-Current Source 84 | * Current Mirror 85 | * Logic Gates 86 | * Random Noise Generator (Bolyestad p329) 87 | 88 | MOSFET 89 | ------ 90 | 91 | SCR 92 | --- 93 | 94 | * Thyristor 95 | * Diac 96 | * Triac 97 | * Zero Crossing Detector 98 | -------------------------------------------------------------------------------- /doc/sphinx/source/themes/PySpiceRtd/layout.html: -------------------------------------------------------------------------------- 1 | {# -*- engine: jinja2 -*- #} 2 | 3 | {%- extends "sphinx_rtd_theme/layout.html" %} 4 | 5 | {%- block extrahead %} 6 | 7 | 8 | 23 | {% endblock %} 24 | 25 | {%- block footer %} 26 | 40 | 41 | {% endblock %} 42 | 43 | {% block sidebartitle %} 44 | 45 | {{ project }} 46 | 47 | 48 | 49 | {#
    #} 50 | 51 | PySpice {{ version }} 52 | 53 | 54 | {% include "searchbox.html" %} 55 | {% endblock %} 56 | -------------------------------------------------------------------------------- /examples/libraries/mosfet/irf150.lib: -------------------------------------------------------------------------------- 1 | * -*- spice -*- 2 | * http://www.irf.com/product-info/models/spice/irf150.spi 3 | * 4 | .SUBCKT irf150 1 2 3 5 | ************************************** 6 | * Model Generated by MODPEX * 7 | *Copyright(c) Symmetry Design Systems* 8 | * All Rights Reserved * 9 | * UNPUBLISHED LICENSED SOFTWARE * 10 | * Contains Proprietary Information * 11 | * Which is The Property of * 12 | * SYMMETRY OR ITS LICENSORS * 13 | *Commercial Use or Resale Restricted * 14 | * by Symmetry License Agreement * 15 | ************************************** 16 | * Model generated on Dec 17, 96 17 | * MODEL FORMAT: SPICE3 18 | * Symmetry POWER MOS Model (Version 1.0) 19 | * External Node Designations 20 | * Node 1 -> Drain 21 | * Node 2 -> Gate 22 | * Node 3 -> Source 23 | M1 9 7 8 8 MM L=100u W=100u 24 | * Default values used in MM: 25 | * The voltage-dependent capacitances are 26 | * not included. Other default values are: 27 | * RS=0 RD=0 LD=0 CBD=0 CBS=0 CGBO=0 28 | .MODEL MM NMOS LEVEL=1 IS=1e-32 29 | +VTO=4.07861 LAMBDA=0.000761669 KP=19.0218 30 | +CGSO=3.57784e-05 CGDO=4.96221e-07 31 | RS 8 3 0.0216597 32 | D1 3 1 MD 33 | .MODEL MD D IS=2.01865e-09 RS=0.11592 N=1.5 BV=100 34 | +IBV=0.001 EG=1 XTI=1 TT=1e-07 35 | +CJO=3.28974e-09 VJ=4.39387 M=0.659734 FC=0.1 36 | RDS 3 1 3.2e+06 37 | RD 9 1 0.00224103 38 | RG 2 7 12.1 39 | D2 4 5 MD1 40 | * Default values used in MD1: 41 | * RS=0 EG=1.11 XTI=3.0 TT=0 42 | * BV=infinite IBV=1mA 43 | .MODEL MD1 D IS=1e-32 N=50 44 | +CJO=3.78329e-09 VJ=0.607074 M=0.893797 FC=1e-08 45 | D3 0 5 MD2 46 | * Default values used in MD2: 47 | * EG=1.11 XTI=3.0 TT=0 CJO=0 48 | * BV=infinite IBV=1mA 49 | .MODEL MD2 D IS=1e-10 N=0.402271 RS=3.00001e-06 50 | RL 5 10 1 51 | FI2 7 9 VFI2 -1 52 | VFI2 4 0 0 53 | EV16 10 0 9 7 1 54 | CAP 11 10 3.78329e-09 55 | FI1 7 9 VFI1 -1 56 | VFI1 11 6 0 57 | RCAP 6 10 1 58 | D4 0 6 MD3 59 | * Default values used in MD3: 60 | * EG=1.11 XTI=3.0 TT=0 CJO=0 61 | * RS=0 BV=infinite IBV=1mA 62 | .MODEL MD3 D IS=1e-10 N=0.402271 63 | .ENDS irf150 64 | 65 | -------------------------------------------------------------------------------- /examples/basic-usages/netlist-manipulations.py: -------------------------------------------------------------------------------- 1 | #r# ======================= 2 | #r# Netlist Manipulations 3 | #r# ======================= 4 | 5 | #r# This example shows how to manipulate netlist. 6 | 7 | #################################################################################################### 8 | 9 | import PySpice.Logging.Logging as Logging 10 | logger = Logging.setup_logging() 11 | 12 | #################################################################################################### 13 | 14 | from PySpice.Spice.Netlist import Circuit, SubCircuitFactory 15 | from PySpice.Unit import * 16 | 17 | #################################################################################################### 18 | 19 | class SubCircuit1(SubCircuitFactory): 20 | NAME = 'sub_circuit1' 21 | NODES = ('n1', 'n2') 22 | def __init__(self): 23 | super().__init__() 24 | self.R(1, 'n1', 'n2', 1@u_Ω) 25 | self.R(2, 'n1', 'n2', 2@u_Ω) 26 | 27 | #r# Let define a circuit. 28 | 29 | circuit = Circuit('Test') 30 | 31 | #r# When we add an element to a circuit, we can get a reference to it or ignore it: 32 | 33 | C1 = circuit.C(1, 0, 1, 1@u_uF) 34 | 35 | circuit.C(2, 1, 2, 2@u_uF) 36 | circuit.subcircuit(SubCircuit1()) 37 | circuit.X('1', 'sub_circuit1', 2, 0) 38 | 39 | #r# We can get back an element of a circuit using its name, either as a class attribute or using the 40 | #r# dictionary interface: 41 | 42 | C1 = circuit.C1 43 | C1 = circuit['C1'] 44 | 45 | #r# and modify it 46 | 47 | C1.capacitance = 10@u_F 48 | 49 | #r# To get the SPICE netlist of a citcuit, we just have to convert it to a string: 50 | 51 | print(circuit) # str(circuit) is implicit here 52 | 53 | #r# same apply to an element 54 | 55 | print(C1) 56 | 57 | #r# We can disable an element in the circuit 58 | 59 | C1.enabled = False 60 | print(circuit) 61 | 62 | #r# We can clone a circuit to another one 63 | 64 | circuit2 = circuit.clone(title='A clone') # title is optional 65 | print(circuit2) 66 | 67 | #r# We can remove an element 68 | 69 | C2 = circuit2.C2.detach() 70 | print(circuit2) 71 | -------------------------------------------------------------------------------- /PySpice/Doc/ExampleTools.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice Package for Python 4 | # Copyright (C) 2017 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | 23 | import logging 24 | import os 25 | import sys 26 | 27 | from PySpice.Tools.Path import parent_directory_of 28 | 29 | #################################################################################################### 30 | 31 | _module_logger = logging.getLogger(__name__) 32 | 33 | #################################################################################################### 34 | 35 | def find_libraries(): 36 | 37 | try: 38 | library_path = os.environ['PySpiceLibraryPath'] 39 | except KeyError: 40 | # Fixme: only works for one level 41 | python_file = os.path.abspath(sys.argv[0]) 42 | examples_root = parent_directory_of(python_file, step=2) 43 | # .../PySpice/examples/diode/__example_rst_factory__nlrrr2fh.py .../PySpice/examples 44 | library_path = os.path.join(examples_root, 'libraries') 45 | 46 | _module_logger.info('SPICE library path is {}'.format(library_path)) 47 | 48 | return library_path 49 | -------------------------------------------------------------------------------- /doc/pelican/theme/scss/addons/_browser.scss: -------------------------------------------------------------------------------- 1 | // ############################################################################# 2 | // 3 | // Styles for Outdated Browsers 4 | // 5 | // This addon adds modified styles to the outdated browser script 6 | // found on outdatedbrowser.com we specifically added changes to class 7 | // names and removed id references to be more compliant. 8 | // 9 | // ############################################################################# 10 | 11 | // Fimxe: how to check ??? 12 | 13 | $old-browser-line-height-computed: 20pxw; 14 | 15 | * html .browser-outdated { 16 | position: absolute; 17 | } 18 | 19 | .browser-outdated { 20 | display: none; 21 | position: fixed; 22 | bottom: 0; 23 | left: 0; 24 | z-index: 9999; 25 | color: #fff; 26 | text-align: center; 27 | text-transform: uppercase; 28 | // do not add paddings or margins on the container 29 | width: 100%; 30 | height: auto; 31 | background-color: $danger; 32 | 33 | h3, 34 | p { 35 | color: #fff; 36 | } 37 | .btn-outline { 38 | color: #fff; 39 | border: 2px solid #fff; 40 | &:hover { 41 | color: $danger; 42 | background: #fff; 43 | } 44 | } 45 | 46 | .last { 47 | position: absolute; 48 | top: $old-browser-line-height-computed / 2; 49 | right: $old-browser-line-height-computed; 50 | a { 51 | display: inline-block; 52 | color: #fff; 53 | font-size: 36px; 54 | line-height: 1; 55 | text-decoration: none; 56 | } 57 | } 58 | 59 | // add spacer in order for cross styling between noscript and out-of-date 60 | .btn-outline, 61 | noscript h3 { 62 | margin-bottom: $old-browser-line-height-computed; 63 | } 64 | } 65 | 66 | // additionally also implement a warning when JavaScript is disabled 67 | .noscript .browser-outdated { 68 | display: block; 69 | p, 70 | h3 { 71 | display: none; 72 | } 73 | noscript h3 { 74 | display: block; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/diode/RingModulator.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | from PySpice.Spice.Netlist import SubCircuitFactory 4 | from PySpice.Unit import * 5 | 6 | #################################################################################################### 7 | 8 | class RingModulator(SubCircuitFactory): 9 | 10 | NAME = 'RingModulator' 11 | NODES = ('input_plus', 'input_minus', 12 | 'carrier_plus', 'carrier_minus', 13 | 'output_plus', 'output_minus') 14 | 15 | ############################################## 16 | 17 | def __init__(self, 18 | outer_inductance, 19 | inner_inductance, 20 | coupling, 21 | diode_model, 22 | ): 23 | 24 | super().__init__() 25 | 26 | input_inductor = self.L('input', 'input_plus', 'input_minus', outer_inductance) 27 | top_inductor = self.L('input_top', 'input_top', 'carrier_plus', inner_inductance) 28 | bottom_inductor = self.L('input_bottom', 'carrier_plus', 'input_bottom', inner_inductance) 29 | self.CoupledInductor('input_top', input_inductor.name, top_inductor.name, coupling) 30 | self.CoupledInductor('input_bottom', input_inductor.name, bottom_inductor.name, coupling) 31 | 32 | self.X('D1', diode_model, 'input_top', 'output_top') 33 | self.X('D2', diode_model, 'output_top', 'input_bottom') 34 | self.X('D3', diode_model, 'input_bottom', 'output_bottom') 35 | self.X('D4', diode_model, 'output_bottom', 'input_top') 36 | 37 | top_inductor = self.L('output_top', 'output_top', 'carrier_minus', inner_inductance) 38 | bottom_inductor = self.L('output_bottom', 'carrier_minus', 'output_bottom', inner_inductance) 39 | output_inductor = self.L('output', 'output_plus', 'output_minus', outer_inductance) 40 | self.CoupledInductor('output_top', output_inductor.name, top_inductor.name, coupling) 41 | self.CoupledInductor('output_bottom', output_inductor.name, bottom_inductor.name, coupling) 42 | -------------------------------------------------------------------------------- /examples/c-examples/ngspice-shared/sharedspice-essential.h: -------------------------------------------------------------------------------- 1 | typedef struct ngcomplex 2 | { 3 | double cx_real; 4 | double cx_imag; 5 | } ngcomplex_t; 6 | 7 | typedef struct vector_info 8 | { 9 | char *v_name; 10 | int v_type; 11 | short v_flags; 12 | double *v_realdata; 13 | ngcomplex_t *v_compdata; 14 | int v_length; 15 | } vector_info, *pvector_info; 16 | 17 | typedef struct vecvalues 18 | { 19 | char *name; 20 | double creal; 21 | double cimag; 22 | bool is_scale; 23 | bool is_complex; 24 | } vecvalues, *pvecvalues; 25 | 26 | typedef struct vecvaluesall 27 | { 28 | int veccount; 29 | int vecindex; 30 | pvecvalues *vecsa; 31 | } vecvaluesall, *pvecvaluesall; 32 | 33 | typedef struct vecinfo 34 | { 35 | int number; 36 | char *vecname; 37 | bool is_real; 38 | void *pdvec; 39 | void *pdvecscale; 40 | } vecinfo, *pvecinfo; 41 | 42 | typedef struct vecinfoall 43 | { 44 | char *name; 45 | char *title; 46 | char *date; 47 | char *type; 48 | int veccount; 49 | pvecinfo *vecs; 50 | } vecinfoall, *pvecinfoall; 51 | 52 | typedef int (SendChar) (char *, int, void *); 53 | typedef int (SendStat) (char *, int, void *); 54 | typedef int (ControlledExit) (int, bool, bool, int, void *); 55 | typedef int (SendData) (pvecvaluesall, int, int, void *); 56 | typedef int (SendInitData) (pvecinfoall, int, void *); 57 | typedef int (BGThreadRunning) (bool, int, void *); 58 | typedef int (GetVSRCData) (double *, double, char *, int, void *); 59 | typedef int (GetISRCData) (double *, double, char *, int, void *); 60 | typedef int (GetSyncData) (double, double *, double, int, int, int, void *); 61 | 62 | int ngSpice_Init (SendChar *, SendStat *, ControlledExit *, SendData *, SendInitData *, BGThreadRunning *, void *); 63 | int ngSpice_Init_Sync (GetVSRCData *, GetISRCData *, GetSyncData *, int *, void *); 64 | 65 | int ngSpice_Command (char *); 66 | pvector_info ngGet_Vec_Info (char *); 67 | int ngSpice_Circ (char **); 68 | char *ngSpice_CurPlot (void); 69 | char **ngSpice_AllPlots (void); 70 | char **ngSpice_AllVecs (char *); 71 | bool ngSpice_running (void); 72 | bool ngSpice_SetBkpt (double); 73 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | 3 | #################################################################################################### 4 | # 5 | # PySpice - A Spice package for Python 6 | # Copyright (C) 2017 Fabrice Salvaire 7 | # 8 | # This program is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | # 21 | #################################################################################################### 22 | 23 | #################################################################################################### 24 | 25 | import sys 26 | 27 | from setuptools import setup 28 | 29 | #################################################################################################### 30 | 31 | # Check for python3 setup.py install 32 | required_python_version = (3, 6) 33 | if sys.version_info < required_python_version: 34 | sys.stderr.write('ERROR: PySpice requires Python {}.{}\n'.format(*required_python_version)) 35 | sys.exit(1) 36 | 37 | #################################################################################################### 38 | 39 | # Fixme: could check for ngspice, Xyce, libngspice.so etc. 40 | 41 | # check a simulator is installed 42 | # try: 43 | # rc = subprocess.check_call(('ngspice', '--version'), stdout=sys.stderr) 44 | # except FileNotFoundError: 45 | # sys.stderr.write('\n\nWarning: You must install ngspice\n\n') 46 | 47 | #################################################################################################### 48 | 49 | from setup_data import setup_dict 50 | setup(**setup_dict) 51 | -------------------------------------------------------------------------------- /tasks/__init__.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice package for Python 4 | # Copyright (C) 2019 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | # http://www.pyinvoke.org 22 | 23 | #################################################################################################### 24 | 25 | from invoke import task, Collection 26 | # import sys 27 | 28 | #################################################################################################### 29 | 30 | # PYSPICE_SOURCE_PATH = Path(__file__).resolve().parent 31 | 32 | #################################################################################################### 33 | 34 | from . import anaconda 35 | from . import clean 36 | from . import doc 37 | from . import git 38 | from . import github 39 | from . import ngspice 40 | from . import release 41 | from . import test 42 | 43 | ns = Collection() 44 | ns.add_collection(Collection.from_module(anaconda)) 45 | ns.add_collection(Collection.from_module(clean)) 46 | ns.add_collection(Collection.from_module(doc)) 47 | ns.add_collection(Collection.from_module(git)) 48 | ns.add_collection(Collection.from_module(github)) 49 | ns.add_collection(Collection.from_module(ngspice)) 50 | ns.add_collection(Collection.from_module(release)) 51 | ns.add_collection(Collection.from_module(test)) 52 | -------------------------------------------------------------------------------- /PySpice/Spice/NgSpice/api.h: -------------------------------------------------------------------------------- 1 | /* Simplified Ngspice API for CFFI parser */ 2 | 3 | typedef struct ngcomplex 4 | { 5 | double cx_real; 6 | double cx_imag; 7 | } ngcomplex_t; 8 | 9 | typedef struct vector_info 10 | { 11 | char *v_name; 12 | int v_type; 13 | short v_flags; 14 | double *v_realdata; 15 | ngcomplex_t *v_compdata; 16 | int v_length; 17 | } vector_info, *pvector_info; 18 | 19 | typedef struct vecvalues 20 | { 21 | char *name; 22 | double creal; 23 | double cimag; 24 | bool is_scale; 25 | bool is_complex; 26 | } vecvalues, *pvecvalues; 27 | 28 | typedef struct vecvaluesall 29 | { 30 | int veccount; 31 | int vecindex; 32 | pvecvalues *vecsa; 33 | } vecvaluesall, *pvecvaluesall; 34 | 35 | typedef struct vecinfo 36 | { 37 | int number; 38 | char *vecname; 39 | bool is_real; 40 | void *pdvec; 41 | void *pdvecscale; 42 | } vecinfo, *pvecinfo; 43 | 44 | typedef struct vecinfoall 45 | { 46 | char *name; 47 | char *title; 48 | char *date; 49 | char *type; 50 | int veccount; 51 | pvecinfo *vecs; 52 | } vecinfoall, *pvecinfoall; 53 | 54 | typedef int (SendChar) (char *, int, void *); 55 | typedef int (SendStat) (char *, int, void *); 56 | typedef int (ControlledExit) (int, bool, bool, int, void *); 57 | typedef int (SendData) (pvecvaluesall, int, int, void *); 58 | typedef int (SendInitData) (pvecinfoall, int, void *); 59 | typedef int (BGThreadRunning) (bool, int, void *); 60 | typedef int (GetVSRCData) (double *, double, char *, int, void *); 61 | typedef int (GetISRCData) (double *, double, char *, int, void *); 62 | typedef int (GetSyncData) (double, double *, double, int, int, int, void *); 63 | 64 | int ngSpice_Init (SendChar *, SendStat *, ControlledExit *, SendData *, SendInitData *, BGThreadRunning *, void *); 65 | int ngSpice_Init_Sync (GetVSRCData *, GetISRCData *, GetSyncData *, int *, void *); 66 | 67 | int ngSpice_Command (char *); 68 | pvector_info ngGet_Vec_Info (char *); 69 | int ngSpice_Circ (char **); 70 | char *ngSpice_CurPlot (void); 71 | char **ngSpice_AllPlots (void); 72 | char **ngSpice_AllVecs (char *); 73 | bool ngSpice_running (void); 74 | bool ngSpice_SetBkpt (double); 75 | 76 | /* End */ 77 | -------------------------------------------------------------------------------- /examples/c-examples/ngspice-shared/test-module.py: -------------------------------------------------------------------------------- 1 | #skip# 2 | 3 | #################################################################################################### 4 | 5 | import PySpice.Logging.Logging as Logging 6 | logger = Logging.setup_logging() 7 | 8 | #################################################################################################### 9 | 10 | from PySpice.Spice.NgSpice.Shared import NgSpiceShared 11 | 12 | #################################################################################################### 13 | 14 | class MyNgSpiceShared(NgSpiceShared): 15 | 16 | ############################################## 17 | 18 | def get_vsrc_data(self, voltage, time, node, ngspice_id): 19 | self._logger.debug('ngspice_id-{} get_vsrc_data @{} node {}'.format(ngspice_id, time, node)) 20 | voltage[0] = 1. 21 | return 0 22 | 23 | ############################################## 24 | 25 | def get_isrc_data(self, current, time, node, ngspice_id): 26 | self._logger.debug('ngspice_id-{} get_isrc_data @{} node {}'.format(ngspice_id, time, node)) 27 | current[0] = 1. 28 | return 0 29 | 30 | #################################################################################################### 31 | 32 | time_step = '1m' 33 | 34 | # circuit = """ .title rc circuit 35 | # * V1 1 0 1 36 | # V1 1 0 dc 0 external 37 | # R1 1 2 1 38 | # C1 2 0 1 ic=0 39 | # .tran {} 3 uic 40 | # .end 41 | # """.format(time_step) 42 | 43 | circuit = """ 44 | .title Low-Pass RC Filter 45 | Vinput in 0 DC 0V AC SIN(0V 1V 50Hz 0s 0) 46 | Rf in out 1k 47 | Cf out 0 1u 48 | .options TNOM = 25 49 | .options TEMP = 25 50 | .ic 51 | .ac dec 10 1 1Meg 52 | .end 53 | """ 54 | 55 | ngspice_shared = MyNgSpiceShared(send_data=False) 56 | ngspice_shared.load_circuit(circuit) 57 | ngspice_shared.run() 58 | print(ngspice_shared.plot_names) 59 | # vectors = ngspice_shared.vectors('tran1') 60 | # print(vectors) 61 | # vectors = ngspice_shared.vectors('ac1') 62 | # print(vectors) 63 | # print(vectors['frequency']) 64 | # print(ngspice_shared.plot('ac1')) 65 | analysis = ngspice_shared.plot('ac1').to_analysis() 66 | 67 | print(analysis.nodes) 68 | print(analysis.branches) 69 | -------------------------------------------------------------------------------- /examples/filter/low-pass-rc-filter.py: -------------------------------------------------------------------------------- 1 | #r# This example shows a low-pass RC Filter. 2 | 3 | #################################################################################################### 4 | 5 | import math 6 | import numpy as np 7 | import matplotlib.pyplot as plt 8 | 9 | #################################################################################################### 10 | 11 | import PySpice.Logging.Logging as Logging 12 | logger = Logging.setup_logging() 13 | 14 | #################################################################################################### 15 | 16 | from PySpice.Plot.BodeDiagram import bode_diagram 17 | from PySpice.Spice.Netlist import Circuit 18 | from PySpice.Unit import * 19 | 20 | #################################################################################################### 21 | 22 | #f# circuit_macros('low-pass-rc-filter.m4') 23 | 24 | circuit = Circuit('Low-Pass RC Filter') 25 | 26 | circuit.SinusoidalVoltageSource('input', 'in', circuit.gnd, amplitude=1@u_V) 27 | R1 = circuit.R(1, 'in', 'out', 1@u_kΩ) 28 | C1 = circuit.C(1, 'out', circuit.gnd, 1@u_uF) 29 | 30 | #r# The break frequency is given by :math:`f_c = \frac{1}{2 \pi R C}` 31 | 32 | break_frequency = 1 / (2 * math.pi * float(R1.resistance * C1.capacitance)) 33 | print("Break frequency = {:.1f} Hz".format(break_frequency)) 34 | #o# 35 | 36 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 37 | analysis = simulator.ac(start_frequency=1@u_Hz, stop_frequency=1@u_MHz, number_of_points=10, variation='dec') 38 | # print(analysis.out) 39 | 40 | #r# We plot the Bode diagram. 41 | 42 | figure, axes = plt.subplots(2, figsize=(20, 10)) 43 | plt.title("Bode Diagram of a Low-Pass RC Filter") 44 | bode_diagram(axes=axes, 45 | frequency=analysis.frequency, 46 | gain=20*np.log10(np.absolute(analysis.out)), 47 | phase=np.angle(analysis.out, deg=False), 48 | marker='.', 49 | color='blue', 50 | linestyle='-', 51 | ) 52 | for ax in axes: 53 | ax.axvline(x=break_frequency, color='red') 54 | 55 | plt.tight_layout() 56 | plt.show() 57 | 58 | #f# save_figure('figure', 'low-pass-rc-filter-bode-diagram.png') 59 | -------------------------------------------------------------------------------- /tasks/anaconda.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice package for Python 4 | # Copyright (C) 2020 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | 23 | from pathlib import Path 24 | import shutil 25 | 26 | from invoke import task 27 | 28 | #################################################################################################### 29 | 30 | # https://github.com/conda-forge/pyspice-feedstock 31 | 32 | # enable anaconda environment 33 | # source .../miniconda3/bin/activate 34 | 35 | @task() 36 | def conda_build(ctx): 37 | with ctx.cd('anaconda'): 38 | ctx.run('conda build .') 39 | # ctx.run('conda build purge') 40 | 41 | @task() 42 | def conda_login(ctx): 43 | path = Path(__file__).parent.joinpath('anaconda-login.txt') 44 | with open(path) as fh: 45 | username = fh.readline().strip() 46 | password = fh.readline().strip() 47 | print('"{}" "{}"'.format(username, password)) 48 | ctx.run('anaconda login --username="{}" --password="{}"'.format(username, password)) 49 | 50 | @task(conda_build, conda_login) 51 | def conda_upload(ctx): 52 | result = ctx.run('conda build . --output') 53 | path = str(result.stdout).strip() 54 | ctx.run('anaconda upload {}'.format(path)) 55 | -------------------------------------------------------------------------------- /examples/basic-usages/subcircuit.py: -------------------------------------------------------------------------------- 1 | #r# ======================= 2 | #r# How to Use SubCircuit 3 | #r# ======================= 4 | 5 | #r# This example shows how to use subcircuits. 6 | 7 | #################################################################################################### 8 | 9 | import PySpice.Logging.Logging as Logging 10 | logger = Logging.setup_logging() 11 | 12 | #################################################################################################### 13 | 14 | from PySpice.Spice.Netlist import Circuit, SubCircuit, SubCircuitFactory 15 | from PySpice.Unit import * 16 | 17 | #################################################################################################### 18 | 19 | #r# There is two ways to define subcircuit with PySpice, either using 20 | #r# :class:`PySpice.Spice.Netlist.SubCircuit` or a simpler alternative 21 | #r# :class:`PySpice.Spice.Netlist.SubCircuitFactory`. 22 | 23 | #r# 24 | #r# Let define a parallel resistor subcircuit using the :class:`PySpice.Spice.Netlist.SubCircuitFactory` 25 | 26 | class ParallelResistor(SubCircuitFactory): 27 | NAME = 'parallel_resistor' 28 | NODES = ('n1', 'n2') 29 | def __init__(self, R1=1@u_Ω, R2=2@u_Ω): 30 | super().__init__() 31 | self.R(1, 'n1', 'n2', R1) 32 | self.R(2, 'n1', 'n2', R2) 33 | 34 | #r# Let define a circuit 35 | 36 | circuit = Circuit('Test') 37 | 38 | #r# then we can use this subcircuit like this 39 | 40 | circuit.subcircuit(ParallelResistor(R2=3@u_Ω)) 41 | circuit.X('1', 'parallel_resistor', 1, circuit.gnd) 42 | 43 | print(circuit) 44 | #o# 45 | 46 | #r# If the above way is not suited for your purpose we can use this second approach 47 | 48 | class ParallelResistor2(SubCircuit): 49 | NODES = ('n1', 'n2') 50 | def __init__(self, name, R1=1@u_Ω, R2=2@u_Ω): 51 | SubCircuit.__init__(self, name, *self.NODES) 52 | self.R(1, 'n1', 'n2', R1) 53 | self.R(2, 'n1', 'n2', R2) 54 | 55 | circuit = Circuit('Test') 56 | circuit.subcircuit(ParallelResistor2('pr1', R2=2@u_Ω)) 57 | circuit.X('1', 'pr1', 1, circuit.gnd) 58 | circuit.subcircuit(ParallelResistor2('pr2', R2=3@u_Ω)) 59 | circuit.X('2', 'pr2', 1, circuit.gnd) 60 | 61 | print(circuit) 62 | #o# 63 | -------------------------------------------------------------------------------- /examples/operational-amplifier/OperationalAmplifier-api-brainstorming.py: -------------------------------------------------------------------------------- 1 | #skip# 2 | 3 | #################################################################################################### 4 | 5 | from PySpice.Spice.Netlist import SubCircuit 6 | from PySpice.Unit import * 7 | 8 | #################################################################################################### 9 | 10 | class BasicOperationalAmplifier(SubCircuit): # SubCircuitFactory 11 | 12 | # 13 | # __init__(self, name, subcircuit_name, *nodes) 14 | # 15 | # name = class name 16 | # node = NODES = interface 17 | # 18 | 19 | NODES = ('non_inverting_input', 'inverting_input', 'output') 20 | 21 | ############################################## 22 | 23 | def __init__(self): 24 | 25 | # comment: we could pass parameters using ctor 26 | 27 | # Input impedance 28 | # comment: 'R'+'2' but for other devices ? name/attribute versus spice name 29 | self.R('input', 'non_inverting_input', 'inverting_input', 10@u_MΩ) 30 | 31 | # dc gain=100k and pole1=100hz 32 | # unity gain = dcgain x pole1 = 10MHZ 33 | # Fixme: gain=... 34 | self.VCVS('gain', 'non_inverting_input', 'inverting_input', 1, self.gnd, kilo(100)) 35 | self.R('P1', 1, 2, 1@u_kΩ) 36 | self.C('P1', 2, self.gnd, 1.5915@u_uF) 37 | 38 | # Output buffer and resistance 39 | self.VCVS('buffer', 2, self.gnd, 3, self.gnd, 1) 40 | self.R('out', 3, 'output', 10@u_Ω) 41 | 42 | #################################################################################################### 43 | 44 | class BasicOperationalAmplifier(SubCircuit): # SubCircuitFactory 45 | 46 | NODES = ('non_inverting_input', 'inverting_input', 'output') 47 | 48 | # Comment: R doesn't know its name, R prefix is redundant 49 | Rinput = R('non_inverting_input', 'inverting_input', 10@u_MΩ) 50 | 51 | gain = VCVS('non_inverting_input', 'inverting_input', 1, self.gnd, kilo(100)) 52 | RP1 = R(1, 2, 1@u_kΩ) 53 | CP1 = C(2, self.gnd, 1.591@u_uF) 54 | 55 | # Comment: buffer is a Python name 56 | buffer = VCVS(2, self.gnd, 3, self.gnd, 1) 57 | Rout = R(3, 'output', 10@u_Ω) 58 | -------------------------------------------------------------------------------- /examples/analyses/pole_zero_analysis.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python3 2 | #skip# 3 | 4 | #################################################################################################### 5 | 6 | # Program to test pole-zero function of ngspice, PySpice 7 | 8 | import argparse 9 | 10 | #################################################################################################### 11 | 12 | import math 13 | import numpy as np 14 | import matplotlib.pyplot as plt 15 | 16 | #################################################################################################### 17 | 18 | import PySpice.Logging.Logging as Logging 19 | 20 | #################################################################################################### 21 | 22 | from PySpice.Spice.Netlist import Circuit, SubCircuit 23 | 24 | class NodeNames: 25 | """Allow setting of nodes with appropriate names.""" 26 | def __init__(self, *args): 27 | for arg in args: 28 | setattr(self, arg, arg) 29 | 30 | def test_simple(): 31 | circuit = Circuit('pole-zero test circuit') 32 | n = NodeNames('input', 'output') 33 | com = 0 34 | circuit.R('1', n.input, n.output, 1e4) 35 | circuit.C('1', n.input, n.output, 1e-6) 36 | circuit.R('2', n.output, com, 1000) 37 | circuit.C('2', n.output, com, 1e-6) 38 | circuit.L('1', n.output, com, 1e-3) 39 | print("circuit",circuit) 40 | simulator = circuit.simulator(temperature=25, nominal_temperature=25) 41 | analysis = simulator.polezero(n.input,com, n.output,com, 'vol', 'pz') 42 | print("Poles") 43 | for n in analysis.nodes: 44 | if not n.startswith('pole'): continue 45 | pole = np.array(analysis[n]) 46 | print(pole) 47 | print("Zeros") 48 | for n in analysis.nodes: 49 | if not n.startswith('zero'): continue 50 | zero = np.array(analysis[n]) 51 | print(zero) 52 | 53 | if __name__ == '__main__': 54 | logger = Logging.setup_logging() 55 | parser = argparse.ArgumentParser("Test pyspice pole-zero function") 56 | parser.add_argument('-ts', action='store_true', dest='t_simple', help='Test simple rlc network.') 57 | args=parser.parse_args() 58 | if args.t_simple: test_simple() 59 | 60 | -------------------------------------------------------------------------------- /examples/ngspice-shared/ngspice-interpreter.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | 3 | #r# 4 | #r# ===================== 5 | #r# NgSpice Interpreter 6 | #r# ===================== 7 | #r# 8 | #r# This example explains how to use the NgSpice binding. 9 | #r# 10 | 11 | #################################################################################################### 12 | 13 | import PySpice.Logging.Logging as Logging 14 | logger = Logging.setup_logging() 15 | 16 | #################################################################################################### 17 | 18 | from PySpice.Spice.NgSpice.Shared import NgSpiceShared 19 | 20 | #################################################################################################### 21 | 22 | ngspice = NgSpiceShared.new_instance() 23 | 24 | print(ngspice.exec_command('version -f')) 25 | print(ngspice.exec_command('print all')) 26 | print(ngspice.exec_command('devhelp')) 27 | print(ngspice.exec_command('devhelp resistor')) 28 | 29 | circuit = ''' 30 | .title Voltage Multiplier 31 | 32 | .SUBCKT 1N4148 1 2 33 | * 34 | R1 1 2 5.827E+9 35 | D1 1 2 1N4148 36 | * 37 | .MODEL 1N4148 D 38 | + IS = 4.352E-9 39 | + N = 1.906 40 | + BV = 110 41 | + IBV = 0.0001 42 | + RS = 0.6458 43 | + CJO = 7.048E-13 44 | + VJ = 0.869 45 | + M = 0.03 46 | + FC = 0.5 47 | + TT = 3.48E-9 48 | .ENDS 49 | 50 | Vinput in 0 DC 0V AC 1V SIN(0V 10V 50Hz 0s 0Hz) 51 | C0 in 1 1mF 52 | X0 1 0 1N4148 53 | C1 0 2 1mF 54 | X1 2 1 1N4148 55 | C2 1 3 1mF 56 | X2 3 2 1N4148 57 | C3 2 4 1mF 58 | X3 4 3 1N4148 59 | C4 3 5 1mF 60 | X4 5 4 1N4148 61 | R1 5 6 1MegOhm 62 | .options TEMP = 25°C 63 | .options TNOM = 25°C 64 | .options filetype = binary 65 | .options NOINIT 66 | .ic 67 | .tran 0.0001s 0.4s 0s 68 | .end 69 | ''' 70 | 71 | ngspice.load_circuit(circuit) 72 | print('Loaded circuit:') 73 | print(ngspice.listing()) 74 | 75 | print(ngspice.show('c3')) 76 | print(ngspice.showmod('c3')) 77 | 78 | ngspice.run() 79 | print('Plots:', ngspice.plot_names) 80 | 81 | print(ngspice.ressource_usage()) 82 | print(ngspice.status()) 83 | 84 | plot = ngspice.plot(simulation=None, plot_name=ngspice.last_plot) 85 | print(plot) 86 | 87 | # ngspice.quit() 88 | -------------------------------------------------------------------------------- /PySpice/Tools/Path.py: -------------------------------------------------------------------------------- 1 | #################################################################################################### 2 | # 3 | # PySpice - A Spice Package for Python 4 | # Copyright (C) 2014 Fabrice Salvaire 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | # 19 | #################################################################################################### 20 | 21 | #################################################################################################### 22 | 23 | import os 24 | 25 | #################################################################################################### 26 | 27 | def to_absolute_path(path): 28 | 29 | # Expand ~ . and Remove trailing '/' 30 | 31 | return os.path.abspath(os.path.expanduser(path)) 32 | 33 | #################################################################################################### 34 | 35 | def parent_directory_of(file_name, step=1): 36 | 37 | directory = file_name 38 | for i in range(step): 39 | directory = os.path.dirname(directory) 40 | return directory 41 | 42 | #################################################################################################### 43 | 44 | def find(file_name, directories): 45 | 46 | if isinstance(directories, bytes): 47 | directories = (directories,) 48 | for directory in directories: 49 | for directory_path, sub_directories, file_names in os.walk(directory): 50 | if file_name in file_names: 51 | return os.path.join(directory_path, file_name) 52 | 53 | raise NameError("File %s not found in directories %s" % (file_name, str(directories))) 54 | --------------------------------------------------------------------------------