aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: d4b6524fa9881145863b109c6ec4c3e6ce879032 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# circgraph

This is a tool for calculating equivalent
resistances/impedances/capacitances for a circuit (represented as a
graph, hence "circuit graph"), written in C++.

# Motivation

This program exists for three reasons: boredom, a desire to brush up
on my C++, and -- most importantly -- laziness. Why do tedious
arithmetic when you can spend hours writing a program to do it for
you?

# Usage

Compile with:

```
make
```

Run as:

```
./circgraph
```

By default, `circgraph` will read a circuit from stdin (see below) and
output the equivalent resistance between the source and sink. The `-C`
flag will switch the calculation mode to capacitance.

`circgraph` can output graphs in Graphviz's `dot` format to stdout for
visualization. Pass stdout to `tests/testgraph.sh` to try (requires
graphviz and evince).

# Circuit Input

`circgraph` represents circuits as weighted undirected graphs, with
nodes representing electrically common elements (i.e. a wire) and
edges and their weights representing either resistors or capacitors
(depending on command-line options).

`circgraph` takes input from stdin in the following format:

```
<source_node> <sink_node>
<node1> <node 2> <weight>
<node1> <node 2> <weight>
...
```

The first line specifies the names of the source and sink nodes. All
subsequent lines represent a weighted edge with the names of the two
nodes and the weight of the edge. Node names are created upon use.

An example input (test5.txt) and its corresponding graph are given
below:

```
a c
a b 1
a c 1
b c 1
```

![test5](https://github.com/built1n/circgraph/raw/master/tests/test5.png)

See the `testX.txt` files for further examples.