Fix all the bugs introduced

This commit is contained in:
Paul Romano 2019-02-21 14:45:59 -06:00
parent 0439eb0fa1
commit e1e4941d8c
13 changed files with 52 additions and 30 deletions

View file

@ -40,7 +40,7 @@ extern "C" {
int openmc_extend_meshes(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_extend_tallies(int32_t n, int32_t* index_start, int32_t* index_end);
int openmc_filter_get_id(int32_t index, int32_t* id);
int openmc_filter_get_type(int32_t index, const char** type);
int openmc_filter_get_type(int32_t index, char* type);
int openmc_filter_set_id(int32_t index, int32_t id);
int openmc_finalize();
int openmc_find_cell(const double* xyz, int32_t* index, int32_t* instance);

View file

@ -68,7 +68,7 @@ extern "C" {
void close_dataset(hid_t dataset_id);
void close_group(hid_t group_id);
int dataset_ndims(hid_t dset);
size_t dataset_typesize(hid_t dset);
size_t dataset_typesize(hid_t obj_id, const char* name);
hid_t file_open(const char* filename, char mode, bool parallel);
void file_close(hid_t file_id);
void get_name(hid_t obj_id, char* name);
@ -239,7 +239,7 @@ inline void
read_dataset(hid_t obj_id, const char* name, std::string& str, bool indep=false)
{
// Create buffer to read data into
auto n = attribute_typesize(obj_id, name);
auto n = dataset_typesize(obj_id, name);
char buffer[n];
// Read attribute and set string

View file

@ -28,7 +28,7 @@ extern bool check_overlaps; //!< check overlaps in geometry?
extern bool confidence_intervals; //!< use confidence intervals for results?
extern bool create_fission_neutrons; //!< create fission neutrons (fixed source)?
extern "C" bool dagmc; //!< indicator of DAGMC geometry
extern bool entropy_on; //!< calculate Shannon entropy?
extern "C" bool entropy_on; //!< calculate Shannon entropy?
extern bool legendre_to_tabular; //!< convert Legendre distributions to tabular?
extern bool output_summary; //!< write summary.h5?
extern bool output_tallies; //!< write tallies.out?
@ -37,7 +37,7 @@ extern "C" bool photon_transport; //!< photon transport turned on?
extern "C" bool reduce_tallies; //!< reduce tallies at end of batch?
extern bool res_scat_on; //!< use resonance upscattering method?
extern bool restart_run; //!< restart run?
extern bool run_CE; //!< run with continuous-energy data?
extern "C" bool run_CE; //!< run with continuous-energy data?
extern bool source_latest; //!< write latest source at each batch?
extern bool source_separate; //!< write source to separate file?
extern bool source_write; //!< write source in HDF5 files?
@ -62,10 +62,10 @@ extern std::string path_statepoint; //!< path to a statepoint file
extern int32_t index_entropy_mesh; //!< Index of entropy mesh in global mesh array
extern int32_t index_ufs_mesh; //!< Index of UFS mesh in global mesh array
extern int32_t n_batches; //!< number of (inactive+active) batches
extern "C" int32_t n_inactive; //!< number of inactive batches
extern int32_t gen_per_batch; //!< number of generations per batch
extern "C" int64_t n_particles; //!< number of particles per generation
extern "C" int32_t n_batches; //!< number of (inactive+active) batches
extern "C" int32_t n_inactive; //!< number of inactive batches
extern "C" int32_t gen_per_batch; //!< number of generations per batch
extern "C" int64_t n_particles; //!< number of particles per generation
extern int electron_treatment; //!< how to treat secondary electrons
extern std::array<double, 4> energy_cutoff; //!< Energy cutoff in [eV] for each particle type

View file

@ -21,7 +21,7 @@ namespace openmc {
class Tally {
public:
Tally() {}
Tally();
void init_from_xml(pugi::xml_node node);
@ -135,7 +135,7 @@ namespace simulation {
extern xt::xtensor_fixed<double, xt::xshape<N_GLOBAL_TALLIES, 3>> global_tallies;
//! Number of realizations for global tallies
extern int32_t n_realizations;
extern "C" int32_t n_realizations;
}
// It is possible to protect accumulate operations on global tallies by using an

View file

@ -1,6 +1,6 @@
from collections.abc import Mapping
from ctypes import c_int, c_int32, c_double, c_char_p, POINTER, \
create_string_buffer
create_string_buffer, c_size_t
from weakref import WeakValueDictionary
import numpy as np
@ -34,13 +34,10 @@ _dll.openmc_energy_filter_get_bins.errcheck = _error_handler
_dll.openmc_energy_filter_set_bins.argtypes = [c_int32, c_int32, POINTER(c_double)]
_dll.openmc_energy_filter_set_bins.restype = c_int
_dll.openmc_energy_filter_set_bins.errcheck = _error_handler
_dll.openmc_extend_filters.argtypes = [c_int32, POINTER(c_int32), POINTER(c_int32)]
_dll.openmc_extend_filters.restype = c_int
_dll.openmc_extend_filters.errcheck = _error_handler
_dll.openmc_filter_get_id.argtypes = [c_int32, POINTER(c_int32)]
_dll.openmc_filter_get_id.restype = c_int
_dll.openmc_filter_get_id.errcheck = _error_handler
_dll.openmc_filter_get_type.argtypes = [c_int32, POINTER(c_char_p)]
_dll.openmc_filter_get_type.argtypes = [c_int32, c_char_p]
_dll.openmc_filter_get_type.restype = c_int
_dll.openmc_filter_get_type.errcheck = _error_handler
_dll.openmc_filter_set_id.argtypes = [c_int32, c_int32]
@ -74,7 +71,7 @@ _dll.openmc_meshsurface_filter_get_mesh.errcheck = _error_handler
_dll.openmc_meshsurface_filter_set_mesh.argtypes = [c_int32, c_int32]
_dll.openmc_meshsurface_filter_set_mesh.restype = c_int
_dll.openmc_meshsurface_filter_set_mesh.errcheck = _error_handler
_dll.openmc_new_filter.argtypes = [c_char_p, POINTER(c_int32_)]
_dll.openmc_new_filter.argtypes = [c_char_p, POINTER(c_int32)]
_dll.openmc_new_filter.restype = c_int
_dll.openmc_new_filter.errcheck = _error_handler
_dll.openmc_spatial_legendre_filter_get_order.argtypes = [c_int32, POINTER(c_int)]
@ -95,6 +92,7 @@ _dll.openmc_zernike_filter_get_order.errcheck = _error_handler
_dll.openmc_zernike_filter_set_order.argtypes = [c_int32, c_int]
_dll.openmc_zernike_filter_set_order.restype = c_int
_dll.openmc_zernike_filter_set_order.errcheck = _error_handler
_dll.tally_filters_size.restype = c_size_t
class Filter(_FortranObjectWithID):
__instances = WeakValueDictionary()
@ -410,7 +408,7 @@ class _FilterMapping(Mapping):
yield _get_filter(i + 1).id
def __len__(self):
return c_int32.in_dll(_dll, 'n_filters').value
return _dll.tally_filters_size()
def __repr__(self):
return repr(dict(self))

View file

@ -1,5 +1,5 @@
from collections.abc import Mapping
from ctypes import c_int, c_char_p, POINTER
from ctypes import c_int, c_char_p, POINTER, c_size_t
from weakref import WeakValueDictionary
import numpy as np
@ -23,7 +23,7 @@ _dll.openmc_load_nuclide.errcheck = _error_handler
_dll.openmc_nuclide_name.argtypes = [c_int, POINTER(c_char_p)]
_dll.openmc_nuclide_name.restype = c_int
_dll.openmc_nuclide_name.errcheck = _error_handler
_dll.nuclides_size.restype = c_int
_dll.nuclides_size.restype = c_size_t
def load_nuclide(name):

View file

@ -26,13 +26,10 @@ _dll.openmc_get_tally_index.errcheck = _error_handler
_dll.openmc_global_tallies.argtypes = [POINTER(POINTER(c_double))]
_dll.openmc_global_tallies.restype = c_int
_dll.openmc_global_tallies.errcheck = _error_handler
_dll.openmc_tally_allocate.argtypes = [c_int32, c_char_p]
_dll.openmc_tally_allocate.restype = c_int
_dll.openmc_tally_allocate.errcheck = _error_handler
_dll.openmc_tally_get_active.argtypes = [c_int32, POINTER(c_bool)]
_dll.openmc_tally_get_active.restype = c_int
_dll.openmc_tally_get_active.errcheck = _error_handler
_dll.openmc_tally_get_estimator.argtypes = [c_int32, POINTER(int32)]
_dll.openmc_tally_get_estimator.argtypes = [c_int32, POINTER(c_int)]
_dll.openmc_tally_get_estimator.restype = c_int
_dll.openmc_tally_get_estimator.errcheck = _error_handler
_dll.openmc_tally_get_id.argtypes = [c_int32, POINTER(c_int32)]
@ -196,7 +193,6 @@ class Tally(_FortranObjectWithID):
index = c_int32()
_dll.openmc_extend_tallies(1, index, None)
_dll.openmc_tally_allocate(index, b'generic')
index = index.value
else:
index = mapping[uid]._index

View file

@ -138,11 +138,13 @@ dataset_ndims(hid_t dset)
size_t
dataset_typesize(hid_t dset)
dataset_typesize(hid_t obj_id, const char* name)
{
hid_t dset = open_dataset(obj_id, name);
hid_t filetype = H5Dget_type(dset);
size_t n = H5Tget_size(filetype);
H5Tclose(filetype);
close_dataset(dset);
return n;
}

View file

@ -202,6 +202,12 @@ void read_mg_cross_sections_header()
ensure_exists(file_id, "energy_groups", true);
read_attribute(file_id, "energy_groups", data::num_energy_groups);
if (attribute_exists(file_id, "delayed_groups")) {
read_attribute(file_id, "delayed_groups", data::num_delayed_groups);
} else {
data::num_delayed_groups = 0;
}
ensure_exists(file_id, "group structure", true);
read_attribute(file_id, "group structure", data::rev_energy_bins);

View file

@ -888,6 +888,12 @@ void check_data_version(hid_t file_id)
}
}
extern "C" size_t
nuclides_size()
{
return data::nuclides.size();
}
//==============================================================================
// C API
//==============================================================================

View file

@ -415,7 +415,7 @@ void load_state_point()
#endif
// Read global tally data
read_dataset(file_id, "global_tallies", H5T_NATIVE_DOUBLE,
simulation::global_tallies.data());
simulation::global_tallies.data(), false);
// Check if tally results are present
bool present;

View file

@ -1,6 +1,7 @@
#include "openmc/tallies/filter.h"
#include <algorithm> // for max
#include <cstring> // for strcpy
#include <string>
#include "openmc/capi.h"
@ -102,6 +103,11 @@ allocate_filter(const std::string& type)
return model::tally_filters.back().get();
}
extern "C" size_t tally_filters_size()
{
return model::tally_filters.size();
}
//==============================================================================
// C API functions
//==============================================================================
@ -144,13 +150,14 @@ openmc_filter_set_id(int32_t index, int32_t id)
}
extern "C" int
openmc_filter_get_type(int32_t index, const char** type)
openmc_filter_get_type(int32_t index, char* type)
{
int err = verify_filter(index);
if (err) return err;
// TODO: off-by-one
*type = model::tally_filters[index-1]->type().c_str();
std::strcpy(type, model::tally_filters[index-1]->type().c_str());
return 0;
}
extern "C" int

View file

@ -224,6 +224,11 @@ score_str_to_int(std::string score_str)
// Tally object implementation
//==============================================================================
Tally::Tally()
{
this->set_filters(nullptr, 0);
}
void
Tally::init_from_xml(pugi::xml_node node)
{
@ -1062,7 +1067,8 @@ openmc_get_tally_index(int32_t id, int32_t* index)
return OPENMC_E_INVALID_ID;
}
*index = it->second;
// TODO: off-by-one
*index = it->second + 1;
return 0;
}
@ -1143,6 +1149,7 @@ openmc_tally_set_id(int32_t index, int32_t id)
// TODO: off-by-one
model::tallies[index-1]->id_ = id;
model::tally_map[id] = index - 1;
return 0;
}