M: Memory Block.
MJMcCann-Consulting

Interval recording, delivers previous values Interpolated or Sample and Hold.
MJMcCann-Consulting Logo

Memory Block.
At its simplest, this is a time delay, but it is more capable if needed.
It stores data pairs, the first is the signal to be reproduced later, the second is a corresponding reference (or basis) signal, for which the default choice is time (Block2).
The data can be retrieved either linearly interpolated (Mode 1) or as sample and hold data (Mode 0). The same storage is used in either case.

Variables as Used
The An connection defines the data to be remembered and Bn the corresponding reference (basis track) signal.
To know how far back to look in the records, Cn and cc define the offset (in units of the Bn signal).
The aa, bb and cc values are used as the initial values to preload the memory. See "Initialization" below to make sure the effects are as expected.
Dn specifies the number of segments and dd is used internally to keep track of the next time a sample is to be taken.
The sample interval is defined by Pn and pp.

How far back to go
The offset is the difference between the current value of the reference (basis) signal and the basis value for which the data is to be recalled. In the simple case (default) where the reference is time, this is the time delay.
However, any monotonically increasing signal can be used for the reference (B, basis signal) connection instead of time.
In particular the cumulative flow through a pipe allows that whatever the flow rate might be (so long as it doesn't reverse) going back a fixed amount corresponding to the volume of the pipe allows delays (for example in delivered concentration) due to variable flow to be modelled. This is the plug flow model for variable flow rate.

Memory Segments
The number of segments multiplied by the segment time defines the maximum age of the data to be retrieved. For efficiency one would expect this to be a bit longer than the required amount. But the segment time can be adjusted by providing an incremental change via the P connection.
The default is 10 segments, using 11 data pairs. It can be changed by changing the Dn value which is NOT a connection but used as an integer. Because changing it rearranges the data storage, only do this prior to a complete Reset (initialization) of the model.

Evaluation by G-functionGenerator Block
The data is stored in the same way as in a function Generator (G-block). As a result, because the function generator can retrieve values from another block's records, the same memory can be accessed as many times as needed, using G-blocks as extractors.
Provide the G-block with, for example, time as input An, the offset as input Bn and point its Pn value to the memory block, and it will seek out the appropriate records and interpolate as needed.

Display by V-Visualizer block
The visualizer will display the contents graphically. The input track is shown vertically and the basis track horizontally. The scales can be set for full scale deflection and offset, though the basis track will probably be left to automatically span the length of the record. The result is a moving chart recorder effect or, if the basis track is another dynamic variable, an X-Y plot such as a phase plane plot.

Initialization
The initialization for the memory creates a "fake" record that has constant value, aa all the way though at uniformly spaced basis channel intervals back as far as abs(cc) before the current value of bb. In the default case where Time is the basis signal, bb automatically takes on the value of StartTime.
To make the initialization and the subsequent simulation work properly you should load cc with the offset needed and only change it later by extra input via the C connection. This process results in a reasonable plot when used as input to a Visualizer or FunctionGenerator block.
The memory block always makes its first sample at the start of the run, so the final step in the initializattion is to pick up the StartTime values from the A and B connections and put them in the most recent data record.

Changing the Offset (Delay)
The Cn input connection can be used to modify the offset. To shift to a closer time a negative input is used and for a longer lag use a positve Cn input.

Trying to go too far back
If an output is requested for a value too far back along the basis data (by making the input from the C connection too big) then the available value farthest back is used.
If an output is requested from the future (presumably an error!) the current value of the input is delivered instead. The simulation does NOT stop.

Memory Block Code

Activation when Simulation is Running:
Procedure ActivateM(ii:integer);
var jj, NN: integer;
    Timely: Boolean;
    BaseThen,   BaseNow,
    SourceNow : real; begin
with B[ii] do begin
if OnOff<=0 then begin dd:=dd+Delt;
       EXIT end ; //delay next sample, not change Output
Timely:=(Time+TinyDelt>=dd);
SourceNow:= B[An].Vn;
BaseNow:=B[Bn].Vn;
BaseThen:=BaseNow - abs(B[Cn].Vn+cc);
 //NN is number data pairs, representing NN-1 segments
NN:=High(Store) div 2;
if Timely then begin
  dd:=NextEventTime(B[Pn].Vn +pp);
  for  jj:= 1 to NN-1 do begin  //Move data along
    Store[jj]:=Store[jj+1];  Store[NN+jj]:=Store[NN+jj+1];
  end{segs};
  //read in new data
  Store[NN]:=SourceNow; Store[NN+NN]:=BaseNow;
end{Timely};
//Every time:
if BaseThen <= Store[NN+1] then begin Vn:=Store[1];
                   EXIT end ; //use oldest available value.
if BaseThen >= Store[NN+NN] then  begin
   Vn:=Interpolate(Store[NN+NN],Store[NN],BaseNow,SourceNow,BaseThen);
   EXIT end;
jj:=1;     //now start looking inside the records...
while BaseThen>Store[NN+jj] do inc(jj);
case State of
 0:Vn:=Store[jj-1];
 1:Vn:=Interpolate(Store[NN+jj-1],Store[jj-1],Store[NN+jj],Store[jj],BaseThen);
  end{case};
end{withBii}
end;

Initialization Step, Gets ready for first sample to be taken immediately
and placed in last pair of entries.
'M'  : begin
	if Bn=2 then bb:=StartTime;
	NN:=High(store) div 2;
	Vn:=aa;  dd:=StartTime;  //present value and next sample time
	for jj:=2 to NN do  //preload the records with reasonable values.
	  begin Store[jj]:=aa ;
       Store[NN+jj]:= (bb-abs(cc))+(jj-2)*abs(cc)/(NN-1) end;
	end{M};

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: m.htm