Skip to content

Commit

Permalink
added all the documentation, Eigen uploaded, final submission
Browse files Browse the repository at this point in the history
  • Loading branch information
sahilbansal17 committed Mar 31, 2018
1 parent 5b67527 commit bfd7afa
Show file tree
Hide file tree
Showing 306 changed files with 116,186 additions and 0 deletions.
Binary file added Docs/design_document.pdf
Binary file not shown.
103 changes: 103 additions & 0 deletions Docs/design_document.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
\documentclass[]{article}
\usepackage[left=0.7in,right=0.7in,top=0.9in,bottom=0.5in]{geometry}
\usepackage{amsmath}
%opening
\title{\textbf{COP290 : Assignment 2 - AC Circuit Solver \\ Design Document}}
\author{Sahil Bansal (2016CSJ0008) \& Sahil Singh(2016CSJ0025)}

\begin{document}

\maketitle

\section{\LARGE Overall Design :}
\Large
An object-oriented design is followed and the code is properly structured into several cpp and header files. The sub-components are described in detail below. Also, all the algorithms used are briefly touched upon.

\section{\LARGE Sub-Components :}
\begin{itemize}
\item \textbf{ac\_circuit\_solver.cpp} is the main file for the entire project and contains the code for solving the circuit, and also calls the \textbf{parse} and \textbf{draw} functions.
\item \textbf{draw.h} and \textbf{draw.cpp}: They contain the main function to draw the entire circuit.
\item \textbf{parse.h} and \textbf{parse.cpp}: They contain the element and source structures and their vectors obtained after parsing the input netlist.
\item \textbf{parseCircuit.y} is the yacc file used while parsing.
\item \textbf{scanCircuit.l} is the lex file used while scanning.
\item \textbf{svg.h} and \textbf{svg.cpp}: They contain the SVG functions used for drawing individual elements and implement onClick events on the text to get an alert box showing statistics of the element when clicked.
\item \textbf{Eigen} library is used for generating and solving the matrices.
\end{itemize}

\section{\LARGE Testing Sub-Components :}
\subsection{Scanner :}
\Large
\begin{itemize}
\item The parser is checked by writing some cases that may violate the syntax or semantic rules. Such case(s) are defined in the \textbf{Public\_cases/syntacticCases} folder. Also, in the test cases provided, cases numbered 2 and 5 don't follow the rules of the netlist as enforced in the README.
\end{itemize}

\subsection{Parser :}
\Large\begin{itemize}
\item It is checked by printing the values stored in the \textbf{sourceElements} and \textbf{circuitElements} vectors declared in the \textbf{parse.h} file.
\item This print function is now moved to \textbf{ac\_circuit\_solver.cpp} and prints to the terminal. It can be verified that the input netlist is stored properly from the terminal.
\end{itemize}

\subsection{SVG :}
\Large\begin{itemize}
\item The SVG functions defined were checked manually by calling all of them in a temporary main function defined in \textbf{svg.cpp} just for the purpose of testing.
\end{itemize}

\subsection{Draw :}
\Large\begin{itemize}
\item Some test cases were designed and are kept in the \textbf{Public\_cases/solveCases} folder.
\item A script \textbf{testScript.sh} was written to simultaneously run all these test cases.
\item The generated SVG outputs were manually then checked for any errors and the errors were corrected as and when they came.
\end{itemize}

\subsection{Solve :}
\Large\begin{itemize}
\item The solving part was checked by separately running the file \textbf{ac\_circuit\_solver.cpp}.
\item For the two solved test cases provided, the matrices used in \textbf{MNA algorithm} were all printed to the screen and calculated manually and matched.
\item The output currents and voltages along with phases were also then matched with the outputs provided.
\item Further testing was done on all the cases in the \textbf{Public\_cases/solveCases} folder to make sure that the algorithm terminated.
\end{itemize}

\section{\LARGE Algorithm used for drawing the Circuit :}
\Large
\begin{itemize}
\item The components are seperated into different vectors each containing those components whose difference between starting and ending nets is the same.
\item It is made sure that for each component the starting net value is smaller than the ending net value. Also, this does not effect the polarity of current or voltage sources as this part is separate from solving. Moreover, \textbf{drawMain function is called after solving the circuit to make sure that elements can be made interactable easily}.
\item Each of these vector is then sorted based on the ending net value.
\item A loop is then run, starting from those elements with the highest net difference value.
\item All the elements with the same net difference values are drawn in a particular iteration of the loop.
\item It contains another nested loop which is for a greedy technique applied to draw the elements such that the next elements' starting net will be higher or equal to the ending net of previous component. This makes sure that maximum no of disjoint components are drawn in a single line.
\item If there are some components which are connected in parallel, this case has also been handled by drawing all such elements first and then moving to the next iteration in another nested loop.
\end{itemize}

\section{\LARGE Modified Nodal Analysis for solving the Circuit :}
\Large
\begin{itemize}
\item In brief, this method, after applying \textbf{Kirchoff's current law} to each node by using some conventions and then writing equations for voltages of each voltage source, reduces the circuit into the form:
\[AX = Z\]
where A, X, and Z are all complex matrices. Further,
\[A = \begin{pmatrix} G & B\\ C & D \end{pmatrix}\]
where G contains the admittances of the passive elements \& B, C and D depend on the active sources and contain only either 1, 0 or -1.
\[Z= \begin{pmatrix} I\\ E \end{pmatrix}\]
where I contains the net current at each node and E contains the known voltage sources.
The matrix \textbf{X} obtained after solving the equation is:
\[X= \begin{pmatrix} v\\ j \end{pmatrix}\]
where \textbf{v} obtained contains the voltages at each node and \textbf{j} contains the current supplied by each voltage source.
\item These matrices are suitably constructed and then after solving:
\begin{itemize}
\item The voltage across an element is simply the difference of voltages across its starting and ending net.
\item The current, thus across it is simply the product of its \textbf{admittance} and the voltage thus obtained.
\end{itemize}
\item For the case when there are \textbf{multiple sources of different frequencies}:
\begin{itemize}
\item First, they are sorted in non-decreasing order of their frequencies.
\item Then, only those which have the same frequency are considered active at a time.
\item The matrices are suitable reconstructed or adjusted to handle such case.
\end{itemize}
\end{itemize}

\section{\LARGE Interactable SVG :}
\Large
The text used for a particular element is provided with a \textbf{onClick} attribute containing the function which takes all the values of the element to be shown as paramters. This function is included in the \textbf{script} tag nested inside the SVG tag and handled by the \textbf{addInteraction} function defined in the \textbf{svg.cpp} file. The arguments are directly passed through the \textbf{drawText} function called while drawing the text in the \textbf{draw.cpp} file.

\end{document}

Binary file added Docs/software_requirement_doc.pdf
Binary file not shown.
24 changes: 24 additions & 0 deletions Docs/software_requirement_doc.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
\documentclass[]{article}
\usepackage[left=0.7in,right=0.7in,top=0.9in,bottom=0.4in]{geometry}

%opening
\title{\textbf{COP290 : Assignment 2 - AC Circuit Solver\\Software Requirement Specification}}
\author{Sahil Bansal(2016CSJ0008) \& Sahil Singh(2016CSJ0025)}

\begin{document}

\maketitle
\vspace{1ex}
\paragraph{
\LARGE{Functionalities involved in the software:}\newline
}
\Large
\begin{itemize}
\item The circuit is drawn in \textbf{SVG} format by drawing individual nets as vertical lines and then connecting the components appropriately. Overlapping is avoided and a properly designed algorithm is implemented.
\item The components are clickable through the text showing the name of the component.
\item Most of the syntax and semantic errors are handled and shown on the terminal. This was possible due to the usage of lex and yacc to parse the netlist.
\item The solving part is handled using the \textbf{Eigen} library in C++ along with \textbf{complex} header file. \textbf{Modified Nodal Analysis} algorithm is used for solving.
\item After solving, the output is displayed in a text file and is in the increasing order of frequencies of the sources. The magnitude and phase values are rounded upto 3 decimal places.
\end{itemize}

\end{document}
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,49 @@
# AC_Circuit_Solver
Given the netlist, this program draws an AC circuit and finds the current/voltage values.

## How to run
1. `make execute`
2. `./ac_circuit_solver input.cir output1.svg output2.txt`

Command 2 runs the program taking NETLIST as input from **input.cir** and generates **output1.svg.html** as output image and **output2.txt** with the voltages and currents after solving the circuit.

## Code structure
The entire code is in the **src/** directory and is structured in the following way:

> 1. *ac_circuit_solver.cpp*
> > This is the main file for the entire project.
> 2. *draw.h* and *draw.cpp*
> > They contain the main function to draw the circuit.
> 3. *parse.h*
> > It contains the element and source structures and their vectors obtained after parsing the input netlist.
> 4. *parseCircuit.y*
> > It is the yacc file used while parsing.
> 5. *scanCircuit.l*
> > It is the lex file used while scanning.
> 6. *svg.cpp* and *svg.h*
> > They contain the svg functions used for drawing individual elements and implement onClick events on text to get an alert box showing statistics of the element when clicked.
> 7. **Eigen/** directory
> > It is the C++ library used for generating and solving matrices.

## Testing
A testing script **testScript.sh** has also been written to run many cases simultaneously. It can be modified as per the usage.

All the test cases used for testing the working are included in the **Public_cases** folder.

## Restrictions on Input Netlist

There are some restrictions kept in the netlist format:

1. The net can have only an non-negative value as name. **eg.** *NET 0*, *Net 1*.
2. The elements can have only non-negative value as name. **eg.** *R5*, *V0*.
3. The only units allowed to specify values are **K(Kilo)**, **N(Nano)** and **M(Milli)**. This is deliberately done for the purpose of easy error reporting in case units are mismatched.
4. For resistor, only the value has to be supplied **eg.** *10K* would mean *10 kilo ohms* whereas for capacitor and inductor, *F* and *H* need to be written after unit. **eg.** *10NF*.
5. **The frequency unit allowed for voltage and current sources is only KHz.**

19 changes: 19 additions & 0 deletions src/Eigen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include(RegexUtils)
test_escape_string_as_regex()

file(GLOB Eigen_directory_files "*")

escape_string_as_regex(ESCAPED_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

foreach(f ${Eigen_directory_files})
if(NOT f MATCHES "\\.txt" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/[.].+" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/src")
list(APPEND Eigen_directory_files_to_install ${f})
endif()
endforeach(f ${Eigen_directory_files})

install(FILES
${Eigen_directory_files_to_install}
DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen COMPONENT Devel
)

install(DIRECTORY src DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen COMPONENT Devel FILES_MATCHING PATTERN "*.h")
41 changes: 41 additions & 0 deletions src/Eigen/Cholesky
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_CHOLESKY_MODULE_H
#define EIGEN_CHOLESKY_MODULE_H

#include "Core"

#include "src/Core/util/DisableStupidWarnings.h"

/** \defgroup Cholesky_Module Cholesky module
*
*
*
* This module provides two variants of the Cholesky decomposition for selfadjoint (hermitian) matrices.
* Those decompositions are also accessible via the following methods:
* - MatrixBase::llt()
* - MatrixBase::ldlt()
* - SelfAdjointView::llt()
* - SelfAdjointView::ldlt()
*
* \code
* #include <Eigen/Cholesky>
* \endcode
*/

#include "src/Cholesky/LLT.h"
#include "src/Cholesky/LDLT.h"
#ifdef EIGEN_USE_LAPACKE
#include "src/misc/lapacke.h"
#include "src/Cholesky/LLT_LAPACKE.h"
#endif

#include "src/Core/util/ReenableStupidWarnings.h"

#endif // EIGEN_CHOLESKY_MODULE_H
/* vim: set filetype=cpp et sw=2 ts=2 ai: */
48 changes: 48 additions & 0 deletions src/Eigen/CholmodSupport
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef EIGEN_CHOLMODSUPPORT_MODULE_H
#define EIGEN_CHOLMODSUPPORT_MODULE_H

#include "SparseCore"

#include "src/Core/util/DisableStupidWarnings.h"

extern "C" {
#include <cholmod.h>
}

/** \ingroup Support_modules
* \defgroup CholmodSupport_Module CholmodSupport module
*
* This module provides an interface to the Cholmod library which is part of the <a href="http://www.suitesparse.com">suitesparse</a> package.
* It provides the two following main factorization classes:
* - class CholmodSupernodalLLT: a supernodal LLT Cholesky factorization.
* - class CholmodDecomposiiton: a general L(D)LT Cholesky factorization with automatic or explicit runtime selection of the underlying factorization method (supernodal or simplicial).
*
* For the sake of completeness, this module also propose the two following classes:
* - class CholmodSimplicialLLT
* - class CholmodSimplicialLDLT
* Note that these classes does not bring any particular advantage compared to the built-in
* SimplicialLLT and SimplicialLDLT factorization classes.
*
* \code
* #include <Eigen/CholmodSupport>
* \endcode
*
* In order to use this module, the cholmod headers must be accessible from the include paths, and your binary must be linked to the cholmod library and its dependencies.
* The dependencies depend on how cholmod has been compiled.
* For a cmake based project, you can use our FindCholmod.cmake module to help you in this task.
*
*/

#include "src/CholmodSupport/CholmodSupport.h"

#include "src/Core/util/ReenableStupidWarnings.h"

#endif // EIGEN_CHOLMODSUPPORT_MODULE_H

Loading

0 comments on commit bfd7afa

Please sign in to comment.