Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/victor-aunon/circuitsolver

Electric circuit solver in DC
https://github.com/victor-aunon/circuitsolver

cpp electrical-engineering electricity learn-to-code learning learning-by-doing

Last synced: about 2 months ago
JSON representation

Electric circuit solver in DC

Awesome Lists containing this project

README

        

# CircuitSolver

## Table of contents
1. [Description](#description)
2. [Building the circuit](#building)
3. [Solving the circuit](#solving)
4. [Acknowledgments](#acknowledgments)

---

## 1. Description
_CircuitSolver_ is a C++ program that calculates the electric currents in a DC circuit. The project was created with the aim of encourage C++ learners to build their own projects and provide engineering students with a tool to solve this type of circuits.

As a learning resource, this project includes a fully commented code that uses:
* Classes
* Structs
* Pointers
* Code separated in headers and implementation files.
* Third party libraries.
* Examples

## 2. Building the circuit
Electric circuits must be built in XML format. The main node is the `` node, which holds the circuit meshes and branches. A `` node should be declared with the attribute `ID` as its identifier, the same happens with a `` node.

The circuit elements should be declared inside a `` node. If the element is a battery, a `` node should be created with the attributes `ID` (the identifier) and `value`, which is the voltage of the battery in volts. Alternatively, if the element is an impedance, a `` node should be created with the attributes `ID` (the identifier) and `value`, which is the resistance in ohms.

When creating a mesh, the user must define an initial direction of the current flow. The program solves the mesh currents by considering that the current flows clockwise through each mesh. So, taking this direction into account, the user must define the battery voltage according to this. If the current goes through the battery from anode to cathode, then the `value` attribute of the `` must be positive; on the contrary, it must be negative. For resistance elements, the user must define the `value` attribute of the `` always positive.

As an example, the following circuit, composed of two meshes, should be declared as follows:

![alt text](https://raw.githubusercontent.com/victor-aunon/CircuitSolver/master/examples/circuit_2_meshes_scheme.png "Two meshes circuit")

```XML


















```

## 3. Solving the circuit
Once the circuit has been created, it must be solved by passing it as an argument to the program. In windows, for instance, the user must call the program in this way:

`CircuitSolver.exe .xml`

If the file does not exist, or it is not an XML file, or it can't be read, the program will raise an error.

Once the circuit XML file has been read correctly, the program solves the circuit and creates a text file called `_solved.txt`. This results file contains the electric currents at each branch and mesh, as well as the power dissipated by each resistance.

Regarding the sign of the current, if the value is positive, it means that the resulting direction of the current matches the initial one, which is clockwise. In case it is negative, the current direction would be anticlockwise. The same happens for branches which are shared between two meshes: its resulting current sign is referred to the one of the first mesh in which the branch was declared.

## 4. Acknowledgments
This software is based on pugixml library (http://pugixml.org). pugixml is Copyright (C) 2006-2018 Arseny Kapoulkine.