cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Creating a string from a table for Coolprop, programming ?

frederico.cms
10-Marble

Creating a string from a table for Coolprop, programming ?

Dears,

 

I´m using with great success the Coolprop wrapper, but one challenging task is to form the "mixture" string.

 

Air for instance must be written as: "O2[0.21]&N2[0.79]"

 

When working with complex mixtures, like up to 10 components, my idea was to use a table and extract a "concat" function from the table. All good doing it the hard way:

fredericocms_0-1683051861297.png

(...)

fredericocms_1-1683051889053.png

Problem: if I add or remove one of the 10 components from the table, maybe for a simpler composition, then the formula for "mixture" would fail.

 

Solution: maybe write a program? But don´t even know how to start.

 

Any help would be great.

 

Best regards,

 

Fred.

 

 

 

ACCEPTED SOLUTION

Accepted Solutions

Here is a function which creates the string, including zero values

Werner_E_0-1683058306700.png

 

Here is a slight modification so that zero values are omitted

Werner_E_1-1683058344587.png

 

And here is a function which can do both, depending on its third argument

Werner_E_2-1683058393518.png

Werner_E_3-1683058438972.png

 

Attached file is in format P9. Maybe someone ( @LucMeekes  ?) can convert it to P8 format or lower.

 

EDIT: There were copy & paste errors in the first version of the functions. Is now fixed.

View solution in original post

5 REPLIES 5

Should be no problem.

But I don't know Coolprop and the syntax that is needed there.

Is it necessary to include names with a mol_frac of zero or could we simply omit them?

 

Many thanks!

 

The string syntax is "component_name[mol%]&component_name[mol%]& ... etc".

 

The requirements are, the sum must be = 1 and the component name must follow the Coolprop library.

 

If the mol fraction is zero, both show or omit is ok, For example:

Air: "O2[0.21]&N2[0.79]"

Only oxygen: "O2[1]&N2[0]" or "O2[1]", all ok

 

In advance, many thanks for the help.

 

Best regards,

 

Fred.

Here is a function which creates the string, including zero values

Werner_E_0-1683058306700.png

 

Here is a slight modification so that zero values are omitted

Werner_E_1-1683058344587.png

 

And here is a function which can do both, depending on its third argument

Werner_E_2-1683058393518.png

Werner_E_3-1683058438972.png

 

Attached file is in format P9. Maybe someone ( @LucMeekes  ?) can convert it to P8 format or lower.

 

EDIT: There were copy & paste errors in the first version of the functions. Is now fixed.

LucMeekes
23-Emerald III
(To:Werner_E)

Here's the file in Prime6.

 

Success!

Luc

Dear Werner,

 

I can´t thank you enough, it is just perfect and elegant. It also helped me a lot to learn more about programming.

 

Best regards,

 

Fred.

Announcements

Top Tags