1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-26 20:18:51 -05:00
This commit is contained in:
hrocho 2018-01-29 18:54:24 +01:00
parent 6821aef367
commit b51005043c
2 changed files with 21 additions and 6 deletions

View File

@ -117,6 +117,12 @@ namespace catima{
*/ */
double weight_fraction(int i) const {return (atoms[i].stn<1.0)?atoms[i].stn:atoms[i].stn*atoms[i].A/M();}; double weight_fraction(int i) const {return (atoms[i].stn<1.0)?atoms[i].stn:atoms[i].stn*atoms[i].A/M();};
/**
* return molar fraction of i-th element
* @return molar fraction
*/
double molar_fraction(int i) const {return (atoms[i].stn<1.0)?atoms[i].stn*M()/atoms[i].A:atoms[i].stn;};
/** /**
* @return number of components in Material * @return number of components in Material
*/ */

View File

@ -234,26 +234,35 @@ const lest::test specification[] =
}, },
CASE("fraction calculation"){ CASE("fraction calculation"){
catima::Material water1({ catima::Material water1({
{0, 1, 0.111894}, {0, 1, 0.111898},
{0, 8, 0.888106} {0, 8, 0.888102}
}); });
catima::Material water2({ catima::Material water2({
{0, 1, 2}, {0, 1, 2},
{0, 8, 1} {0, 8, 1}
}); });
EXPECT(water1.weight_fraction(0)==0.111894); EXPECT(water1.weight_fraction(0)==0.111898);
EXPECT(water2.weight_fraction(0)==approx(water1.weight_fraction(0)).R(1e-3)); EXPECT(water2.weight_fraction(0)==approx(water1.weight_fraction(0)).R(1e-5));
EXPECT(water1.weight_fraction(1)==0.888106); EXPECT(water1.weight_fraction(1)==0.888102);
EXPECT(water2.weight_fraction(1)==approx(water1.weight_fraction(1)).R(1e-3)); EXPECT(water2.weight_fraction(1)==approx(water1.weight_fraction(1)).R(1e-5));
EXPECT(water2.M()==approx(18).epsilon(0.1)); EXPECT(water2.M()==approx(18).epsilon(0.1));
EXPECT(water1.M()==approx(6.0,0.1)); EXPECT(water1.M()==approx(6.0,0.1));
EXPECT(water2.M()==approx(18,0.1)); EXPECT(water2.M()==approx(18,0.1));
EXPECT(water1.molar_fraction(0)==approx(2.0/3.0).R(1e-5));
EXPECT(water2.molar_fraction(0)==approx(2.0).R(1e-5));
EXPECT(water1.molar_fraction(1)==approx(1.0/3.0).R(1e-5));
EXPECT(water2.molar_fraction(1)==approx(1.0).R(1e-5));
EXPECT(water1.molar_fraction(0)/water1.molar_fraction(1)==approx(2.0).R(1e-5));
EXPECT(water2.molar_fraction(0)/water2.molar_fraction(1)==approx(2.0).R(1e-5));
catima::Material mat({12.0,6,1}); catima::Material mat({12.0,6,1});
EXPECT(mat.M()==approx(12.0,0.001)); EXPECT(mat.M()==approx(12.0,0.001));
EXPECT(mat.weight_fraction(0)==approx(1.0).R(1e-6)); EXPECT(mat.weight_fraction(0)==approx(1.0).R(1e-6));
} }
}; };