Commit 3fc2c2f8 authored by Sterling Harper's avatar Sterling Harper Committed by GitHub

Merge pull request #1234 from matiaslavista/develop_clean

Moving special case of keff calculation (n<=3) to cpp side
parents b3b021f0 8fd5d76d
......@@ -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,
// 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
......
k-combined:
0.000000E+00 0.000000E+00
5.497140E-02 INF
tally 1:
1.548980E-02
2.399339E-04
......
k-combined:
0.000000E+00 0.000000E+00
2.149726E-02 INF
tally 1:
7.588170E-03
5.758032E-05
......
11755ecac8355b5e79384f5d72974e618b6f95500c0a5718c01bb340c5d1c8ceafc33de65b9e94b7e9d78f16ec209f8a0fdf6a531eab5430657688d0125db7ef
\ No newline at end of file
2ee0162762999f71ad2178936509fd9e054928023a9e0e90c078cede3ecf6583267069486adf15f1b02188333d1bfe1fc41b341bc00aab53feddd1395441f1f8
\ No newline at end of file
k-combined:
0.000000E+00 0.000000E+00
1.121246E-01 INF
tally 1:
2.265319E-02
5.131668E-04
......
k-combined:
0.000000E+00 0.000000E+00
2.976389E-01 3.770725E-03
1.892327E+00 -3.385257E+00 6.702632E-01
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