﻿ 20-sim webhelp > Editor > Compiling > Causal Form

Causal Form

Equations within 20-sim may be entered in random form. During compilation, 20-sim will automatically try to rewrite equations into a causal form and set them in a correct order. I.e. a form where all output variables are written as function of input variables. Consider for example the following model:

variables

real u,z;

equations

u = sin(time);

u = cos(z);

Here the (input) variable u is given by the equation u = sin(time). Consequently the (output) variable z should be written as a function of u. This is exactly what 20-sim will try to do while compiling the model into simulation code. I.e. the function cos will be inverted and the model will be rewritten to:

variables

real u,z;

equations

u = sin(time);

z = arccos(u);

Some functions cannot be inverted. Consequently not all equations can be rewritten. 20-sim will report this to the user, during model checking.

Indifferent Causality

For some models the causal form is not known beforehand. For example the iconic diagram model that describes a damper can be written as:

parameters

real d;

equations

p.F = d*p.v;

Here p.F denotes the force and p.v denotes the velocity of the powerport p. There is no preferred input (force or velocity). This can be explicitly stated, by giving the powerport p an indifferent causality. During compilation 20-sim will determine whether p.F or p.v is the input variable and consequently rewrite the equations.

Preferred Causality

For some models there is a preferred causal form. For example the iconic diagram model that describes a spring can be written as:

parameters

real k;

equations

p.F = (1/k)*int(p.v);

Here p.F denotes the force and p.v denotes the velocity of the powerport p. The equation is written in integral form which is preferred. Consequently the preferred input is the velocity. Should the force be the input, the equation must be rewritten to a differential form, which is leads to less efficient simulation. This can be explicitly stated, by giving the powerport p an preferred causality. During compilation 20-sim will try to keep the model in this preferred form. If this is not possible the equations will be rewritten to the less preferred form.

Preferred causality has a lower priority than fixed causality. During compilation 20-sim will first assign all models with a fixed causality and then all models with preferred causality.

Likes Causality

For some models there is a causal form which is liked more than the other. For example the iconic diagram model that describes a parasitic volume can be written as:

effortincausality(p) then

p.phi = 0;

else

volume_ratio = int(p.phi/V);

p.p = B * volume_ratio + p_initial;

end;

Here p.phi denotes the volume flow and p.p denotes the pressure of the powerport p. The equation is written in integral form which is liked. Consequently the preferred output is the pressure. Should the pressure be the input, the equation gives a zero flow as output. During compilation 20-sim will first try to keep all models the liked form. If this is not possible the equations will be rewritten to the other form.

Liked causality has a lower priority than preferred causality. During compilation 20-sim will first assign all models with a preferred causality and then all models with likes causality.

Fixed Causality

For some models there is only one causal form. For example a simple iconic diagram model that describes coulomb friction can be written as:

parameters

real Rc;

equations

p.F = Rc*abs(p.v);

Here p.F denotes the force and p.v denotes the velocity of the powerport p. The equation cannot be rewritten to a form where p.F is the input. This can be explicitly stated, by giving the powerport p a fixed causality. During compilation 20-sim will try to keep the model in this fixed form. If this is not possible an error message will be generated.

Fixed causality has a lower priority than a likes causality. During compilation 20-sim will first assign all models with a likes causality and then all models with fixed causality.

Setting Causality

For some models, the equations are too complex to analyze causality. To help 20-sim, using the right causality, you can set causality for every port in the Interface Editor.