mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Requested updates to source
Rename sample_source -> sample. Use std::string as type of argument to openmc_create_source. Use reinterpret_cast when accessing dlsym. Also moves check for dlerror to be before the attempt to create the source (avoids null reference if fails) and capture error message before dlclose, so that the error message is still available. Formatting updates and some refactoring for examples and tests.
This commit is contained in:
parent
9435020197
commit
21e8d91e90
6 changed files with 40 additions and 49 deletions
|
|
@ -46,7 +46,7 @@ std::vector<SourceDistribution> external_sources;
|
|||
namespace {
|
||||
|
||||
void* custom_source_library;
|
||||
std::string custom_source_parameters = "";
|
||||
std::string custom_source_parameters;
|
||||
std::unique_ptr<CustomSource> custom_source;
|
||||
|
||||
}
|
||||
|
|
@ -373,18 +373,20 @@ void load_custom_source_library()
|
|||
dlerror();
|
||||
|
||||
// get the function to create the CustomSource from the library
|
||||
create_custom_source_t* create_custom_source = (create_custom_source_t*) dlsym(custom_source_library, "openmc_create_source");
|
||||
|
||||
// create a pointer to an instance of the CustomSource
|
||||
custom_source = create_custom_source(custom_source_parameters.c_str());
|
||||
auto create_custom_source = reinterpret_cast<create_custom_source_t*>(
|
||||
dlsym(custom_source_library, "openmc_create_source"));
|
||||
|
||||
// check for any dlsym errors
|
||||
auto dlsym_error = dlerror();
|
||||
if (dlsym_error) {
|
||||
std::string error_msg = fmt::format("Couldn't open the openmc_create_source symbol: {}", dlsym_error);
|
||||
dlclose(custom_source_library);
|
||||
fatal_error(fmt::format("Couldn't open the sample_source symbol: {}", dlsym_error));
|
||||
fatal_error(error_msg);
|
||||
}
|
||||
|
||||
// create a pointer to an instance of the CustomSource
|
||||
custom_source = create_custom_source(custom_source_parameters);
|
||||
|
||||
#else
|
||||
fatal_error("Custom source libraries have not yet been implemented for "
|
||||
"non-POSIX systems");
|
||||
|
|
@ -409,7 +411,7 @@ void close_custom_source_library()
|
|||
Particle::Bank sample_custom_source_library(uint64_t* seed)
|
||||
{
|
||||
// sample from the instance of the CustomSource
|
||||
return custom_source->sample_source(seed);
|
||||
return custom_source->sample(seed);
|
||||
}
|
||||
|
||||
void fill_source_bank_custom_source()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue