htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

commit f0eef338c12c2ec584dfac1992257c0e1e646d7d
parent bf9f54f4b6da395ab21f867f2016693ef965f806
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  2 Oct 2018 16:24:39 +0200

Update the -D parameter

Sun direction is now provided as {azimuth,elevation} angles and not as a
3D vector

Diffstat:
Msrc/htrdr.c | 29++++++++++++++++++++++++++++-
Msrc/htrdr_args.c | 32+++++++++++++++++++++++++-------
Msrc/htrdr_args.h | 6++++--
3 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/src/htrdr.c b/src/htrdr.c @@ -267,6 +267,30 @@ error: goto exit; } +static INLINE void +spherical_to_cartesian_dir + (const double azimuth, /* In radians */ + const double elevation, /* In radians */ + double dir[3]) +{ + double cos_azimuth; + double sin_azimuth; + double cos_elevation; + double sin_elevation; + ASSERT(azimuth >= 0 && azimuth < 2*PI); + ASSERT(elevation >= 0 && elevation <= PI/2.0); + ASSERT(dir); + + cos_azimuth = cos(azimuth); + sin_azimuth = sin(azimuth); + cos_elevation = cos(elevation); + sin_elevation = sin(elevation); + + dir[0] = cos_elevation * cos_azimuth; + dir[1] = cos_elevation * sin_azimuth; + dir[2] = sin_elevation; +} + /******************************************************************************* * Local functions ******************************************************************************/ @@ -277,6 +301,7 @@ htrdr_init struct htrdr* htrdr) { double proj_ratio; + double sun_dir[3]; const char* output_name = NULL; size_t ithread; res_T res = RES_OK; @@ -352,7 +377,9 @@ htrdr_init res = htrdr_sun_create(htrdr, &htrdr->sun); if(res != RES_OK) goto error; - htrdr_sun_set_direction(htrdr->sun, args->main_dir); + spherical_to_cartesian_dir + (MDEG2RAD(args->sun_azimuth), MDEG2RAD(args->sun_elevation), sun_dir); + htrdr_sun_set_direction(htrdr->sun, sun_dir); res = htrdr_sky_create(htrdr, htrdr->sun, args->filename_les, args->filename_gas, args->filename_mie, args->optical_thickness, diff --git a/src/htrdr_args.c b/src/htrdr_args.c @@ -40,7 +40,11 @@ print_help(const char* cmd) printf( " -d dump octree data to OUTPUT wrt the VTK ASCII file format.\n"); printf( -" -D X,Y,Z direction toward the sun.\n"); +" -D AZIMUTH,ELEVATION\n" +" sun direction in degrees. Following the right-handed\n" +" convention, the azimuthal rotation is counter-clockwise\n" +" around the Z axis, with 0 aligned on the X axis. The\n" +" elevation rotation starts from 0 up to 90 at zenith.\n"); printf( " -f overwrite the OUTPUT file if it already exists.\n"); printf( @@ -263,23 +267,37 @@ error: static res_T parse_sun_dir(struct htrdr_args* args, const char* str) { - double norm; + double angles[2]; size_t len; res_T res = RES_OK; ASSERT(args && str); - res = cstr_to_list_double(str, ',', args->main_dir, &len, 3); - if(res == RES_OK && len != 3) res = RES_BAD_ARG; + res = cstr_to_list_double(str, ',', angles, &len, 2); + if(res == RES_OK && len != 2) res = RES_BAD_ARG; if(res != RES_OK) { fprintf(stderr, "Invalid direction `%s'.\n", str); goto error; } - norm = d3_normalize(args->main_dir, args->main_dir); - if(eq_eps(norm, 0, 1.e-6)) { - fprintf(stderr, "Invalid null direction `%s'.\n", str); + + if(angles[0] < 0 || angles[0] >= 360) { + fprintf(stderr, + "Invalid azimuth angle `%g'. Azimuth must be in [0, 360[ degrees.\n", + angles[0]); + res = RES_BAD_ARG; + goto error; + } + + if(angles[1] < 0 || angles[1] > 90) { + fprintf(stderr, + "Invalid elevation angle `%g'. Elevation must be in [0, 90] degrees.\n", + angles[1]); res = RES_BAD_ARG; goto error; } + + args->sun_azimuth = angles[0]; + args->sun_elevation = angles[1]; + exit: return res; error: diff --git a/src/htrdr_args.h b/src/htrdr_args.h @@ -44,7 +44,8 @@ struct htrdr_args { unsigned spp; /* #samples per pixel */ } image; - double main_dir[3]; + double sun_azimuth; /* In degrees */ + double sun_elevation; /* In degrees */ double optical_thickness; /* Threshold used during octree building */ unsigned nthreads; /* Hint on the number of threads to use */ @@ -74,7 +75,8 @@ struct htrdr_args { {32, 32}, /* image definition */ \ 1 /* #samples per pixel */ \ }, \ - {0, 0, 1}, /* Main direction */ \ + 0, /* Sun azimuth */ \ + 90, /* Sun elevation */ \ 1.0, /* Optical thickness */ \ (unsigned)~0, /* #threads */ \ 0, /* Force overwriting */ \