- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » 'failed to elaborate expression' in...
'failed to elaborate expression' in equation section with ext func.
'failed to elaborate expression' in equation section with ext func.
Hello,
I've got a model that giving me a Translation Error. I can't tell too much about the problem from the error message:
[1] 16:49:53 Translation Error
[PodRunSim.Components: 23:5-23:74]: Failed to elaborate expression: .PodRunSim.Utilities.getEddyBrakeData(con, v, h, f_drag, f_lift, H_y_max, H_y_mean, q_max, q_mean).
[2] 16:49:53 Translation Error
Error occurred while flattening model PodRunSim.Examples.HelloPodRunSim
The model is HelloPodRunSim in the dev branch of this repo: https://github.com/adamLange/podRunSim
What might be causing this error?
Adam
- adamLange
- 29 Posts
Re: 'failed to elaborate expression' in equation section with ext func.
My guess is because the function is declared to take only 3 inputs.
- sjoelund.se
- 1700 Posts
Re: 'failed to elaborate expression' in equation section with ext func.
There are only three inputs. f_drag, f_lift, H_y_max, H_y_mean, q_max, q_mean are all outputs.
Code:
function getEddyBrakeData
input EddyBrakeConnection con;
input Real v;
input Real h;
output Real f_drag;
output Real f_lift;
output Real H_y_max;
output Real H_y_mean;
output Real q_max;
output Real q_mean;
external "C" getEddyBrakeData(con,v,h,f_drag,f_lift,H_y_max,H_y_mean,q_max,q_mean) annotation(
Library="eddybrakeclient",
LibraryDirectory="modelica://PodRunSim/ExternalLibraries");
end getEddyBrakeData;
The c function is defined as follows:
Code:
int getEddyBrakeData(void* object,
double v,double h,
double* f_drag,double* f_lift,
double* H_y_max,double* H_y_mean,
double* q_max,double* q_mean)
The outputs are written to wherever the pointer point.
Would it be better if return the outputs as an array?
- adamLange
- 29 Posts
Re: 'failed to elaborate expression' in equation section with ext func.
I think I found the answer in the Modelica specification version 3.3 revision 1 section 12.9.5.2:
12.9.5.2 Arbitrary Placement of Output Parameters, No External Function Value
[In the following example, the external function call is given explicitly which allows passing the arguments in a
different order than in the Modelica version.
Code:
function foo
input Real x;
input Integer y;
output Real
u1;
output Integer u2;
external "C" myfoo(x, u1, y, u2);
end foo;
This corresponds to the following C-prototype:
Code:
void myfoo(double, double *, int, int *);
Example call in Modelica:
Code:
(z1,i2) = foo(2.4, 3);
Translated call in C:
Code:
myfoo(2.4, &z1, 3, &i2);
]
- adamLange
- 29 Posts
Re: 'failed to elaborate expression' in equation section with ext func.
Yep, that was it:
In a component I tried to call the external function with the "c" call signature and this generated the error failed to elaborate expression:
Code:
equation
getEddyBrakeData(con,v,h,f_drag,f_lift,H_y_max,H_y_mean,q_max,q_mean);
...
I changed the modelica code to this and now there's no problem!:
Code:
equation
(f_drag,f_lift,H_y_max,H_y_mean,q_max,q_mean) = getEddyBrakeData(con,v,h);
...
- adamLange
- 29 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » 'failed to elaborate expression' in...