- Index
- » Programming
- » Modelica Language
- » External Function C in Modelica...
External Function C in Modelica involving derivative "der" function
External Function C in Modelica involving derivative "der" function
Hello,
I am trying to call an external function in C that returns an array (size of 2, double) of the derivative of the system's state (der(enthalpy_fluid) and der(enthalpy_solid)). I had some success in calling an external function in C that returns an array (without involving any "der" function), by using an implicit call, as shown below:
function foo
input Real raw_input[:];
input Real params;
output Real out[outputsize];
external "C" run_surrogate_multi_output(
raw_input,
params,
out
)
annotation(IncludeDirectory="modelica://SolarTherm/Resources/Include",
Include="#include \"tf.c\"",
Library = "tensorflow");
end foo;
I followed the same logic (literally using the same function), and calling my function like this in the equation:
equation
{out[1,1], out[1,2]} = foo(
X_in[1,1:inputdim],
params
);
der(h_fluid[1]) = out[1,1];
der(h_solid[1]) = out[1,2];
however, I got an error in compilation, and the message was:
SolarTherm.Systems.Publications.Thermocline.Constant_Charging.Time_Controlled.Part2_MgO_6h_10h_8h_NeuralNetTank_02nls.c:8100:40: warning: implicit declaration of function 'der' is invalid in C99 [-Wimplicit-function-declaration]
tmp7 = (*real_array_element_addr1(&der(thermocline_Tank.Tank_A.h_p[89,1]), 1, ((modelica_integer) 1))) - ((*real_array_element_addr1(&thermocline_Tank.Tank_A.out[89,2,1], 1, ((modelica_integer) 1))));
^
SolarTherm.Systems.Publications.Thermocline.Constant_Charging.Time_Controlled.Part2_MgO_6h_10h_8h_NeuralNetTank_02nls.c:8100:72: warning: expression result unused [-Wunused-value]
tmp7 = (*real_array_element_addr1(&der(thermocline_Tank.Tank_A.h_p[89,1]), 1, ((modelica_integer) 1))) - ((*real_array_element_addr1(&thermocline_Tank.Tank_A.out[89,2,1], 1, ((modelica_integer) 1))));
^~
SolarTherm.Systems.Publications.Thermocline.Constant_Charging.Time_Controlled.Part2_MgO_6h_10h_8h_NeuralNetTank_02nls.c:8100:44: error: use of undeclared identifier 'thermocline_Tank'
tmp7 = (*real_array_element_addr1(&der(thermocline_Tank.Tank_A.h_p[89,1]), 1, ((modelica_integer) 1))) - ((*real_array_element_addr1(&thermocline_Tank.Tank_A.out[89,2,1], 1, ((modelica_integer) 1))));
fatal error: too many errors emitted, stopping now [-ferror-limit=]
I read online and I suspected that no function name "der" is declared in the code, but how can this happen since "der" function is "native" to Modelica? Does anybody have any idea of how to tackle this problem?
Thanks a lot and have a great day!
Cheers,
Philipe
Re: External Function C in Modelica involving derivative "der" function
This seems like a bug, what version of OpenModelica are you using?
Are you using the new or the old front-end?
Are you compiling in OMEdit or via command line?
- adrpo
- 885 Posts
Re: External Function C in Modelica involving derivative "der" function
Hi Ardpo,
Thanks for getting back to me about this issue. I found a workaround by using the algorithm section instead of calling the external C function in the equation. Which I am not entirely sure how it affects the performance and accuracy of the model.
I was using the new frontend (the "Enable new frontend use in the OMC API" is ticked under the tools tab) I believe and compiled it in the OMEdit, my compiler is OMC version 1.14.2.
How should we proceed with this bug reporting?
Thanks a lot!
Cheers,PG
- Index
- » Programming
- » Modelica Language
- » External Function C in Modelica...