-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
Wrapper of IF97 for postgreSQL | ||
================================================ | ||
|
||
This wrapper will provide Functions in postgreSQL that provide thermodynamic and transport properties for water/steam at specified state points based on the IAPWS Industrial Formulation for the Properties of Water and Steam. | ||
|
||
This wrapper been developed and tested on postgreSQL 9 and 10 | ||
|
||
------ | ||
|
||
To Use | ||
====== | ||
|
||
* Build the wrapper as a shared lib | ||
|
||
* Install .so file into the postgres external module directory (given by pg_config --pkglibdir) | ||
|
||
* run the .sql file to notify you postgreSQL database to use the shared lib | ||
|
||
* use provided function : if97_hmass_Tp() and if97_Tsat97() as SQL functions | ||
|
||
------ | ||
|
||
To Build | ||
======== | ||
|
||
Follow the build procedures below to create the IF97 module for postgreSQL. | ||
|
||
Pre-Requisites | ||
-------------- | ||
|
||
* You will need to have postgreSQL *server* installed | ||
* You will need g++ | ||
|
||
Download the IF97 Repository | ||
---------------------------- | ||
|
||
* Open a Git window at the drive location where you want to create your local IF97 repository | ||
|
||
* Clone the CoolProp/IF97 repository to a local repository (If you haven't already cloned it recursively with CoolProp).:: | ||
|
||
git clone https://github.com/CoolProp/IF97 | ||
|
||
* Change directory (cd) to the IF97 directory you just created.:: | ||
|
||
cd IF97 | ||
|
||
Build and Install | ||
----------------------------- | ||
|
||
* Go to the wrapper/Postgresql directory run `build.sh` | ||
|
||
* Connect to your postgreSQL server with your favorite client and execute if97.sql commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
g++ -c -fPIC -Wall -Werror -g3 -O0 -I`pg_config --includedir-server` -I`pg_config --includedir-server`/utils if97.c | ||
g++ -shared -o if97.so if97.o | ||
mkdir -p `pg_config --pkglibdir`/if97 | ||
cp ./if97.so `pg_config --pkglibdir`/if97 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Filename: if97.c | ||
*/ | ||
|
||
extern "C" { | ||
#include <postgres.h> | ||
#include <fmgr.h> | ||
#include <utils/elog.h> | ||
PG_MODULE_MAGIC; | ||
} | ||
|
||
#include "../../IF97.h" | ||
|
||
extern "C" { | ||
// double hmass(double T, double p) | ||
PG_FUNCTION_INFO_V1(if97_hmass_Tp); | ||
Datum if97_hmass_Tp(PG_FUNCTION_ARGS) { | ||
try { | ||
PG_RETURN_FLOAT8(IF97::hmass_Tp(PG_GETARG_FLOAT8(0),PG_GETARG_FLOAT8(1))); | ||
} catch (const std::exception& e) { | ||
elog(WARNING, "if97: %s",e.what()); | ||
PG_RETURN_NULL(); | ||
} | ||
} | ||
|
||
// double Tsat97(double p) | ||
PG_FUNCTION_INFO_V1(if97_Tsat97); | ||
Datum if97_Tsat97(PG_FUNCTION_ARGS) { | ||
try { | ||
PG_RETURN_FLOAT8(IF97::Tsat97(PG_GETARG_FLOAT8(0))); | ||
} catch (const std::exception& e) { | ||
elog(WARNING, "if97: %s",e.what()); | ||
PG_RETURN_NULL(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE OR REPLACE FUNCTION | ||
if97_hmass_Tp(FLOAT8, FLOAT8) | ||
RETURNS FLOAT8 AS '$libdir/if97/if97.so', 'if97_hmass_Tp' | ||
LANGUAGE C WITH ( ISSTRICT ); | ||
|
||
CREATE OR REPLACE FUNCTION | ||
if97_Tsat97(FLOAT8) | ||
RETURNS FLOAT8 AS '$libdir/if97/if97.so', 'if97_Tsat97' | ||
LANGUAGE C WITH ( ISSTRICT ); |