Skip to content

Commit

Permalink
Correct a critical bug while previously protecting against rounding e…
Browse files Browse the repository at this point in the history
…rrors in the backward randomisation of DELs.
  • Loading branch information
niess committed Jul 28, 2017
1 parent 8344079 commit b16bc67
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pumas.c
Original file line number Diff line number Diff line change
Expand Up @@ -4362,8 +4362,12 @@ void del_randomise_target(struct pumas_context * context,
}
}

double zeta = context->random(context) * stot;
if (zeta > stot) zeta = stot; /* Prevent rounding error. */
double zeta;
for (;;) {
/* Prevent rounding errors. */
zeta = context->random(context) * stot;
if ((zeta > 0.) && (zeta < stot)) break;
}
double s = 0., csf_last = 0.;
component = s_shared->composition[material];
for (ic = ic0; ic < ic0 + s_shared->elements_in[material];
Expand All @@ -4380,8 +4384,7 @@ void del_randomise_target(struct pumas_context * context,
const double csf1 = *table_get_CSf(ip, ic, i1);
const double csf2 = *table_get_CSf(ip, ic, i2);
const double csf = (csf2 - csf1) * h + csf1;
if (!(zeta > s) ||
(ip == N_DEL_PROCESSES - 1)) {
if (!(zeta > s)) {
double csn;
double csn1 =
*table_get_CSn(ip, iel, i1);
Expand Down

0 comments on commit b16bc67

Please sign in to comment.