From 475656e6e030cc7e9a77ecab8a255f5986a8a8ec Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 5 Aug 2020 16:10:04 +0100 Subject: [PATCH] Simplify test and fix typos in documentation --- docs/source/usersguide/settings.rst | 4 +- .../parameterized_source_sampling.cpp | 37 +++---------------- 2 files changed, 8 insertions(+), 33 deletions(-) diff --git a/docs/source/usersguide/settings.rst b/docs/source/usersguide/settings.rst index 7bb8875be..30bf71132 100644 --- a/docs/source/usersguide/settings.rst +++ b/docs/source/usersguide/settings.rst @@ -288,8 +288,8 @@ the custom source, based on the value supplied in the // you must have external C linkage here otherwise // dlopen will not find the file - extern "C" ParameterizedSource* openmc_create_source(const char* parameterized_source) { - return new ParameterizedSource(std::stod(parameters)); + extern "C" ParameterizedSource* openmc_create_source(const char* parameter) { + return new ParameterizedSource(atof(parameter)); } As with the basic custom source functionality, the custom source library diff --git a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp index 9fcb841d0..b3e9ca9cd 100644 --- a/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp +++ b/tests/regression_tests/source_parameterized_dlopen/parameterized_source_sampling.cpp @@ -1,37 +1,12 @@ -#include - -#include "openmc/random_lcg.h" #include "openmc/source.h" #include "openmc/particle.h" class ParameterizedSource : public openmc::CustomSource { - protected: - double energy_; - - // Protect the constructor so that the class can only be created by serialisation. - ParameterizedSource(double energy) { - energy_ = energy; - } - public: - // Getters for the values that we want to use in sampling. - double energy() { return energy_; } + double energy; - // Defines a function that can create a pointer to a new instance of this class - // by deserializing from the provided string. - static ParameterizedSource* from_string(const char* parameters) { - std::unordered_map parameter_mapping; - - std::stringstream ss(parameters); - std::string parameter; - while (std::getline(ss, parameter, ',')) { - parameter.erase(0, parameter.find_first_not_of(' ')); - std::string key = parameter.substr(0, parameter.find_first_of('=')); - std::string value = parameter.substr(parameter.find_first_of('=') + 1, parameter.length()); - parameter_mapping[key] = value; - } - - return new ParameterizedSource(std::stod(parameter_mapping["energy"])); + ParameterizedSource(double energy) { + this->energy = energy; } // Samples from an instance of this class. @@ -46,7 +21,7 @@ class ParameterizedSource : public openmc::CustomSource { particle.r.z = 0.0; // angle particle.u = {1.0, 0.0, 0.0}; - particle.E = this->energy(); + particle.E = this->energy; particle.delayed_group = 0; return particle; @@ -55,6 +30,6 @@ class ParameterizedSource : public openmc::CustomSource { // you must have external C linkage here otherwise // dlopen will not find the file -extern "C" ParameterizedSource* openmc_create_source(const char* parameters) { - return ParameterizedSource::from_string(parameters); +extern "C" ParameterizedSource* openmc_create_source(const char* parameter) { + return new ParameterizedSource(atof(parameter)); }