Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 387 #388

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "PROPOSAL/propagation_utility/PropagationUtilityIntegral.h"
#include "PROPOSAL/Constants.h"

#include <cassert>
#include <stdexcept>

using namespace PROPOSAL;

Expand All @@ -26,7 +26,11 @@ double UtilityIntegral::GetUpperLimit(double energy_initial, double rnd)
auto sum = integral.IntegrateWithRandomRatio(
energy_initial, lower_lim, FunctionToIntegral, 4, -rnd);

assert(sum > rnd); // searched energy is below lower_lim
if (rnd > sum) {
throw std::logic_error("Unable to calculate GetUpperLimit since result"
"is below lower_lim. rnd was " + std::to_string(rnd)
+ " with rnd_max " + std::to_string(sum));
}
(void)sum;

return integral.GetUpperLimit();
Expand Down
28 changes: 23 additions & 5 deletions tests/Displacement_TEST.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ TEST(UpperLimitTrackIntegral, ConsistencyCheck)
DisplacementBuilder disp_calc(GetCrossSections(), std::false_type());
double E_i = 1.e8;
double E_f_old = E_i;

double max_disp = disp_calc.SolveTrackIntegral(E_i, disp_calc.GetLowerLim()); // highest possible displacement

for (double logDisp = 1; logDisp < 5; logDisp+=1.e-2) {
double disp = std::pow(logDisp, 10.);
double E_f = disp_calc.UpperLimitTrackIntegral(E_i, disp);
EXPECT_LE(E_f, E_f_old);
E_f_old = E_f;
if (disp > max_disp) {
EXPECT_THROW(disp_calc.UpperLimitTrackIntegral(E_i, disp), std::logic_error);
} else {
double E_f = disp_calc.UpperLimitTrackIntegral(E_i, disp);
EXPECT_LE(E_f, E_f_old);
E_f_old = E_f;
}
}
}

Expand All @@ -95,15 +102,26 @@ TEST(UpperLimitTrackIntegral, CompareIntegralInterpolant)
DisplacementBuilder disp_calc_integral(GetCrossSections(), std::false_type());
DisplacementBuilder disp_calc_interpol(GetCrossSections(), std::true_type());
double E_i = 1e8;
bool exception_integral, exception_interpol;
for (double logDisp = 1; logDisp < 5; logDisp+=1.e-2) {
exception_integral = false;
exception_interpol = false;
double disp = std::pow(logDisp, 10.);
double E_f_integral = disp_calc_integral.UpperLimitTrackIntegral(E_i, disp);
double E_f_interpol;

double E_f_integral, E_f_interpol;
try {
E_f_integral = disp_calc_integral.UpperLimitTrackIntegral(E_i, disp);
} catch (std::logic_error& e) {
E_f_integral = disp_calc_integral.GetLowerLim();
exception_integral = true;
}
try {
E_f_interpol = disp_calc_interpol.UpperLimitTrackIntegral(E_i, disp);
} catch (std::logic_error& e) {
E_f_interpol = disp_calc_interpol.GetLowerLim();
exception_interpol = true;
}
EXPECT_EQ(exception_interpol, exception_integral);
EXPECT_NEAR(E_f_integral, E_f_interpol, E_f_integral*1e-3);
}
}
Expand Down
Loading