Commit c2d53379 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Adding forgotten tstDecayDb file.

parent 5d6967cb
#include "gtest/gtest.h"
#include "radixcore/system.hh"
#include "radixio/decaydb.hh"
#include "radixio/f71stream.hh"
#include <tuple>
#include <unordered_map>
#include <fstream>
using namespace radix;
TEST(Radixio, DecayDb)
{
F71Stream stream(std::string(dirname(__FILE__) + "/data/test.s61.f71"));
std::vector<F71Case> cases;
bool result = true;
while (result)
{
F71Case single_case;
result = stream.read_case(single_case);
if (result) cases.emplace_back(single_case);
}
ASSERT_TRUE(cases.size() == 1);
F71Case& first = cases[0];
// calculate activity (curies) for each nuclide
const std::vector<int>& light_nucs = first.lightElementNuclides();
const std::vector<int>& ac_nucs = first.actinideNuclides();
const std::vector<int>& fp_nucs = first.fissionProductNuclides();
const std::vector<float>& light_abs = first.lightElementNuclideAbundances();
const std::vector<float>& ac_abs = first.actinideNuclideAbundances();
const std::vector<float>& fp_abs = first.fissionProductNuclideAbundances();
ASSERT_EQ(light_nucs.size(), light_abs.size());
ASSERT_EQ(ac_nucs.size(), ac_abs.size());
ASSERT_EQ(fp_nucs.size(), fp_abs.size());
// collapse nuclides to a single set with all three abundances
std::unordered_map<int, std::tuple<float, float, float>> master;
for (size_t i = 0; i < light_nucs.size(); ++i)
{
int zaid = light_nucs[i];
float abs = light_abs[i];
auto it = master.find(zaid);
if (it == master.end())
{
master.insert(std::make_pair(zaid, std::make_tuple(abs, 0.f, 0.f)));
}
// we won't have this nuclide in the master list before
}
for (size_t i = 0; i < ac_nucs.size(); ++i)
{
int zaid = ac_nucs[i];
float abs = ac_abs[i];
auto it = master.find(zaid);
if (it == master.end())
{
master.insert(std::make_pair(zaid, std::make_tuple(0.f, abs, 0.f)));
}
else
{
std::get<1>(it->second) = abs;
}
}
for (size_t i = 0; i < fp_nucs.size(); ++i)
{
int zaid = fp_nucs[i];
float abs = fp_abs[i];
auto it = master.find(zaid);
if (it == master.end())
{
master.insert(std::make_pair(zaid, std::make_tuple(0.f, 0.f, abs)));
}
else
{
std::get<2>(it->second) = abs;
}
}
std::cout << "Unique nuclides: " << master.size() << std::endl;
DecayDb decaydb;
float total_activity = 0.f;
for (const auto& it : master)
{
int zaid = it.first;
float light_abs = std::get<0>(it.second);
float ac_abs = std::get<1>(it.second);
float fp_abs = std::get<2>(it.second);
float activity =
decaydb.calculate_activity(zaid, light_abs, ac_abs, fp_abs);
radix_line("Calculated activity(" << activity << ") for " << zaid << "["
<< light_abs << ", " << ac_abs << ", "
<< fp_abs << "]");
total_activity += activity;
}
std::cout << "Total activity(" << total_activity << ")" << std::endl;
EXPECT_NEAR(1.31421e-14f, total_activity, 1e-4);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment