{"id":25201354,"url":"https://github.com/haxscramper/ngspice","last_synced_at":"2025-10-07T02:49:51.333Z","repository":{"id":134341417,"uuid":"287032534","full_name":"haxscramper/ngspice","owner":"haxscramper","description":"Analog circuit simulation library; wrapper for ngspice","archived":false,"fork":false,"pushed_at":"2020-08-31T15:27:35.000Z","size":24,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T19:50:04.754Z","etag":null,"topics":["ngspice","simulation"],"latest_commit_sha":null,"homepage":"","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haxscramper.png","metadata":{"files":{"readme":"readme.org","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-12T14:16:18.000Z","updated_at":"2023-11-28T05:24:02.000Z","dependencies_parsed_at":"2023-08-10T10:15:55.967Z","dependency_job_id":null,"html_url":"https://github.com/haxscramper/ngspice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/haxscramper/ngspice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxscramper%2Fngspice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxscramper%2Fngspice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxscramper%2Fngspice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxscramper%2Fngspice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haxscramper","download_url":"https://codeload.github.com/haxscramper/ngspice/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haxscramper%2Fngspice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278711895,"owners_count":26032699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ngspice","simulation"],"created_at":"2025-02-10T04:37:29.639Z","updated_at":"2025-10-07T02:49:51.328Z","avatar_url":"https://github.com/haxscramper.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+title: readme\n\nNim wrapper for ngspice library - simulation of analog circuits.\n\n* Installation\n\n#+begin_src bash\nnimble install ngspice\n#+end_src\n\nThis library is a wrapper for ngspice C library - you need to have it\ninstalled.\n\n* Links\n\n- [[https://github.com/haxscramper/ngspice][github]]\n- [[https://haxscramper.github.io/ngspice-doc/src/ngspice.html][api reference]]\n- [[https://discord.gg/hjfYJCU][discord server]]\n- [[https://nimble.directory/pkg/ngspice][nimble package]]\n\n* nim API\n\nC api for ngspice is based on callbacks - you provide several\nfunctions and textual description of the netlist. Callback functions\nare used for reporting simulation progress.\n\nngspice provides two APis - synchronous and asynchronous. Only first\none is implemented.\n\n* Netlist syntax description\n\nFor full documentation of ngspice netlist syntax see [[http://ngspice.sourceforge.net/docs/ngspice-html-manual/manual.xhtml][manual]] and\n[[http://ngspice.sourceforge.net/docs/ngspice-html-manual/manual.xhtml#magicparlabel-28301][glossary]] for list of terms. Only brief outline is presented here.\n\nIf you are familliar with spice/ngspice circuit netlist you can skip\nthis section.\n\nNgspice netlist is a textual description of circuit graph. In most\ncases each element (card) is put on its own line, in form of\n~\u003cElementType\u003e\u003cIdx\u003e \u003cconnector-1\u003e \u003cconnector-2\u003e \u003c... arguments ...\u003e~.\nFor example ~5V~ voltage source between terminals ~0~ and ~1~ will be\nwritten as ~V1 0 1 5~.\n\nTo perform actual simulation you need to add simulation command in the\nnetlist. For example, If I want to perform ~DC~ [[http://ngspice.sourceforge.net/docs/ngspice-html-manual/manual.xhtml#subsec__DC__DC_Transfer][simulation]] of voltage\nsource ~V1~, with voltage in range ~[0-5]~, step ~1~ I will need to\nadd ~.dc v1 0 5 1~.\n\n* Use example\n\n#+begin_src nim\n  import ngspice\n  import strformat\n\n  ngspiceInit(\n    printfcn = ( # Callback for printing regular output of the simulation\n      proc(msg: string, a2: int): int = echo \"@ \", msg\n    ).addPtr(),\n    statfcn = ( # Callback for printing simulation progress\n      proc(msg: string, a2: int): int = echo \"# \", msg\n    ).addPtr(),\n    sdata = # Callback after simulation of new vector completed\n      proc(vdata: VecValuesAll, a2: int, a3: int, a4: pointer): int =\n        echo \u0026\"Processed {vdata.vecindex}/{vdata.veccount} vectors\"\n  )\n\n  ngSpiceCirc(\n    @[ # terminal ~0~ is used as ground\n      \"V1 0 1 5\", # Voltage source\n      \"V2 0 2 5\",\n      \"R1 0 1 10\", # Resistor\n      \"R2 0 2 10\",\n      \".dc v1 0 5 1\" # DC simulation in range [0-5] volts\n    ]\n  )\n\n  ngSpice_Command(\"run\"); # Run execute command to run simulation\n\n  let cp: string = ngSpiceCurPlot() # Get name of current simulation\n                                    # plot (collection of\n  for vec in ngSpiceAllVecs(cp):\n    let res: NGVectorInfo = ngGetVecInfo(cp \u0026 \".\" \u0026 vec)\n    echo vec, \":  \", res.realdata # voltage between group and each terminal\n\n  echo \"done\"\n#+end_src\n\n#+RESULTS:\n#+begin_example\n@ stdout ******\n@ stdout ** ngspice-32 shared library\n@ stdout ** Creation Date: Tue Jun 16 21:35:13 UTC 2020\n@ stdout ******\n# Source Deck\n@ stdout Circuit: circuit simulation\n# Prepare Deck\n# Circuit2\n# Circuit2: 12.5%\n# Circuit2: 25.0%\n# Circuit2: 37.5%\n# Circuit2: 50.0%\n# Circuit2: 62.5%\n# Circuit2: 75.0%\n# Circuit2: 87.5%\n@ stdout Doing analysis at TEMP = 27.000000 and TNOM = 27.000000\n# Device Setup\nProcessed 0/5 vectors\n# dc: 20.0%\nProcessed 1/5 vectors\n# dc: 40.0%\nProcessed 2/5 vectors\n# dc: 60.0%\nProcessed 3/5 vectors\n# dc: 80.0%\nProcessed 4/5 vectors\n# --ready--\nProcessed 5/5 vectors\n# --ready--\n@ stdout No. of Data Rows : 6\nv1#branch:  @[0.0, -0.1, -0.2, -0.3, -0.4, -0.5]\nv2#branch:  @[-0.5, -0.5, -0.5, -0.5, -0.5, -0.5]\nV(2):  @[-5.0, -5.0, -5.0, -5.0, -5.0, -5.0]\nV(1):  @[0.0, -1.0, -2.0, -3.0, -4.0, -5.0]\nv-sweep:  @[0.0, 1.0, 2.0, 3.0, 4.0, 5.0]\ndone\n#+end_example\n\n* Contribution \u0026 development\n\nTodo\n- [ ] add documentation for static wrappers for netlist description\n- [ ] Document raspberry pi simulation unit test\n\nIf you have any question about implementation or usage feel free to\njoin my [[https://discord.gg/hjfYJCU][discord server]].\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaxscramper%2Fngspice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaxscramper%2Fngspice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaxscramper%2Fngspice/lists"}