﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5402	sample(...) operator does not work in Cpp FMU runtime	Anatoly Trosinenko	Lennart Ochel	"When using `sample` operator in a model, an FMU is compiled successfully, but it does not ""tick"".

== How to reproduce ==

Compile this model:

**TestSample.mo:**
{{{#!modelica
model TestSample
  output Integer counter;
initial algorithm
  counter := 0;
algorithm
  when sample(0, 0.25) then
    counter := counter + 1;
  end when;
end TestSample;
}}}

... with the following script:
**tester.mos:**
{{{#!modelica
print(buildModelFMU(TestSample));
print(getErrorString());
}}}

... in C and Cpp modes.

{{{
$ omc --simCodeTarget=C tester.mos TestSample.mo                     
/tmp/TestSample.fmu

$ ~/soft/FMUChecker-2.0.4/build/fmuCheck.linux64 -n 10 TestSample.fmu
[INFO][FMUCHK] FMI compliance checker Test [FMILibrary: Test] build date: Sep  1 2018
[INFO][FMUCHK] Called with following options:
[INFO][FMUCHK] /home/trosinenko/soft/FMUChecker-2.0.4/build/fmuCheck.linux64 -n 10 TestSample.fmu
[INFO][FMUCHK] Will process FMU TestSample.fmu
[INFO][FMILIB] XML specifies FMI standard version 2.0
[INFO][FMUCHK] Model name: TestSample
[INFO][FMUCHK] Model GUID: {376610ce-4dff-45b4-9f45-3324c6b1c663}
[INFO][FMUCHK] Model version: 
[INFO][FMUCHK] FMU kind: ModelExchange
[INFO][FMUCHK] The FMU contains:
0 constants
0 parameters
3 discrete variables
0 continuous variables
0 inputs
1 outputs
2 local variables
0 independent variables
0 calculated parameters
0 real variables
2 integer variables
0 enumeration variables
1 boolean variables
0 string variables

[INFO][FMUCHK] Printing output file header
""time"",""counter""
[INFO][FMUCHK] Model identifier for ModelExchange: TestSample
[INFO][FMILIB] Loading 'linux64' binary with 'default' platform types
[INFO][FMUCHK] Version returned from ME FMU: '2.0'

[INFO][FMUCHK] Initialized FMU for simulation starting at time 0
0.0000000000000000E+00,1
1.0000000000000001E-01,1
2.0000000000000001E-01,1
3.4999999999999998E-01,2
4.4999999999999996E-01,2
5.0000000000000000E-01,3
5.9999999999999998E-01,3
6.9999999999999996E-01,3
8.4999999999999998E-01,4
9.4999999999999996E-01,4
1.0000000000000000E+00,5
[INFO][FMUCHK] Simulation finished successfully at time 1
FMU check summary:
FMU reported:
        0 warning(s) and error(s)
Checker reported:
        0 Warning(s)
        0 Error(s)
$ omc --simCodeTarget=Cpp tester.mos TestSample.mo
/tmp/TestSample.fmu

$ ~/soft/FMUChecker-2.0.4/build/fmuCheck.linux64 -n 10 TestSample.fmu
[INFO][FMUCHK] FMI compliance checker Test [FMILibrary: Test] build date: Sep  1 2018
[INFO][FMUCHK] Called with following options:
[INFO][FMUCHK] /home/trosinenko/soft/FMUChecker-2.0.4/build/fmuCheck.linux64 -n 10 TestSample.fmu
[INFO][FMUCHK] Will process FMU TestSample.fmu
[INFO][FMILIB] XML specifies FMI standard version 2.0
[INFO][FMUCHK] Model name: TestSample
[INFO][FMUCHK] Model GUID: {9b7ffb92-39d7-42ca-abff-65d03f7643cc}
[INFO][FMUCHK] Model version: 
[INFO][FMUCHK] FMU kind: ModelExchange
[INFO][FMUCHK] The FMU contains:
0 constants
0 parameters
3 discrete variables
0 continuous variables
0 inputs
1 outputs
2 local variables
0 independent variables
0 calculated parameters
0 real variables
2 integer variables
0 enumeration variables
1 boolean variables
0 string variables

[INFO][FMUCHK] Printing output file header
""time"",""counter""
[INFO][FMUCHK] Model identifier for ModelExchange: TestSample
[INFO][FMILIB] Loading 'linux64' binary with 'default' platform types
[INFO][FMUCHK] Version returned from ME FMU: '2.0'

[INFO][FMUCHK] Initialized FMU for simulation starting at time 0
0.0000000000000000E+00,0
1.0000000000000001E-01,0
2.0000000000000001E-01,0
3.4999999999999998E-01,0
4.4999999999999996E-01,0
5.0000000000000000E-01,0
5.9999999999999998E-01,0
6.9999999999999996E-01,0
8.4999999999999998E-01,0
9.4999999999999996E-01,0
1.0000000000000000E+00,0
[INFO][FMUCHK] Simulation finished successfully at time 1
FMU check summary:
FMU reported:
        0 warning(s) and error(s)
Checker reported:
        0 Warning(s)
        0 Error(s)
}}}

== What is expected ==

Both tick every 1/4 second.

== What really happens ==

The Cpp FMU compiles successfully but does not work as expected. Maybe I should have used something like `counter := pre(counter) + 1;` but this does not work, too.

For me, this looks quite serious, since when compiler refuses to compile model (even with an internal error), it is clear that something gone wrong. But in this case nothing suspicious happens nor when compiling nor in run-time."	defect	new	high	Future	Code Generation	v1.14.0-dev-nightly		cpp fmu sample	
