いわて駐在研究日誌

OpenCAE、電子工作、R/C等、徒然なるままに

OF+外部ライブラリ

OFの計算で冷媒ガスの熱物性値を参照したいと考え調査してみた。

事例としては、

・OF+FreeSteam (水蒸気:IAPWSIF97)

があっただけで、NIST REFPROP(最新版9.1)や、同様の機能を持つOSS版のCoolProp(最新版4.2.5?5系が開発中??)とOFとの連携事例は、少なくとも公開されたものは無さそうである。

前者は、Fortranのライブラリなので、lib.soにするGithubプロジェクトはあった。https://github.com/jowr/librefprop.so

 

- fortranのsharedライブラリを利用する方法(上述のプロジェクト)

ライブラリファイルlibrefprop.soはパスの通った場所においておくこと。

Fortranから

プロジェクト中のサンプルを実行してみる(make fortest)

cd librefprop.so/src

gfortran -O3 -ffast-math -fPIC  -g -o ex_mix.o -c ex_mix.for

gfortran -g -o ex_mix_for ex_mix.o -lrefprop -lgfortran -L/usr/local/lib
./ex_mix_for

   300.0000  1740.5894    14.4550     0.9628
   300.0000  1735.1589    14.2345     0.9603

c/c++から

プロジェクト中のサンプルのビルドには他にPocoが必要(make ctest/cpptestが下記のようにエラー)。

NIST オリジナルのcppサンプル、サイトのFAQからDLできるcサンプルは、いずれもWindows上でdllファイルを利用するものなので注意。

make cpptest
g++ -O3 -ffast-math -Wall -pedantic -fbounds-check -ansi -Wpadded -Wpacked -mpreferred-stack-boundary=8 -g -o ./src/ex_mix.o -c ./src/ex_mix.cpp
./src/ex_mix.cpp:37:32: error: .....[snip]

まず、オープンソースC++用クラスライブラリPOCOのヘッダーファイルが必要なので、yum install poco* してヘッダーファイルをsrcフォルダにコピーする。

su

yum install poco-foundation poco-devel

cp -r /usr/include/Poco src/

make cpptest

bin/ex_mix_cpp files/fluids/   ← fluidsフォルダのパスを指定する

 

REFPROP_PATH as string: files/fluids/
FLD_PATH as string: files/fluids/
LIBRARY_CHAR as string: librefprop.so
Running on: Linux

RPVersion(v) returned v = 9.1                                                       

                                                                                                                                                                                                   
SETPATHdll(hpth) called with hpth = files/fluids/
SETUPdll(i,hfld,hfm,hrf,ierr,herr) called with hfld = nitrogen.fld
INFOdll(info_index,wm,ttp,tnbp,tc,pc,dc,zc,acf,dip,rgas) called with index = %
WM,ACF,DIP,TTP,TNBP      28.0135,    0.0372,    0.0000,   63.1510,   77.3550
TC,PC,DC,RGAS           126.1920, 3395.8000,   11.1839,    8.3145

SETUPdll(i,hfld,hfm,hrf,ierr,herr) called with hfld = nitrogen.fld|argon.fld|oxygen.fld
WM,ACF,DIP,TTP,TNBP      28.0135,    0.0372,    0.0000,   63.1510,   77.3550
TC,PC,DC,RGAS           126.1920, 3395.8000,   11.1839,    8.3143

wm            28.9586
P,Dl,Dv,xl[0],xv[0]   246737.7308,   37.0063,    0.0000,    0.7812,    0.7812
P,Dl,Dv,xl[0],xv[0]     566.1072,   28.3583,    0.7823,    0.5887,    0.7812
T,Dl,Dv,xl(1),xv(1)     100.0000,   28.3583,    0.7823,    0.5887,    0.7812
T,P,D                   300.0000,20000.0000,    7.7603
T,P,D,H,CP              300.0000,20000.0000,    7.7603, 7697.3871,   36.9445
F,B,C                 15780.5409,   -0.0071,    0.0013
dP/dD,d2P/dD2,dP/dT    2920.5520,  169.7492,   93.9553
Enthalpy derivatives     33.9945,   36.9445,  -91.7000,   -1.1484,   -0.0314
T,SURF. TN.             300.0000,    0.0000
VIS.,TH.CND.             24.1942,   37.6405
T, D, P from TDFLSH     300.0000,    7.7603,   20.0000
T, D, P from PDFLSH     300.0000,    7.7603,   20.0000
T, D, P from PHFLSH     300.0000,    7.7603,   20.0000
T, D, P from PSFLSH     300.0000,    7.7603,   20.0000
T, D, P from DHFLSH     300.0000,    7.7603,   20.0000
T, D, P from THFLSH     300.0000,    7.7603,   20.0000
Melting pressure(MPa)   246.7377,  100.0000
Melting temperature(K)  100.0000,  246.7377
Sublimation pr.(kPa)      5.0047,  200.0000
Sublimation temp.(K)     61.4977,    5.0047

 (2015/5追記)

SL7/CentOS7ではPocoが標準でパッケージがなさそうなので、本家からソースを持ってきてビルドします。

wget http://pocoproject.org/releases/poco-1.6.0/poco-1.6.0.tar.gz

 ./configure

make

su

make install