Saturday, October 25, 2008

BasicSimulator Released

Today, I release my first circuit simulator. I worked a lot on this project and I am very satisfied with the results.

In this post, I will present the functionality and limitations of BasicSimulator (this is the name I chose for my program), and I will explain how to use it. A link to download the source code and binaries of the program can be found at the end of this post.


Functionality and Limitations

The BasicSimulator can perform two types of DC analysis: operating point analysis and DC sweep. All circuit elements supported by the simulator are linear elements. It cannot simulate circuits with diodes, transistors, or any nonlinear element. Here is a list of all supported circuit elements.
  • Resistors
  • Capacitors
  • Inductors
  • Independent voltage sources
  • Independent current sources
  • Voltage controlled voltage sources
  • Voltage controlled current sources
  • Current controlled voltage sources
  • Current controlled current sources
  • Ideal OpAmps
  • Transformers
With DC, capacitors are just open circuits, and inductors and transformers are just short circuits. These elements are not very important in a simulator that can only perform DC analysis, but I included them anyway.


Input Files

The input to the simulator consists of two XML files, the first contains the circuit description, and the second contains the analysis command. The paths to the files should be passed to the program as command line arguments.

BasicSimulator <circuit file> <analysis command file>


1) The circuit description file

Circuits are described using the Circuit Description Language (CDL) which is an XML-based language invented by myself. I wrote an XML Schema to formally define the CDL and to validate the user files before parsing them. The Schema file can be found at
...\BasicSimulator\BasicSimulator\Schemas\CDL.xsd
The CDL is defined in the XML namespace
Bassem.BasicSimulator.CDL
Instance documents should create an alias for this namespace and prefix the root element
<Circuit> with this alias.

<cdl:Circuit xmlns:cdl="Bassem.BasicSimulator.CDL">
    ...

   <!-- circuit description here -->
    ...

</Circuit>


Because CDL is an XML-based language, it is self-descriptive. The user can learn it from the circuit files I used to test the program. These can be found at
...\BasicSimulator\BasicSimulator\Tests\Test1\Circuit.xml,
...\BasicSimulator\BasicSimulator\Tests\Test2\Circuit.xml, and
...\BasicSimulator\BasicSimulator\Tests\Test3\Circuit.xml.

2) The analysis command file

The analysis command specifies the type of analysis to be performed. Depending on the type of analysis, it may or may not contain additional information. To request an operating point analysis, only the type of analysis needs to be specified in the analysis command file. If a DC sweep analysis is requested, the user should provide the ID of the independent source which value is to be swept, the starting value of the sweep, the stopping value, and the size of the increment.

The XML schema document that specifies the structure of the analysis command file can be found at
...\BasicSimulator\BasicSimulator\Schemas\AnalysisCommand.xsd
The namespace of the XML vocabulary used in analysis command files is
Bassem.BasicSimulator.AnalysisCommand

The following analysis command specifies that operating point analysis should be performed on the circuit.

<ac:OperatingPoint xmlns:ac="Bassem.BasicSimulator.AnalysisCommands" />


The following analysis command specifies that DC sweep analysis should be performed on the circuit by sweeping the value of the independent source 'V7' from 0 to 30 with a step size of 5.

<ac:DCSweep xmlns:ac="Bassem.BasicSimulator.AnalysisCommands">
    <SourceName>V7</SourceName>
    <Start>0</Start>
    <Stop>30</Stop>
    <Increment>5</Increment>
</ac:DCSweep>



Querying the Analysis Results

The ResQuery is the language used to query the analysis results. Again, this is a language invented by myself. It is very simple. A ResQuery has one of two forms:

node:<node name>
element:<element ID>


The first query gets the node voltage or voltages depending on the analysis type. The second query gets the analysis results associated with the element. For example if the element is a current controlled voltage source, the query will get the value(s) of the input current, the output voltage drop, the output current, and the power consumption in the element.

Click here to download the source code and binaries of the BasicSimulator.