- Index
- » Users
- » Ruben
- » Profile
Posts
Posts
Hi,
I was wondering if it would be possible/feasible to calculate derivatives (not time derivatives, but parameter derivatives) from the DAE with forward automatic differentiation. If this could be accomplished, is it also possible to export those derivatives in a .mat-file, together with the other results?
Kind Regards
I am afraid that there's still something wrong. Why is OpenModelica not treating the external functions as a black box? The only thing I do is passing on a few real numbers to a C-function, which makes and solves a sparse matrix. OpenModelica only has to give the real numbers and receive the solution vector.
The options nogen and noevalfun doesn't seem to reduce the compile time of the code.
Best Regards
Ruben
Hi,
To speed op my calculations I implemented an external function to solve sparse matrices [Ax=b stuff, with A sparse] (using CSpares of Tim Davis). The syntax I used is quite straigthforward.
function FunctionName
input a;
input b;
...
output result;
external "C";
annotation(Include="#include <HeaderFile.h>", Library={"LibraryFile"});
end FunctionName;
The function does what it has to do. At least for small matrices (lets say size(b)=400 and A = 400x400 but square) . When I increase the matrix size (within the C-code: size(b)=40000 and A = 40000x40000) OpenModelica takes a tremendous long time to compile the code. (I tried for 2 hours, but even after this time OpenModelica had not finished yet)
This is very strange, because when I compile the c-function with gcc to an .exe-file it only needs a few seconds to give me the solution (of the case where size(b)=40000 and A = 40000x40000). Has anyone any idea why OpenModelica needs so much time? Is it because it has to process the solution-vector x?
Kind regards
Ruben G
Ps. To test this I used a model which only uses this function. So basically OpenModelica only needs to call this function, give it a few doubles (to specify the matrix size) as an input (the matrices are build inside the c-function) and receive the solution vector x (from Ax=b) as an output.
Hi,
I Have tried to use Modelica.Math.Matrices.solve(), but it doesn't seem to work (although the same code runs perfectly in Dymola). This is what I get:
Error: Error building simulator. Buildlog: The syntax of the command is incorrec
t.
g++ -I. -o Fourier_case2D.test3.exe Fourier_case2D.test3.cpp \"-LC:/OpenModelic
a1.7.0/lib/omlibrary/msl31/Resources/Library/mingw32\" \"-LC:/OpenModelica1.7.0/
lib/omlibrary/msl31/Resources/Library/win32\" \"-LC:/OpenModelica1.7.0/lib/omlib
rary/msl31/Resources/Library\" -llapack-mingw -ltmglib-mingw -lblas-mingw -lf2c
-lModelicaExternalC -lsim -linteractive -I\"C:/OpenModelica1.7.0//include/omc\
" -O3 -falign-functions -msse2 -mfpmath=sse -lsendData -lQtNetwork-mingw -lQtC
ore-mingw -lQtGui-mingw -luuid -lole32 -lws2_32 -L\"C:/OpenModelica1.7.0//lib/om
c\" -lc_runtime -lregex -Wl,-Bstatic -lf2c -Wl,-Bdynamic Fourier_case2D.test3_re
cords.c
In file included from Fourier_case2D.test3.cpp:8:
Fourier_case2D.test3_functions.h:67: error: declaration of C function `void dges
v_(const int*, int*, double*, const int*, int*, double*, const int*, int*)' conf
licts with
C:/OpenModelica1.7.0//include/omc/matrix.h:47: error: previous declaration `int
dgesv_(integer*, integer*, doublereal*, integer*, integer*, doublereal*, integer
*, integer*)' here
\\MinGW\\bin\\mingw32-make: *** [Fourier_case2D.test3] Error 1
",
timeFrontend = 0.0,
timeBackend = 0.0,
timeSimCode = 0.0,
timeTemplates = 0.0,
timeCompile = 0.0,
timeSimulation = 0.0,
timeTotal = 0.0
end SimulationResult;
I use OpenModelica 1.7.0.
Do you have any idea what I am doing wrong?
Grtz
Ruben
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
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;
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)
- Index
- » Users
- » Ruben
- » Profile