commit 4f0069cb02dfe1308e32574c510eed5ba2fc82b6
parent 285fbf8ec1c4ad2ea1db707af6dc15e3269be7b6
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 7 Mar 2017 18:39:49 +0100
Change the way sun direction is put on the command line: using angles.
This allows to remove the -3 x,y,z option introduced previously (using
now the -D option).
The output has to be adapted and now includes the used angles so that we
can get them back from reference files.
Finally we had to update all the reference files accordingly.
Diffstat:
11 files changed, 43 insertions(+), 94 deletions(-)
diff --git a/src/solstice.c b/src/solstice.c
@@ -20,6 +20,8 @@
#include "solstice_args.h"
#include "parser/solparser.h"
+#include <rsys/double2.h>
+
#include <sys/stat.h>
#include <sys/types.h>
@@ -306,31 +308,37 @@ static res_T
setup_sun_dirs(struct solstice* solstice, const struct solstice_args* args)
{
double* sun_dirs = NULL;
- size_t i, ii;
+ double* sun_angles = NULL;
+ size_t i;
res_T res = RES_OK;
ASSERT(solstice && args);
- res = darray_double_resize(&solstice->sun_dirs, (args->nsun_dirs + args->nsun_dirs3)*3/*#dims*/);
+ res = darray_double_resize(&solstice->sun_dirs, args->nsun_dirs*3/*#dims*/);
if(res != RES_OK) {
fprintf(stderr,
"Could not reserve the list of %lu sun directions.\n",
(unsigned long)args->nsun_dirs);
goto error;
-
}
-
+ res = darray_double_resize(&solstice->sun_angles, args->nsun_dirs*2/*#dims*/);
+ if (res != RES_OK) {
+ fprintf(stderr,
+ "Could not reserve the list of %lu sun angles.\n",
+ (unsigned long)args->nsun_dirs);
+ goto error;
+ }
sun_dirs = darray_double_data_get(&solstice->sun_dirs);
+ sun_angles = darray_double_data_get(&solstice->sun_angles);
FOR_EACH(i, 0, args->nsun_dirs) {
spherical_to_cartesian_sun_dir(args->sun_dirs + i, sun_dirs + i*3/*#dims*/);
- }
- FOR_EACH(ii, 0, args->nsun_dirs3) {
- d3_normalize(sun_dirs + (i + ii) * 3/*#dims*/, &args->sun_dirs3[ii].x);
+ d2(sun_angles + i*2, args->sun_dirs[i].azimuth, args->sun_dirs[i].elevation);
}
exit:
return res;
error:
darray_double_clear(&solstice->sun_dirs);
+ darray_double_clear(&solstice->sun_angles);
goto exit;
}
@@ -534,6 +542,7 @@ solstice_init
darray_nodes_init(allocator, &solstice->roots);
darray_nodes_init(allocator, &solstice->pivots);
darray_double_init(allocator, &solstice->sun_dirs);
+ darray_double_init(allocator, &solstice->sun_angles);
solstice->allocator = allocator ? allocator : &mem_default_allocator;
@@ -634,12 +643,14 @@ solstice_release(struct solstice* solstice)
darray_nodes_release(&solstice->roots);
darray_nodes_release(&solstice->pivots);
darray_double_release(&solstice->sun_dirs);
+ darray_double_release(&solstice->sun_angles);
}
res_T
solstice_run(struct solstice* solstice)
{
const double* sun_dirs = NULL;
+ const double* sun_angles = NULL;
size_t nsun_dirs = 0;
size_t i;
int dump;
@@ -648,6 +659,7 @@ solstice_run(struct solstice* solstice)
ASSERT(solstice);
sun_dirs = darray_double_cdata_get(&solstice->sun_dirs);
+ sun_angles = darray_double_cdata_get(&solstice->sun_angles);
nsun_dirs = darray_double_size_get(&solstice->sun_dirs);
ASSERT(nsun_dirs%3 == 0);
nsun_dirs /= 3/*#dims*/;
@@ -667,7 +679,8 @@ solstice_run(struct solstice* solstice)
} else {
FOR_EACH(i, 0, nsun_dirs) {
const double* sun_dir = sun_dirs + i*3/*#dims*/;
- fprintf(solstice->output, "#--- Sun direction: %g %g %g\n", SPLIT3(sun_dir));
+ fprintf(solstice->output, "#--- Sun direction: %g %g (%g %g %g)\n",
+ SPLIT2(sun_angles), SPLIT3(sun_dir));
res = solstice_update_entities(solstice, sun_dir);
if(res != RES_OK) goto error;
diff --git a/src/solstice.h b/src/solstice.h
@@ -92,6 +92,7 @@ struct solstice {
enum solstice_args_dump_split_mode dump_split_mode;
struct darray_double sun_dirs; /* List of double3 */
+ struct darray_double sun_angles;
size_t nrealisations; /* # realisations */
FILE* output; /* Output stream */
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -44,8 +44,6 @@ print_help(const char* program)
printf(
" -D <dirs> list of sun directions.\n");
printf(
-" -3 <dir> sun direction.\n");
- printf(
" -f do not prompt before overwriting the output file submitted\n"
" with the '-o' option.\n");
printf(
@@ -164,57 +162,6 @@ error:
}
static res_T
-parse_sun_dir3(const char* str, struct solstice_args* args)
-{
- char buf[512];
- char* tk;
- 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 list of sun directions `%s'.\n", str);
- res = RES_MEM_ERR;
- goto error;
- }
- strncpy(buf, str, sizeof(buf));
-
- tk = strtok_r(buf, ":", &ctx);
- while (tk) {
- struct solstice_args_dir3 tmp;
-
- res = cstr_to_list_double(tk, ',', &tmp.x, &len, 3);
- if (res == RES_OK && len != 3) res = RES_BAD_ARG;
- if (res != RES_OK) {
- fprintf(stderr, "Invalid sun direction `%s'.\n", tk);
- goto error;
- }
-
- if (tmp.x == 0 && tmp.y == 0 && tmp.z == 0) {
- fprintf(stderr, "Invalid 0,0,0 sun direction.\n");
- res = RES_BAD_ARG;
- goto error;
- }
- sa_push(args->sun_dirs3, tmp);
-
- tk = strtok_r(NULL, ":", &ctx);
- }
- args->nsun_dirs3 += sa_size(args->sun_dirs3);
-
-exit:
- return res;
-error:
- if (args->sun_dirs3) {
- sa_release(args->sun_dirs3);
- args->sun_dirs3 = NULL;
- args->nsun_dirs3 = 0;
- }
- goto exit;
-}
-
-static res_T
parse_image_definition
(const char* str,
unsigned long* width,
@@ -491,14 +438,11 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
*args = SOLSTICE_ARGS_DEFAULT;
optind = 0;
- while((opt = getopt(argc, argv, "D:3:fg:Hhn:o:qR:r:t:")) != -1) {
+ while((opt = getopt(argc, argv, "D:fg:Hhn:o:qR:r:t:")) != -1) {
switch(opt) {
case 'D':
res = parse_sun_dir_list(optarg, args);
break;
- case '3':
- res = parse_sun_dir3(optarg, args);
- break;
case 'f': args->force_overwriting = 1; break;
case 'H': args->output_hits = 1; break;
case 'h':
@@ -532,7 +476,7 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
if(!args->rendering
&& args->dump_format == SOLSTICE_ARGS_DUMP_NONE
- && 0 == args->nsun_dirs + args->nsun_dirs3) {
+ && !args->nsun_dirs) {
fprintf(stderr, "Missing sun direction.\n");
res = RES_BAD_ARG;
goto error;
@@ -561,7 +505,6 @@ solstice_args_release(struct solstice_args* args)
{
ASSERT(args);
sa_release(args->sun_dirs);
- sa_release(args->sun_dirs3);
*args = SOLSTICE_ARGS_NULL;
}
diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in
@@ -24,10 +24,6 @@ struct solstice_args_spherical {
double elevation; /* In radians */
};
-struct solstice_args_dir3 {
- double x, y, z;
-};
-
enum solstice_args_dump_format {
SOLSTICE_ARGS_DUMP_OBJ,
SOLSTICE_ARGS_DUMP_NONE
@@ -49,8 +45,6 @@ struct solstice_args {
/* List of sun directions */
struct solstice_args_spherical* sun_dirs;
size_t nsun_dirs;
- struct solstice_args_dir3* sun_dirs3;
- size_t nsun_dirs3;
struct {
double pos[3];
@@ -87,8 +81,6 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__;
\
NULL, /* sun_dirs */ \
0, /* # nsun_dirs */ \
- NULL, /* sun_dirs3 */ \
- 0, /* # nsun_dirs3 */ \
\
{ /* Camera */ \
{ @SOLSTICE_ARGS_DEFAULT_CAMERA_POS@ }, \
diff --git a/src/test_model/test_model.c b/src/test_model/test_model.c
@@ -70,19 +70,19 @@ sundir_header [] = "#--- Sun direction:";
static res_T
get_dir_and_counts
(FILE* ref_file,
- double sun_dir[3],
+ double sun_angles[2],
size_t* recv_count,
size_t* realisation_count)
{
char line[MAX_LINE_LEN];
- ASSERT(ref_file);
+ ASSERT(ref_file && sun_angles);
if (!fgets(line, sizeof(line), ref_file)) return RES_BAD_ARG;
if (!IS_NEW_BLOC(line, sundir_header))
return RES_BAD_ARG;
/* get sun dir */
- if (3 != sscanf(line + strlen(sundir_header),
- "%lg%lg%lg", &sun_dir[0], &sun_dir[1], &sun_dir[2])) {
+ if (2 != sscanf(line + strlen(sundir_header),
+ "%lg%lg", &sun_angles[0], &sun_angles[1])) {
return RES_BAD_ARG;
}
/* get sun dir */
@@ -145,10 +145,10 @@ check_1_reference
{
res_T res = RES_OK;
ASSERT(tested_file && rcv_name && reference_E && reference_SE);
- double d[3];
+ double a[2];
size_t c1, c2;
- res = get_dir_and_counts(tested_file, d, &c1, &c2); /* skip headers */
+ res = get_dir_and_counts(tested_file, a, &c1, &c2); /* skip headers */
if (res != RES_OK) goto error;
while(!feof(tested_file)) {
char line[MAX_LINE_LEN];
@@ -187,13 +187,13 @@ check_1_global
{
res_T res = RES_OK;
char line[MAX_LINE_LEN];
- double d[3];
+ double a[2];
size_t recv_count, r2;
unsigned i;
int nb;
double tested_E, tested_SE;
- res = get_dir_and_counts(tested_file, d, &recv_count, &r2);
+ res = get_dir_and_counts(tested_file, a, &recv_count, &r2);
if (res != RES_OK) goto error;
/* skip receivers */
for ( ; recv_count--; ) {
@@ -320,7 +320,7 @@ do_check(const char* base_name)
}
while (!feof(ref_file)) {
char cmd[128 + 3 * MAX_PATH];
- double sun_dir[3];
+ double sun_angles[2];
char tested_file_name[L_tmpnam_s];
#ifdef COMPILER_CL
const char* exe_name = "..\\Debug\\solstice.exe";
@@ -328,15 +328,15 @@ do_check(const char* base_name)
const char* exe_name = "../Debug/solstice.exe";
#endif
- res = get_dir_and_counts(ref_file, sun_dir, &c1, &realisation_count);
+ res = get_dir_and_counts(ref_file, sun_angles, &c1, &realisation_count);
if (res != RES_OK) goto end;
res = create_tmp_file_name(tested_file_name);
if (res != RES_OK) goto end;
snprintf(cmd, sizeof(cmd),
- "%s -o %s -f -3 %lg,%lg,%lg -n %zu -R %s%s_receiver.yaml %s%s.yaml",
- exe_name, tested_file_name, SPLIT3(sun_dir), realisation_count,
+ "%s -o %s -f -D %g,%g -n %zu -R %s%s_receiver.yaml %s%s.yaml",
+ exe_name, tested_file_name, SPLIT2(sun_angles), realisation_count,
dir, base_name, dir, base_name);
if (system(cmd)) {
res = RES_BAD_ARG;
diff --git a/yaml/beam_down.ref b/yaml/beam_down.ref
@@ -1,10 +1,10 @@
-#--- Sun direction: -3.7494e-33 -6.12323e-17 -1
+#--- Sun direction: 0 90 (-3.7494e-33 -6.12323e-17 -1)
2 10000
tower.secondary.hyperbol 10 465.464 0.00509812 0 0 0 0 0 0 0 0 0 0 34.5362 0.00509812 0 0 0.930847 1.01954e-05 0 0
tower.receptor 14 465.464 0.00509812 -1 -1 0 0 -1 -1 0 0 -1 -1 34.5362 0.00509812 -1 -1 0.930847 1.01954e-05 -1 -1
0 0
0 0
-#--- Sun direction: -0.413176 -0.492404 -0.766044
+#--- Sun direction: 50 50 (-0.413176 -0.492404 -0.766044)
2 10000
tower.secondary.hyperbol 10 400.231 0.107226 0 0 0 0 0 0 0 0 0 0 99.7686 0.107226 0 0 0.800393 0.000214433 0 0
tower.receptor 14 136.51 1.90718 -1 -1 0 0 -1 -1 0 0 -1 -1 32.9896 0.464742 -1 -1 0.272997 0.00381404 -1 -1
diff --git a/yaml/test01.ref b/yaml/test01.ref
@@ -1,4 +1,4 @@
-#--- Sun direction: -6.12323e-17 -0 -1
+#--- Sun direction: 0 90 (-6.12323e-17 -0 -1)
1 10000
square_receiver 2 -1 -1 1 0 -1 -1 0 0 -1 -1 0 0 -1 -1 0 0 -1 -1 1 0
0 0
diff --git a/yaml/test02.ref b/yaml/test02.ref
@@ -1,4 +1,4 @@
-#--- Sun direction: -6.12323e-17 -0 -1
+#--- Sun direction: 0 90 (-6.12323e-17 -0 -1)
1 100000
square_receiver 2 -1 -1 1 0.0313065 -1 -1 0 0 -1 -1 0 0 -1 -1 0 0 -1 -1 0.01003 0.000315109
0 0
diff --git a/yaml/test03.ref b/yaml/test03.ref
@@ -1,4 +1,4 @@
-#--- Sun direction: -0.707107 -0 -0.707107
+#--- Sun direction: 0 45 (-0.707107 -0 -0.707107)
1 10000
square_receiver 2 -1 -1 0.707107 0 -1 -1 0 0 -1 -1 0 0 -1 -1 0.292893 0 -1 -1 0.707107 0
0 0
diff --git a/yaml/test04.ref b/yaml/test04.ref
@@ -1,4 +1,4 @@
-#--- Sun direction: -0.707107 -0 -0.707107
+#--- Sun direction: 0 45 (-0.707107 -0 -0.707107)
1 10000
square_receiver 2 0 0 0.707107 0 0 0 0 0 0 0 0 0 0 0 0.292893 0 0 0 0.707107 0
0 0
diff --git a/yaml/test05.ref b/yaml/test05.ref
@@ -1,4 +1,4 @@
-#--- Sun direction: -6.12323e-17 -0 -1
+#--- Sun direction: 0 90 (-6.12323e-17 -0 -1)
1 10000
spherical_receiver 2 -1 -1 1 0 -1 -1 0 0 -1 -1 0 0 -1 -1 0 0 -1 -1 1 0
0 0