CS522A (Fall 2003) Assignment 1 - SOLUTION

Thomas

Download: [PDF] [PS]


Contents



1 Code

The following files are modified. Replace the old ones in the hand-out package gives you the final solution to Assignment 1.

2 Purely Algebraic Models

The simulation result of algebraTest_CausalBlockDiagram_mdl.py (with time_max=0) is shown in Figure 1.

Figure 1: Simulation result of algebraic model (time_max=0), time vs y
\includegraphics[width=10cm]{algebraic1.eps}

Another test is run, with time_max=50, as shown in Figure 2.

Figure 2: Simulation result of algebraic model (time_max=50), time vs y
\includegraphics[width=10cm]{algebraic2.eps}

3 Dependency Loops

The solver detects dependency loops and highlights them (by calling the HighLight function of the graph objects). It runs loopTest_CausalBlockDiagram_mdl.py and gives the output shown in Figure 3.

Figure 3: A loop detected in the loop model
\includegraphics[width=14cm]{loop1.eps}

In addition, such an exception is thrown and dumped to the console:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/thomas/tools/lib/python2.3/threading.py", line 436, in __bootstrap
    self.run()
  File "/home/thomas/tools/lib/python2.3/threading.py", line 416, in run
    self.__target(*self.__args, **self.__kwargs)
  File "CausalBlockDiagram/SIM_startResume.py", line 105, in initSimul
    raise NotImplementedError, "algebraic loop detected"
NotImplementedError: algebraic loop detected

4 Delay Blocks

The solver recognizes delay blocks. Model delayTest_CausalBlockDiagram_mdl.py runs correctly (Figure 4).

Figure 4: Simulation result of the delay model, time vs x
\includegraphics[width=10cm]{delay1.eps}

5 Signals

All the (previous and current) values of the connections are stored in their signal lists. Please read the commented SIM_startResume.py file to get more insight. block_tmp_value is completely removed. block_out_value is used only to retrieve the values of constant blocks (whose pre-defined block_out_value attribute is given by the designer).

6 Completeness of the Solver

All the blocks are considered, except Integrator, Derivative, Time and FileIO. If any one of them is encountered in a model, an exception is raised and the simulation stops.

7 Discretized Circle Test Model

The circle is defined by equations:

\begin{displaymath}
\left \{
\begin{array}{l}
x''=-x\\
x_0=0\\
x'_0=1
\end{array}\right .
\end{displaymath}

This can be rewritten as:

\begin{displaymath}
\left \{
\begin{array}{l}
\displaystyle\frac{dx}{dt}=y\\
...
...style\frac{dy}{dt}=-x\\
x_0=0\\
y_0=1
\end{array}\right .
\end{displaymath}

And since $\displaystyle\frac{dx}{dt}=\frac{x_i-x_{i-1}}{\Delta t}$, we can substitute the above equations as:

\begin{displaymath}
\left \{
\begin{array}{l}
\displaystyle\frac{x_i-x_{i-1}}{...
...{i-1}}{\Delta t}=-x_i\\
x_0=0\\
y_0=1
\end{array}\right .
\end{displaymath}

Note that in the first equation ( $\displaystyle\frac{dx}{dt}$), backward approximation ($y_{i-1}$) is used, while in the second one, we use forward approximation ($x_i$). This is because:

The graphical model is depicted in Figure 5.

Figure 5: Discretized Circle Model
\includegraphics[width=16cm]{circle1.eps}

The termination condition is the completion of a full circle. This is tested with 2 test blocks: the upper one returns 2 if $x_i$ is larger than 0; the lower one returns 8 if $-x_{i-1}$ is larger than 0 (that is, $x_{i-1}\leq0$). This two test results are added. Only when both conditions are satisfied (the plot crosses the last point) will the final result be (subtracted by 9.5) larger than 0. Simulation stops at that time.

Figures 6, 7 and 8 shows the simulation result.

Figure 6: Simulation result of the discretized circle model, x vs y
\includegraphics[width=10cm]{circle2.eps}

Figure 7: Simulation result of the discretized circle model, t vs x
\includegraphics[width=10cm]{circle3.eps}

Figure 8: Simulation result of the discretized circle model, t vs y
\includegraphics[width=10cm]{circle4.eps}



Thomas Huining Feng
2003-10-06