.ModelicaDEVS.SinkBlocks.Interpolator

Information

The Interpolator Block

The following sections discuss the need/advantage of the Interpolator block, and show how it works.


The Interpolator as a simple Interface

One of the Interpolator's purposes is to provide an interface from a ModelicaDEVS model to a conventional Modelica model by transforming the signals coming from DEVS blocks into signals for non-DEVS blocks. Given that DEVS blocks have input and output ports consisting of a vector of size four (see the section about ModelicaDEVS for a syntactically correct description of ports), whereas normal Modelica blocks have scalar inputs and outputs, the first task of the interpolator is a simple type conversion, such that DEVS signals can be passed to other Modelica blocks.
The Interpolator can be said to be the counterpart to the sampler blocks, which take a signal of type real and transform it into a DEVS event.

The simplest way to pass a DEVS-input-signal to a conventional Modelica block is to just forward a truncated version of the input DEVS vector, namely its first entry.

The next section shows however why this approach is not the best one possible, and why it is more advantageous to slightly change the input signal before passing it to the next block.


Function Smoothening

The second purpose of the Interpolator (apart from the type conversion) is to smoothen the piecewise constant trajectory of DEVS state variables. Of course, conventional Modelica blocks are able to process a piecewise constant signal, but this would yield a very poor approximation of the true function.
Remember that simulating a continuous system using the DEVS formalism means to numerically approximate the theoretical trajectories of the state variables. The output values generated by DEVS blocks are then points on that approximating curve. When displayed in Dymola, the output points are connected by piecewise constant straight lines and thus give rise to the well known piecewise constant output function of ModelicaDEVS blocks. Note that given the discrete nature of the state variables, these stair-like trajectories are a precise reproduction of the virtual block behaviour: the state variables keep a certain value for a given amount of time and then jump to another value:



A smoother approximation of the true function could be obtained if we were to interpolate two output values by a higher-order curve than a piecewise constant function.
Unfortunately, given the aforementioned discrete nature of the state variables, it makes no sense for Dymola to connect two output events by a straight line, or even a quadratic or cubic curve. So, if we want to have smoother output, we have to interpolate "by ourselves":



Interpolation in this case results in a function consisting of consecutive interpolation segments that are of a higher approximation order than a piecewise constant function.

For an illustration of the output of an Interpolator (connected to an Integrator) see the subsequent figure, where the green line is the discrete output of the integrator, the red line is the (linear) interpolation and the blue line is the real solution, computed with the DASSL method of Dymola. The simulated model is the one shown in Figure \ref{fig:example11}.



After having established the advantages of an Interpolator component, it will now be explained in more detail how it works. Since the Integrator is the only block the output of which is meaningful to interpolate, let us examine the collaboration of an Interpolator that receives signals from an Integrator block. For simplicity reasons, we shall only consider the first-order case where the connection between two output points are straight lines. Quadradic and cubic interpolation works analogously.

Two points x and x(t+h) can be linearly connected if x and the first derivative dx/dt are known. Hence, this information has to be given to the Interpolator, in order to make it able to interpolate the output of the Integrator.
Given that the input of an Integrator block is the derivative of its output, the QSS1 (linear approximation) Integrator passes the current function value X and its own input value uVal[1] to the Interpolator.
yIntVal[1]= X;       //coefficient of the constant term of the Taylor series
yIntVal[2]= uVal[1]; //coefficient of the linear term of the Taylor series
yIntVal[3]= 0;       //coefficient of the quadratic term of the Taylor series
yIntVal[4]= 0;       //coefficient of the cubic term of the Taylor series
From these values the Interpolator is able to compute the trajectory from the current to the next output value of the Integrator (note that the instructions shown above are not actual code of the Interpolator block. At this point however, they are probably more suited to illustrate the way the Interpolator works than the real formulae would be):
 y=uVal[1] + uVal[2]*(time-pre(lastTime));
where Interpolator.uVal[1] contains Integrator.X, and Interpolator.uVal[2] contains the value of Integrator.uVal[1].
Note that by passing the values X and uVal[1] to the Interpolator, the Integrator implicitly assumes that there will be no external event between the current event and the next internal one. This assumption is too simplifying of course, but it is the only possible approximation. In the case however that the Integrator indeed has to execute an external transition before it reaches the moment when - according to the value of sigma - it would have to execute its next internal transition, the slope of the interpolation probably changes, because due to the external transition that the Integrator has to execute, also the value of uVal[1] is likely to change. Thus, in the case of an external event, the Integrator simply sends a new set of X and uVal[1] to the Interpolator, in order to inform it about the changed situation.
At every arrival of an external event, the Interpolator interrupts the current simulation, adjusts the value of the interpolation slope to the new value received from the Integrator, and restarts the interpolation applying the new slope.




The above figure sketches a scenario where an Integrator executes internal transitions at time instants t=0, t=1, t=3 and t=6 and receives an external event at t=4. At every step, the illustration shows the output vector that the Integrator passes to the Interpolator. The variable yVal[1] holds the actual integration value, yVal[2] stores the first derivative (which is equal to the Integrator's input port uVal[1]).
The trajectory of the Interpolator until t=3 is rather easy to comprehend. At t=3 however the output of the Integrator reaches a value of 4, the estimated next value would be 5, reached in 2 more time steps (σ=2). While the Integrator is "waiting" for these two time steps to pass, it receives an external event, so uVal[1] is updated (from 0.5 to 1.5), and by executing the external transition also X changes (from 4 to 4.5). When the Interpolator receives the new (external) event at t=4, it substitutes the old interpolation slope by the new one. We can identify this substitution by the buckling in the trajectory of the last picture in the figure at time t=4.


Interpolator Specific Ports

Given that the Interpolator cannot work with the normal output vectors of DEVS blocks, but requires additional information about the possible future state trajectory, the Integrator features a second output port supplementary to the common one. Through this port, the Integrator emits events consisting of the following four values: The dissimilarity of the normal output/input vectors and the special vector that is required by the Interpolator is also highlighted graphically in the layout of the blocks: instead of the common blue input ports, the Interpolator has a red input port that is connectable only to the red output port of the Integrator.

Contents

NameDescription
 interpolate
 der_interpolate
 der_2_interpolate

Generated at 2024-12-17T19:26:02Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos