commit c7baffa6340d69d67651ee70fbc4fc3cc7119476
parent d09dd1731d105a100f25c5218de228372bebb252
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Mon, 22 Jun 2026 17:16:18 +0200
Add a command line option to set the DNI
The sun's description in the input data already includes a mandatory dni
value. The new option allow to supersede this dni value from the command
line.
Diffstat:
6 files changed, 82 insertions(+), 18 deletions(-)
diff --git a/doc/solstice-input.5 b/doc/solstice-input.5
@@ -321,6 +321,10 @@ property is its direct normal irradiance, or
in W/m².
Its value is a scalar defining the direct irradiance received on a plane
perpendicular to the main sun direction.
+This value, even though mandatory, can be superseded by another value provided
+by the
+.Xr solstice 1
+command.
The optional
.Em spectrum
parameter describes the per-wavelength distribution of the sun
diff --git a/doc/solstice.1.in b/doc/solstice.1.in
@@ -184,12 +184,13 @@ is set to
.El
.It Fl h
List short help and exit.
-.It Fl n Ar samples-count
-Number of Monte-Carlo samples used to estimate the solar flux.
-By default
-.Ar samples-count
-is set to
-.Sy @SOLSTICE_ARGS_DEFAULT_NREALISATIONS@ .
+.It Fl I Ar dni
+Set the Direct Normal Irradiance value, in in W/m\u2\s0\d, used for the
+computation.
+Must be in ]0 INF).
+If unset, use the mandatory
+.Ar dni
+value describing the sun in the input data.
.It Fl L Ar latitude,longitude
Define the location of the solar plant.
The
@@ -202,6 +203,12 @@ must be in [-180, 180] degrees relative to Greenwich, counting
positive towards the east.
A location must be defined before any time is defined.
It is then applied to any following time until a new location is defined.
+.It Fl n Ar samples-count
+Number of Monte-Carlo samples used to estimate the solar flux.
+By default
+.Ar samples-count
+is set to
+.Sy @SOLSTICE_ARGS_DEFAULT_NREALISATIONS@ .
.It Fl o Ar output
Write results to
.Ar output
diff --git a/src/solstice.c b/src/solstice.c
@@ -673,6 +673,16 @@ solstice_init
solstice->dump_split_mode = args->dump_split_mode;
solstice->dump_paths = args->dump_paths;
+ /* If a dni value is provided on the command line, the dni defined in the yaml
+ * description of the sun is no longer used */
+ if(args->dni > 0) {
+ res = ssol_sun_set_dni(solstice->sun, args->dni);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not setup the DNI of the sun.\n");
+ goto error;
+ }
+ }
+
solstice->path_tracker = SSOL_PATH_TRACKER_DEFAULT;
solstice->path_tracker.infinite_ray_length = args->infinite_ray_length;
solstice->path_tracker.sun_ray_length = args->sun_ray_length;
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -54,6 +54,8 @@ print_help(const char* program)
printf(
" -h display this help and exit.\n");
printf(
+" -I <DNI> set the DNI value.\n");
+ printf(
" -n SAMPLES number of Monte Carlo samples. Default is %lu.\n",
SOLSTICE_ARGS_DEFAULT.nexperiments);
printf(
@@ -625,21 +627,12 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
}
optind = 0;
- while((opt = getopt(argc, argv, "D:fG:g:hn:L:o:p:qR:r:T:t:v")) != -1) {
+ while((opt = getopt(argc, argv, "D:fG:g:hI:n:L:o:p:qR:r:T:t:v")) != -1) {
switch(opt) {
case 'D': /* 1 sun direction */
res = parse_sun_spherical(optarg, args);
break;
case 'f': args->force_overwriting = 1; break;
- case 'h': /* Print short help and exit */
- print_help(argv[0]);
- solstice_args_release(args);
- args->quit = 1;
- goto exit;
- case 'n': /* Define the number of MC samples */
- 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;
@@ -649,12 +642,31 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
fprintf(stderr, "%s: missing a dump format -- `%s'.\n",
argv[0], optarg);
res = RES_BAD_ARG;
+ goto error;
+ }
+ break;
+ case 'h': /* Print short help and exit */
+ print_help(argv[0]);
+ solstice_args_release(args);
+ args->quit = 1;
+ goto exit;
+ case 'I': /* DNI */
+ res = cstr_to_double(optarg, &args->dni);
+ if(res == RES_OK && args->dni <= 0) {
+ fprintf(stderr, "%s: invalid DNI value -- `%s'.\n",
+ argv[0], optarg);
+ res = RES_BAD_ARG;
+ goto error;
}
break;
case 'L': /* Plant location */
L_defined = 1;
res = parse_location(optarg, current_loc, args);
break;
+ case 'n': /* Define the number of MC samples */
+ res = cstr_to_ulong(optarg, &args->nexperiments);
+ if(res == RES_OK && !args->nexperiments) res = RES_BAD_ARG;
+ break;
case 'o': args->output_filename = optarg; break;
case 'p': /* Switch in dump radiative paths mode and configure it */
args->dump_paths = 1;
@@ -669,9 +681,10 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
case 'T': /* 1 time */
if(!L_defined) {
fprintf(stderr,
- "%s: cannot use the -%c option with no current location defined '%s'\n",
+ "%s: cannot use the -%c option with no location defined '%s'\n",
argv[0], opt, optarg);
res = RES_BAD_ARG;
+ goto error;
break;
}
res = parse_time(optarg, current_loc, args);
diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in
@@ -71,6 +71,7 @@ struct solstice_args {
const char* output_filename;
const char* input_filename; /* May be NULL <=> read data from stdin */
const char* receivers_filename;
+ double dni;
unsigned long nexperiments; /* #experiments */
unsigned nthreads; /* #threads */
@@ -121,6 +122,7 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__;
NULL, /* output_filename */ \
NULL, /* input_filename */ \
NULL, /* receivers_filename */ \
+ -1, \
@SOLSTICE_ARGS_DEFAULT_NREALISATIONS@, \
SSOL_NTHREADS_DEFAULT, \
\
diff --git a/src/test_solstice_args.c b/src/test_solstice_args.c
@@ -507,7 +507,6 @@ test_threads_count(void)
cmd = cmd_create(0, "test", "-D", "0,90", "-t", NULL);
CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG);
cmd_delete(cmd);
-
}
static void
@@ -845,6 +844,34 @@ test_rng(void)
cmd_delete(cmd);
}
+static void
+test_dni(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.dni == -1);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-I", "1", NULL);
+ CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_OK);
+ CHK(args.dni == 1);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-I", "0", NULL);
+ CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG);
+ solstice_args_release(&args);
+ cmd_delete(cmd);
+
+ cmd = cmd_create(0, "test", "-D", "0,90", "-I", NULL);
+ CHK(solstice_args_init(&args, cmd_size(cmd), cmd) == RES_BAD_ARG);
+ cmd_delete(cmd);
+}
+
int
main(int argc, char** argv)
{
@@ -861,6 +888,7 @@ main(int argc, char** argv)
test_dump();
test_dump_paths();
test_rng();
+ test_dni();
CHK(mem_allocated_size() == 0);
return 0;
}