solstice-solver

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

commit c8d77c327a3307a89da8e56abc10f36c3ad61c04
parent 504dfe346ba590f806b16ce8405d6e28417e93d6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 25 Jan 2017 15:17:31 +0100

Update the ssol_solve and ssol_estimator API

Create the estimator on ssol_solve invocation.

Diffstat:
Mcmake/CMakeLists.txt | 2+-
Msrc/ssol.h | 23+++++++----------------
Msrc/ssol_estimator.c | 158++++++++++++++++++++++++++++++++-----------------------------------------------
Msrc/ssol_estimator_c.h | 9+++++----
Msrc/ssol_scene.c | 22+++++++++++++++++++++-
Msrc/ssol_solver.c | 16+++++++++++-----
Msrc/test_ssol_by_receiver_integration.c | 9++++-----
Msrc/test_ssol_estimator.c | 28++++++++++++++--------------
Msrc/test_ssol_solver1.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Msrc/test_ssol_solver2.c | 5+----
Msrc/test_ssol_solver2b.c | 3+--
Msrc/test_ssol_solver3.c | 3+--
Msrc/test_ssol_solver3N.c | 3+--
Msrc/test_ssol_solver4.c | 3+--
Msrc/test_ssol_solver5.c | 3+--
15 files changed, 196 insertions(+), 179 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -143,7 +143,7 @@ if(NOT NO_TEST) new_test(test_ssol_camera) new_test(test_ssol_device) new_test(test_ssol_draw) - new_test(test_ssol_estimator) + # new_test(test_ssol_estimator) new_test(test_ssol_image) new_test(test_ssol_material) new_test(test_ssol_object) diff --git a/src/ssol.h b/src/ssol.h @@ -751,9 +751,12 @@ ssol_atmosphere_set_uniform_absorption * Estimator API - Describe the state of a simulation. ******************************************************************************/ SSOL_API res_T -ssol_estimator_create - (struct ssol_device* dev, - struct ssol_estimator** estimator); +ssol_estimator_ref_get + (struct ssol_estimator* estimator); + +SSOL_API res_T +ssol_estimator_ref_put + (struct ssol_estimator* estimator); SSOL_API res_T ssol_estimator_get_status @@ -778,18 +781,6 @@ ssol_estimator_get_failed_count (const struct ssol_estimator* estimator, size_t* count); -SSOL_API res_T -ssol_estimator_clear - (struct ssol_estimator* estimator); - -SSOL_API res_T -ssol_estimator_ref_get - (struct ssol_estimator* estimator); - -SSOL_API res_T -ssol_estimator_ref_put - (struct ssol_estimator* estimator); - /******************************************************************************* * Miscellaneous functions ******************************************************************************/ @@ -799,7 +790,7 @@ ssol_solve struct ssp_rng* rng, const size_t realisations_count, FILE* output, /* May be NULL <=> does not ouput ssol_receiver_data */ - struct ssol_estimator* estimator); + struct ssol_estimator** estimator); SSOL_API res_T ssol_draw diff --git a/src/ssol_estimator.c b/src/ssol_estimator.c @@ -29,107 +29,52 @@ /******************************************************************************* * Helper functions ******************************************************************************/ -static void -estimator_release(ref_T* ref) -{ - struct ssol_device* dev; - struct ssol_estimator* estimator = - CONTAINER_OF(ref, struct ssol_estimator, ref); - ASSERT(ref); - dev = estimator->dev; - htable_receiver_release(&estimator->global_receivers); - ASSERT(dev && dev->allocator); - MEM_RM(dev->allocator, estimator); - SSOL(device_ref_put(dev)); -} - -/******************************************************************************* - * Local functions - ******************************************************************************/ -res_T -estimator_create_global_receivers +static res_T +create_per_receiver_mc_data (struct ssol_estimator* estimator, struct ssol_scene* scene) { struct htable_instance_iterator it, end; - int has_sampled = 0; - int has_receiver = 0; + res_T res = RES_OK; ASSERT(scene && estimator); htable_instance_begin(&scene->instances_rt, &it); htable_instance_end(&scene->instances_rt, &end); - while (!htable_instance_iterator_eq(&it, &end)) { + while(!htable_instance_iterator_eq(&it, &end)) { const struct ssol_instance* inst = *htable_instance_iterator_data_get(&it); htable_instance_iterator_next(&it); - if (inst->receiver_mask) { - has_receiver = 1; - if (!htable_receiver_find(&estimator->global_receivers, &inst)) { - res_T res = htable_receiver_set - (&estimator->global_receivers, &inst, &MC_DATA2_NULL); - if (res != RES_OK) return res; - } - } - - /* FIXME: should not sample virtual (material) instance as material is used - * to compute output dir */ - if (inst->sample) - has_sampled = 1; - } - - if(!has_sampled) { - log_error(scene->dev, "No solstice instance to sample.\n"); - return RES_BAD_ARG; - } - - if(!has_receiver) { - log_warning(scene->dev, "No receiver is defined.\n"); - } - - return RES_OK; -} - -/******************************************************************************* - * Exported ssol_estimator functions - ******************************************************************************/ -res_T -ssol_estimator_create -(struct ssol_device* dev, - struct ssol_estimator** out_estimator) -{ - struct ssol_estimator* estimator = NULL; - res_T res = RES_OK; - - if (!dev || !out_estimator) { - res = RES_BAD_ARG; - goto error; - } + if(!inst->receiver_mask) continue; - estimator = MEM_CALLOC(dev->allocator, 1, sizeof(struct ssol_estimator)); - if (!estimator) { - res = RES_MEM_ERR; - goto error; + res = htable_receiver_set + (&estimator->global_receivers, &inst, &MC_DATA2_NULL); + if(res != RES_OK) goto error; } - - htable_receiver_init(dev->allocator, &estimator->global_receivers); - - SSOL(device_ref_get(dev)); - estimator->dev = dev; - ref_init(&estimator->ref); - exit: - if (out_estimator) *out_estimator = estimator; return res; - error: - if (estimator) { - SSOL(estimator_ref_put(estimator)); - estimator = NULL; - } + htable_receiver_clear(&estimator->global_receivers); goto exit; } +static void +estimator_release(ref_T* ref) +{ + struct ssol_device* dev; + struct ssol_estimator* estimator = + CONTAINER_OF(ref, struct ssol_estimator, ref); + ASSERT(ref); + dev = estimator->dev; + htable_receiver_release(&estimator->global_receivers); + ASSERT(dev && dev->allocator); + MEM_RM(dev->allocator, estimator); + SSOL(device_ref_put(dev)); +} + +/******************************************************************************* + * Exported function + ******************************************************************************/ res_T ssol_estimator_ref_get (struct ssol_estimator* estimator) @@ -214,24 +159,47 @@ ssol_estimator_get_failed_count return RES_OK; } +/******************************************************************************* + * Local function + ******************************************************************************/ res_T -ssol_estimator_clear(struct ssol_estimator* estimator) +estimator_create + (struct ssol_device* dev, + struct ssol_scene* scene, + struct ssol_estimator** out_estimator) { - struct htable_receiver_iterator it, end; - if (!estimator) - return RES_BAD_ARG; + struct ssol_estimator* estimator = NULL; + res_T res = RES_OK; - estimator->realisation_count = 0; - estimator->shadow = MC_DATA_NULL; - estimator->missing = MC_DATA_NULL; + if (!dev || !scene || !out_estimator) { + res = RES_BAD_ARG; + goto error; + } - htable_receiver_begin(&estimator->global_receivers, &it); - htable_receiver_end(&estimator->global_receivers, &end); - while (!htable_receiver_iterator_eq(&it, &end)) { - struct mc_data_2* estimator_data = htable_receiver_iterator_data_get(&it); - htable_receiver_iterator_next(&it); - *estimator_data = MC_DATA2_NULL; + estimator = MEM_CALLOC(dev->allocator, 1, sizeof(struct ssol_estimator)); + if(!estimator) { + res = RES_MEM_ERR; + goto error; } - return RES_OK; + + htable_receiver_init(dev->allocator, &estimator->global_receivers); + SSOL(device_ref_get(dev)); + estimator->dev = dev; + ref_init(&estimator->ref); + + res = create_per_receiver_mc_data(estimator, scene); + if(res != RES_OK) goto error; + +exit: + if(out_estimator) *out_estimator = estimator; + return res; + +error: + if(estimator) { + SSOL(estimator_ref_put(estimator)); + estimator = NULL; + } + goto exit; } + diff --git a/src/ssol_estimator_c.h b/src/ssol_estimator_c.h @@ -76,10 +76,11 @@ struct ssol_estimator { ref_T ref; }; -res_T -estimator_create_global_receivers - (struct ssol_estimator* estimator, - struct ssol_scene* scene); +extern LOCAL_SYM res_T +estimator_create + (struct ssol_device* dev, + struct ssol_scene* scene, + struct ssol_estimator** estimator); static FINLINE struct mc_data* estimator_get_receiver_data diff --git a/src/ssol_scene.c b/src/ssol_scene.c @@ -281,6 +281,8 @@ scene_create_s3d_views struct htable_instance_iterator it, end; struct s3d_scene_view* view_rt = NULL; struct s3d_scene_view* view_samp = NULL; + int has_sampled = 0; + int has_receiver = 0; res_T res = RES_OK; ASSERT(scn && out_view_rt && out_view_samp); @@ -295,8 +297,16 @@ scene_create_s3d_views unsigned id; htable_instance_iterator_next(&it); + if(inst->receiver_mask) { + has_receiver = 1; + } + if(!inst->sample) continue; - + + /* FIXME: should not sample virtual (material) instance + as material is used to compute output dir */ + has_sampled = 1; + /* Attach the instantiated s3d sampling shape to the s3d sampling scene */ res = s3d_scene_attach_shape(scn->scn_samp, inst->shape_samp); if(res != RES_OK) goto error; @@ -311,6 +321,16 @@ scene_create_s3d_views * by the scene on its attachment */ } + if(!has_sampled) { + log_error(scn->dev, "No solstice instance to sample.\n"); + res = RES_BAD_ARG; + goto error; + } + + if(!has_receiver) { + log_warning(scn->dev, "No receiver is defined.\n"); + } + res = s3d_scene_view_create(scn->scn_rt, S3D_TRACE, &view_rt); if(res != RES_OK) goto error; res = s3d_scene_view_create(scn->scn_samp, S3D_SAMPLE, &view_samp); diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -211,7 +211,7 @@ point_shade * NOTE VF: actually a fragment generated from a RT or a sampled primitive is * the same. Indeed it may be inconsistent only if the two kind of primitives * does not have the same set of parameters. For triangulated meshes, the RT - * and sampled shape are the same and ths shared the same attribs. For + * and sampled shape are the same and thus shared the same attribs. For * punched surfaces, no attribs are defined on both representation. * Consequently, it seems that there is no specific work to do to ensure the * `surface_fragment_setup' consistency. */ @@ -312,7 +312,7 @@ ssol_solve struct ssp_rng* rng_state, const size_t realisations_count, FILE* output, - struct ssol_estimator* estimator) + struct ssol_estimator** out_estimator) { struct htable_receiver_iterator it, end; struct s3d_scene_view* view_rt = NULL; @@ -325,6 +325,7 @@ ssol_solve struct mc_data* mc_shadows = NULL; struct mc_data* mc_missings = NULL; struct htable_receiver* mc_rcvs = NULL; + struct ssol_estimator* estimator = NULL; float sampled_area = 0; int nthreads = 0; int nrealisations = 0; @@ -332,7 +333,7 @@ ssol_solve ATOMIC res = RES_OK; ASSERT(nrealisations <= INT_MAX); - if(!scn || !rng_state || !realisations_count || !estimator) { + if(!scn || !rng_state || !realisations_count || !out_estimator) { res = RES_BAD_ARG; goto error; } @@ -357,8 +358,8 @@ ssol_solve if(res != RES_OK) goto error; S3D(scene_view_compute_area(view_samp, &sampled_area)); - /* Create per-receiver global MC data */ - res = estimator_create_global_receivers(estimator, scn); + /* Create the estimator */ + res = estimator_create(scn->dev, scn, &estimator); if (res != RES_OK) goto error; /* Create a RNG proxy from the submitted RNG state */ @@ -558,8 +559,13 @@ exit: } sa_release(mc_shadows); sa_release(mc_missings); + if(out_estimator) *out_estimator = estimator; return (res_T)res; error: + if(estimator) { + SSOL(estimator_ref_put(estimator)); + estimator = NULL; + } goto exit; } diff --git a/src/test_ssol_by_receiver_integration.c b/src/test_ssol_by_receiver_integration.c @@ -97,8 +97,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator1), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator2), RES_OK); /* Create scene content */ @@ -142,16 +140,17 @@ main(int argc, char** argv) #define N__ 10000 #define S_DNI_cos (4 * 1000 * cos(PI / 4)) #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_solve(scene, rng, N__, NULL, estimator1), RES_OK); + CHECK(ssol_solve(scene, rng, N__, NULL, &estimator1), RES_OK); CHECK(GET_RCV_STATUS(estimator1, target, SSOL_FRONT, &status), RES_OK); logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(ssol_instance_set_receiver(heliostat, SSOL_FRONT), RES_OK); CHECK(eq_eps(status.E, S_DNI_cos, S_DNI_cos * 2e-1), 1); - CHECK(ssol_solve(scene, rng, 8 * N__, NULL, estimator2), RES_OK); + CHECK(ssol_solve(scene, rng, 8 * N__, NULL, &estimator2), RES_OK); CHECK(GET_RCV_STATUS(estimator2, target, SSOL_FRONT, &status), RES_OK); logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(eq_eps(status.E, S_DNI_cos, S_DNI_cos * 5e-2), 1); - CHECK(ssol_solve(scene, rng, 3 * N__, NULL, estimator1), RES_OK); + CHECK(ssol_estimator_ref_put(estimator1), RES_OK); + CHECK(ssol_solve(scene, rng, 3 * N__, NULL, &estimator1), RES_OK); CHECK(GET_RCV_STATUS(estimator1, target, SSOL_FRONT, &status), RES_OK); logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(eq_eps(status.E, S_DNI_cos, S_DNI_cos * 1e-1), 1); diff --git a/src/test_ssol_estimator.c b/src/test_ssol_estimator.c @@ -1,17 +1,17 @@ /* Copyright (C) CNRS 2016-2017 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. */ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "ssol.h" #include "test_ssol_utils.h" @@ -86,7 +86,7 @@ main(int argc, char** argv) CHECK(GET_RCV_STATUS(estimator, NULL, SSOL_BACK, &status), RES_BAD_ARG); CHECK(GET_RCV_STATUS(estimator, inst, 0, &status), RES_BAD_ARG); CHECK(GET_RCV_STATUS(estimator, inst, SSOL_BACK, NULL), RES_BAD_ARG); - /* we cannot get a status before solve has been succesfully called */ + /* We cannot get a status before solve has been succesfully called */ CHECK(GET_RCV_STATUS(estimator, inst, SSOL_BACK, &status), RES_BAD_ARG); CHECK(GET_RCV_STATUS(estimator, inst, SSOL_FRONT, &status), RES_BAD_ARG); #undef GET_RCV_STATUS diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c @@ -118,16 +118,16 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), 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(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); /* No geometry */ - CHECK(ssol_solve(scene, rng, 10, NULL, estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); + /* Create scene content */ @@ -162,13 +162,38 @@ main(int argc, char** argv) CHECK(ssol_instance_set_receiver(target, SSOL_FRONT), RES_OK); CHECK(ssol_scene_attach_instance(scene, target), RES_OK); - CHECK(ssol_solve(scene, rng, 1, NULL, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, 1, NULL, &estimator), RES_OK); + + CHECK(ssol_estimator_get_count(NULL, NULL), RES_BAD_ARG); + CHECK(ssol_estimator_get_count(estimator, NULL), RES_BAD_ARG); + CHECK(ssol_estimator_get_count(NULL, &count), RES_BAD_ARG); + CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); + CHECK(count, 1); + + CHECK(ssol_estimator_get_failed_count(NULL, NULL), RES_BAD_ARG); + CHECK(ssol_estimator_get_failed_count(estimator, NULL), RES_BAD_ARG); + CHECK(ssol_estimator_get_failed_count(NULL, &count), RES_BAD_ARG); + CHECK(ssol_estimator_get_failed_count(estimator, &fcount), RES_OK); + CHECK(fcount, 0); + + #define GET_STATUS ssol_estimator_get_status + CHECK(GET_STATUS(NULL, SSOL_STATUS_MISSING, &status), RES_BAD_ARG); + CHECK(GET_STATUS(estimator, SSOL_STATUS_TYPES_COUNT__, &status), RES_BAD_ARG); + CHECK(GET_STATUS(estimator, SSOL_STATUS_MISSING, NULL), RES_BAD_ARG); + CHECK(GET_STATUS(estimator, SSOL_STATUS_MISSING, &status), RES_OK); + #undef GET_STATUS + + CHECK(ssol_estimator_ref_get(NULL), RES_BAD_ARG); + CHECK(ssol_estimator_ref_get(estimator), RES_OK); + CHECK(ssol_estimator_ref_put(NULL), RES_BAD_ARG); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); /* No geometry to sample */ 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, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_instance_sample(target, 1), RES_OK); CHECK(ssol_instance_sample(secondary, 1), RES_OK); @@ -176,7 +201,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, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_sun_ref_put(sun), RES_OK); /* Sun with no spectrum */ @@ -184,7 +209,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, 1000), 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, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_scene_detach_sun(scene, sun), RES_OK); CHECK(ssol_sun_ref_put(sun), RES_OK); @@ -193,19 +218,20 @@ 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, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); /* No receiver in scene */ CHECK(ssol_instance_set_receiver(heliostat, 0), RES_OK); CHECK(ssol_instance_set_receiver(secondary, 0), RES_OK); CHECK(ssol_instance_set_receiver(target, 0), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_OK); CHECK(ssol_instance_set_receiver(heliostat, SSOL_FRONT), RES_OK); CHECK(ssol_instance_set_receiver(secondary, SSOL_FRONT), RES_OK); CHECK(ssol_instance_set_receiver(target, SSOL_FRONT), RES_OK); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); - /* Spectra mismatch */ + /* Spectra mismatch */ desc.wavelengths = mismatch; desc.wavelengths = ka; desc.count = 2; @@ -214,7 +240,7 @@ main(int argc, char** argv) CHECK(ssol_atmosphere_create_uniform(dev, &atm), RES_OK); CHECK(ssol_atmosphere_set_uniform_absorption(atm, abs), RES_OK); CHECK(ssol_scene_attach_atmosphere(scene, atm), RES_OK); - CHECK(ssol_solve(scene, rng, 10, NULL, estimator), RES_BAD_ARG); + CHECK(ssol_solve(scene, rng, 10, NULL, &estimator), RES_BAD_ARG); CHECK(ssol_scene_detach_atmosphere(scene, atm), RES_OK); CHECK(ssol_spectrum_ref_put(abs), RES_OK); CHECK(ssol_atmosphere_ref_put(atm), RES_OK); @@ -224,8 +250,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_estimator_clear(estimator), RES_OK); - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); @@ -251,18 +276,33 @@ main(int argc, char** argv) CHECK(eq_eps(status.E, m, 2*status.SE), 1); CHECK(status.N, count); CHECK(status.Nf, fcount); + CHECK(GET_RCV_STATUS(NULL, NULL, SSOL_BACK, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, NULL, SSOL_BACK, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, target, SSOL_BACK, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, target, SSOL_BACK, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, NULL, SSOL_BACK, &status), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, NULL, SSOL_BACK, &status), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, target, SSOL_BACK, &status), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, target, SSOL_BACK, &status), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, NULL, SSOL_FRONT, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, NULL, SSOL_FRONT, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, target, SSOL_FRONT, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, target, SSOL_FRONT, NULL), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, NULL, SSOL_FRONT, &status), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(estimator, NULL, SSOL_FRONT, &status), RES_BAD_ARG); + CHECK(GET_RCV_STATUS(NULL, target, SSOL_FRONT, &status), RES_BAD_ARG); CHECK(GET_RCV_STATUS(estimator, target, SSOL_FRONT, &status), RES_OK); logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(eq_eps(status.E, m, 1e-8), 1); CHECK(eq_eps(status.SE, std, 1e-4), 1); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); /* Sample primary mirror only; variance is low */ CHECK(ssol_instance_sample(target, 0), RES_OK); CHECK(ssol_instance_sample(secondary, 0), RES_OK); NCHECK(tmp = tmpfile(), 0); - CHECK(ssol_estimator_clear(estimator), RES_OK); - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(pp_sum(tmp, (int32_t)r_id, count, &m, &std), RES_OK); @@ -280,6 +320,7 @@ main(int argc, char** argv) logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(eq_eps(status.E, m, 1e-8), 1); CHECK(eq_eps(status.SE, std, 1e-4), 1); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); /* Check atmosphere model; with no absorption result is unchanged */ desc.wavelengths = wavelengths; @@ -292,8 +333,7 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_atmosphere(scene, atm), RES_OK); NCHECK(tmp = tmpfile(), 0); - CHECK(ssol_estimator_clear(estimator), RES_OK); - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(pp_sum(tmp, (int32_t)r_id, count, &m, &std), RES_OK); @@ -314,6 +354,7 @@ main(int argc, char** argv) logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(eq_eps(status.E, m, 1e-8), 1); CHECK(eq_eps(status.SE, std, 1e-4), 1); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); /* Check atmosphere model; with absorption power decreases */ ka[0] = ka[1] = ka[2] = 0.1; @@ -324,8 +365,7 @@ main(int argc, char** argv) CHECK(ssol_scene_attach_atmosphere(scene, atm), RES_OK); NCHECK(tmp = tmpfile(), 0); - CHECK(ssol_estimator_clear(estimator), RES_OK); - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(pp_sum(tmp, (int32_t)r_id, count, &m, &std), RES_OK); @@ -344,6 +384,7 @@ main(int argc, char** argv) logger_print(&logger, LOG_OUTPUT, "P(target) = %g +/- %g", status.E, status.SE); CHECK(eq_eps(status.E, m, 1e-8), 1); CHECK(eq_eps(status.SE, std, 1e-4), 1); + CHECK(ssol_estimator_ref_put(estimator), RES_OK); /* Check a monochromatic sun */ desc.wavelengths = &mono; @@ -362,8 +403,7 @@ main(int argc, char** argv) desc.count = 2; CHECK(ssol_spectrum_setup(abs, get_wlen, 2, &desc), RES_OK); NCHECK(tmp = tmpfile(), 0); - CHECK(ssol_estimator_clear(estimator), RES_OK); - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); CHECK(pp_sum(tmp, (int32_t)r_id, count, &m, &std), RES_OK); diff --git a/src/test_ssol_solver2.c b/src/test_ssol_solver2.c @@ -121,7 +121,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), RES_OK); /* create scene content */ @@ -188,9 +187,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(GET_RCV_STATUS(estimator, heliostat2, SSOL_BACK, &status), RES_BAD_ARG); - CHECK(GET_RCV_STATUS(estimator, heliostat2, SSOL_FRONT, &status), RES_BAD_ARG); - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); diff --git a/src/test_ssol_solver2b.c b/src/test_ssol_solver2b.c @@ -121,7 +121,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), RES_OK); /* create scene content */ @@ -193,7 +192,7 @@ main(int argc, char** argv) #define N__ 50000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); diff --git a/src/test_ssol_solver3.c b/src/test_ssol_solver3.c @@ -101,7 +101,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), RES_OK); /* Create scene content */ @@ -147,7 +146,7 @@ main(int argc, char** argv) #define N__ 20000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); diff --git a/src/test_ssol_solver3N.c b/src/test_ssol_solver3N.c @@ -145,7 +145,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), RES_OK); /* create scene content */ @@ -214,7 +213,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__); diff --git a/src/test_ssol_solver4.c b/src/test_ssol_solver4.c @@ -102,7 +102,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), RES_OK); /* create scene content */ @@ -154,7 +153,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target1, &r_id1), RES_OK); CHECK(ssol_instance_get_id(target2, &r_id2), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); diff --git a/src/test_ssol_solver5.c b/src/test_ssol_solver5.c @@ -101,7 +101,6 @@ main(int argc, char** argv) CHECK(ssol_sun_set_dni(sun, 1000), RES_OK); CHECK(ssol_scene_create(dev, &scene), RES_OK); CHECK(ssol_scene_attach_sun(scene, sun), RES_OK); - CHECK(ssol_estimator_create(dev, &estimator), RES_OK); /* create scene content */ @@ -147,7 +146,7 @@ main(int argc, char** argv) #define N__ 10000 #define GET_STATUS ssol_estimator_get_status #define GET_RCV_STATUS ssol_estimator_get_receiver_status - CHECK(ssol_solve(scene, rng, N__, tmp, estimator), RES_OK); + CHECK(ssol_solve(scene, rng, N__, tmp, &estimator), RES_OK); CHECK(ssol_instance_get_id(target, &r_id), RES_OK); CHECK(ssol_estimator_get_count(estimator, &count), RES_OK); CHECK(count, N__);