Functions and lumping of equations

4 posts / 0 new
Last post
janpeter
Offline
Joined: 2010-09-11
Functions and lumping of equations

Hi,
 
I am about to model a more complicated system still only 3 states, taken from the literature.
To make the model transparent certain static equations are grouped into functions in the article.
These functions depend on the state and are later used to express the dynamic state equations.
 
Since these functions are slightly nested  (i.e. one of the functions is used in another - but no circular use) 
and I would like to simply code them as they are, I consider to express them as Modelica functions.
However, I strongly suspect that formulating static equations into functions will severly limit
the automatic symbolic equation handling. 
 
So I guess one should just write up these long "function-expressions" as equations and do not use
the Modelic function concept (since functions are essentailly algorithms and  assignments not equations).
 
My source of refernce is the book by Michael Tiller "Introduction to Physical Modeling with Modelica" but I
cannot see that he deals with this issue, which I think should be quite common. Or I misunderstand something.
 
I would appreciate some comment/advice.
 
Thanks
Jan Peter

janpeter
Offline
Joined: 2010-09-11
An example

Hi again,
An example that shows the impact of the choice of "function" or "equation" mentioned aboe, is when you want to model a short pulse. If I describe this as function
u = pulse(time,t1,t2)
or if I use an equation
u = if t < t1 then 0 else if t<t2 then 1 else 0
severly affect the numerics. Only when I keep the pulse as an equation the software detects the discontinuities and manage to give a good solution. When the pulse is "buried" in a function (with algorithm statements) then the software cannot detect the discontinuity and for shorter pulses the pulse is simply missed.
I suspect that also in other situations it might be important to make a good choice between using function or keep as equation.
Advice or comments?
 
Jan Peter
 
 
 
 
 
 
 

jakesson
Offline
Joined: 2009-03-14
Hi Jan Peter,   Your

Hi Jan Peter,
 
Your observation is correct: events are not generated inside Modelica functions according to the Modelica specification. So in this case, expressing the pulse as an equation is critical. As a rule of thumb, functions are used for algorithmic code that you would like to reuse and that does not generate any events.
 
Best
/Johan

janpeter
Offline
Joined: 2010-09-11
Hi Johan,   Is there not

Hi Johan,
 
Is there not other modeling situations, apart from events and "discontinuities", where "functions" or perhapts rather "algorithm" sections should be avoided if possible. I have just a vague understanding of what the symbolic manipulation does during compilation etc, but I suspect these manipulations operate on equations only.
 
It is often convenient during "paper and pen analysis" of a model to lump complicated expressions to function like f() g() etc. It is also a way to re-use complicated expresseions, similar to the idea of models and blocks. Still it seems to me that Modelica does not support this very basic and elementary way of  abstraction. (I note for instance during compilation that a function must have an algorithm section). I could of course use a block or model for this purpose, but then I must give the parameters to the block or model when the instance is made.
 
I suspect I misunderstand something, or is there some other modelling concept other than function, block, model that do the job?
 
Jan Peter
 
 
 
 

Login or register to post comments