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

Recompiling of nested functions

Recompiling of nested functions

I have written a function "FEM_fourier2D" that calls other functions like "R_th_cap", "R_th_conv", ... multiple times.
When I compile a model in which I invoke the function "FEM_fourier2D" I notice that files like ModelName_R_th_cap.c, ModelName_R_th_cap.records.c, ModelName_R_th_cap.dll, ... are overwritten all the time. It appears to me that the compiler never compiles the function "FEM_fourier2D", but keeps invoking and compiling the inner functions over and over again.
Has anyone any idea why this is happening or how I can avoid this?

(I use OpenModelica1.7.0)

Re: Recompiling of nested functions

If your function has constant parameters it will be build into a dll during model compilation.
You can use +d=nogen to force not to generate the function during model compilation.

Cheers,
Adrian Pop/

Re: Recompiling of nested functions

Thanks for the quick reply, but unfortunately it didn't do the trick. Inspired by your suggestion, I also included +showErrorMessages and +d=failtrace. The resulting errors from the command line are printed below (or ad least the result after 10sec running the code). Do you have any idea how I can avoid these divisions by zero?

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\u0063942>cd C:\Users\u0063942\Documents\Doctoraat\Werkpakket2\Probeers
ls\Fourier_case2D

C:\Users\u0063942\Documents\Doctoraat\Werkpakket2\Probeersels\Fourier_case2D>C:
OpenModelica1.7.0\bin\omc.exe +d=nogen +showErrorMessages +d=failtrace simulati
n.mos
true
true
true
{"Error: Class OpenModelica.Scripting.simulate not found in scope <global scope
(looking for a function or record).", "TRANSLATION", "Error", "3"}
- Static.elabCall failed
function: OpenModelica.Scripting.simulate   posargs: Fourier_case2D.test3
prefix: <Prefix.NOPRE()>- Static.canonCref failed, cr: b[nh]
- Static.canonCref failed, cr: b[i]
- Static.canonCref failed, cr: b[i]
- Static.canonCref failed, cr: b[i]
- Static.canonCref failed, cr: b[i]
- Ceval.ceval DAE.CALL failed: integer(1.0 + (Real(nh * (nv - 1)) + Real(nh - n
chip) / 2.0))
- Static.canonCref failed, cr: b[i]
- Ceval.ceval DAE.CALL failed: integer(Real(2 + nh * (nv - 1)))
- Static.canonCref failed, cr: b[i]
- Ceval.ceval DAE.CALL failed: integer(Real(i) + Real(n_chip + nh) / 2.0 - 1.0)
- Static.canonCref failed, cr: b[integer(Real(i) + Real(n_chip + nh) / 2.0 - 1.
)]
- Static.canonCref failed, cr: b[1 + nh]
- Static.canonCref failed, cr: b[2 * nh]
- Static.canonCref failed, cr: b[1 + nh * (nv - 1)]
- Static.canonCref failed, cr: b[nh * nv]
- Static.canonCref failed, cr: b[i]
- Expression.subscriptIndexExp failed on 1:index - 1
- Expression.subscriptIndexExp failed on 1:index - 1
- Expression.subscriptIndexExp failed on 1:index - 1
- Ceval.ceval DAE.CALL failed: Modelica.Math.Vectors.length(i_r)
- Ceval.ceval DAE.CALL failed: Modelica.Math.Vectors.length(i_r)
- Ceval.ceval DAE.CALL failed: Modelica.Math.Vectors.length(i_r)
- Ceval.ceval DAE.CALL failed: integer(Modelica.Math.Vectors.length(i_r))
- Ceval.ceval DAE.CALL failed: integer(i_r[i])
- Static.canonCref failed, cr: A[integer(i_r[i]),integer(j_c[i])]
{"Error: Division by zero in 1.0 / cp * m", "TRANSLATION", "Error", "15"}
- CevalFunction.evaluateStatement failed for:
  R_th := 1.0 / (cp * m);

- CevalFunction.evaluateFunction failed.

- CevalFunction.evaluate failed for function
function Fourier_case2D.R_th_cap
  input Real m(quantity = "MassFlowRate", unit = "kg/s");
  input Real cp(quantity = "SpecificHeatCapacity", unit = "J/(kg.K)");
  output Real R_th(quantity = "ThermalResistance", unit = "K/W");
algorithm
  R_th := 1.0 / (cp * m);
end Fourier_case2D.R_th_cap;


{"Error: Division by zero in 1.0 / cp * m", "TRANSLATION", "Error", "15"}
- CevalFunction.evaluateStatement failed for:
  R_th := 1.0 / (cp * m);

- CevalFunction.evaluateFunction failed.

- CevalFunction.evaluate failed for function
function Fourier_case2D.R_th_cap
  input Real m(quantity = "MassFlowRate", unit = "kg/s");
  input Real cp(quantity = "SpecificHeatCapacity", unit = "J/(kg.K)");
  output Real R_th(quantity = "ThermalResistance", unit = "K/W");
algorithm
  R_th := 1.0 / (cp * m);
end Fourier_case2D.R_th_cap;

Re: Recompiling of nested functions

Hi,

It depends on your model. You could have an if and return 0 from the function if any of the cp or m are zero.
It seems you also have negative indexes in arrays, so you could also have a look there.

I could probably tell you more if you post the entire model (if is possible, i mean public).
If the model is not public you could send it to me via email (Adrian <dot> Pop <at> liu.se) and I can have a look and maybe I could tell you more.

Cheers,
Adrian Pop/

Re: Recompiling of nested functions

Thanks again for your quick response.

I have made a small example to isolate the problem.

function Prullefunctie
output Real[2] c;
protected
  Real[2] b;
algorithm
  for i in 1:2 loop
    b[i]:= R_th_cap(10^(-5),4181.3);
  end for;
  c:=b;
end Prullefunctie;


function R_th_cap
  //input SIunits.SpecificHeatCapacity cp;

  input Real m;
  input Real cp;

  output Real R_th;

algorithm
  R_th := 1/(m*cp);
end R_th_cap;

model Simple_case4
  Real[2] answer;
equation
  answer = Prullefunctie();
end Simple_case4;

model test4
  Simple_case4 simple_case4;
end test4;

Which gives the following output:
C:\Users\u0063942\Documents\Doctoraat\Werkpakket2\Probeersels\Fourier_case2D>C:\
OpenModelica1.7.0\bin\omc.exe +d=nogen +showErrorMessages +d=failtrace simulatio
n.mos
true
true
true
{"Error: Class OpenModelica.Scripting.simulate not found in scope <global scope>
(looking for a function or record).", "TRANSLATION", "Error", "3"}
- Static.elabCall failed
function: OpenModelica.Scripting.simulate   posargs: Fourier_case2D.test4
prefix: <Prefix.NOPRE()>- Static.canonCref failed, cr: b[i]
{"Error: Division by zero in 1.0 / cp * m", "TRANSLATION", "Error", "15"}
- CevalFunction.evaluateStatement failed for:
  R_th := 1.0 / (cp * m);

- CevalFunction.evaluateFunction failed.

- CevalFunction.evaluate failed for function
function Fourier_case2D.R_th_cap
  input Real m;
  input Real cp;
  output Real R_th;
algorithm
  R_th := 1.0 / (cp * m);
end Fourier_case2D.R_th_cap;


- BackendDAEOptimize.addExtendReplacement failed
- BackendDAEOptimize.addExtendReplacement failed
{"Error: Error building simulator. Buildlog: The syntax of the command is incorr
ect.
g++ -I. -o Fourier_case2D.test4.exe Fourier_case2D.test4.cpp    -lsim -linteract
ive  -I"C:/OpenModelica1.7.0//include/omc" -O3 -falign-functions -msse2 -mfpmath
=sse   -lsendData -lQtNetwork-mingw -lQtCore-mingw -lQtGui-mingw -luuid -lole32
-lws2_32 -L"C:/OpenModelica1.7.0//lib/omc" -lc_runtime -lregex -Wl,-Bstatic -lf2
c -Wl,-Bdynamic Fourier_case2D.test4_records.c
In file included from Fourier_case2D.test4.cpp:10:
Fourier_case2D.test4_functions.cpp: In function `Fourier__case2D_Prullefunctie_r
ettype _Fourier__case2D_Prullefunctie()':
Fourier_case2D.test4_functions.cpp:40: error: invalid token
Fourier_case2D.test4_functions.cpp:40: error: expected `;' before "INF"
\MinGW\bin\mingw32-make: *** [Fourier_case2D.test4] Error 1
", "TRANSLATION", "Error", "22"}
record SimulationResult
    resultFile = "",
    simulationOptions = "startTime = 0.0, stopTime = 150.0, numberOfIntervals =
500, tolerance = 1e-05, method = 'dassl', fileNamePrefix = 'Fourier_case2D.test4
', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', var
iableFilter = '.*', measureTime = false, cflags = ''",
    messages = "Simulation failed for model: Fourier_case2D.test4
",
    timeFrontend = 0.0,
    timeBackend = 0.0,
    timeSimCode = 0.0,
    timeTemplates = 0.0,
    timeCompile = 0.0,
    timeSimulation = 0.0,
    timeTotal = 0.0
end SimulationResult;

Cheers Ruben

Re: Recompiling of nested functions

Seems this was a bug that we fixed a while back.
With the current trunk I get this:

Code:

adrpo@ida-liu050 ~/dev/OpenModelicaBackend/build/bin/ruben

$ ../omc Simple.mo
function Prullefunctie
  output Real[2] c;
  protected Real[2] b;
algorithm
  for i in 1:2 loop
    b[i] := 23.916006983474;
  end for;
  c := {b[1],b[2]};
end Prullefunctie;

function R_th_cap
  input Real m;
  input Real cp;
  output Real R_th;
algorithm
  R_th := 1.0 / (cp * m);
end R_th_cap;

class Simple_case4
  Real answer[1];
  Real answer[2];
equation
  answer[1] = 23.916006983474;
  answer[2] = 23.916006983474;
end Simple_case4;

I'll try to make a new nighly-build later today that should fix this issue.
I'll let you know when is available.

Cheers,
Adrian Pop/

Re: Recompiling of nested functions

In the meantime, you could use:
omc +d=nogen,noevalfunc simulation.mos
This will disable function evaluation (by interpretation or via a .dll).

Cheers,
Adrian Pop/

Re: Recompiling of nested functions

You can disregard my last relpy, it seems 10^(-5) is still 0 in when calling R_th_cap from inside Prullefunctie even with +d=nogen,noevalfunc.

Cheers,
Adrian Pop/

Re: Recompiling of nested functions

A new build is up that fixes this issue:
http://build.openmodelica.org/omc/build … ly-builds/

Cheers,
Adrian Pop/

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