solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 3ccc2432d3179d05535786e1d2bc210288c4c153
parent b188669b3a15b2fcb7c307cedacbfcbc7eccaad0
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Tue, 26 Sep 2017 15:24:47 +0200

Add an arg to solve() to control the max failure count.

solve stops and returns when #failure is at least this.

Diffstat:
Msrc/ssol.h | 1+
Msrc/ssol_solver.c | 8+++-----
Msrc/test_ssol_by_receiver_integration.c | 6+++---
Msrc/test_ssol_solver1.c | 38+++++++++++++++++++-------------------
Msrc/test_ssol_solver10.c | 4++--
Msrc/test_ssol_solver2.c | 2+-
Msrc/test_ssol_solver2b.c | 2+-
Msrc/test_ssol_solver3.c | 2+-
Msrc/test_ssol_solver4.c | 2+-
Msrc/test_ssol_solver5.c | 2+-
Msrc/test_ssol_solver6.c | 2+-
Msrc/test_ssol_solver7.c | 2+-
Msrc/test_ssol_solver8.c | 2+-
Msrc/test_ssol_solver9.c | 2+-
14 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/src/ssol.h b/src/ssol.h @@ -1182,6 +1182,7 @@ ssol_solve (struct ssol_scene* scn, struct ssp_rng* rng, const size_t realisations_count, + const size_t max_failed_count, const struct ssol_path_tracker* tracker, /* NULL<=>Do not record the paths */ struct ssol_estimator** estimator); diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -43,9 +43,6 @@ #include <limits.h> #include <omp.h> -/* How many percent of random walk realisations may fail before an error occurs */ -#define MAX_PERCENT_FAILURES 0.01 - /******************************************************************************* * Thread context ******************************************************************************/ @@ -1084,6 +1081,7 @@ ssol_solve (struct ssol_scene* scn, struct ssp_rng* rng_state, const size_t realisations_count, + const size_t max_failed_count, const struct ssol_path_tracker* path_tracker, struct ssol_estimator** out_estimator) { @@ -1114,12 +1112,12 @@ ssol_solve /* CL compiler supports OpenMP parallel loop whose indices are signed. The * following line ensures that the unsigned number of realisations does not * overflow the realisation index. */ - if(realisations_count > INT64_MAX) { + if(realisations_count > INT64_MAX || max_failed_count > INT64_MAX) { res = RES_BAD_ARG; goto error; } nrealisations = (int64_t)realisations_count; - max_failures = (int64_t)((double)nrealisations * MAX_PERCENT_FAILURES); + max_failures = (int64_t)max_failed_count; nthreads = (int)scn->dev->nthreads; res = scene_check(scn, FUNC_NAME); diff --git a/src/test_ssol_by_receiver_integration.c b/src/test_ssol_by_receiver_integration.c @@ -134,7 +134,7 @@ main(int argc, char** argv) #define S_DNI_cos (4 * 1000 * cos(PI / 4)) #define GET_MC_RCV ssol_estimator_get_mc_receiver #define GET_MC_SAMP_X_RCV ssol_estimator_get_mc_sampled_x_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator1), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator1), RES_OK); CHECK(GET_MC_RCV(estimator1, target, SSOL_FRONT, &mc_rcv), RES_OK); printf("Ir(target) = %g +/- %g\n", mc_rcv.incoming_flux.E, mc_rcv.incoming_flux.SE); @@ -142,13 +142,13 @@ main(int argc, char** argv) CHECK(eq_eps (mc_rcv.incoming_flux.E, S_DNI_cos, mc_rcv.incoming_flux.SE*3), 1); - CHECK(ssol_solve(scene, rng, 8 * N__, NULL, &estimator2), RES_OK); + CHECK(ssol_solve(scene, rng, 8 * N__, 0, NULL, &estimator2), RES_OK); CHECK(GET_MC_RCV(estimator2, target, SSOL_FRONT, &mc_rcv), RES_OK); printf("Ir(target) = %g +/- %g\n", mc_rcv.incoming_flux.E, mc_rcv.incoming_flux.SE); CHECK(eq_eps(mc_rcv.incoming_flux.E, S_DNI_cos, mc_rcv.incoming_flux.SE*3), 1); CHECK(ssol_estimator_ref_put(estimator1), RES_OK); - CHECK(ssol_solve(scene, rng, 3 * N__, NULL, &estimator1), RES_OK); + CHECK(ssol_solve(scene, rng, 3 * N__, 0, NULL, &estimator1), RES_OK); CHECK(GET_MC_RCV(estimator1, target, SSOL_FRONT, &mc_rcv), RES_OK); printf("Ir(target) = %g +/- %g\n", mc_rcv.incoming_flux.E, mc_rcv.incoming_flux.SE); diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c @@ -120,14 +120,14 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, DNI), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); - CHECK(ssol_solve(NULL, rng, 10, NULL, &estimator), RES_BAD_ARG); - CHECK(ssol_solve(scene, NULL, 10, NULL, &estimator), RES_BAD_ARG); - CHECK(ssol_solve(scene, rng, 0, NULL, &estimator), RES_BAD_ARG); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); - CHECK(ssol_solve(scene, rng, 10, NULL, NULL), RES_BAD_ARG); + CHECK(ssol_solve(NULL, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, NULL, 10, 0, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 0, 0, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, NULL), RES_BAD_ARG); /* No geometry */ - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); /* Create scene content */ CHECK(ssol_shape_create_mesh(dev, &dummy), RES_OK); @@ -163,14 +163,14 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_instance(scene, target), RES_OK); /* No sun */ - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_ref_put(estimator), RES_OK); CHECK(ssol_solve - (scene, rng, 1, &SSOL_PATH_TRACKER_DEFAULT, &estimator), RES_OK); + (scene, rng, 1, 0, &SSOL_PATH_TRACKER_DEFAULT, &estimator), RES_OK); CHECK(ssol_estimator_get_tracked_paths_count(NULL, NULL), RES_BAD_ARG); CHECK(ssol_estimator_get_tracked_paths_count(estimator, NULL), RES_BAD_ARG); @@ -247,7 +247,7 @@ main(int argc, char** argv) CHECK(ssol_instance_sample(target, 0), RES_OK); CHECK(ssol_instance_sample(secondary, 0), RES_OK); CHECK(ssol_instance_sample(heliostat, 0), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_estimator_get_mc_sampled(estimator, heliostat, &sampled), RES_BAD_ARG); CHECK(ssol_instance_sample(target, 1), RES_OK); @@ -256,7 +256,7 @@ main(int argc, char** argv) /* No attached sun */ CHECK(ssol_scene_detach_sun(scene, sun), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_sun_ref_put(sun), RES_OK); /* Sun with no spectrum */ @@ -264,7 +264,7 @@ main(int argc, char** argv) CHECK(ssol_sun_set_direction(sun, d3(dir, 1, 0, -1)), RES_OK); CHECK(ssol_sun_set_dni(sun, DNI), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_scene_detach_sun(scene, sun), RES_OK); CHECK(ssol_sun_ref_put(sun), RES_OK); @@ -273,14 +273,14 @@ main(int argc, char** argv) CHECK(ssol_sun_set_direction(sun, d3(dir, 1, 0, -1)), RES_OK); CHECK(ssol_sun_set_spectrum(sun, spectrum), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_sun_set_dni(sun, DNI), RES_OK); /* No receiver in scene */ CHECK(ssol_instance_set_receiver(heliostat, 0, 0), RES_OK); CHECK(ssol_instance_set_receiver(secondary, 0, 0), RES_OK); CHECK(ssol_instance_set_receiver(target, 0, 0), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, 10, 0, NULL, &estimator), RES_OK); CHECK(ssol_instance_set_receiver(heliostat, SSOL_FRONT, 0), RES_OK); CHECK(ssol_instance_set_receiver(secondary, SSOL_FRONT, 0), RES_OK); CHECK(ssol_instance_set_receiver(target, SSOL_FRONT, 0), RES_OK); @@ -290,7 +290,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_MC_RCV ssol_estimator_get_mc_receiver #define GET_MC_GLOBAL ssol_estimator_get_mc_global - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(ssol_estimator_get_failed_count(estimator, &fcount), RES_OK); @@ -332,7 +332,7 @@ main(int argc, char** argv) CHECK(ssol_instance_sample(target, 0), RES_OK); CHECK(ssol_instance_sample(secondary, 0), RES_OK); - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); m = 4 * DNI_cos; @@ -356,7 +356,7 @@ main(int argc, char** argv) CHECK(ssol_atmosphere_set_extinction(atm, &extinction), RES_OK); CHECK(ssol_scene_attach_atmosphere(scene, atm), RES_OK); - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); m = 4 * DNI_cos; @@ -400,7 +400,7 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_atmosphere(scene, atm), RES_OK); CHECK(ssol_instance_set_receiver(target, SSOL_FRONT, 1), RES_OK); - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define K (exp(-KA * 4 * sqrt(2))) @@ -487,7 +487,7 @@ main(int argc, char** argv) extinction.value.spectrum = abs_spectrum; CHECK(ssol_atmosphere_set_extinction(atm, &extinction), RES_OK); - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define K2 (exp(-0.121 * 4 * sqrt(2))) diff --git a/src/test_ssol_solver10.c b/src/test_ssol_solver10.c @@ -126,7 +126,7 @@ main(int argc, char** argv) #define N1__ 10000 #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N1__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N1__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N1__); CHECK(ssol_estimator_get_failed_count(estimator, &count), RES_OK); @@ -167,7 +167,7 @@ main(int argc, char** argv) CHECK(ssol_estimator_ref_put(estimator), RES_OK); #define N2__ 100000 - CHECK(ssol_solve(scene, rng, N2__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N2__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N2__); CHECK(ssol_estimator_get_failed_count(estimator, &count), RES_OK); diff --git a/src/test_ssol_solver2.c b/src/test_ssol_solver2.c @@ -177,7 +177,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define COS cos(PI / 4) diff --git a/src/test_ssol_solver2b.c b/src/test_ssol_solver2b.c @@ -180,7 +180,7 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_instance(scene, target), RES_OK); #define N__ 50000 - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define COS cos(PI / 4) diff --git a/src/test_ssol_solver3.c b/src/test_ssol_solver3.c @@ -135,7 +135,7 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_instance(scene, target), RES_OK); #define N__ 20000 - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define COS cos(PI / 4) diff --git a/src/test_ssol_solver4.c b/src/test_ssol_solver4.c @@ -144,7 +144,7 @@ main(int argc, char** argv) #define N__ 100000 #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define COS cos(0) diff --git a/src/test_ssol_solver5.c b/src/test_ssol_solver5.c @@ -135,7 +135,7 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_instance(scene, target), RES_OK); #define N__ 10000 - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); #define COS cos(0) diff --git a/src/test_ssol_solver6.c b/src/test_ssol_solver6.c @@ -176,7 +176,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_mc_global(estimator, &mc_global), RES_OK); PRINT_GLOBAL(mc_global); CHECK(eq_eps(mc_global.shadowed.E, 100000, 2 * 100000/sqrt(N__)), 1); diff --git a/src/test_ssol_solver7.c b/src/test_ssol_solver7.c @@ -191,7 +191,7 @@ main(int argc, char** argv) #define TOTAL (HELIOSTAT_SZ * HELIOSTAT_SZ * DNI_cos) #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_mc_global(estimator, &mc_global), RES_OK); CHECK(ssol_estimator_get_sampled_area(estimator, &area), RES_OK); diff --git a/src/test_ssol_solver8.c b/src/test_ssol_solver8.c @@ -139,7 +139,7 @@ main(int argc, char** argv) #define N__ 100000 #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(ssol_estimator_get_failed_count(estimator, &count), RES_OK); diff --git a/src/test_ssol_solver9.c b/src/test_ssol_solver9.c @@ -133,7 +133,7 @@ main(int argc, char** argv) #define N__ 100000 #define GET_MC_RCV ssol_estimator_get_mc_receiver - CHECK(ssol_solve(scene, rng, N__, NULL, &estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, 0, NULL, &estimator), RES_OK); CHECK(ssol_estimator_get_realisation_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(ssol_estimator_get_failed_count(estimator, &count), RES_OK);