Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Function with Enumeration-Type Parameter

Function with Enumeration-Type Parameter

Hello community!

I'm new to Modelica, so probably the answer to my question is simple. I have a construct which basically looks like this:

Code:


package myPackage
  type myType = enumeration(item1, item2);

  connector myConnector
    Real myConnectorValue;
  end myConnector;

  block myBlock
    function myFunction
      input myType myFunctionParameter; // <-- THIS LINE IS THE KILLER
      output Real myFunctionResult;

      algortithm
      /* yet empty */
    end myFunction;

    parameter myType myBlockParameter = myType.item1;
    myConnector out;

    equation
      out.myConnectorValue= myFunction(myFunctionParameter = myBlockParameter);
  end myBlock;
end myPackage;

Trying to simulate a model containing a myBlock fails with

Code:

resultFile = "Simulation failed. Error: Internal error Code generation of Modelica functions failed."

The error also occures, when the myFunction is not even called. When the type of myFunctionParameter is changed to Real, everything goes smoothly.

Environment: OpenModelica 1.5.0 on Win7/64bit.

What am I missing?
Regards,
Hannes

Re: Function with Enumeration-Type Parameter

I fixed the spelling of algorithm and it started working fine.

Note that 1.5.0 is not released yet, and the release candidates are about 6 months old. I am using the latest version and don't have access to the old ones.

Re: Function with Enumeration-Type Parameter

Thanks a lot for the quick response. The typo you mentioned happened only in my posting, not in my original code. I use 1.5.0 RC2 - Is there any newer RC or should I better downgrade to the latest stable?

Re: Function with Enumeration-Type Parameter

I didn't know Adrian made an rc2 so recently. Sadly, I don't really think downgrading to 1.4.5 will help much since we barely supported enumerations back then.

I also checked the nightly builds (http://www.ida.liu.se/~pelab/modelica/O … y-builds/), but it seems to have the same date stamp as rc2.

Edit: On second thought, try rc1. rc2 was made right after a large commit that changed function generation - there might be some issues with it.

Re: Function with Enumeration-Type Parameter

Downgrade to 1.5 RC1 does not solve the problem for me and downgrade to 1.4.5 just leads to another error (doesn't recognize the elements of the enumeration list while flattening).

Before I start implementing on a workaround: You sayed that you were able to run the code from my initial posting without error - Which environment did you use for that?

Another thing: During the last weeks I also noticed other issues with enumerations: In one case the elements of the enumeration list were missing after a redeclaration of an enumeration-variable, while the enumeration type itself still was present in the scope. In another case OMC produced code which couldn't be compiled by the GCC than. I'm new to Modelica, so of course it's possible that I just messed something up myself, but after our little chat here and since most of my troubles are somehow "mysteriously" connected with enumerations, I'm not so sure about that any longer... current/smile

Re: Function with Enumeration-Type Parameter

I use the latest development version on 64-bit OSX 10.6 and 64-bit Ubuntu 9.10.

As for enumerations being buggy... I would love to see some more models using enumerations that do not work on the development version of OpenModelica. Whenever we fix a bug, we also add a testcase so it will keep on working.

Re: Function with Enumeration-Type Parameter

I think we had the affected parts of the code commented out for a while, before we finally deleted them. So there should be traces left in out SVN. I'll try to dig it out over the weekend and send it to you then.

Thanks for your support so far!

Edit: After uninstalling 1.5 RC1, reinstalling 1.5 RC2, reboot & restart the whole environment from the scratch the problem as described in my initial posting is now gone. I really can't tell, what the exact reason was, but it seems the problem was somehow related to "leftovers" in my development environment.

I'll keep my eyes on it, but at the moment I don't see any reason, not to trust in OpenModelica's enumeration handling.

There are 0 guests and 0 other users also viewing this topic
You are here: