commit 8f63b1ee910237777ac9e18be6d5f7100c9d68ae
parent c96ce42b800b755412b86b4b1a24338c858b1983
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 26 Sep 2017 15:40:14 +0200
Make use of the new max_failure arg of the solver.
Solstice's behaviour remains unchanged in standard solve() mode,
but when invoked in order to dump paths, the new arg is used
so that solve() does stops early.
Thus, the user always get the required number of paths.
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/solstice_solve.c b/src/solstice_solve.c
@@ -19,6 +19,11 @@
#include <solstice/ssol.h>
#include <star/ssp.h>
+/* How many percent of random walk realisations may fail before solve() stops
+ * in a standard solve() invocation.
+ * It is not used when solve() is invoked in order to dump paths. */
+#define MAX_PERCENT_FAILURES 0.01
+
/*******************************************************************************
* Helper function
******************************************************************************/
@@ -500,6 +505,7 @@ solstice_solve(struct solstice* solstice)
{
struct ssol_estimator* estimator = NULL;
struct ssp_rng* rng = NULL;
+ size_t max_failure;
res_T res = RES_OK;
ASSERT(solstice);
@@ -509,7 +515,11 @@ solstice_solve(struct solstice* solstice)
goto error;
}
- res = ssol_solve(solstice->scene, rng, solstice->nexperiments,
+ max_failure = solstice->dump_paths ?
+ solstice->nexperiments
+ : (size_t)((double)solstice->nexperiments * MAX_PERCENT_FAILURES);
+
+ res = ssol_solve(solstice->scene, rng, solstice->nexperiments, max_failure,
solstice->dump_paths ? &solstice->path_tracker : NULL, &estimator);
if(res != RES_OK) {
fprintf(stderr, "Error in integrating the solar flux.\n");