Commit db8a2072 authored by Henderson, Shane's avatar Henderson, Shane
Browse files

Fix path input interfaces

parent 691e39cc
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -40,7 +40,12 @@ Default_Data_Store::Default_Data_Store()
void Default_Data_Store::load(const std::string& fPath)
{
    std::ifstream inFile(fPath.data());
    if(inFile.is_open())
    {
        load(inFile);
    }else{
        throw std::runtime_error("Falied to open input file");
    }
}

//---------------------------------------------------------------------------//
+9 −6
Original line number Diff line number Diff line
@@ -42,8 +42,16 @@ void R_Kister_Data_Store::load(const std::string& rkfPath, const std::string& df
    //Set up a default data store
    d = Default_Data_Store();
    std::ifstream inFile(dfPath.data());
    if(!inFile.is_open())
    {
        throw std::runtime_error("Falied to open input data file.");
    }

    std::ifstream rkinFile(rkfPath.data());
    if(!rkinFile.is_open())
    {
        throw std::runtime_error("Falied to open input RK data file.");
    }
    load(rkinFile,inFile);

}
@@ -69,14 +77,9 @@ void R_Kister_Data_Store::load(std::istream& rkinFile,std::istream& inFile)

    // Jaunt through lines until we find the Redlich-Kister parameters
    std::string line;
    while( std::getline(rkinFile,line) )
    {
        if( line.find("RK parameters") != std::string::npos ) break;
    }
    // Its possible we could have a bum input. That should break here.

    // this is  a comment line
    std::getline(rkinFile,line);
    std::getline(rkinFile,line);

    // Read the input data. TODO currently only uses density
    while( std::getline(rkinFile,line))
+78 −0
Original line number Diff line number Diff line
@@ -370,3 +370,81 @@ TEST(default_data, FLiNaK_465_115_042)
    tp.setComposition({"LiF","BeF2","ThF4"},{0.6998,0.1499,0.1503});
    ASSERT_FALSE(tp.valid_mu());
}
TEST(default_data, full_load)
{
    Default_Data_Store d; d.load("/home/oxh/dev/mstdb-tp/Molten_Salt_Thermophysical_Properties.csv");
    Thermophysical_Properties tp;
    ASSERT_TRUE(tp.initialize(&d));
    // Ensure that the composition set correctly
    ASSERT_TRUE(tp.setComposition({"LiF","NaF","KF"},{0.465,0.115,0.42}));

    // Test Density
    std::vector<double> tks           = {700.0, 750.0, 800.0, 850.0, 860.0, 1000.0};
    // Expected calculated values (note these have been rounded)
    std::vector<double> rho_calc_ref  = {2.1425,2.1113,2.0801,2.04890,2.04266,1.9553};
    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        EXPECT_NEAR(rho_calc_ref[i], tp.rho(t_k), 1e-3);
    }
    EXPECT_NEAR(tp.rho_h(tp.h_t(900)), tp.rho(900), 1e-4);
    EXPECT_FLOAT_EQ(tp.rho(900)*1000.0,tp.rho_kgm3(900));
    tks.clear();

    // Test Heat Capacity
    // Using values from reference https://doi.org/10.1021/je00029a041
    tks           = {700.0, 750.0, 800.0, 850.0, 860.0, 1000.0};
    // Expected calculated values (note these have been rounded)
    std::vector<double> cp_calc_ref  = {71.0316, 73.2255, 75.4194, 77.6133, 78.0521, 84.195};

    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        EXPECT_NEAR(cp_calc_ref[i], tp.cp(t_k), 6e-3);
    }
    EXPECT_FLOAT_EQ(tp.cp(900)*(1000.0/41.2909),tp.cp_kg(900));
    EXPECT_NEAR(tp.cp_h(tp.h_t(1200)), tp.cp(1200), 4e-2);
    tks.clear();

    // Test Viscosity
    // Using values from reference https://doi.org/10.1021/je60084a007
    tks                              = {700.0, 822.45, 872.65, 973.45, 922.95, 770.15, 1000.0};
    // Expected calculated value
    std::vector<double> mu_calc_ref  = {17.9814 , 5.6296, 4.0862, 2.5436, 3.1494, 8.5459, 2.3095};

    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        EXPECT_NEAR(mu_calc_ref[i], tp.mu(t_k), 5e-2);
    }
    tks.clear();

    EXPECT_NEAR(tp.mu_h(tp.h_t(900)), tp.mu(900), 6e-4);

    // Test Thermal Conductivity
    // Using values from reference https://doi.org/10.1016/j.ijheatmasstransfer.2015.07.042
    tks                              = {700.0, 773.0,  823.0,  873.0,  923.0,  973.0, 1000.0};
    // Expected calculated value
    std::vector<double> k_calc_ref  = {0.56, 0.6549, 0.7199, 0.7849, 0.8499, 0.9149, 0.95};

    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        EXPECT_NEAR(k_calc_ref[i], tp.k(t_k), 5e-4);
    }
    EXPECT_NEAR(tp.k_h(tp.h_t(970)), tp.k(970), 1e-4);

    // Test temperature to enthalpy conversion
    EXPECT_NEAR(748.77152178380845, tp.t_h(1000), 1e-6);
    EXPECT_NEAR(tp.t_h(tp.h_t(970)),970,5e-2);
    EXPECT_NEAR(tp.t_h_kg(tp.h_t_kg(970)),970,5e-2);

    // Set an incomplete data sets to test validity functions
    tp.setComposition({"LiF","BeF2","ThF4"},{0.727,0.157,0.116});
    ASSERT_FALSE(tp.valid_rho());
    ASSERT_FALSE(tp.valid_k());
    ASSERT_FALSE(tp.valid_cp());
    ASSERT_TRUE(tp.valid_mu());
    tp.setComposition({"LiF","BeF2","ThF4"},{0.6998,0.1499,0.1503});
    ASSERT_FALSE(tp.valid_mu());
}
+38 −2
Original line number Diff line number Diff line
@@ -27,8 +27,7 @@ LiF-BeF2-ThF4 , 11 , 71.4958 , 0.6998-0.1499-0.1503 , 816.60 , 0.00 , Cantor
LiF-BeF2-ThF4 , 12 , 61.9697  , 0.727-0.157-0.116    , 826.20  , 0.00   , Cantor1973  , 0.0     , 0.0    , ----           , 0.0       , 0.0       , 0.0-0.0       , 0.0    , ----          , 1.094E-01 , 3.402E+04 , 0.000E+00  , 0.000E+00  , 0.000E+00 , 826-946       , 15.00  , Cantor1973   , 0.000E+00  , 0.000E+00  , 0.0-0.0      , 0.0    , ----        , 0.000E+00 , 0.000E+00  , 0.000E+00  , 0.000E+00 , 0.0    , ----
)ORNL_format";

static const char* tst_data_rk = R"ORNL_format(
//RK parameters
static const char* tst_data_rk = R"ORNL_format(//
//C 1 , C 2     , A1            , B1            , A2            , B2            , A3           , B3           , T min        , T max        , Reference
KF    , LiF     , -5.383100E-03 , -4.142700E-05 , +0.000000E+00 , +0.000000E+00 , 0.000000E+00 , 0.000000E+00 , 1.006150E+03 , 1.314150E+03 , 'Taniuchi, K.; Kanai, T. Density of Binary Molten Salts of Lithium Fluoride-Potassium Fluoride and Lithium Fluoride-Calcium Fluoride Systems. Denki Kagaku oyobi Kogyo Butsuri Kagaku 1977, 45 (6), 401-404. https://doi.org/10.5796/kogyobutsurikagaku.45.401'
KF    , NaF     , -3.747500E-01 , +2.354000E-04 , +0.000000E+00 , +0.000000E+00 , 0.000000E+00 , 0.000000E+00 , 1.050000E+03 , 1.350000E+03 , 'Porter, B., and Meaker, R. E., United States Department of the Interior, Report of Investigations 6838, 1966.'
@@ -115,5 +114,42 @@ TEST(rk_data_store,input_order)
    ASSERT_FALSE(tp_rk.valid_k());
    ASSERT_FALSE(tp_rk.valid_cp());
    ASSERT_FALSE(tp_rk.valid_mu());
}

TEST(rk_data_store,full_load)
{
    // Set up the interpolation object
    R_Kister_Data_Store rk_DS; rk_DS.load("/home/oxh/dev/mstdb-tp/Molten_Salt_Thermophysical_Properties_RK.csv","/home/oxh/dev/mstdb-tp/Molten_Salt_Thermophysical_Properties.csv");
    Thermophysical_Properties tp_rk;
    ASSERT_TRUE(tp_rk.initialize(&rk_DS));

    std::vector<double> tks           = {1080,1130,1180,1230};
    tp_rk.setComposition({"LiF","NaF","KF"},{0.465,0.115,0.42});
    std::vector<double> ref(tks.size());
    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        ref[i] = tp_rk.rho(t_k);
    }

    tp_rk.setComposition({"NaF","LiF","KF"},{0.115,0.465,0.42});
    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        EXPECT_NEAR(tp_rk.rho(t_k),ref[i],1e-6);
    }

    tp_rk.setComposition({"KF","NaF","LiF"},{0.42,0.115,0.465});
    for( size_t i = 0; i < tks.size(); ++i)
    {
        double t_k = tks[i];
        EXPECT_NEAR(tp_rk.rho(t_k),ref[i],1e-6);
    }

    // Set an incomplete data sets to test validity functions
    tp_rk.setComposition({"LiF","UF3","ZrF4"},{0.80,0.07,0.13});
    ASSERT_FALSE(tp_rk.valid_rho());
    ASSERT_FALSE(tp_rk.valid_k());
    ASSERT_FALSE(tp_rk.valid_cp());
    ASSERT_FALSE(tp_rk.valid_mu());
}