Skip to content

[thermo] RedlichKwongMFTP critical property lookups#464

Closed
decaluwe wants to merge 0 commit intoCantera:masterfrom
decaluwe:critProps
Closed

[thermo] RedlichKwongMFTP critical property lookups#464
decaluwe wants to merge 0 commit intoCantera:masterfrom
decaluwe:critProps

Conversation

@decaluwe
Copy link
Copy Markdown
Member

@decaluwe decaluwe commented Jul 3, 2017

Changes proposed in this pull request:
-Makes it so that Thermo::RedlichKwongMFTP input files do not necessarily have to provide pureFluidParameters for every species. Since these can be calculated from the critical temperature and pressure for the Redlich Kwong EoS, we provide the ability to look up Tc and Pc for well-known species.
-Provides a database of species with well-known critical properties. Species are currently matched by chemical formula, so isomers are currently prohibited. Can possibly add functionality to scan by species name, but this seems like it could lead to significant ambiguity. My preference is to keep this database limited to species where potential ambiguity is near zero. Database is stored in the data folder. Updating the database is relatively straight-foward for any end users - user simply has to lookup Tc and Pc and enter them into the database, rather than lookup Tc and Pc, calculate a and b parameters for R-K EoS, and then update the cti file.
-Adds test suite coverage for this capability.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 3, 2017

Codecov Report

Merging #464 into master will increase coverage by 0.04%.
The diff coverage is 80.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #464      +/-   ##
==========================================
+ Coverage   58.23%   58.28%   +0.04%     
==========================================
  Files         386      386              
  Lines       42310    42393      +83     
  Branches     7252     7266      +14     
==========================================
+ Hits        24640    24707      +67     
- Misses      15488    15495       +7     
- Partials     2182     2191       +9
Impacted Files Coverage Δ
include/cantera/thermo/RedlichKwongMFTP.h 100% <ø> (ø) ⬆️
test/thermo/RedlichKwongMFTP_Test.cpp 100% <100%> (ø) ⬆️
src/thermo/RedlichKwongMFTP.cpp 49.42% <73.91%> (+2.08%) ⬆️
src/base/stringUtils.cpp 64.06% <0%> (+0.78%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6bf74d1...38535fc. Read the comment docs.

Copy link
Copy Markdown
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really interesting, and will certainly make the RedlichKwong class much easier to use!

Based on the implementation, I would say that species are matched by name (identifier), not formula (composition), which does allow you to define isomers, but with no standard naming scheme. In order to expand the database and eliminate ambiguities, I think we would need to have a better identifier present, e.g. something like InChI. Not something that we need to worry about now, but worth considering for the future.

Rather than having users update this database, the other option for providing Tc/Pc instead of the a and b coefficients would be to look for this information in the species declaration as well. I think this would be worth looking at after we get a bit further with the new input file format.

@@ -0,0 +1,1150 @@
<ctml>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reference for these values?

@@ -0,0 +1,1150 @@
<ctml>

<species name= "CCL4">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces, not tabs, please.

doublereal* RedlichKwongMFTP::getCoeff(const std::string& iName)
{
vector_fp vParams;
static doublereal spCoeff[2];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend against using static arrays, as they introduce potential race conditions. Better to have this function return a vector<double>.

b_vec_Curr_[iSpecies]);
}
else
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer writing this on one line, e.g.

    end block 1;
} else {
    start block 2;

for (size_t isp = 0; isp < nDatabase; isp++)
{
XML_Node& acNodeDoc = doc->child(isp);
acNodeDocPtr = &acNodeDoc;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like this variable ever gets used.

P_crit = P_crit * 100000;

spCoeff[0] = 0.42748 * pow(GasConstant, 2) * pow(T_crit, 2.5) / P_crit; //coeff a
spCoeff[1] = 0.08664 *GasConstant * T_crit / P_crit; // coeff b
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nitpick: space on both sides of the *.

@@ -0,0 +1,3 @@
<ctml>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be deleted (preferably, do this as a separate commit, then do an interactive rebase and squash that commit with the one that introduced the file in this location, so that it's like it never existed)

TEST_F(RedlichKwongMFTP_Test, construct_from_cti)
{
const std::string valid_file("../data/co2_RK_example.cti");
initializeTestPhase(valid_file);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to just write initializeTestPhase("../data/co2_RK_example.cti");

public:
RedlichKwongMFTP_Test() {
test_phase.reset(newPhase("../data/co2_RK_example.cti"));
void initializeTestPhase(const std::string & filename)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our normal style is to not have the space between the typename and the &, e.g. std::string& filename.


TEST_F(RedlichKwongMFTP_Test, critPropLookup)
{
// Check to make sure that RedlichKwongMFTP is able to properly calcualte a and b
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"calculate"

@speth
Copy link
Copy Markdown
Member

speth commented Dec 2, 2017

Before making any more changes on this branch, I think we should address the warning regarding conflicts and rebase this PR on top of the current master. I have already done this if you want to pull the branch https://github.com/speth/cantera/tree/critProps and reset this PR to that commit.

@decaluwe
Copy link
Copy Markdown
Member Author

decaluwe commented Dec 2, 2017 via email

@speth
Copy link
Copy Markdown
Member

speth commented Dec 2, 2017

That's strange. What do you get if you use writelog to print out the species name from each source as you go through the loop? If you want to push a branch showing the problem, I can take a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants