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 fcd28c46ddd6977662747c44dc9243440d087d13
parent ded931b64237f1a24c661149cedc53e2d355549f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 25 Jan 2017 10:55:09 +0100

By default, rm the per receiver hits from the output

Use the -H option to enable the per receiver hits.

Diffstat:
Mdoc/cli | 1+
Mdoc/output | 12++++--------
Msrc/solstice.c | 1+
Msrc/solstice.h | 1+
Msrc/solstice_args.c | 10+++++++---
Msrc/solstice_args.h.in | 2++
Msrc/solstice_solve.c | 75++++++++++++++++++++++++++++++---------------------------------------------
7 files changed, 46 insertions(+), 56 deletions(-)

diff --git a/doc/cli b/doc/cli @@ -1,4 +1,5 @@ solstice + -b # Output binary per receiver hits -d <date-list>:<pos-on-earth> -D <sun-dir-list> -h # Short help and exit diff --git a/doc/output b/doc/output @@ -1,16 +1,15 @@ <output> ::= - <receiver-count> -[ <receiver-mapping> ... ] + <receivers-count> [ <mc-receiver> ... ] <mc-shadow> <mc-missing> [ <receiver-hit> ... ] -<receiver-count> ::= +<receivers-count> ::= INTEGER -<receiver-mapping> ::= - <receiver-id> <receiver-name> +<mc-receiver> ::= + <receiver-name> <receiver-id> <estimation> <receiver-id> ::= INTEGER @@ -24,9 +23,6 @@ <mc-missing> ::= <estimation> -<mc-receiver> ::= - <receiver-id> <estimation> - <estimation> ::= REAL REAL # Expected value and standard error diff --git a/src/solstice.c b/src/solstice.c @@ -415,6 +415,7 @@ solstice_init } solstice->nrealisations = args->nrealisations; + solstice->output_hits = args->output_hits; exit: return res; diff --git a/src/solstice.h b/src/solstice.h @@ -128,6 +128,7 @@ struct solstice { size_t nrealisations; /* # realisations */ FILE* output; /* Output stream */ + int output_hits; /* Output per receiver hits */ struct mem_allocator* allocator; }; diff --git a/src/solstice_args.c b/src/solstice_args.c @@ -44,6 +44,8 @@ print_help(const char* program) printf( " -D <dirs> list of sun directions.\n"); printf( +" -H output the per receiver hit data.\n"); + printf( " -h display this help and exit.\n"); printf( " -n number of realisation. Default is %lu.\n", @@ -55,9 +57,10 @@ print_help(const char* program) printf( " -q do not print the helper message when no FILE is submitted.\n"); printf( -" -r <rendering> switch in rendering mode and configure it.\n"); +" -R RECEIVERS define the file from which the list of receivers are read.\n"); printf( -" -R RECEIVERS define the file from which the list of receivers are read.\n\n"); +" -r <rendering> switch in rendering mode and configure it.\n"); + printf("\n"); printf( "Solstice (C) 2016-2017 CNRS. This is a free software released under the GNU GPL\n" "license, version 3 or later. You are free to change or redistribute it under\n" @@ -318,11 +321,12 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv) *args = SOLSTICE_ARGS_DEFAULT; optind = 1; - while((opt = getopt(argc, argv, "D:hn:o:qR:r:")) != -1) { + while((opt = getopt(argc, argv, "D:Hhn:o:qR:r:")) != -1) { switch(opt) { case 'D': res = parse_sun_dir_list(optarg, args); break; + case 'H': args->output_hits = 1; break; case 'h': print_help(argv[0]); solstice_args_release(args); diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in @@ -46,6 +46,7 @@ struct solstice_args { } img; int rendering; + int output_hits; /* Output the per receiver hits */ int quiet; int quit; /* Quit the application */ }; @@ -75,6 +76,7 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__; }, \ \ 0, /* Rendering */ \ + 0, /* Output hits */ \ 0, /* Quiet */ \ 0 /* Quit */ \ } diff --git a/src/solstice_solve.c b/src/solstice_solve.c @@ -22,33 +22,15 @@ * Helper function ******************************************************************************/ static void -write_header(struct solstice* solstice) -{ - struct htable_receiver_iterator it, end; - ASSERT(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; - SSOL(instance_get_id(receiver->node->instance, &id)); - fprintf(solstice->output, "%u %s\n", id, str_cget(&receiver->name)); - htable_receiver_iterator_next(&it); - } -} - -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); + fprintf(solstice->output, "%lu\n", + (unsigned long)htable_receiver_size_get(&solstice->receivers)); + htable_receiver_begin(&solstice->receivers, &it); htable_receiver_end(&solstice->receivers, &end); while(!htable_receiver_iterator_eq(&it, &end)) { @@ -75,7 +57,8 @@ write_global_mc(struct solstice* solstice, struct ssol_estimator* estimator) default: FATAL("Unreachable code.\n"); break; } SSOL(instance_get_id(inst, &id)); - fprintf(solstice->output, "%u %g %g %g %g\n", (unsigned)id, + fprintf(solstice->output, "%s %u %g %g %g %g\n", + str_cget(&rcv->name), (unsigned)id, front.E, front.SE, back.E, back.SE); } @@ -105,11 +88,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; + if(solstice->output_hits) { + 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); @@ -118,10 +103,8 @@ solstice_solve(struct solstice* solstice) goto error; } - write_header(solstice); - res = ssol_solve(solstice->scene, rng, solstice->nrealisations, - /*bin_stream FIXME*/NULL, estimator); + bin_stream, estimator); if(res != RES_OK) { fprintf(stderr, "Error in integrating the solar flux.\n"); goto error; @@ -129,22 +112,24 @@ solstice_solve(struct solstice* solstice) 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; + if(solstice->output_hits) { + 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; } - sz -= read_sz; } exit: