commit 0889082d8b2920ed0acb9c47cc1f80470e74cfa4 parent c5a320ccbf7ca4e71820cb5214e3f3604568ad83 Author: Vincent Forest <vincent.forest@meso-star.com> Date: Tue, 4 Jun 2019 16:11:58 +0200 Merge branch 'release_0.9' Diffstat:
70 files changed, 273 insertions(+), 87 deletions(-)
diff --git a/README.md b/README.md @@ -60,6 +60,12 @@ informations on CMake. ## Release notes +### Version 0.9 + +- Add the `-G` option that saves and restores the state of the random number + generator. This option can be used to ensure the statistical independence + between successive runs. + ### Version 0.8.2 - Fix man pages: the -D option of the solstice CLI was wrongly documented. The @@ -192,11 +198,12 @@ for each triangle of a receiver. Its value can be: - Add the verbose option `-v`. - Update the output format of the simulation. -## Licenses +## License Solstice is developed by [|Meso|Star>](http://www.meso-star.com) for the [National Center for Scientific Research](http://www.cnrs.fr/index.php) (CNRS). -This is a free software copyright (C) 2016-2018 CNRS released under the GPL v3+ -license: GNU GPL version 3 or later. You are welcome to redistribute it under -certain conditions; refer to the COPYING file for details. +Copyright (C) 2016-2018 CNRS, 2018-2019 +[|Meso|Star>](http://www.meso-star.com). It is free software released under the +GPL v3+ license: GNU GPL version 3 or later. You are welcome to redistribute it +under certain conditions; refer to the COPYING file for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2018 CNRS +# Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> # # 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 @@ -45,7 +45,7 @@ find_package(LibYAML REQUIRED) find_package(RCMake 0.2.3 REQUIRED) find_package(RSys 0.6 REQUIRED) find_package(SolAnim 0.2 REQUIRED) -find_package(SolSolver 0.7 REQUIRED) +find_package(SolSolver 0.8 REQUIRED) find_package(Star3DUT 0.2 REQUIRED) find_package(StarSP 0.8 REQUIRED) find_package(StarSTL 0.3.1 REQUIRED) @@ -96,8 +96,8 @@ configure_file(${SOLSTICE_SOURCE_DIR}/../doc/solstice.1.txt.in ${CMAKE_CURRENT_BINARY_DIR}/doc/solstice.1.txt @ONLY) set(VERSION_MAJOR 0) -set(VERSION_MINOR 8) -set(VERSION_PATCH 2) +set(VERSION_MINOR 9) +set(VERSION_PATCH 0) set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) configure_file(${SOLSTICE_SOURCE_DIR}/solstice_version.h.in diff --git a/cmake/doc/CMakeLists.txt b/cmake/doc/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2018 CNRS +# Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> # # 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 diff --git a/cmake/parser/CMakeLists.txt b/cmake/parser/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2018 CNRS +# Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> # # 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 diff --git a/cmake/receivers/CMakeLists.txt b/cmake/receivers/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2018 CNRS +# Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> # # 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 diff --git a/doc/solstice-input.5.txt b/doc/solstice-input.5.txt @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2018 CNRS +// Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> // // This is free documentation: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/doc/solstice-man.css b/doc/solstice-man.css @@ -1,4 +1,4 @@ -/* Copyright (C) CNRS 2016-2017 +/* Copyright (C) 2016-2018 CNRS * * This is free style sheet: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/doc/solstice-output.5.txt b/doc/solstice-output.5.txt @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2018 CNRS +// Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> // // This is free documentation: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/doc/solstice-receiver.5.txt b/doc/solstice-receiver.5.txt @@ -1,4 +1,4 @@ -// Copyright (C) 2016-2018 CNRS +// Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> // // This is free documentation: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by diff --git a/doc/solstice.1.txt.in b/doc/solstice.1.txt.in @@ -1,4 +1,4 @@ -// Copyright (C) CNRS 2016-2017 +// Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> // // This is free documentation: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -86,8 +86,26 @@ respectively, while -D__alpha__,90 will produce {0,0,-1} regardless of _alpha_ value. *-f*:: - Force overwrite of the _output_ file. - + Force overwrite of the output files, i.e. the _output_ file and the file + where the state of the random number generator is saved (see the *-G* + option). + +*-G* <__sub-option__:...>:: + Save and restore the state of the random number generator. This option can be + used to ensure the statistical independence between successive simulations + on the same system. For instance, one can run a new simulation and + initialising its random number generator with the final state of the + generator as defined by the previous run. Available sub options are: + + **istate=**_input_rng_state_;; + Define the file from which the initial state of the random number generator + is read. If not defined, the random number generator is initialised with + its default seed. + + **ostate=**_output_rng_state_;; + Define the file where the final state of the random number generator is + written. If not defined, this state is simply discarded. + *-g* <__sub-option__:...>:: Generate the shape of the geometry defined in the submitted _file_ and store it in _output_. Available sub-options are: @@ -239,9 +257,9 @@ remaining data to the *feh*(1) image viewer. COPYRIGHT --------- -*solstice* is copyright © 2016-2018 CNRS. License GPLv3+: GNU GPL version -3 or later <http://gnu.org/licenses/gpl.html>. This is a free software. You are -free to change and redistribute it. There is NO WARRANTY, to the extent +Copyright © 2016-2018 CNRS, 2018-2019 |Meso|Star>. License GPLv3+: GNU GPL +version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software. +You are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO diff --git a/src/main.c b/src/main.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser.c b/src/parser/solparser.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser.h b/src/parser/solparser.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_atmosphere.c b/src/parser/solparser_atmosphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_atmosphere.h b/src/parser/solparser_atmosphere.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_c.h b/src/parser/solparser_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_entity.c b/src/parser/solparser_entity.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_entity.h b/src/parser/solparser_entity.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_geometry.c b/src/parser/solparser_geometry.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_geometry.h b/src/parser/solparser_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_image.c b/src/parser/solparser_image.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_image.h b/src/parser/solparser_image.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_material.c b/src/parser/solparser_material.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_material.h b/src/parser/solparser_material.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_medium.c b/src/parser/solparser_medium.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_medium.h b/src/parser/solparser_medium.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_mtl_data.c b/src/parser/solparser_mtl_data.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_mtl_data.h b/src/parser/solparser_mtl_data.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_pivot.c b/src/parser/solparser_pivot.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_pivot.h b/src/parser/solparser_pivot.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_shape.h b/src/parser/solparser_shape.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_spectrum.c b/src/parser/solparser_spectrum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_spectrum.h b/src/parser/solparser_spectrum.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_sun.c b/src/parser/solparser_sun.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/solparser_sun.h b/src/parser/solparser_sun.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser.c b/src/parser/test_solparser.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser2.c b/src/parser/test_solparser2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser3.c b/src/parser/test_solparser3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser4.c b/src/parser/test_solparser4.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser5.c b/src/parser/test_solparser5.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser6.c b/src/parser/test_solparser6.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser7.c b/src/parser/test_solparser7.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser8.c b/src/parser/test_solparser8.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser_mirror.c b/src/parser/test_solparser_mirror.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser_normal_map.c b/src/parser/test_solparser_normal_map.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/parser/test_solparser_spectrum.c b/src/parser/test_solparser_spectrum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/receivers/srcvl.c b/src/receivers/srcvl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/receivers/srcvl.h b/src/receivers/srcvl.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/receivers/test_srcvl.c b/src/receivers/test_srcvl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/receivers/test_srcvl2.c b/src/receivers/test_srcvl2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice.c b/src/solstice.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 @@ -637,6 +637,21 @@ solstice_init res = setup_sun_dirs(solstice, args); if(res != RES_OK) goto error; + if(args->rng_state_input_filename) { + solstice->rng_state_input = fopen(args->rng_state_input_filename, "r"); + if(!solstice->rng_state_input) { + fprintf(stderr, "Could not open the input RNG state file.\n"); + res = RES_IO_ERR; + goto error; + } + } + + if(args->rng_state_output_filename) { + res = open_output_stream(args->rng_state_output_filename, + args->force_overwriting, &solstice->rng_state_output); + if(res != RES_OK) goto error; + } + if(!args->output_filename) { solstice->output = stdout; } else { @@ -715,6 +730,8 @@ solstice_release(struct solstice* solstice) if(solstice->framebuffer) SSOL(image_ref_put(solstice->framebuffer)); if(solstice->output && solstice->output != stdout) fclose(solstice->output); if(solstice->mtl_virtual) SSOL(material_ref_put(solstice->mtl_virtual)); + if(solstice->rng_state_input) fclose(solstice->rng_state_input); + if(solstice->rng_state_output) fclose(solstice->rng_state_output); htable_material_release(&solstice->materials); htable_object_release(&solstice->objects); htable_anchor_release(&solstice->anchors); diff --git a/src/solstice.h b/src/solstice.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 @@ -193,6 +193,10 @@ struct solstice { FILE* output; /* Output stream */ int dump_paths; + /* Stream used to load/store RNG state */ + FILE* rng_state_input; + FILE* rng_state_output; + struct logger logger; struct mem_allocator* allocator; }; diff --git a/src/solstice_args.c b/src/solstice_args.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 @@ -46,7 +46,10 @@ print_help(const char* program) printf( " -D <dirs> list of sun directions.\n"); printf( -" -f overwrite the OUTPUT file if it already exists.\n"); +" -f overwrite the output files if they already exist, i.e. the\n" +" OUTPUT file and the output RNG state.\n"); + printf( +" -G <rng> save and restore the state of the random number generator.\n"); printf( " -g <dump> switch in dump geometry mode and configure it.\n"); printf( @@ -74,9 +77,9 @@ print_help(const char* program) " --version display version information and exit.\n"); printf("\n"); printf( -"Solstice (C) 2016-2018 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" -"certain conditions <http://gnu.org/licenses/gpl.html>.\n"); +"Solstice (C) 2016-2018 CNRS, 2018-2019 |Meso|Star>. This is a free software\n" +"released under the GNU GPL license, version 3 or later. You are free to change\n" +"or redistribute it under certain conditions <http://gnu.org/licenses/gpl.html>.\n"); } static res_T @@ -264,7 +267,7 @@ parse_rendering_option(const char* str, struct solstice_args* args) char* val; char* ctx; size_t len; - res_T res; + res_T res = RES_OK; ASSERT(str && args); if(strlen(str) >= sizeof(buf) - 1/*NULL char*/) { @@ -482,6 +485,56 @@ error: goto exit; } +static res_T +parse_rng_option(const char* str, struct solstice_args* args) +{ + char buf[128]; + char* key; + char* val; + char* ctx; + size_t len; + res_T res = RES_OK; + ASSERT(str && args); + + if(strlen(str) >= sizeof(buf)-1/*NULL char*/) { + fprintf(stderr, + "Could not duplicate the RNG option string `%s'\n", str); + res = RES_MEM_ERR; + goto error; + } + strncpy(buf, str, sizeof(buf)); + + key = strtok_r(buf, "=", &ctx); + val = strtok_r(NULL, "", &ctx); + + if(!val) { + fprintf(stderr, "Missing a value to the RNG option `%s'.\n", key); + res = RES_BAD_ARG; + goto error; + } + + if(!strcmp(key, "istate")) { /* Input state */ + len = strlen(val); + args->rng_state_input_filename = mem_calloc(len+1, sizeof(char)); + if(!args->rng_state_input_filename) { res = RES_MEM_ERR; goto error; } + strcpy(args->rng_state_input_filename, val); + } else if(!strcmp(key, "ostate")) { /* Output state */ + len = strlen(val); + args->rng_state_output_filename = mem_calloc(len+1, sizeof(char)); + if(!args->rng_state_output_filename) { res = RES_MEM_ERR; goto error; } + strcpy(args->rng_state_output_filename, val); + } else { + fprintf(stderr, "Invalid RNG option `%s'.\n", key); + res = RES_BAD_ARG; + goto error; + } + +exit: + return res; +error: + goto exit; +} + /******************************************************************************* * Local function ******************************************************************************/ @@ -507,7 +560,7 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv) } optind = 0; - while((opt = getopt(argc, argv, "D:fg:hn:o:p:qR:r:t:v")) != -1) { + while((opt = getopt(argc, argv, "D:fG:g:hn:o:p:qR:r:t:v")) != -1) { switch(opt) { case 'D': /* Sun directions */ res = parse_sun_dir_list(optarg, args); @@ -522,6 +575,9 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv) res = cstr_to_ulong(optarg, &args->nexperiments); if(res == RES_OK && !args->nexperiments) res = RES_BAD_ARG; break; + case 'G': /* Setup the random number generator */ + res = parse_multiple_options(optarg, args, parse_rng_option); + break; case 'g': /* Switch in dump geometry mode and configure it */ res = parse_multiple_options(optarg, args, parse_dump_option); if(res == RES_OK && args->dump_format == SOLSTICE_ARGS_DUMP_NONE) { @@ -600,6 +656,8 @@ solstice_args_release(struct solstice_args* args) { ASSERT(args); sa_release(args->sun_dirs); + if(args->rng_state_input_filename) mem_rm(args->rng_state_input_filename); + if(args->rng_state_output_filename) mem_rm(args->rng_state_output_filename); *args = SOLSTICE_ARGS_NULL; } diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in @@ -1,4 +1,4 @@ -/* Copyright (C) CNRS 2016-2017 +/* Copyright (C) CNRS 2016-2018 * * 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 @@ -75,6 +75,10 @@ struct solstice_args { double sun_ray_length; /* Length of the sun rays. */ double infinite_ray_length; /* Length of the rays going to infinity. */ + /* RNG options */ + char* rng_state_input_filename; + char* rng_state_output_filename; + int force_overwriting; int dump_paths; /* Dump radiative paths */ int rendering; @@ -118,6 +122,9 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__; -1, /* Sun ray length */ \ -1, /* Infinite ray length */ \ \ + NULL, /* RNG state input filename */ \ + NULL, /* RNG state output filename */ \ + \ 0, /* Force overwriting */ \ 0, /* Dump radiative paths */ \ 0, /* Rendering */ \ diff --git a/src/solstice_atmosphere.c b/src/solstice_atmosphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_c.h b/src/solstice_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_draw.c b/src/solstice_draw.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_dump.c b/src/solstice_dump.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_entity.c b/src/solstice_entity.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_material.c b/src/solstice_material.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_node.c b/src/solstice_node.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_object.c b/src/solstice_object.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_solve.c b/src/solstice_solve.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 @@ -548,6 +548,15 @@ solstice_solve(struct solstice* solstice) goto error; } + if(solstice->rng_state_input) { + rewind(solstice->rng_state_input); + res = ssp_rng_read(rng, solstice->rng_state_input); + if(res != RES_OK) { + fprintf(stderr, "Could not read the input RNG state.\n"); + goto error; + } + } + max_failure = solstice->dump_paths ? solstice->nexperiments : (size_t)((double)solstice->nexperiments * MAX_PERCENT_FAILURES); @@ -566,6 +575,16 @@ solstice_solve(struct solstice* solstice) write_per_receiver_mc_primitive(solstice, estimator); } + if(solstice->rng_state_output) { + const struct ssp_rng* rng_state = NULL; + SSOL(estimator_get_rng_state(estimator, &rng_state)); + res = ssp_rng_write(rng_state, solstice->rng_state_output); + if(res != RES_OK) { + fprintf(stderr, "Could not write the RNG state.\n"); + goto error; + } + } + exit: if(estimator) SSOL(estimator_ref_put(estimator)); if(rng) SSP(rng_ref_put(rng)); diff --git a/src/solstice_spectrum.c b/src/solstice_spectrum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_sun.c b/src/solstice_sun.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_sun_spectrum.c b/src/solstice_sun_spectrum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/solstice_sun_spectrum.h b/src/solstice_sun_spectrum.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 @@ -670,6 +670,61 @@ test_dump_paths(void) cmd_delete(cmd); } +static void +test_rng(void) +{ + struct solstice_args args = SOLSTICE_ARGS_NULL; + char** cmd = NULL; + + cmd = cmd_create(0, "test", "-D", "0,90", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_OK); + CHK(args.rng_state_input_filename == NULL); + CHK(args.rng_state_output_filename == NULL); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "ostate=/tmp/rng_output.txt", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_OK); + CHK(args.rng_state_input_filename == NULL); + CHK(!strcmp(args.rng_state_output_filename, "/tmp/rng_output.txt")); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "istate=/tmp/rng_input.txt", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_OK); + CHK(!strcmp(args.rng_state_input_filename, "/tmp/rng_input.txt")); + CHK(args.rng_state_output_filename == NULL); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "istate=in.txt:ostate=out.txt", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_OK); + CHK(!strcmp(args.rng_state_input_filename, "in.txt")); + CHK(!strcmp(args.rng_state_output_filename, "out.txt")); + solstice_args_release(&args); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "istate=", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "ostate=", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "istate=in.txt:ostate=", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", "istate=:ostate=out", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG); + cmd_delete(cmd); + + cmd = cmd_create(0, "test", "-D", "0,90", "-G", NULL); + CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG); + cmd_delete(cmd); +} + int main(int argc, char** argv) { @@ -685,6 +740,7 @@ main(int argc, char** argv) test_input(); test_dump(); test_dump_paths(); + test_rng(); CHK(mem_allocated_size() == 0); return 0; } diff --git a/src/test_solstice_simulation.c b/src/test_solstice_simulation.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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 diff --git a/src/test_solstice_utils.h b/src/test_solstice_utils.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016-2018 CNRS +/* Copyright (C) 2016-2018 CNRS, 2018-2019 |Meso|Star> * * 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