You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
double desiredCDF = RAND->Random(); // Random desired CDF
3077
+
3078
+
const boost::uintmax_t maxit = ADAPTIVE_RV_MAX_ITERATIONS; // Limit to maximum iterations.
3079
+
boost::uintmax_t it = maxit; // Initially our chosen max iterations, but updated with actual.
3080
+
3081
+
// find root
3082
+
// we use an iterative algorithm to find the root here:
3083
+
// - if the root finder throws an exception, we stop and return a negative value for the root (indicating no root found)
3084
+
// - if the root finder reaches the maximum number of (internal) iterations, we stop and return a negative value for the root (indicating no root found)
3085
+
// - if the root finder returns a solution, we check that func(solution) = 0.0 +/ ROOT_ABS_TOLERANCE
3086
+
// - if the solution is acceptable, we stop and return the solution
3087
+
// - if the solution is not acceptable, we reduce the search step size and try again
3088
+
// - if we reach the maximum number of search step reduction iterations, or the search step factor reduces to 1.0 (so search step size = 0.0),
3089
+
// we stop and return a negative value for the root (indicating no root found)
3090
+
3091
+
double guess = 100.0; // guess at 100 km s^-1 (arbitrary initial guess)
// could be too many iterations, or unable to bracket root - it may not
3122
+
// be a hard error - so no matter what the reason is that we are here,
3123
+
// we'll just emit a warning and keep trying
3124
+
if (it >= maxit) { SHOW_WARN(ERROR::TOO_MANY_RV_ITERATIONS); } // too many root finder iterations
3125
+
else { SHOW_WARN(ERROR::ROOT_FINDER_FAILED, e.what()); } // some other problem - show it as a warning
3136
3126
}
3137
3127
3138
-
// JR: should we issue a warning, or throw an error, if the root finder didn't actually find the roor here (i.e. we stopped because pf maxIter)?
3139
-
// To be consistent, should we use the Boost root solver here?
3140
-
// **Ilya** both questions above -- IM: yes to both, TBC
3141
-
3142
-
gsl_root_fsolver_free(s); // de-allocate memory for root solver
3128
+
// we have a solution from the root finder - it may not be an acceptable solution
3129
+
// so we check if it is within our preferred tolerance
3130
+
if (fabs(func(root.first + (root.second - root.first) / 2.0)) <= ROOT_ABS_TOLERANCE) { // solution within tolerance?
3131
+
done = true; // yes - we're done
3132
+
}
3133
+
elseif (fabs(func(root.first)) <= ROOT_ABS_TOLERANCE) { // solution within tolerance at endpoint 1?
3134
+
root.second=root.first;
3135
+
done = true; // yes - we're done
3136
+
}
3137
+
elseif (fabs(func(root.second)) <= ROOT_ABS_TOLERANCE) { // solution within tolerance at endpoint 2?
3138
+
root.first=root.second;
3139
+
done = true; // yes - we're done
3140
+
}
3141
+
else { // no - try again
3142
+
// we don't have an acceptable solution - reduce search step size and try again
3143
+
factorFrac /= 2.0; // reduce fractional part of factor
3144
+
factor = 1.0 + factorFrac; // new search step size
3145
+
tries++; // increment number of tries
3146
+
if (tries > ADAPTIVE_RV_MAX_TRIES || fabs(factor - 1.0) <= ROOT_ABS_TOLERANCE) { // too many tries, or step size 0.0?
3147
+
// we've tried as much as we can - fail here with -ve return value
3148
+
root.first = -1.0; // yes - set error return
3149
+
root.second = -1.0;
3150
+
SHOW_WARN(ERROR::TOO_MANY_RV_TRIES); // show warning
3151
+
done = true; // we're done
3152
+
}
3153
+
}
3143
3154
}
3144
-
3145
-
returnresult;
3155
+
3156
+
returnroot.first + (root.second - root.first) / 2.0; // Midway between brackets is our result, if necessary we could return the result as an interval here.
Copy file name to clipboardExpand all lines: src/changelog.h
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1672,6 +1672,7 @@
1672
1672
// 03.26.02 IM - October 26, 2025 - Enhancements
1673
1673
// - Added option -USSN-kicks-overwrite-mandel-muller ; if set to true, use user-defined USSN kicks (as a fixed value) in lieu of the Mandel & Muller kick prescription for USSNe
1674
1674
// - Replaced --scale-CHE-mass-loss-with-surface-helium-abundance with the more general --scale-mass-loss-with-surface-helium-abundance
1675
+
// - Updated rotational velocity solver to use boost root finder
0 commit comments