Help - Search - Members - Calendar
Full Version: “Variability” error in model with function call
Modelica Forum > Modelica > Modelica
Felix Felgner
Using DYMOLA, I sometimes get the following error message in models calling a Modelica function which returns an Integer or a Boolean:

“Error: Trying to assign a discrete variable a value with higher variability.”


Example: The error message occurs when checking the following model “FunctionCall.mo” in DYMOLA 6.


model FunctionCall
Boolean result;
algorithm
result := F(time);
end FunctionCall;

function F
input Real p1;
output Boolean result;
algorithm
if (p1 < 0.5) then
result:=true;
else
result:=false;
end if;
end F;



It’s unclear to me what should be wrong with this model.

Regards,
Felix
wagner
Hello Felix,

I checked your model and function. There seems to be a problem with a consistency check in the Modelica compiler of Dymola. As soon as you call a function with a real value as parameter, it expects at least one return value of the type Real. The Problem does not appear when using Integer or Boolean as a parameter value.

My workaround would be to add a second return value in your function F:

function F
input Real p1;
output Boolean result;
output Real dummy;
algorithm
if (p1 < 0.5) then
result:=false;
else
result:=true;
end if;
dummy:=0;
end F;

Your functional call would look like this

model FunctionCall
Boolean result;
Real dummy;
algorithm
(result,dummy) := F(time);
end FunctionCall;


I hope this could help you.

Greetings

Florian
Felix Felgner
Hi Florian,

Many thanks for your advice, and please excuse my delayed resonse. I've integrated a dummy output of the type Real in my application, and now it works fine. This obvious peculiarity of DYMOLA also explains some previous problems I couldn't reproduce so far.

Best regards,
Felix
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.