McSimAPN: Operation/Execution.
MJMcCann-Consulting

Running, numerical integration, time stepping, computational sequence.
MJMcCann-Consulting Logo

Running, Time stepping
The model runs by stepping time, the independent variable, along in increments of Delt.
At each step, every block is activated and it performs its required function.
The control of the stepping process also checks for the timeliness of operations such as updating the graphs (GrDel), coming up to a HOLD time or to FINTIM or if the block designated as the HOLD block has passed above Zero. The designation for the HOLD block is done via the timing control window: Rt-Click on one of the clocks at the bottom of the screen
An essential feature to give the interactive behaviour is that at every time step the "application" (McSimAPN) checks to see if it has received any external inputs, such as key presses or mouse events. If such an event has occured, then McSimAPN responds to it, probably by interupting the run to allow the user to make changes.
When the user restarts McSimAPN (by using RUN button), the running programme loop will continue till it is next told to HOLD, either by the checking process or an external input.
Delt can be changed as the run progresses to skip along or slow down.

Computational Sequence.
In a pure numerical integration process, all the derivative functions are estimated before an increment is made to the values of the integrated variables. (In all but the simplest Euler integration, as used here, there are multiple evaluations of the derivatives.) All state variables are then incremented simultaneously before the next step starts.
It isn't difficult to make a sorting algorithm for the equations, or in this case the blocks, but I have deliberately chosen not to do so.
Instead, for all the "algebraic" blocks (i.e. other than Integrators and Containers), the ID number is the sequence number for calculation. This includes the Memory blocks which are recalling earlier values, and the Petri Net blocks A, B,D which make instantaneous state changes. The user can therefore control the sequence by chosing the naming order of the blocks. The user can modify the sequence by Insert and Copy editing functions, as described below.

Reset
At RESET (to initial conditions), the Integrators and Containers are set to their specified initial values. Memory blocks are filled with the starting value, if given. Inductors are set to initial current. Hysteresis blocks go back to zero as the previous position. The next event time for Timers and the User block is set to its initial value. The A,B and D blocks are set to state 1 (meaning empty), and the contents of the conveyor Belt are also removed. You can edit the contents to other values if needed. If these standard rules don't suit, then you can make changes (maybe a short run) and save the model as you want it and recall it instead of using RESET.
Note that the system timing blocks, made available as "constants/containers", are controlled by the running system. In particular the RepCounter, which is used for repetitive runs is not reset at all (otherwise it couldn't function).
Then the ('algebraic' or 'instantaneous') blocks are processed. Note, this means that if an A or D block (reset to empty/waiting) has tokens ready for its inputs, it will take them immediately and set its next event time. B blocks will wait for delt before moving. Timers that are free running will act on reset so can, by double RESET clicks have their output value (zero or one) flipped.

Stepwise Computation
In the subsequent steps, the integrators are brought up to date first, using the defined derivatives from the freshly calculated 'algebraic blocks'. Then the time is incremented and the 'algebraic' values are processed to prepare the model for the next step and provide time coherent values for records and display. Thus the model shows time and the corresponding state and the derivatives that will be available over the next incremental time period.
Thus the user can, if it is important, prepare all the derivatives in the algebraic blocks using a correct computational sequence, knowing that the integration step will proceed correctly too.
However, by allowing the integrator blocks to do a bit of calculating themselves, the model can be simpler. (For example first order lags become one block) while the effects on the final accuracy are normally immaterial since model parameters are rarely well enough known to recognize the effect.

Handling Discontinuities in Simulation
But there are other benefits from the approach of using Euler integration with controllable sequence. Because we are typically dealing with systems where things happen discontinuously, in a "proper" numerical integration process, we would have to make sure that the sudden changes only took place at the ends of steps. Since we don't break a step up into sub-steps as in the Runge Kutta methods and the like, that is not a problem.
Secondly, we can take advantage of the control of sequence to do some tricks to make our models more capable.

Time Sequence Tricks in Continuous systems
If two algebraic blocks, B1 and B2 with B1 being before B2 in ID sequence form a chain in which the computational sequence is the other way round, so that B2 provides input to B1, then the input to B1 is delayed by one time step (Delt).
Sometimes that sort of delay will serve as a good enough model for some relatively fast part of the process. So we can make (short) chain and bucket delay lines like little conveyor belts. We can do operations in which the delay is important, as occurs in discrete filter design. As a very simple example such a reversal provides an easy way to generate an estimate of a time derivative, by differencing the signal with a one step delayed version of itself.
The final value lies in providing a convergence method for algebraic loops. It doesn't always work, but successive approximation may get you there. In numerical integrations, in which the steps are small this may keep the loop close enough to convergence.
I suspect that most algebraic loops really represent dynamic parts that are rather quick so, doing it this way is often not a bad approach, especially when compared to messing about with stiff differential equation solvers.
For systems that become temporarily "stiff", Delt can be changed as the run progresses to skip along or slow down.

Time Sequence Tricks in Discrete systems
In the Petri Net components, entry (take, input) transitions take place instantaneously at computation instants as do the, usually later, exit (put, place) transitions.
But McSimAPN's key Activity A-block can be made to operate with NO delay between 'take' and 'put' (So can D- and B-Blocks, not that it makes much sense with a conveyor belt). It becomes two transitions with no time separation. So by controlling the sequence of computation, choices can be made and priorities assigned that are implicit in the sequence, even if they are not visually apparent in the behaviour, even of an animated diagram.
For example: a token can be moved into place (container), where a second (later in sequence) A-block has a chance to take it. If not taken, a third block (even later in the sequence) can put it back or move it elsewhere. This way if the second block wasn't able to use it, the original token can follow a different path. The fast moving token has become a model of an opportunity. For example, if the opportunity occurs at regular intervals then the token can represent a clocked opening of a gate. An example is in the demo model, Diverter_1_in_N.txt, in which Block109 gets a chance to remove an item before Block110.
The insertion of blocks to modify a sequence is described below

ID/Computation Sequence Modification
Having made a model by creating blocks, it may become necessary to insert other blocks into the sequence so that some of the tricks identified above can be used.
Use the menu item "Edit" then "Insert" and the option appears to define what type of block to insert and where to insert it. The existing block which is already using that number will have its ID incremented by one and the new block will go into its place. All the other blocks with higher numbers will also have their ID numbers moved up and appropriate adjustments will be made to all the linking data so the rest of the model is preserved.
Compare the models QueuingTheory01.txt and QueuingTheory03.txt. In QT01, the limited space for a queue can be filled so arrivals are blocked. In QT03, the new arrival will either be taken into the queue if there is space, or the arrival will be transfered into the LostCustom counter. The second model can be made from the first by inserting blocks into the sequence.
Copying blocks (Menu item "Edit" then "Copy") can overwrite an existing block, which may also have the effect of changing a sequence (beware!), but is intended for making repeated structures or replicating a block with chosen parameters.

MJMcCann-Consulting

Help Index:
Index/Search

Background
Simulation Concepts
Continuous Systems
Discrete Systems
McSimAPN Structure
McSimAPN Operation

Using McSimAPN
Start McSimAPN
Save Model,data
Create Blocks
Run-Hold-Reset
Link Excel+VBA

PetriNet Block Types
A activity/action
B belt conveyor
C container/constant
D diverter(random)

Analogue Block Types
E exponents
F flux/flow
G function Generator
H hysteresis
I integrator
J inductor
K logic element
L logarithms
M memory
N note/label
O oscilloscope/graph
p not assigned
Q quantizer/rounding
R relay on/off
S sin/asin/atan
T timer/clock
U user link Excel
V visual voltmeter
W sWitch selector/MUX
X multiply
y not assigned
Z random (fuZZ)
& signed summation
% division/difference
@ access/move values

Invitation. McCann can help if you have a design or operational problem that needs some technical support that is outside your team's experience, some quantitative assessment of what is really the cause of the difficulties, some design alternatives or just a fresh look by an intelligent interrogator.
If you have a problem with the behaviour of a market sector, plant, process or item of equipment and would like to get a quantitative handle on it to improve yield or optimise performance, then contact us. We are always ready to give a little time to discuss a new puzzle, in confidence, of course. We'll only worry about fees when we have some defined work. We can be flexible about how we work with you.
Top
MJMcCann-Consulting,
POB 902,
Chadds Ford PA
19317 USA.
T: 1 302 654-2953
F: 1 302 429 9458
E: mjmccann@iee.org
Request. Please let us know how you found this software and your interests by sending an email to mjmccann@iee.org Thank you Date: 2012.02.26
File: process.htm