Giter Club home page Giter Club logo

nodal's Introduction

Nodal.py

Nodal.py is a simple electrical circuit simulator that uses nodal analysis to solve linear networks made up of resistors and ideal current or voltage sources, both independent and controlled.

The intendend use case of nodal is through the two provided commandline scripts. Even so, the package has been carefully written so that it might be used to programmatically simulate circuits from inside another application.

The numerical work is done by the numpy package. For larger circuits, the user may choose to use sparce matrices, in which case computation is powered by scipy instead.

Table of contents

Installation

To get the stable release download it and run

$ pip install nodal-1.3.0.whl

To try out the latest developments use flit instead:

$ git clone https://github.com/EnricoMiccoli/nodal.git
$ cd nodal
$ flit install

Command line scripts

Defining the input

All scripts read their input from a netlist in the csv format. Each line represents a component and contains informations about its electrical values (e.g. the resistance in ohm for a resistor) and all the connections it makes with other components.

Many annotated examples of netlists are available in the doc/ directory.

Circuit solver

Usage: $ nodal-solver netlist.csv. If the circuit is particularly large, one might use $ nodal-solver -s netlist.csv instead to save memory and runtime.

The output is printed in the following format:

e(node_name) = node potential (volt)
i(component_name) = current passing through the component (ampere)

The ground node is used as a potential reference. It is set at 0 volt.

Resistance calculator

Usage: $ nodal-resistance netlist.csv or $ nodal-resistance -s netlist.csv.

This will print the equivalent resistance (unit is ohm) as seen through the nodes named 1 and g in the netlist.

Component specification

Type Value Lead + Lead - Control + Control - Driver
Resistor R resistance (ohm) first second NA NA NA
Voltage source E voltage (volt) + voltage ground NA NA NA
Current source A current (ampere) + current ground NA NA NA
CCCS CCCS gain (adimensional) + current ground + driving current - driving current component determining the current
CCVS CCVS gain (ohm) + tension ground + driving current - driving current component determining the current
VCCS VCCS gain (ohm^-1) + current ground + driving voltage - driving voltage NA
VCVS VCVS gain (adimensional) + voltage ground + driving voltage - driving voltage NA
OPAMP, simulated OPMODEL feedback resistance (ohm) output ground + terminal - terminal NA

Note that opamps are not supported directly, but they are instead internally simulated with an equivalent circuit. For example this is the circuit generated to model a voltage buffer:

Voltage buffer circuit diagram

Usage example

Suppose we wanted to solve this circuit:

Circuit diagram

First we would prepare a file describing the circuit. Each line represents a component, using the format
name, type, value, first lead, second lead.

Input file netlist.csv:

a1,A,1,1,3
r1,R,1,1,2
r2,R,1,2,3

Take notice of the orientation of the current generator: current flows toward the node connected to the first lead. Component type can either be

  • A for current generators
  • R for resistors

Default units are ampere and ohm.

We can then execute $ nodal-solver netlist.csv to get the list of node potentials (unit is volt).

Printed output:

Ground node: 1
e(2)    = -1.0
e(3)    = -2.0

A more advanced example

Circuit diagram

Example circuit from: Esercizi da temi d'esame di Elettrotecnica

Input file 1.6.1.csv:

r1,R,2,1,4
r2,R,2,1,g
r3,R,0.5,1,2
e1,E,8,4,g
a1,A,4,1,2
d1,CCCS,2,2,g,1,g,r2

Output:

Ground node: g
e(1)    = 2.0
e(2)    = -1.0
e(4)    = 8.0
i(d1)   = -2.0
i(e1)   = 3.0

A more contrived example

What is the resistance between two points that are a knight's move away on an infinite grid of 1 ohm resistors?

nodal's People

Contributors

enricomiccoli avatar ethanholz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ethanholz

nodal's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.