From cba132c4b487a2c8cd6318f6a049354575e2a7f4 Mon Sep 17 00:00:00 2001 From: John Tramm Date: Mon, 24 Feb 2025 17:25:11 -0600 Subject: [PATCH] Random Ray Linear Source Stability Improvement (#3322) --- src/random_ray/linear_source_domain.cpp | 16 +- .../linear/results_true.dat | 12 +- .../linear_xy/results_true.dat | 12 +- .../linear_xy/results_true.dat | 168 +++++++++--------- .../test.py | 2 +- .../random_ray_void/linear/results_true.dat | 12 +- .../hybrid/results_true.dat | 12 +- .../naive/results_true.dat | 12 +- .../simulation_averaged/results_true.dat | 12 +- 9 files changed, 132 insertions(+), 126 deletions(-) diff --git a/src/random_ray/linear_source_domain.cpp b/src/random_ray/linear_source_domain.cpp index a8300ba3f..3819c7d70 100644 --- a/src/random_ray/linear_source_domain.cpp +++ b/src/random_ray/linear_source_domain.cpp @@ -78,13 +78,19 @@ void LinearSourceDomain::update_neutron_source(double k_eff) source_regions_.source(sr, g_out) = (scatter_flat + fission_flat * inverse_k_eff) / sigma_t; - // Compute the linear source terms - // In the first 10 iterations when the centroids and spatial moments - // are not well known, we will leave the source gradients as zero - // so as to avoid causing any numerical instability. - if (simulation::current_batch > 10) { + // Compute the linear source terms. In the first 10 iterations when the + // centroids and spatial moments are not well known, we will leave the + // source gradients as zero so as to avoid causing any numerical + // instability. If a negative source is encountered, this region must be + // very small/noisy or have poorly developed spatial moments, so we zero + // the source gradients (effectively making this a flat source region + // temporarily), so as to improve stability. + if (simulation::current_batch > 10 && + source_regions_.source(sr, g_out) >= 0.0) { source_regions_.source_gradients(sr, g_out) = invM * ((scatter_linear + fission_linear * inverse_k_eff) / sigma_t); + } else { + source_regions_.source_gradients(sr, g_out) = {0.0, 0.0, 0.0}; } } } diff --git a/tests/regression_tests/random_ray_fixed_source_linear/linear/results_true.dat b/tests/regression_tests/random_ray_fixed_source_linear/linear/results_true.dat index 46200b19c..2fc08d0a4 100644 --- a/tests/regression_tests/random_ray_fixed_source_linear/linear/results_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_linear/linear/results_true.dat @@ -1,9 +1,9 @@ tally 1: -2.339084E+00 -2.747299E-01 +2.339085E+00 +2.747304E-01 tally 2: -1.090051E-01 -6.073265E-04 +1.089827E-01 +6.069324E-04 tally 3: -7.300117E-03 -2.715425E-06 +7.300831E-03 +2.715940E-06 diff --git a/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/results_true.dat b/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/results_true.dat index ea711a925..f4c8546aa 100644 --- a/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/results_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_linear/linear_xy/results_true.dat @@ -1,9 +1,9 @@ tally 1: -2.335701E+00 -2.742860E-01 +2.335703E+00 +2.742866E-01 tally 2: -1.081600E-01 -5.980902E-04 +1.081884E-01 +5.983316E-04 tally 3: -7.295015E-03 -2.711589E-06 +7.295389E-03 +2.711859E-06 diff --git a/tests/regression_tests/random_ray_fixed_source_subcritical/linear_xy/results_true.dat b/tests/regression_tests/random_ray_fixed_source_subcritical/linear_xy/results_true.dat index 43a6d8258..49813144d 100644 --- a/tests/regression_tests/random_ray_fixed_source_subcritical/linear_xy/results_true.dat +++ b/tests/regression_tests/random_ray_fixed_source_subcritical/linear_xy/results_true.dat @@ -1,168 +1,168 @@ tally 1: -1.583461E+02 -1.007023E+03 +1.583465E+02 +1.007029E+03 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.891511E+01 -1.392800E+02 +5.891526E+01 +1.392807E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.028333E+01 -1.649217E+01 +2.028338E+01 +1.649224E+01 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.453681E+01 -2.413486E+01 +2.453687E+01 +2.413498E+01 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.235799E+01 -1.099237E+02 +5.235812E+01 +1.099243E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -9.394382E+01 -3.543494E+02 +9.394406E+01 +3.543513E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.676269E+01 -1.303097E+02 +5.676284E+01 +1.303104E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.007853E+02 -1.616208E+03 +2.007858E+02 +1.616216E+03 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -7.319692E+01 -2.146291E+02 +7.319709E+01 +2.146301E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.566725E+01 -2.640687E+01 +2.566730E+01 +2.640697E+01 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.934697E+01 -3.453012E+01 +2.934703E+01 +3.453026E+01 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.737202E+01 -1.318574E+02 +5.737215E+01 +1.318580E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -9.495251E+01 -3.613355E+02 +9.495275E+01 +3.613372E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.799236E+01 -1.356172E+02 +5.799250E+01 +1.356178E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -1.066411E+02 -4.570264E+02 -1.254011E+01 -6.325603E+00 -3.052011E+01 -3.746896E+01 -4.977289E+01 -9.940494E+01 -2.345784E+00 -2.208432E-01 -5.709169E+00 -1.308139E+00 -1.953078E+01 -1.528285E+01 -1.998229E-01 -1.599785E-03 -4.863290E-01 -9.476135E-03 -2.307190E+01 -2.133049E+01 -2.432475E-01 -2.371063E-03 -5.920158E-01 -1.404471E-02 -5.299849E+01 -1.125570E+02 -1.959909E-01 -1.539183E-03 -4.770085E-01 -9.117394E-03 -1.186130E+02 -5.641029E+02 -5.781214E-02 -1.341752E-04 -1.430521E-01 -8.215282E-04 -7.995712E+01 -2.570085E+02 -3.452925E-01 -4.844032E-03 -9.604136E-01 -3.747567E-02 -1.556790E+02 -9.726171E+02 +1.066414E+02 +4.570291E+02 +1.254014E+01 +6.325640E+00 +3.052020E+01 +3.746918E+01 +4.977302E+01 +9.940548E+01 +2.345790E+00 +2.208444E-01 +5.709184E+00 +1.308146E+00 +1.953082E+01 +1.528292E+01 +1.998234E-01 +1.599792E-03 +4.863302E-01 +9.476180E-03 +2.307196E+01 +2.133059E+01 +2.432481E-01 +2.371074E-03 +5.920173E-01 +1.404478E-02 +5.299862E+01 +1.125576E+02 +1.959914E-01 +1.539191E-03 +4.770098E-01 +9.117441E-03 +1.186133E+02 +5.641060E+02 +5.781230E-02 +1.341759E-04 +1.430525E-01 +8.215326E-04 +7.995734E+01 +2.570099E+02 +3.452934E-01 +4.844058E-03 +9.604162E-01 +3.747587E-02 +1.556795E+02 +9.726232E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.816710E+01 -1.357523E+02 +5.816726E+01 +1.357531E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.018475E+01 -1.633543E+01 +2.018480E+01 +1.633551E+01 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -2.453470E+01 -2.413604E+01 +2.453476E+01 +2.413615E+01 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.269366E+01 -1.113096E+02 +5.269380E+01 +1.113102E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -9.550190E+01 -3.658245E+02 +9.550216E+01 +3.658264E+02 0.000000E+00 0.000000E+00 0.000000E+00 0.000000E+00 -5.846305E+01 -1.379618E+02 +5.846320E+01 +1.379625E+02 0.000000E+00 0.000000E+00 0.000000E+00 diff --git a/tests/regression_tests/random_ray_fixed_source_subcritical/test.py b/tests/regression_tests/random_ray_fixed_source_subcritical/test.py index 6c2c569c6..e2f3cf175 100644 --- a/tests/regression_tests/random_ray_fixed_source_subcritical/test.py +++ b/tests/regression_tests/random_ray_fixed_source_subcritical/test.py @@ -17,7 +17,7 @@ class MGXSTestHarness(TolerantPyAPITestHarness): @pytest.mark.parametrize("shape", ["flat", "linear_xy"]) -def test_random_ray_source(shape): +def test_random_ray_fixed_source_subcritical(shape): with change_directory(shape): openmc.reset_auto_ids() diff --git a/tests/regression_tests/random_ray_void/linear/results_true.dat b/tests/regression_tests/random_ray_void/linear/results_true.dat index e289b2f13..befa507a5 100644 --- a/tests/regression_tests/random_ray_void/linear/results_true.dat +++ b/tests/regression_tests/random_ray_void/linear/results_true.dat @@ -1,9 +1,9 @@ tally 1: -2.356821E+00 -2.782548E-01 +2.356818E+00 +2.782542E-01 tally 2: -1.082935E-01 -6.029854E-04 +1.082843E-01 +6.028734E-04 tally 3: -7.301975E-03 -2.717553E-06 +7.302705E-03 +2.718076E-06 diff --git a/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/results_true.dat b/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/results_true.dat index 46200b19c..2fc08d0a4 100644 --- a/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/results_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator_linear/hybrid/results_true.dat @@ -1,9 +1,9 @@ tally 1: -2.339084E+00 -2.747299E-01 +2.339085E+00 +2.747304E-01 tally 2: -1.090051E-01 -6.073265E-04 +1.089827E-01 +6.069324E-04 tally 3: -7.300117E-03 -2.715425E-06 +7.300831E-03 +2.715940E-06 diff --git a/tests/regression_tests/random_ray_volume_estimator_linear/naive/results_true.dat b/tests/regression_tests/random_ray_volume_estimator_linear/naive/results_true.dat index 02bfc5266..5258ffd9c 100644 --- a/tests/regression_tests/random_ray_volume_estimator_linear/naive/results_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator_linear/naive/results_true.dat @@ -1,9 +1,9 @@ tally 1: -2.339575E+00 -2.748441E-01 +2.339567E+00 +2.748423E-01 tally 2: -1.086360E-01 -6.030557E-04 +1.085878E-01 +6.024509E-04 tally 3: -7.298937E-03 -2.741185E-06 +7.299803E-03 +2.741867E-06 diff --git a/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/results_true.dat b/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/results_true.dat index 93e54feea..1e8aa9fb7 100644 --- a/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/results_true.dat +++ b/tests/regression_tests/random_ray_volume_estimator_linear/simulation_averaged/results_true.dat @@ -1,9 +1,9 @@ tally 1: -2.670874E+02 -4.432876E+05 +2.670850E+02 +4.432939E+05 tally 2: -1.117459E-01 -6.497788E-04 +1.116994E-01 +6.491358E-04 tally 3: -7.563753E-03 -2.947210E-06 +7.564527E-03 +2.947794E-06