Thermodynamic Properties of Water and Steam (IF97 equations)

Use this forum to post Vensim related questions.
Post Reply
warrick
Member
Posts: 21
Joined: Tue Jul 19, 2016 8:49 pm
Vensim version: DSS

Thermodynamic Properties of Water and Steam (IF97 equations)

Post by warrick » Wed Dec 20, 2017 6:51 pm

Good day,

Using: Vensim 7.1 DSS

I have a similar query to the two links below which both aimed to have a 'dynamic' link with Excel. Not sure how it was solved in the end, hence this post.
viewtopic.php?f=2&t=5009
viewtopic.php?f=2&t=5273

The second deals with using Vensim as a DDE Client. From the examples provided (DDE Client) I was able to link Excel and Vensim. Input from Excel is straightforward with GET XLS functions but to send values from Vensim to Excel is less basic.

What I am trying to achieve is:
1. Vensim to send values (Pressure and Temperature of Steam) to Excel
2. Excel via Water97.xla Add-Inn to calculate the steam properties, for instance specific enthalpy
3. Excel to send back the calculated values to Vensim
4. Vensim to simulate

So currently the above has been achieved but the link/process is 'static'. For instance, when SynTheSim is used the steam proprieties are not automatically updated. What I 'need' is to have the Water97 Excel Add-In to be a user defined function in Vensim or similar. How are UDF created in Vensim?

What makes the process more complicated is that after Step 4 the values (Pressure and Temperature) may be updated in the simulation, so an iterative approach is required. In Excel this is achieved with "Enable iterative calculations". I assume one could manage this with simultaneous equations in Vensim.

Attached is the Excel file and Vensim example model. Unforuntely, .xla files are not allowed but Excel Add-In (Water97_v13.xla) can be downloaded from http://files.engineering.com/getfile.as ... 97_v13.xla

To get the setup to work the directory needs to be changed. The Excel Add-In would also need to be saved and activated (similar to built-in Solver). For the example Excel could be doing basic calculations based and Vensim inputs and then send back (but then you would not need Excel / Excel Add-In ;) ), the same principle applies.

Is the DDE Client route a good choice? I am not a programming wizard. What would you recommend?

Thank you in advance.
Attachments
ConnectVE.mdl
(1.96 KiB) Downloaded 40 times
Connect.XLS
(43 KiB) Downloaded 41 times

tomfid
Administrator
Posts: 2408
Joined: Wed May 24, 2006 4:54 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by tomfid » Wed Dec 20, 2017 7:16 pm

This sounds doable, but painful.

External functions are defined in C, http://vensim.com/documentation/dss_external_fn.htm It's not particularly hard in many cases, but if you're not a C programmer, the learning curve will be long.

A much simpler option, if you can get away with it, would be to use a 2D array to store precalculated values of steam properties, then look up what you need. This will probably be MUCH faster to execute.

Administrator
Super Administrator
Posts: 3129
Joined: Wed Mar 05, 2003 3:10 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by Administrator » Thu Dec 21, 2017 3:38 pm

Do you have source code for the functions within the Excel add-on? It might be straightforward to re-code them in C.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

tomfid
Administrator
Posts: 2408
Joined: Wed May 24, 2006 4:54 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by tomfid » Thu Dec 21, 2017 4:02 pm

... or even to recode them in Vensim with FIND ZERO.

warrick
Member
Posts: 21
Joined: Tue Jul 19, 2016 8:49 pm
Vensim version: DSS

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by warrick » Thu Dec 21, 2017 7:44 pm

Sorry for the delay.

I also thought about the Lookup option but this has its drawbacks as the phase (superheated, saturated, compressed) would need to be 'set' per point in the steam cycle. If time does not allow for the below to work out then I will look into it further. It would be cool to compare the two methods...

OK so it seems External Functions is the better way to go. I will have to get going with C (had one-semester of it many years ago).

Yes the source code is freely available, attached in word format. The actual .xla can be downloaded from website previously provided.

Not sure how to start with re-coding and setting up the External Function. Please point me in the right direction, any advise much appreciated. I have the holiday to figure out but just want to make sure I do not waste days of work.

Is FIND ZERO for the iterative approach / simultaneous equations?
Attachments
water97_Code.docx
(37.32 KiB) Downloaded 38 times

Administrator
Super Administrator
Posts: 3129
Joined: Wed Mar 05, 2003 3:10 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by Administrator » Thu Dec 21, 2017 9:39 pm

Are any of these functions already in the GNU Scientific Library?
http://vensim.com/workbench/#gnu-scient ... vensim-dss

If the functions were generic and straightforward enough, I'd have probably coded them into the GNU DLL. But there is not much documentation in the the code and things like
"If temperature >= 273.15 And temperature <= 623.15 Then"
I've got no idea what the 273.15 and 623.15 are. They should really be coded as defined constants rather than numbers. And there is a lot of mention of "regions" which makes me think this is a worked example rather than the source code for these functions.

The function "densSatVapTW" (density of saturated steam as a function of temperature) seems like it might be a candidate for something that is already in the GNU scientific library.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

Administrator
Super Administrator
Posts: 3129
Joined: Wed Mar 05, 2003 3:10 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by Administrator » Thu Dec 21, 2017 9:44 pm

Does this contain all the functions you need?
https://github.com/CoolProp/IF97
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

warrick
Member
Posts: 21
Joined: Tue Jul 19, 2016 8:49 pm
Vensim version: DSS

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by warrick » Fri Dec 22, 2017 6:52 am

Yes GitHub is based on the same documentation as the Excel Add-In from the International Association for the Properties of Water and Steam. MIT has actually taken it further by including the backward equations - returns Temperature. The IF (IF97) stands for Industrial Formulation. Really cool, great find :)

Attached is the same IAPWS document referenced by MIT. This explains the code previously sent and includes the backward equations. Sorry I should of included it earlier.

I had a look at the GNU files, including the referenced manual, specifically chapter 44 Physical Constants. No water properties (as the name says its only constants). Also checked the GSLHelper spreadsheet, no mention of water/steam properties.

Is IF97 the solution? :) This seems almost too good to be true.
Attachments
IF97-Rev.pdf
(397.41 KiB) Downloaded 36 times

Administrator
Super Administrator
Posts: 3129
Joined: Wed Mar 05, 2003 3:10 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by Administrator » Fri Dec 22, 2017 9:22 am

I've coded these into an external function library for use with Vensim DSS.

They are completely untested (as I wouldn't know how to test) other than to make sure the functions show up from within Vensim. If you want to create a demo model that uses these, feel free to do so and I'll add it to the download page on vensim.com.

To get a list of the functions and what they do, view https://github.com/CoolProp/IF97/blob/master/IF97.h and search for "API". The first function listed below this is "rhomass_Tp".

http://vensim.com/workbench/#if97-equat ... vensim-dss
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

warrick
Member
Posts: 21
Joined: Tue Jul 19, 2016 8:49 pm
Vensim version: DSS

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by warrick » Tue Jan 02, 2018 10:31 am

Sorry for the delay.

After extracting the provided zip folder I saved VensimCoolPropIF97.dll under C:\Users\Public\Vensim\plugins and then directed Vensim to the .dll file with Tool > Options > Startup: External function library.

The IF97 functions are now like built in functions, under User Defined. Attached is an demo/example model. From Pressure (Pa) and Temperature (K) the specific enthalpy and specific entropy are calculated. From this the Temperature and Pressure are found and compared to the inputted values (round trip). The difference is negligible - less than 1000th of a percent. I also checked a few IF97 outputs with other sources and found them to to be same, for instance https://www.steamtablesonline.com/Steam97Web.aspx and mentioned Excel Add-In.

For some reason the mass density (rhomass Tp) provides the following ERROR: Unable to execute external function "rhomass Tp" computing -Mass Density P T. There are ways to get around this, for instance calculating density from Pressure and specific entropy (instead of Pressure and Temperature). There may be other issues but this is the only one I picked up.

Otherwise working well. Thank you so much :)
Attachments
IF97_example.mdl
(4.45 KiB) Downloaded 42 times

Administrator
Super Administrator
Posts: 3129
Joined: Wed Mar 05, 2003 3:10 am

RE: Thermodynamic Properties of Water and Steam (IF97 equations)

Post by Administrator » Tue Jan 02, 2018 11:08 am

I've updated the library, the function should now work ok.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559

Post Reply