I tried out the Fortran Wapper in CoolProp Sources
The example fortran code given in the wrapper uses the function PropsSI in CoolProp.
double precision T,Q,D,h,s,P
character(LEN=32) Ref,Output, Name1, Name2
double precision outVal,Prop1,Prop2
integer inte
T = 400
Q = 1;
Output = "D"//CHAR(0)
Name1 = "Q"//CHAR(0)
Prop1 = Q
Name2 = "T"//CHAR(0)
Prop2 = T
Ref = "IF97::Water"//CHAR(0)
outval = 9999999
call PropsSi(Output, Name1, Prop1, Name2, Prop2, Ref, outVal)
I followed these steps to call the above function in Modelica:
- Built a static Coolprop library: In the root directory of the CoolProp(also tried out in my own package repo) I built a static library with the code:
mkdir build && cd build
mkdir gccstatic && cd gccstatic
cmake ../.. -DCOOLPROP_STATIC_LIBRARY=ON -DCOOLPROP_EXTERNC_LIBRARY=ON -DCMAKE_VERBOSE_MAKEFILE=ON
cmake --build .
The library generated in the code was moved then to the modelica package repo
- Linked fortran file to Coolprop shared libary libCoolProp.a. Used multiple methods but the logic was the same:
f77 main.f -L. -lCoolProp
- Used external keyword in modelica to call the function
function propssi
extends Modelica.Icons.Function;
input Real T;
input Real Q;
output Real D;
protected
String out = "D";
String n1 = "Q";
String n2 = "T";
String ref= "IF97::Water";
external "FORTRAN 77" D = PropsSI(out, n1, Q, n2, T, ref) annotation(Library = {"testfunction"});
end propssi;
After doing this in multiple variations, i am getting a compilation error from modelica which i cant figure out.
/usr/bin/ld: /usr/local/lib/libCoolProp.a(CoolPropLib.cpp.o): undefined reference to symbol '_ZTVN10__cxxabiv121__vmi_class_type_infoE@@CXXABI_1.3' /usr/bin/ld: /lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [UseFortran.makefile:37: omc_main_target] Error 1 Compilation process failed. Exited with code 2.
Can anyone suggest alternate methods to access the coolprop library functions or to properly call the existing fortran example code