mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Load new serializable form of source function
Updates the SourceDistribution to optionally look for a function template accepting char* as the second argument. If serialization is defined as an attribute on the source element provided in the settings.xml then the new form with serialization will be used. Otherwise the existing form to load the custom source as-is from the library will be used.
This commit is contained in:
parent
6b193882c3
commit
67e846c4d5
1 changed files with 21 additions and 4 deletions
|
|
@ -46,6 +46,9 @@ namespace {
|
|||
|
||||
using sample_t = Particle::Bank (*)(uint64_t* seed);
|
||||
sample_t custom_source_function;
|
||||
std::string serialization;
|
||||
using serialized_sample_t = Particle::Bank (*)(uint64_t* seed, const char* serialization);
|
||||
serialized_sample_t custom_serialized_source_function;
|
||||
void* custom_source_library;
|
||||
|
||||
}
|
||||
|
|
@ -94,6 +97,10 @@ SourceDistribution::SourceDistribution(pugi::xml_node node)
|
|||
fatal_error(fmt::format("Source library '{}' does not exist.",
|
||||
settings::path_source_library));
|
||||
}
|
||||
|
||||
if (check_for_node(node, "serialization")) {
|
||||
serialization = get_node_value(node, "serialization", false, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
// Spatial distribution for external source
|
||||
|
|
@ -367,9 +374,15 @@ void load_custom_source_library()
|
|||
// reset errors
|
||||
dlerror();
|
||||
|
||||
// get the function from the library
|
||||
using sample_t = Particle::Bank (*)(uint64_t* seed);
|
||||
custom_source_function = reinterpret_cast<sample_t>(dlsym(custom_source_library, "sample_source"));
|
||||
if (serialization.empty()) {
|
||||
// get the function from the library
|
||||
using sample_t = Particle::Bank (*)(uint64_t* seed);
|
||||
custom_source_function = reinterpret_cast<sample_t>(dlsym(custom_source_library, "sample_source"));
|
||||
} else {
|
||||
// get the function from the library using the provided serialization
|
||||
using sample_t = Particle::Bank (*)(uint64_t* seed, const char* serialization);
|
||||
custom_serialized_source_function = reinterpret_cast<sample_t>(dlsym(custom_source_library, "sample_source"));
|
||||
}
|
||||
|
||||
// check for any dlsym errors
|
||||
auto dlsym_error = dlerror();
|
||||
|
|
@ -396,7 +409,11 @@ void close_custom_source_library()
|
|||
|
||||
Particle::Bank sample_custom_source_library(uint64_t* seed)
|
||||
{
|
||||
return custom_source_function(seed);
|
||||
if (serialization.empty()) {
|
||||
return custom_source_function(seed);
|
||||
} else {
|
||||
return custom_serialized_source_function(seed, serialization.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void fill_source_bank_custom_source()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue