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

When equations - limitations

When equations - limitations

Hi OM developers!

I want to use when-equations in my model to perform I/O operations at certain points of time. See the flatened model:

Code:


"function OpenRobotica.TestSuite.BlockWithWhen2OM.processReadEvent
  input Real lastWriteEvent;
  output Real nextWriteEvent;
algorithm
  nextWriteEvent := 0.1 + lastWriteEvent;
end OpenRobotica.TestSuite.BlockWithWhen2OM.processReadEvent;

function OpenRobotica.TestSuite.BlockWithWhen2OM.processWriteEvent
  input Real t(quantity = "Time", unit = "s");
  output Real nextReadEvent;
algorithm
  nextReadEvent := 0.02 + t;
end OpenRobotica.TestSuite.BlockWithWhen2OM.processWriteEvent;

class OpenRobotica.TestSuite.TestBlockWithWhen2OM
  protected discrete Real blockWithWhen2OM.nextWriteEvent(start = 0.0);
  protected discrete Real blockWithWhen2OM.nextReadEvent(start = 1e+60);
  protected Boolean blockWithWhen2OM.writeEvent(start = false);
  protected Boolean blockWithWhen2OM.readEvent(start = false);
equation
  blockWithWhen2OM.writeEvent = time > blockWithWhen2OM.nextWriteEvent;
  blockWithWhen2OM.readEvent = time > blockWithWhen2OM.nextReadEvent;
  when {edge(blockWithWhen2OM.writeEvent),initial()} then
  blockWithWhen2OM.nextReadEvent = OpenRobotica.TestSuite.BlockWithWhen2OM.processWriteEvent(time);
  end when;
  when {edge(blockWithWhen2OM.readEvent)} then
  blockWithWhen2OM.nextWriteEvent = OpenRobotica.TestSuite.BlockWithWhen2OM.processReadEvent(blockWithWhen2OM.nextWriteEvent);
  end when;
end OpenRobotica.TestSuite.TestBlockWithWhen2OM;
"
""
"Check of OpenRobotica.TestSuite.TestBlockWithWhen2OM completed successfully.


Class OpenRobotica.TestSuite.TestBlockWithWhen2OM has 4 equation(s) and 4 variable(s).
0 of these are trivial equation(s).
"
""
Failure: ...
{"",""}
"[/home/shui/unisoned/workspace/OpenRobotica_msl3.1/OpenRobotica/../OpenRobotica/TestSuite/BlockWithWhen2OM.mo:29:5-29:45:writable] Error: The language feature non-linear equations within when-equations is not supported. Suggested workaround: Perform non-linear operations outside the when-equation (this is slower, but works)
[/home/shui/unisoned/workspace/OpenRobotica_msl3.1/OpenRobotica/../OpenRobotica/TestSuite/BlockWithWhen2OM.mo:29:5-29:45:writable] Error: Internal error SimCode.createNonlinearResidualEquations failed for equation: blockWithWhen2OM.nextReadEvent := OpenRobotica.TestSuite.BlockWithWhen2OM.processWriteEvent(time) when clause no: 1
[/home/shui/unisoned/workspace/OpenRobotica_msl3.1/OpenRobotica/../OpenRobotica/TestSuite/BlockWithWhen2OM.mo:26:3-26:36:writable] Error: Internal error SimCode.createNonlinearResidualEquations failed for equation: blockWithWhen2OM.writeEvent = time > blockWithWhen2OM.nextWriteEvent
Error: Internal error createOdeSystem2 failed
Error: Internal error createOdeSystem failed
Error: Internal error createEquations failed
Error: Internal error Generation of simulation using code using templates failed
"

Should this work since nextWriteEvent / nextReadEvent are declared discrete? Anyway, i do not understand the suggested workaround.
Can somebody help please?

Probably there is an example demonstrating things like that?

Cheers

P.S.
I have a workaround when i use when equations in a algorithm section. But then, write- and readEvent are not called exactly at nextWriteEvent / nextReadEvent...

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