diff --git a/examples/serialized_custom_source/CMakeLists.txt b/examples/parameterized_custom_source/CMakeLists.txt similarity index 57% rename from examples/serialized_custom_source/CMakeLists.txt rename to examples/parameterized_custom_source/CMakeLists.txt index 9d76718e5..3024e90cf 100644 --- a/examples/serialized_custom_source/CMakeLists.txt +++ b/examples/parameterized_custom_source/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(openmc_sources CXX) -add_library(serialized_source SHARED serialized_source_ring.cpp) +add_library(parameterized_source SHARED parameterized_source_ring.cpp) find_package(OpenMC REQUIRED) if (OpenMC_FOUND) message(STATUS "Found OpenMC: ${OpenMC_DIR}") endif() -target_link_libraries(serialized_source OpenMC::libopenmc) +target_link_libraries(parameterized_source OpenMC::libopenmc) diff --git a/examples/parameterized_custom_source/README.md b/examples/parameterized_custom_source/README.md new file mode 100644 index 000000000..9116fadea --- /dev/null +++ b/examples/parameterized_custom_source/README.md @@ -0,0 +1,23 @@ +# Building a Parameterized Custom Source + +To run this example, you first need to compile the custom source library, which +requires headers from OpenMC. A CMakeLists.txt file has been set up for you that +will search for OpenMC and build the custom library. To build the source +library, you can run: + + mkdir build && cd build + OPENMC_ROOT= cmake .. + make + +After this, you can build the model by running `python build_xml.py`. In the XML +files that are created, you should see a reference to build/libparameterized_source.so, +the custom source library that was built by CMake, and values in the parameters +attribute. The model is also set up with a mesh tally of the flux, so once you run +`openmc`, you will get a statepoint file with the tally results in it. Running +`python show_flux.py` will pull in the results from the statepoint file and display +them. If all worked well, you should see a ring "imprint" as well as a higher flux to +the right side (since the custom source has all particles moving in the positive x +direction). + +Once built, you can edit the parameters attribute on the source to change the radius of +the sampled ring or the energy of the sampled particles. diff --git a/examples/serialized_custom_source/build_xml.py b/examples/parameterized_custom_source/build_xml.py similarity index 95% rename from examples/serialized_custom_source/build_xml.py rename to examples/parameterized_custom_source/build_xml.py index 31ba2ac3e..5edb204df 100644 --- a/examples/serialized_custom_source/build_xml.py +++ b/examples/parameterized_custom_source/build_xml.py @@ -19,7 +19,7 @@ settings.run_mode = 'fixed source' settings.batches = 10 settings.particles = 1000 source = openmc.Source() -source.library = 'build/libserialized_source.so' +source.library = 'build/libparameterized_source.so' source.parameters = 'radius=3.0, energy=14.08e6' settings.source = source settings.export_to_xml() diff --git a/examples/serialized_custom_source/serialized_source_ring.cpp b/examples/parameterized_custom_source/parameterized_source_ring.cpp similarity index 81% rename from examples/serialized_custom_source/serialized_source_ring.cpp rename to examples/parameterized_custom_source/parameterized_source_ring.cpp index 7584b152c..7b0089090 100644 --- a/examples/serialized_custom_source/serialized_source_ring.cpp +++ b/examples/parameterized_custom_source/parameterized_source_ring.cpp @@ -5,13 +5,13 @@ #include "openmc/source.h" #include "openmc/particle.h" -class SerializedSource : public openmc::CustomSource { +class ParameterizedSource : public openmc::CustomSource { protected: double radius_; double energy_; // Protect the constructor so that the class can only be created by serialisation. - SerializedSource(double radius, double energy) { + ParameterizedSource(double radius, double energy) { radius_ = radius; energy_ = energy; } @@ -23,7 +23,7 @@ class SerializedSource : public openmc::CustomSource { // Defines a function that can create a pointer to a new instance of this class // by deserializing from the provided string. - static SerializedSource* from_string(const char* parameters) { + static ParameterizedSource* from_string(const char* parameters) { std::unordered_map parameter_mapping; std::stringstream ss(parameters); @@ -35,7 +35,7 @@ class SerializedSource : public openmc::CustomSource { parameter_mapping[key] = value; } - return new SerializedSource(std::stod(parameter_mapping["radius"]), std::stod(parameter_mapping["energy"])); + return new ParameterizedSource(std::stod(parameter_mapping["radius"]), std::stod(parameter_mapping["energy"])); } // Samples from an instance of this class. @@ -62,13 +62,13 @@ class SerializedSource : public openmc::CustomSource { // A function to create a pointer to an instance of this class when generated // via a plugin call using dlopen/dlsym. // You must have external C linkage here otherwise dlopen will not find the file -extern "C" SerializedSource* create(const char* parameters) { - return SerializedSource::from_string(parameters); +extern "C" ParameterizedSource* create(const char* parameters) { + return ParameterizedSource::from_string(parameters); } // A function to destroy a pointer to an instance of this class when generated // via a plugin call using dlopen/dlsym. // You must have external C linkage here otherwise dlopen will not find the file -extern "C" void destroy(SerializedSource* source) { +extern "C" void destroy(ParameterizedSource* source) { delete source; } diff --git a/examples/serialized_custom_source/show_flux.py b/examples/parameterized_custom_source/show_flux.py similarity index 100% rename from examples/serialized_custom_source/show_flux.py rename to examples/parameterized_custom_source/show_flux.py diff --git a/examples/serialized_custom_source/README.md b/examples/serialized_custom_source/README.md deleted file mode 100644 index d5c5ee120..000000000 --- a/examples/serialized_custom_source/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Building a Serialized Custom Source - -To run this example, you first need to compile the custom source library, which -requires headers from OpenMC. A CMakeLists.txt file has been set up for you that -will search for OpenMC and build the custom library. To build the source -library, you can run: - - mkdir build && cd build - OPENMC_ROOT= cmake .. - make - -After this, you can build the model by running `python build_xml.py`. In the XML -files that are created, you should see a reference to build/libserialized_source.so, -the custom source library that was built by CMake, and the serialized representation -of the source in the parameters attribute. The model is also set up with a mesh tally -of the flux, so once you run `openmc`, you will get a statepoint file with the tally -results in it. Running `python show_flux.py` will pull in the results from the -statepoint file and display them. If all worked well, you should see a ring "imprint" -as well as a higher flux to the right side (since the custom source has all particles -moving in the positive x direction). - -Once built, you can edit the parameters attribute on the source to change the radius of -the sampled ring or the energy of the sampled particles. diff --git a/include/openmc/source.h b/include/openmc/source.h index bd24f093f..2492cb2b7 100644 --- a/include/openmc/source.h +++ b/include/openmc/source.h @@ -66,7 +66,7 @@ class CustomSource { virtual Particle::Bank sample_source(uint64_t* seed) = 0; }; -typedef CustomSource* create_custom_source_t(const char* serialized_source); +typedef CustomSource* create_custom_source_t(const char* parameters); typedef void destroy_custom_source_t(CustomSource*); //============================================================================== diff --git a/tests/regression_tests/source_serialized_dlopen/__init__.py b/tests/regression_tests/source_parameterized_dlopen/__init__.py similarity index 100% rename from tests/regression_tests/source_serialized_dlopen/__init__.py rename to tests/regression_tests/source_parameterized_dlopen/__init__.py diff --git a/tests/regression_tests/source_serialized_dlopen/inputs_true.dat b/tests/regression_tests/source_parameterized_dlopen/inputs_true.dat similarity index 87% rename from tests/regression_tests/source_serialized_dlopen/inputs_true.dat rename to tests/regression_tests/source_parameterized_dlopen/inputs_true.dat index c7765d20a..a7462ae7f 100644 --- a/tests/regression_tests/source_serialized_dlopen/inputs_true.dat +++ b/tests/regression_tests/source_parameterized_dlopen/inputs_true.dat @@ -19,5 +19,5 @@ 1000 10 0 - + diff --git a/tests/regression_tests/source_serialized_dlopen/serialized_source_sampling.cpp b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp similarity index 79% rename from tests/regression_tests/source_serialized_dlopen/serialized_source_sampling.cpp rename to tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp index a951ef3cd..b50c9d284 100644 --- a/tests/regression_tests/source_serialized_dlopen/serialized_source_sampling.cpp +++ b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp @@ -4,12 +4,12 @@ #include "openmc/source.h" #include "openmc/particle.h" -class SerializedSource : public openmc::CustomSource { +class ParameterizedSource : public openmc::CustomSource { protected: double energy_; // Protect the constructor so that the class can only be created by serialisation. - SerializedSource(double energy) { + ParameterizedSource(double energy) { energy_ = energy; } @@ -19,7 +19,7 @@ class SerializedSource : public openmc::CustomSource { // Defines a function that can create a pointer to a new instance of this class // by deserializing from the provided string. - static SerializedSource* from_string(const char* parameters) { + static ParameterizedSource* from_string(const char* parameters) { std::unordered_map parameter_mapping; std::stringstream ss(parameters); @@ -31,7 +31,7 @@ class SerializedSource : public openmc::CustomSource { parameter_mapping[key] = value; } - return new SerializedSource(std::stod(parameter_mapping["energy"])); + return new ParameterizedSource(std::stod(parameter_mapping["energy"])); } // Samples from an instance of this class. @@ -55,12 +55,12 @@ class SerializedSource : public openmc::CustomSource { // you must have external C linkage here otherwise // dlopen will not find the file -extern "C" SerializedSource* create(const char* serialized_source) { - return SerializedSource::from_string(serialized_source); +extern "C" ParameterizedSource* create(const char* parameters) { + return ParameterizedSource::from_string(parameters); } // you must have external C linkage here otherwise // dlopen will not find the file -extern "C" void destroy(SerializedSource* source) { +extern "C" void destroy(ParameterizedSource* source) { delete source; } diff --git a/tests/regression_tests/source_serialized_dlopen/results_true.dat b/tests/regression_tests/source_parameterized_dlopen/results_true.dat similarity index 100% rename from tests/regression_tests/source_serialized_dlopen/results_true.dat rename to tests/regression_tests/source_parameterized_dlopen/results_true.dat diff --git a/tests/regression_tests/source_serialized_dlopen/test.py b/tests/regression_tests/source_parameterized_dlopen/test.py similarity index 90% rename from tests/regression_tests/source_serialized_dlopen/test.py rename to tests/regression_tests/source_parameterized_dlopen/test.py index 09ed11be3..6c88c37c2 100644 --- a/tests/regression_tests/source_serialized_dlopen/test.py +++ b/tests/regression_tests/source_parameterized_dlopen/test.py @@ -20,9 +20,9 @@ def compile_source(request): f.write(textwrap.dedent(""" cmake_minimum_required(VERSION 3.3 FATAL_ERROR) project(openmc_sources CXX) - add_library(serialized_source SHARED serialized_source_sampling.cpp) + add_library(parameterized_source SHARED parameterized_source_sampling.cpp) find_package(OpenMC REQUIRED HINTS {}) - target_link_libraries(serialized_source OpenMC::libopenmc) + target_link_libraries(parameterized_source OpenMC::libopenmc) """.format(openmc_dir))) # Create temporary build directory and change to there @@ -63,7 +63,7 @@ def model(): # custom source from shared library source = openmc.Source() - source.library = 'build/libserialized_source.so' + source.library = 'build/libparameterized_source.so' source.parameters = 'energy=1e3' model.settings.source = source