Start reading nuclides on C++ side

This commit is contained in:
Paul Romano 2018-11-15 15:25:48 -06:00
parent 31c92bf511
commit 6940656c8a
3 changed files with 57 additions and 0 deletions

View file

@ -5,11 +5,32 @@
#define OPENMC_NUCLIDE_H
#include <array>
#include <vector>
#include <hdf5.h>
#include "openmc/constants.h"
namespace openmc {
//===============================================================================
// Data for a nuclide
//===============================================================================
class Nuclide {
public:
// Constructors
Nuclide(hid_t group);
// Data members
std::string name_; //! Name of nuclide, e.g. "U235"
int Z_; //! Atomic number
int A_; //! Mass number
int metastable_; //! Metastable state
double awr_; //! Atomic weight ratio
};
//==============================================================================
// Global variables
//==============================================================================
@ -21,6 +42,8 @@ namespace data {
extern std::array<double, 2> energy_min;
extern std::array<double, 2> energy_max;
extern std::vector<Nuclide> nuclides;
} // namespace data
//===============================================================================

View file

@ -1,5 +1,7 @@
#include "openmc/nuclide.h"
#include "openmc/hdf5_interface.h"
namespace openmc {
//==============================================================================
@ -11,8 +13,25 @@ namespace data {
std::array<double, 2> energy_min {0.0, 0.0};
std::array<double, 2> energy_max {INFTY, INFTY};
std::vector<Nuclide> nuclides;
} // namespace data
//==============================================================================
// Nuclide implementation
//==============================================================================
Nuclide::Nuclide(hid_t group)
{
// Get name of nuclide from group, removing leading '/'
name_ = object_name(group).substr(1);
read_attribute(group, "Z", Z_);
read_attribute(group, "A", A_);
read_attribute(group, "metastable", metastable_);
read_attribute(group, "atomic_weight_ratio", awr_);
}
//==============================================================================
// Fortran compatibility functions
//==============================================================================
@ -24,4 +43,9 @@ set_particle_energy_bounds(int particle, double E_min, double E_max)
data::energy_max[particle - 1] = E_max;
}
extern "C" void nuclide_from_hdf5_c(hid_t group)
{
data::nuclides.emplace_back(group);
}
} // namespace openmc

View file

@ -363,6 +363,16 @@ contains
type(VectorInt) :: temps_to_read
type(VectorInt) :: index_inelastic_scatter
interface
subroutine nuclide_from_hdf5_c(group) bind(C)
import HID_T
integer(HID_T), value :: group
end subroutine
end interface
! Read data on C++ side
call nuclide_from_hdf5_c(group_id)
! Get name of nuclide from group
this % name = get_name(group_id)