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

Trouble using built-in variable time in functions

Trouble using built-in variable time in functions

Hello!

I have a problem which is best illustrated by the following example:

Code:


function time_dependent_function
  output Real i;
algorithm
  i := time;
end time_dependent_function;

fclass test
  Real x;
equation
  x = time_dependent_function();
end test;

When building the simulator for that class, the following error occures:

Code:


Error: Error building simulator. Buildlog: g++ -I"C:\OpenModelica1.5.0\/include/omc" -msse2 -mfpmath=sse  -I. -o funktionstest.exe funktionstest.cpp -L"C:/Users/Hannes Edinger/workspace/OIB_RL6/OIB_RL6/../OIB_RL6/OENORM_B8110_6"  -lsim -L"C:\OpenModelica1.5.0\/lib/omc" -lc_runtime -lf2c -linteractive -lsendData -lQtNetwork-mingw -lQtCore-mingw -lQtGui-mingw -luuid -lole32 -lws2_32
In file included from funktionstest.cpp:14:
funktionstest_functions.cpp: In function `time__dependent__function_rettype _time__dependent__function()':
funktionstest_functions.cpp:34: error: cannot convert `time_t ()(time_t*)' to `modelica_real' in assignment
mingw32-make: *** [funktionstest] Error 1

I think the crux of the matter is the part "cannot convert `time_t ()(time_t*)' to `modelica_real' in assignment".

How to deal with that?

Regards,
Hannes

Re: Trouble using built-in variable time in functions

You can't access time from within a function in Modelica. You need to pass it as an argument if you want to use it.

Re: Trouble using built-in variable time in functions

Ah - Didn't know that (obviously). Thanks a lot!

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