Commit 5fbae7ca authored by lavistam's avatar lavistam

Moving special case of keff calculation (n<=3) to cpp side

parent b3b021f0
......@@ -230,18 +230,9 @@ def keff():
Mean k-eigenvalue and standard deviation of the mean
"""
n = openmc.capi.num_realizations()
if n > 3:
# Use the combined estimator if there are enough realizations
k = (c_double*2)()
_dll.openmc_get_keff(k)
return tuple(k)
else:
# Otherwise, return the tracklength estimator
mean = c_double.in_dll(_dll, 'keff').value
std_dev = c_double.in_dll(_dll, 'keff_std').value \
if n > 1 else np.inf
return (mean, std_dev)
k = (c_double*2)()
_dll.openmc_get_keff(k)
return tuple(k)
def master():
......
......@@ -29,6 +29,7 @@
#include <cmath> // for sqrt, abs, pow
#include <iterator> // for back_inserter
#include <string>
#include <limits> //for infinity
namespace openmc {
......@@ -388,10 +389,15 @@ int openmc_get_keff(double* k_combined)
k_combined[0] = 0.0;
k_combined[1] = 0.0;
// Make sure we have at least four realizations. Notice that at the end,
// there is a N-3 term in a denominator.
//Special case for n <=3. Notice that at the end,
//there is a N-3 term in a denominator.
if (simulation::n_realizations <= 3) {
return -1;
k_combined[0] = simulation::keff;
k_combined[1] = simulation::keff_std;
if (simulation::n_realizations <=1){
k_combined[1] = std::numeric_limits<double>::infinity();
}
return 0;
}
// Initialize variables
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment