Search code examples
modelicaopenmodelicadymola

“Variability” error in model with function call


The following code

model FunctionCall
  Boolean result;

  function F
    input Real p1;
    output Boolean result;
  algorithm 
    result :=p1 < 0.5;
  end F;

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

(also described in http://www.modelica-forum.com/forums/index.php?showtopic=2) still throws an error in Dymola 2018FD01, while in OpenModelica it is accepted. Is this wrong Modelica code or a Dymola bug? Thanks in advance.


Solution

  • Hans answer is the correct one for your question.

    Your unasked question may be how one can get the same behavior within the language specifications. Below I have provided one possible solution.

    model FunctionCall
      Boolean result;
    
      function F
        input Real p1;
        output Integer result;
      algorithm 
        result := if p1 < 0.5 then 1 else 0;
      end F;
    
    algorithm 
    
      result := if F(time) < 0.5 then false else true;
    
    end FunctionCall;