Thursday, December 25, 2008

The Program Structure

The program consists of one assembly "BasicSimulator.exe" containing three namespaces
  • BasicSimulator
  • BasicSimulator.CircuitElements
  • BasicSimulator.Math

The BasicSimulator namespace


I will now present the most notable classes in the namespace BasicSimulator.

The class DomParser is responsible for validating and parsing the Document Object Model (DOM) trees representing the input files: circuit files and analysis command files.

The class Analyst can perform two types of analysis: operating point and DC sweep analysis.
Analyst does not contain the details of how element contributions are stamped or how linear equations are solved. Such details are the responsibility of worker classes controlled by Analyst. Analyst is only concerned with the high-level steps.

The class ResQueryProcessor contains the method Execute which validates and parses ResQueries. It then returns a data structure containing the requested analysis results.

The UIManager class is responsible for the user interface. It gets ResQueries from the user and forwards them to ResQueryProcessor.Execute. It then formats and presents the contents of the data structures returned by the method.
The user interacts with the ResQueryProcessor through the UIManager.


The class Program contains the Main method of the program. Main processes the command-line arguments and loads the input files.


The BasicSimulator.CircuitElements namespace

This namespace contains the classes that represent the circuit elements supported by the simulator (Resistor, Inductor, IndependentVoltageSource, ...etc) and the base classes from which the element specific classes derive.

The following figure shows the inheritance hierarchy of the circuit element classes.




All elements that, in the context of DC analysis, do not have an admittance description, implement IAdmittancelessElement. This interface has two member properties:
  • ExcessEquationsCount: The value of this property is hard-coded in the element definition. It is needed when numbering the elements that do not have an admittance description (refer back to the formulation step 2 in my post "Circuit Formulation").
  • FirstExcessEquationIndex: The value of this property is set by the client. It is needed when stamping the admittanceless element contribution.

There is two other circuit elements that only make sense in the context of DC sweep analysis: SweepableCurrentSource and SweepableVoltageSource.



The classes that implement ISweepableSource should expose the properties StartingValue, StoppingValue, IncrementingValue, and the method StampIncrement.
The current version of the simulator supports circuits with only one sweepable source.

CircuitElement and its children decorate some of their properties with the AnalysisResultAttribute attribute. This means that the target property gets or derives an analysis result related to the element from the values in the solution vector.
For example the class Resistor decorates two of its properties with the AnalysisResultAttribute attribute: VoltageDrop and Current. It also inherits from OnePortNetwork the property PowerConsumption which is decorated with the same attribute.
The ResQueryProcessor uses reflection to get the names and values of the properties decorated with the AnalysisResultAttribute attribute for the circuit element specified in the ResQuery. These analysis results are then displayed to the user by the UIManager.


The namespace BasicSimulator.Math

This namespace contains the class LinearEquations which was discussed in my previous post "The LinearEquations Class".