Opened 7 years ago

Closed 2 years ago

#4239 closed defect (fixed)

Errors in compilation of AdvancedNoise.Examples.TimeBasedNoise

Reported by: adrpo Owned by: lochel
Priority: high Milestone: 1.19.0
Component: Backend Version:
Keywords: AdvancedNoise Cc:

Description

See also:
https://www.openmodelica.org/forum/default-topic/2091-advancednoise

I tried model AdvancedNoise.Examples.TimeBasedNoise and got errors such as:

AdvancedNoise.Examples.TimeBasedNoise.c: In function 'AdvancedNoise_Examples_TimeBasedNoise_eqFunction_13':
AdvancedNoise.Examples.TimeBasedNoise.c:315:32: error: '$PnBuffer' undeclared (first use in this function)
     switch((((modelica_integer)$PnBuffer == ((modelica_integer) 1))?((modelica_integer) 1):((modelica_integer) 1) + (_event_integer(DIVISION_SIM(data->localData[0]->timeValue - data->localData[0]->realVars[4] /* timeBasedNoise._bufferStartTime DISCRETE */,data->simulationInfo->realParameter[2] /* timeBasedNoise._samplePeriod PARAM */,"timeBasedNoise.samplePeriod",equationIndexes), ((modelica_integer) 0), data))))

Seems to be an issue with inlining of function:

function AdvancedNoise.Sources.TimeBasedNoise$timeBasedNoise.interpolation.interpolate "Inline before index reduction" "Constant interpolation in a buffer of random values"
  input Real[:] buffer "Buffer of random numbers";
  input Real offset "Offset from buffer start (0..size(buffer)-1";
  input Real samplePeriod = 1.0 "The sample period of the noise buffer";
  output Real y "Interpolated value at position offset";
  protected Integer nBuffer = size(buffer, 1) "Size of the buffer";
algorithm
  y := buffer[if nBuffer == 1 then 1 else 1 + integer(offset)];
end AdvancedNoise.Sources.TimeBasedNoise$timeBasedNoise.interpolation.interpolate;

in equation

  timeBasedNoise.y = if not timeBasedNoise.generateNoise or time < timeBasedNoise.startTime then timeBasedNoise.y_off else AdvancedNoise.Sources.TimeBasedNoise$timeBasedNoise.interpolation.interpolate({timeBasedNoise.buffer[1], timeBasedNoise.buffer[2]}, (time - timeBasedNoise.bufferStartTime) / timeBasedNoise.samplePeriod + /*Real*/(timeBasedNoise.nPast), timeBasedNoise.samplePeriod);

as it produces this C code:

    switch((((modelica_integer)$PnBuffer == ((modelica_integer) 1))?((modelica_integer) 1):((modelica_integer) 1) + (_event_integer(DIVISION_SIM(data->localData[0]->timeValue - data->localData[0]->realVars[4] /* timeBasedNoise._bufferStartTime DISCRETE */,data->simulationInfo->realParameter[2] /* timeBasedNoise._samplePeriod PARAM */,"timeBasedNoise.samplePeriod",equationIndexes), ((modelica_integer) 0), data))))

where $PnBuffer is not declared at all.

Change History (9)

comment:1 Changed 7 years ago by lochel

  • Keywords AdvancedNoise added
  • Milestone changed from Future to 1.12.0
  • Status changed from new to accepted

I can confirm that the issue is connected to function inlining.
One can disable inlining of functions as a workaround using the following omc-flag: -d=-inlineFunctions.

comment:3 Changed 6 years ago by casella

  • Milestone changed from 1.12.0 to 1.13.0

Milestone moved to 1.13.0 due to 1.12.0 already being released.

comment:4 Changed 5 years ago by casella

  • Milestone changed from 1.13.0 to 1.14.0

Rescheduled to 1.14.0 after 1.13.0 releasee

comment:5 Changed 5 years ago by casella

  • Milestone changed from 1.14.0 to 1.16.0

Releasing 1.14.0 which is stable and has many improvements w.r.t. 1.13.2. This issue is rescheduled to 1.16.0

comment:6 Changed 3 years ago by casella

  • Milestone changed from 1.16.0 to 1.17.0

Retargeted to 1.17.0 after 1.16.0 release

comment:7 Changed 3 years ago by casella

  • Milestone changed from 1.17.0 to 1.18.0

Retargeted to 1.18.0 because of 1.17.0 timed release.

comment:8 Changed 3 years ago by casella

  • Milestone 1.18.0 deleted

Ticket retargeted after milestone closed

comment:9 Changed 2 years ago by perost

  • Milestone set to 1.19.0
  • Resolution set to fixed
  • Status changed from accepted to closed

TimeBasedNoise seems to be working fine now according to the library testing.

Note: See TracTickets for help on using tickets.