Skip to content

Commit

Permalink
Merge pull request neams-th-coe#853 from aprilnovak/std_dev_bug
Browse files Browse the repository at this point in the history
Fix bug in tally relative error calculation.
  • Loading branch information
aprilnovak authored Feb 27, 2024
2 parents a3a6201 + 535051e commit df9dd54
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/base/OpenMCCellAverageProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@ class OpenMCCellAverageProblem : public OpenMCProblemBase

/**
* Local tallies; multiple tallies will only exist when
* translating multiple unstructured meshes throughout the geometry
* translating multiple unstructured meshes throughout the geometry. Each tally
* may have multiple scores which are simultaneously tracked.
*/
std::vector<openmc::Tally *> _local_tally;

Expand Down
3 changes: 2 additions & 1 deletion src/base/OpenMCCellAverageProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,8 @@ OpenMCCellAverageProblem::relaxAndNormalizeTally(const int & t, const unsigned i
auto mean_tally = tallySum(tally, score);
current_raw = normalizeLocalTally(mean_tally, score);

auto sum_sq = xt::view(tally->results_, xt::all(), 0, static_cast<int>(openmc::TallyResult::SUM_SQ));
auto sum_sq =
xt::view(tally->results_, xt::all(), score, static_cast<int>(openmc::TallyResult::SUM_SQ));
auto rel_err = relativeError(mean_tally, sum_sq, tally->n_realizations_);
current_raw_std_dev = rel_err * current_raw;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
time,heating_max,heating_min,kf_max,kf_min,max_ht,max_kf,min_ht,min_kf
0,0,0,0,0,0,0,0,0
1,0.035555464514196,0.029889937640975,0.035548762735905,0.029978352900852,0.035555464514196,0.035548762735905,0.029889937640975,0.029978352900852
106 changes: 106 additions & 0 deletions test/tests/postprocessors/fission_tally_relative_error/ratio.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
[Mesh]
[sphere]
type = FileMeshGenerator
file = ../../neutronics/meshes/sphere.e
[]
[solid]
type = CombinerGenerator
inputs = sphere
positions = '0 0 0
0 0 4
0 0 8'
[]
[]

[Problem]
type = OpenMCCellAverageProblem
power = 100.0
tally_blocks = '1'
cell_level = 0
tally_type = cell
check_tally_sum = false

tally_score = 'heating kappa_fission'
output = 'unrelaxed_tally_std_dev'
initial_properties = xml
[]

# the ratio of the std_dev variable and the output tally should give
# the relative error in the tallies.out
[AuxVariables]
[heating_rel_err]
family = MONOMIAL
order = CONSTANT
[]
[kappa_fission_rel_err]
family = MONOMIAL
order = CONSTANT
[]
[]

[AuxKernels]
[heating]
type = ParsedAux
variable = heating_rel_err
expression = 'heating_std_dev / heating'
coupled_variables = 'heating_std_dev heating'
[]
[kappa_fission]
type = ParsedAux
variable = kappa_fission_rel_err
expression = 'kappa_fission_std_dev / kappa_fission'
coupled_variables = 'kappa_fission_std_dev kappa_fission'
[]
[]

[Executioner]
type = Transient
num_steps = 1
[]

[Postprocessors]
[heating_max]
type = ElementExtremeValue
value_type = max
variable = heating_rel_err
[]
[heating_min]
type = ElementExtremeValue
value_type = min
variable = heating_rel_err
[]
[kf_max]
type = ElementExtremeValue
value_type = max
variable = kappa_fission_rel_err
[]
[kf_min]
type = ElementExtremeValue
value_type = min
variable = kappa_fission_rel_err
[]
[max_ht]
type = TallyRelativeError
value_type = max
tally_score = 'heating'
[]
[min_ht]
type = TallyRelativeError
value_type = min
tally_score = 'heating'
[]
[max_kf]
type = TallyRelativeError
value_type = max
tally_score = 'kappa_fission'
[]
[min_kf]
type = TallyRelativeError
value_type = min
tally_score = 'kappa_fission'
[]
[]

[Outputs]
csv = true
[]
10 changes: 10 additions & 0 deletions test/tests/postprocessors/fission_tally_relative_error/tests
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@
requirement = "The system shall error if trying to specify more than one score per postprocessor"
required_objects = 'OpenMCCellAverageProblem'
[]
[manual_rel_err_calc]
type = CSVDiff
input = ratio.i
csvdiff = 'ratio_out.csv'
# This test has very few particles, and OpenMC will error if there aren't enough source particles
# in the fission bank on a process
max_parallel = 8
requirement = "The system shall prove equivalence between a by-hand calculation of relative error (std_dev output divided by tally value) as compared to the tally relative error postprocessor."
required_objects = 'OpenMCCellAverageProblem'
[]
[]

0 comments on commit df9dd54

Please sign in to comment.