tstDecayResourceIO.cpp

./Core/io/tests/tstDecayResourceIO.cpp

#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <sstream>
#include <string>
#include <vector>
#include "ScaleData/Core/Utils.h"
#include "Nemesis/gtest/nemesis_gtest.hh"
#include "Nemesis/harness/DBC.hh"
#include "Origen/Core/TestPaths.h"
TEST( DecayResourceIOTester, Simple )
{
// Load
bool pass;
{
ScaleUtils::IO::DB opts;
pass = io.load( dr, Origen::decay_filepath, opts );
ASSERT_TRUE( pass ) << opts.writeErrorStack();
}
// Check the object for correctness.
std::vector<std::string> errors;
pass = dr.check( errors );
if( !pass )
{
std::cout << "Checking Errors:" << std::endl;
ScaleUtils::IO::DB db;
db.appendErrorStack( errors );
std::cout << db.dumpErrorStack() << std::endl;
}
ASSERT_TRUE( pass );
// Check that hydrogen is present.
EXPECT_TRUE( dr.is_present( 1001 ) );
// Check out hydrogen in detail.
EXPECT_EQ( 0.0, dr.get_parent_map()[1001].get_half_life() );
EXPECT_LT( 0, dr.get_parent_map()[1001].get_time_units() );
EXPECT_EQ( 0.0, dr.get_parent_map()[1001].get_recoverable_energy_value() );
EXPECT_EQ( 0.0, dr.get_parent_map()[1001].get_q_fraction_from_photons() );
EXPECT_EQ( 0.0, dr.get_parent_map()[1001].get_decay_constant() );
EXPECT_EQ( 1.0, dr.get_parent_map()[1001].get_rcg_for_air() );
EXPECT_EQ( 1.0, dr.get_parent_map()[1001].get_rcg_for_water() );
// Test changing something directly.
dr.get_parent_map()[1001].set_decay_constant( 3.04 );
EXPECT_FLOAT_EQ( 3.04, dr.get_parent_map()[1001].get_decay_constant() );
dr.get_parent_map()[1001].set_decay_constant( 0.0 );
EXPECT_EQ( 0.0, dr.get_parent_map()[1001].get_decay_constant() );
// Check out Cs-137 with half life 30.1 yrs.
{
EXPECT_TRUE( dr.is_present( 55137 ) );
// Check the decay constant for 1% difference.
double ref_decay = log( 2.0 ) / ( 30.1 * 365 * 24 * 60 * 60 );
Origen::DecayParent parent = dr.get_parent_map()[55137];
EXPECT_NEAR( ref_decay, parent.get_decay_constant(), ref_decay * 0.01 );
EXPECT_TRUE(
dr.has_decay_mode( 55137, ScaleData::Utils::DECAY_BETA_MINUS ) );
parent.get_channel_map()[ScaleData::Utils::DECAY_BETA_MINUS];
channel.get_yield_type() );
EXPECT_NEAR( 1.0, channel.get_branch_ratio(), 1e-5 );
EXPECT_NEAR( 0.053, channel.get_yield_map()[0], 0.053 * 0.01 );
EXPECT_NEAR( 0.947, channel.get_yield_map()[1], 0.947 * 0.01 );
}
// Check out Cm-250
{
EXPECT_TRUE( dr.is_present( 96250 ) );
dr.get_parent_map()[96250]
.get_channel_map()[ScaleData::Utils::DECAY_SPONTANEOUS_FISSION];
channel.get_yield_type() );
EXPECT_NEAR( 0.74, channel.get_branch_ratio(), 0.74 * 0.01 );
}
// Print the decay resource as JSON.
if( false )
{
Scale::Json::Value json = dr.to_json();
std::cout << json.toStyledString() << std::endl;
}
// Print the decay resource in a table.
if( false ) printDecayTable( dr, std::cout );
}
TEST( DecayResourceIOTester, ErrorTryingToLoadYields )
{
bool pass;
{
ScaleUtils::IO::DB opts;
pass = io.load( dr, Origen::yields_filepath, opts );
EXPECT_FALSE( pass );
EXPECT_EQ( 2, opts.numError() ) << opts.writeErrorStack();
opts.clearErrorStack();
}
}