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 28e03a5561dec00dcc0e88ef160c77c0b6860418
parent 54063690d4d35aa3203b94c32cf2c938c9b605fc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 31 May 2017 16:36:52 +0200

Add the verbose option '-v' to the solstice command

Diffstat:
Mdoc/solstice.1.txt.in | 25++++++++++++++++---------
Msrc/solstice.c | 32+++++++++++++++++++++++++++++++-
Msrc/solstice.h | 2++
Msrc/solstice_args.c | 14++++++++------
Msrc/solstice_args.h.in | 4+++-
Msrc/test_solstice_args.c | 21+++++++++++++++++++++
6 files changed, 81 insertions(+), 17 deletions(-)

diff --git a/doc/solstice.1.txt.in b/doc/solstice.1.txt.in @@ -77,9 +77,6 @@ OPTIONS *-f*:: Force overwrite of the _output_ file. -*-h*:: - List short help and exit. - *-g* <__sub-option__:...>:: Generate the shape of the geometry defined in the submitted _file_ and store it in _output_. Available sub-options are: @@ -95,6 +92,13 @@ OPTIONS mesh is generated for the whole solar facility. By default, the *split* option is set to *none*. +*-h*:: + List short help and exit. + +*-n* _experiments-count_:: + Number of Monte-Carlo experiments used to estimate the solar flux. By + default _experiments-count_ is set to @SOLSTICE_ARGS_DEFAULT_NREALISATIONS@. + *-o* _output_:: Write results to _output_ with respect to the *solstice-output*(5) format. If not defined, write results to standard output. @@ -117,9 +121,9 @@ OPTIONS *-q*:: Do not print the helper message when no _file_ is submitted. -*-n* _experiments-count_:: - Number of Monte-Carlo experiments used to estimate the solar flux. By - default _experiments-count_ is set to @SOLSTICE_ARGS_DEFAULT_NREALISATIONS@. +*-R* _receivers_:: + *solstice-receiver*(5) file defining the scene receivers, i.e. the solar + plant entities for which *solstice* computes Monte-Carlo estimates. *-r* <__sub-option__:...>:: Render an image of the scene through a pinhole camera, for each submitted @@ -166,9 +170,12 @@ OPTIONS direction toward the top of the skydome. By default, *up* is set to {@SOLSTICE_ARGS_DEFAULT_CAMERA_UP@}. -*-R* _receivers_:: - *solstice-receiver*(5) file defining the scene receivers, i.e. the solar - plant entities for which *solstice* computes Monte-Carlo estimates. +*-t* _threads-count_:: + Hint on the number of threads to use. By default us as many threads as CPU + cores. + +*-v*:: + Make solstice more verbose. EXAMPLES -------- diff --git a/src/solstice.c b/src/solstice.c @@ -48,6 +48,30 @@ * Helper functions ******************************************************************************/ static void +log_err(const char* msg, void* ctx) +{ + ASSERT(msg); + (void)ctx; +#if OS_WINDOWS + fprintf(stderr, "error: %s", msg); +#else + fprintf(stderr, "\x1b[31merror:\x1b[0m %s", msg); +#endif +} + +static void +log_warn(const char* msg, void* ctx) +{ + ASSERT(msg); + (void)ctx; +#ifdef OS_WINDOWS + fprintf(stderr,"warning: %s", msg); +#else + fprintf(stderr, "\x1b[33mwarning:\x1b[0m %s", msg); +#endif +} + +static void clear_materials(struct htable_material* materials) { struct htable_material_iterator it, end; @@ -553,7 +577,12 @@ solstice_init solstice->allocator = allocator ? allocator : &mem_default_allocator; - res = ssol_device_create(NULL, allocator, args->nthreads, 0, &solstice->ssol); + logger_init(solstice->allocator, &solstice->logger); + logger_set_stream(&solstice->logger, LOG_ERROR, log_err, NULL); + logger_set_stream(&solstice->logger, LOG_WARNING, log_warn, NULL); + + res = ssol_device_create(&solstice->logger, allocator, args->nthreads, + args->verbose, &solstice->ssol); if(res != RES_OK) { fprintf(stderr, "Could not create the Solstice Solver device.\n"); goto error; @@ -666,6 +695,7 @@ solstice_release(struct solstice* solstice) darray_nodes_release(&solstice->pivots); darray_double_release(&solstice->sun_dirs); darray_double_release(&solstice->sun_angles); + logger_release(&solstice->logger); } res_T diff --git a/src/solstice.h b/src/solstice.h @@ -22,6 +22,7 @@ #include <rsys/dynamic_array_double.h> #include <rsys/hash_table.h> +#include <rsys/logger.h> #include <rsys/mem_allocator.h> #include <rsys/str.h> @@ -122,6 +123,7 @@ struct solstice { FILE* output; /* Output stream */ int dump_paths; + struct logger logger; struct mem_allocator* allocator; }; diff --git a/src/solstice_args.c b/src/solstice_args.c @@ -38,8 +38,9 @@ print_help(const char* program) { printf( "Usage: %s [OPTIONS] [FILE]\n" -"Integrate the solar flux in a complex solar facility described in FILE. If\n" -"not define, the solar facility is read from standard input.\n\n", +"Integrate the solar flux in a complex solar facility described in FILE. If not\n" +"define, the solar facility is read from standard input. Refer to solstice(1)\n" +"man page for more informations.\n\n", program); printf( " -D <dirs> list of sun directions.\n"); @@ -47,15 +48,13 @@ print_help(const char* program) " -f do not prompt before overwriting the output file submitted\n" " with the '-o' option.\n"); printf( -" -H output hit-on-receiver data (binary format).\n"); +" -g <dump> switch in dump geometry mode and configure it.\n"); printf( " -h display this help and exit.\n"); printf( " -n EXPERIMENTS number of Monte Carlo experiments. Default is %lu.\n", SOLSTICE_ARGS_DEFAULT.nexperiments); printf( -" -g <dump> switch in dump geometry mode and configure it.\n"); - printf( " -o OUTPUT write results to OUTPUT. If not defined, write results to\n" " standard output.\n"); printf( @@ -69,6 +68,8 @@ print_help(const char* program) printf( " -t THREADS hint on the number of threads to use. By default use as\n" " many threads as CPU cores.\n"); + printf( +" -v make the program more verbose.\n"); printf("\n"); printf( "Solstice (C) 2016-2017 CNRS. This is a free software released under the GNU GPL\n" @@ -492,7 +493,7 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv) *args = SOLSTICE_ARGS_DEFAULT; optind = 0; - while((opt = getopt(argc, argv, "D:fg:hn:o:p:qR:r:t:")) != -1) { + while((opt = getopt(argc, argv, "D:fg:hn:o:p:qR:r:t:v")) != -1) { switch(opt) { case 'D': /* Sun directions */ res = parse_sun_dir_list(optarg, args); @@ -530,6 +531,7 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv) res = cstr_to_uint(optarg, &args->nthreads); if(res == RES_OK && !args->nthreads) res = RES_BAD_ARG; break; + case 'v': args->verbose = 1; break; default: res = RES_BAD_ARG; break; } if(res != RES_OK) { diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in @@ -80,6 +80,7 @@ struct solstice_args { int rendering; int quiet; int quit; /* Quit the application */ + int verbose; }; #define SOLSTICE_ARGS_NULL__ {0} @@ -121,7 +122,8 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__; 0, /* Dump radiative paths */ \ 0, /* Rendering */ \ 0, /* Quiet */ \ - 0 /* Quit */ \ + 0, /* Quit */ \ + 0 /* Verbose */ \ } static const struct solstice_args SOLSTICE_ARGS_DEFAULT = SOLSTICE_ARGS_DEFAULT__; diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c @@ -440,6 +440,26 @@ test_quiet(void) } static void +test_verbose(void) +{ + struct solstice_args args = SOLSTICE_ARGS_NULL; + char** cmd = NULL; + + cmd = cmd_create(0, "test", "-D", "0,90", NULL); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK); + CHECK(args.verbose, SOLSTICE_ARGS_DEFAULT.verbose); + CHECK(args.verbose, 0); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-v", NULL); + CHECK(solstice_args_init(&args, cmd_size(cmd), cmd), RES_OK); + CHECK(args.verbose, 1); + solstice_args_release(&args); + cmd_delete(cmd); +} + +static void test_receivers(void) { struct solstice_args args = SOLSTICE_ARGS_NULL; @@ -660,6 +680,7 @@ main(int argc, char** argv) test_threads_count(); test_output(); test_quiet(); + test_verbose(); test_receivers(); test_input(); test_dump();