solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit 162cd10a1fe8d2f1fda9a36aa7dff96d066731fb
parent 78f1e5d6d914ca403349f268e221fd0dd5c9ac26
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 23 Jan 2017 16:10:01 +0100

Define and implement the layout of the output data

Diffstat:
Adoc/output | 33+++++++++++++++++++++++++++++++++
Msrc/solstice_solve.c | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/doc/output b/doc/output @@ -0,0 +1,33 @@ +<output> ::= + <receiver-count> +[ <receiver-mapping> ... ] +[ <mc-receiver> ... ] + <mc-shadow> + <mc-missing> +[ <receiver-hit> ... ] + +<receiver-count> ::= + INTEGER + +<receiver-mapping> ::= + <receiver-id> <receiver-name> + +<receiver-id> ::= + INTEGER + +<receiver-name> ::= + STRING + +<mc-shadow> ::= + <estimation> + +<mc-missing> ::= + <estimation> + +<mc-receiver> ::= + <receiver-id> <estimation> + +<estimation> ::= + REAL REAL # Expected value and standard error + +<receiver-hit> ::= TODO diff --git a/src/solstice_solve.c b/src/solstice_solve.c @@ -30,6 +30,9 @@ write_header(struct solstice* solstice) htable_receiver_begin(&solstice->receivers, &it); htable_receiver_end(&solstice->receivers, &end); + fprintf(solstice->output, "%lu\n", + (unsigned long)htable_receiver_size_get(&solstice->receivers)); + while(!htable_receiver_iterator_eq(&it, &end)) { struct solstice_receiver* receiver = htable_receiver_iterator_data_get(&it); uint32_t id; @@ -39,15 +42,60 @@ write_header(struct solstice* solstice) } } +static void +write_global_mc(struct solstice* solstice, struct ssol_estimator* estimator) +{ + struct ssol_estimator_status status; + struct htable_receiver_iterator it, end; + ASSERT(solstice && estimator); + + htable_receiver_begin(&solstice->receivers, &it); + htable_receiver_end(&solstice->receivers, &end); + while(!htable_receiver_iterator_eq(&it, &end)) { + struct solstice_receiver* rcv = htable_receiver_iterator_data_get(&it); + struct ssol_instance* inst = rcv->node->instance; + struct ssol_estimator_status front; + struct ssol_estimator_status back; + uint32_t id; + + htable_receiver_iterator_next(&it); + switch(rcv->side) { + case SRCVL_FRONT: + SSOL(estimator_get_receiver_status(estimator, inst, SSOL_FRONT, &front)); + back.E = back.SE = -1; + break; + case SRCVL_BACK: + SSOL(estimator_get_receiver_status(estimator, inst, SSOL_BACK, &back)); + front.E = front.SE = -1; + break; + case SRCVL_FRONT_AND_BACK: + SSOL(estimator_get_receiver_status(estimator, inst, SSOL_FRONT, &front)); + SSOL(estimator_get_receiver_status(estimator, inst, SSOL_BACK, &back)); + break; + default: FATAL("Unreachable code.\n"); break; + } + SSOL(instance_get_id(inst, &id)); + fprintf(solstice->output, "%u %g %g %g %g\n", (unsigned)id, + front.E, front.SE, back.E, back.SE); + } + + SSOL(estimator_get_status(estimator, SSOL_STATUS_SHADOW, &status)); + fprintf(solstice->output, "%g %g\n", status.E, status.SE); + SSOL(estimator_get_status(estimator, SSOL_STATUS_MISSING, &status)); + fprintf(solstice->output, "%g %g\n", status.E, status.SE); +} + /******************************************************************************* * Local functions ******************************************************************************/ res_T solstice_solve(struct solstice* solstice) { + char buf[1024]; struct ssol_estimator* estimator = NULL; - struct ssol_estimator_status status; struct ssp_rng* rng = NULL; + FILE* bin_stream = NULL; + size_t sz; res_T res = RES_OK; ASSERT(solstice); @@ -57,6 +105,13 @@ solstice_solve(struct solstice* solstice) goto error; } + bin_stream = tmpfile(); + if(!bin_stream) { + fprintf(stderr, "Could not create the temporary output binary stream.\n"); + res = RES_IO_ERR; + goto error; + } + res = ssol_estimator_create(solstice->ssol, &estimator); if(res != RES_OK) { fprintf(stderr, "Error in creating the Solstice Estimator.\n"); @@ -66,13 +121,34 @@ solstice_solve(struct solstice* solstice) write_header(solstice); res = ssol_solve(solstice->scene, rng, solstice->nrealisations, - solstice->output, estimator); + /*bin_stream FIXME*/NULL, estimator); if(res != RES_OK) { fprintf(stderr, "Error in integrating the solar flux.\n"); goto error; } + write_global_mc(solstice, estimator); + + sz = (size_t)ftell(bin_stream); + rewind(bin_stream); + + while(sz) { + const size_t read_sz = MMIN(sz, sizeof(buf)); + if(fread(buf, 1, read_sz, bin_stream) != read_sz) { + fprintf(stderr, "Could not read the output binary stream.\n"); + res = RES_IO_ERR; + goto error; + } + if(fwrite(buf, 1, read_sz, solstice->output) != read_sz) { + fprintf(stderr, "Could not write the output binary stream.\n"); + res = RES_IO_ERR; + goto error; + } + sz -= read_sz; + } + exit: + if(bin_stream) fclose(bin_stream); if(estimator) SSOL(estimator_ref_put(estimator)); if(rng) SSP(rng_ref_put(rng)); return res;