htrdr

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

commit b995d4fb967e539c021d49e2b7dce2f0139ad456
parent 8eaa95b0370c6c03de827d8e4aa16d882e81c64b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  6 Jul 2018 16:43:17 +0200

Load the Mie data in the sky data structure

Diffstat:
Mcmake/CMakeLists.txt | 3++-
Msrc/htrdr.c | 3++-
Msrc/htrdr_args.c | 23+++++++++++++++++------
Msrc/htrdr_args.h | 6++++--
Msrc/htrdr_sky.c | 144++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Msrc/htrdr_sky.h | 1+
6 files changed, 121 insertions(+), 59 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -28,6 +28,7 @@ find_package(RSys 0.6 REQUIRED) find_package(StarSP 0.7 REQUIRED) find_package(SVX REQUIRED) find_package(HTCP REQUIRED) +find_package(HTMIE REQUIRED) find_package(OpenMP 1.2 REQUIRED) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) @@ -70,7 +71,7 @@ rcmake_prepend_path(HTRDR_FILES_INC ${HTRDR_SOURCE_DIR}) rcmake_prepend_path(HTRDR_FILES_DOC ${PROJECT_SOURCE_DIR}/../) add_executable(htrdr ${HTRDR_FILES_SRC} ${HTRDR_FILES_INC}) -target_link_libraries(htrdr HTCP RSys SVX StarSP) +target_link_libraries(htrdr HTCP HTMIE RSys SVX StarSP) if(CMAKE_COMPILER_IS_GNUCC) target_link_libraries(htrdr m) diff --git a/src/htrdr.c b/src/htrdr.c @@ -218,7 +218,8 @@ htrdr_init res = open_output_stream(htrdr, args); if(res != RES_OK) goto error; } - res = htrdr_sky_create(htrdr, args->input, &htrdr->sky); + res = htrdr_sky_create + (htrdr, args->filename_les, args->filename_mie, &htrdr->sky); if(res != RES_OK) goto error; exit: diff --git a/src/htrdr_args.c b/src/htrdr_args.c @@ -32,6 +32,8 @@ print_help(const char* cmd) ASSERT(cmd); printf("Usage: %s -i INPUT [OPIONS]\n\n", cmd); printf( +" -c FILENAME path of the HTCP cloud properties file.\n"); + printf( " -d dump octree data to OUTPUT wrt the VTK ASCII file format.\n"); printf( " -D X,Y,Z sun direction.\n"); @@ -40,10 +42,10 @@ print_help(const char* cmd) printf( " -h display this help and exit.\n"); printf( -" -i INPUT path of the input HTCP file.\n"); - printf( " -I <image> define the image to compute.\n"); printf( +" -m FILENAME path of the Mie data file.\n"); + printf( " -o OUTPUT file where data are written. If not defined, data are\n" " written to standard output.\n"); printf( @@ -270,8 +272,9 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) *args = HTRDR_ARGS_DEFAULT; - while((opt = getopt(argc, argv, "D:dfhI:i:o:r:t:v")) != -1) { + while((opt = getopt(argc, argv, "c:D:dfhI:m:o:r:t:v")) != -1) { switch(opt) { + case 'c': args->filename_les = optarg; break; case 'D': res = parse_sun_dir(args, optarg); break; case 'd': args->dump_vtk = 1; break; case 'f': args->force_overwriting = 1; break; @@ -284,7 +287,7 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) res = parse_multiple_parameters (args, optarg, parse_image_parameter); break; - case 'i': args->input = optarg; break; + case 'm': args->filename_mie = optarg; break; case 'o': args->output = optarg; break; case 'r': res = parse_multiple_parameters @@ -305,11 +308,19 @@ htrdr_args_init(struct htrdr_args* args, int argc, char** argv) goto error; } } - if(!args->input) { - fprintf(stderr, "Missing input file.\n"); + if(!args->filename_les) { + fprintf(stderr, + "Missing the path of the cloud properties file -- option '-c'\n"); res = RES_BAD_ARG; goto error; } + if(!args->filename_mie) { + fprintf(stderr, + "Missing the path toward the file of the Mie's data -- option '-m'\n"); + res = RES_BAD_ARG; + goto error; + } + exit: return res; error: diff --git a/src/htrdr_args.h b/src/htrdr_args.h @@ -19,7 +19,8 @@ #include <rsys/rsys.h> struct htrdr_args { - const char* input; + const char* filename_les; + const char* filename_mie; const char* output; struct { @@ -44,7 +45,8 @@ struct htrdr_args { }; #define HTRDR_ARGS_DEFAULT__ { \ - NULL, /* Input filename */ \ + NULL, /* LES filename */ \ + NULL, /* Mie filename */ \ NULL, /* Output filename */ \ { \ {0, 0, 0}, /* plane position */ \ diff --git a/src/htrdr_sky.c b/src/htrdr_sky.c @@ -18,6 +18,7 @@ #include <star/svx.h> #include <high_tune/htcp.h> +#include <high_tune/htmie.h> #include <rsys/dynamic_array_double.h> #include <rsys/dynamic_array_size_t.h> @@ -71,6 +72,7 @@ struct octree_data { struct htrdr_sky { struct svx_tree* clouds; struct htcp* htcp; + struct htmie* htmie; struct htcp_desc htcp_desc; @@ -81,6 +83,10 @@ struct htrdr_sky { struct htrdr* htrdr; }; +/* + * K<a|s> particle = C<a|s> * RCT + */ + /******************************************************************************* * Helper function ******************************************************************************/ @@ -250,74 +256,39 @@ vox_challenge_merge(const void* voxels[], const size_t nvoxs, void* context) return (kext_max - kext_min)*ctx->dst_max <= ctx->tau_threshold; } -static void -release_sky(ref_T* ref) +static res_T +setup_clouds(struct htrdr_sky* sky) { - struct htrdr_sky* sky; - ASSERT(ref); - sky = CONTAINER_OF(ref, struct htrdr_sky, ref); - if(sky->clouds) SVX(tree_ref_put(sky->clouds)); - if(sky->htcp) HTCP(ref_put(sky->htcp)); - darray_split_release(&sky->svx2htcp_z); - MEM_RM(sky->htrdr->allocator, sky); -} - -/******************************************************************************* - * Local functions - ******************************************************************************/ -res_T -htrdr_sky_create - (struct htrdr* htrdr, - const char* htcp_filename, - struct htrdr_sky** out_sky) -{ - struct htrdr_sky* sky = NULL; struct svx_voxel_desc vox_desc = SVX_VOXEL_DESC_NULL; struct build_octree_context ctx; size_t nvoxs[3]; - double sz[3]; double low[3]; double upp[3]; + double sz[3]; res_T res = RES_OK; - ASSERT(htrdr && htcp_filename && out_sky); - - sky = MEM_CALLOC(htrdr->allocator, 1, sizeof(*sky)); - if(!sky) { - res = RES_MEM_ERR; - goto error; - } - ref_init(&sky->ref); - sky->htrdr = htrdr; - darray_split_init(htrdr->allocator, &sky->svx2htcp_z); - - res = htcp_create(&htrdr->logger, htrdr->allocator, htrdr->verbose, &sky->htcp); - if(res != RES_OK) { - htrdr_log_err(htrdr, "could not create the loader of cloud properties.\n"); - goto error; - } + ASSERT(sky); - res = htcp_load(sky->htcp, htcp_filename); + res = htcp_get_desc(sky->htcp, &sky->htcp_desc); if(res != RES_OK) { - htrdr_log_err(htrdr, "error loading the cloud properties -- `%s'.\n", - htcp_filename); + htrdr_log_err(sky->htrdr, "could not retrieve the HTCP descriptor.\n"); goto error; } - HTCP(get_desc(sky->htcp, &sky->htcp_desc)); - /* Define the number of voxels */ nvoxs[0] = sky->htcp_desc.spatial_definition[0]; nvoxs[1] = sky->htcp_desc.spatial_definition[1]; nvoxs[2] = sky->htcp_desc.spatial_definition[2]; - /* Define the octree AABB */ + /* Define the octree AABB exepted for the Z dimension */ low[0] = sky->htcp_desc.lower[0]; low[1] = sky->htcp_desc.lower[1]; low[2] = sky->htcp_desc.lower[2]; upp[0] = low[0] + (double)nvoxs[0] * sky->htcp_desc.vxsz_x; upp[1] = low[1] + (double)nvoxs[1] * sky->htcp_desc.vxsz_y; - if(!sky->htcp_desc.irregular_z) { /* Refular voxel size in Z */ + if(!sky->htcp_desc.irregular_z) { + /* Regular voxel size along the Z dimension: compute its upper boundary as + * the others dimensions */ upp[2] = low[2] + (double)nvoxs[2] * sky->htcp_desc.vxsz_z[0]; } else { /* Irregular voxel size along Z */ double min_vxsz_z; @@ -332,13 +303,13 @@ htrdr_sky_create len_z += sky->htcp_desc.vxsz_z[iz]; min_vxsz_z = MMIN(min_vxsz_z, sky->htcp_desc.vxsz_z[iz]); } - /* Allocate the svx2htcp LUT. The LUT is a regular table whose absolute + /* Allocate the svx2htcp LUT. This LUT is a regular table whose absolute * size is the size of a Z column in the htcp file. The size of its cells * is the minimal voxel size in Z of the htcp file */ nsplits = (size_t)ceil(len_z / min_vxsz_z); res = darray_split_resize(&sky->svx2htcp_z, nsplits); if(res != RES_OK) { - htrdr_log_err(htrdr, + htrdr_log_err(sky->htrdr, "could not allocate the table mapping regular to irregular Z.\n"); goto error; } @@ -375,14 +346,89 @@ htrdr_sky_create vox_desc.size = sizeof(double)*HTRDR_SKY_SVX_PROPS_COUNT__; /* Create the octree */ - res = svx_octree_create(htrdr->svx, low, upp, nvoxs, &vox_desc, &sky->clouds); + res = svx_octree_create + (sky->htrdr->svx, low, upp, nvoxs, &vox_desc, &sky->clouds); if(res != RES_OK) { - htrdr_log_err(htrdr, + htrdr_log_err(sky->htrdr, "could not create the octree of the cloud properties.\n"); goto error; } exit: + return res; +error: + if(sky->clouds) SVX(tree_ref_put(sky->clouds)); + darray_split_clear(&sky->svx2htcp_z); + goto exit; +} + +static void +release_sky(ref_T* ref) +{ + struct htrdr_sky* sky; + ASSERT(ref); + sky = CONTAINER_OF(ref, struct htrdr_sky, ref); + if(sky->clouds) SVX(tree_ref_put(sky->clouds)); + if(sky->htcp) HTCP(ref_put(sky->htcp)); + if(sky->htmie) HTMIE(ref_put(sky->htmie)); + darray_split_release(&sky->svx2htcp_z); + MEM_RM(sky->htrdr->allocator, sky); +} + +/******************************************************************************* + * Local functions + ******************************************************************************/ +res_T +htrdr_sky_create + (struct htrdr* htrdr, + const char* htcp_filename, + const char* htmie_filename, + struct htrdr_sky** out_sky) +{ + struct htrdr_sky* sky = NULL; + res_T res = RES_OK; + ASSERT(htrdr && htcp_filename && htmie_filename && out_sky); + + sky = MEM_CALLOC(htrdr->allocator, 1, sizeof(*sky)); + if(!sky) { + htrdr_log_err(htrdr, "could not allocate the sky data structure.\n"); + res = RES_MEM_ERR; + goto error; + } + ref_init(&sky->ref); + sky->htrdr = htrdr; + darray_split_init(htrdr->allocator, &sky->svx2htcp_z); + + res = htcp_create(&htrdr->logger, htrdr->allocator, htrdr->verbose, &sky->htcp); + if(res != RES_OK) { + htrdr_log_err(htrdr, "could not create the loader of cloud properties.\n"); + goto error; + } + + res = htcp_load(sky->htcp, htcp_filename); + if(res != RES_OK) { + htrdr_log_err(htrdr, "error loading the cloud properties -- `%s'.\n", + htcp_filename); + goto error; + } + + res = htmie_create(&htrdr->logger, htrdr->allocator, htrdr->verbose, &sky->htmie); + if(res != RES_OK) { + htrdr_log_err(htrdr, "could not create the loader of Mie's data.\n"); + goto error; + } + + res = htmie_load(sky->htmie, htmie_filename); + if(res != RES_OK) { + htrdr_log_err(htrdr, "error loading the Mie's data -- `%s'.\n", + htmie_filename); + goto error; + } + + res = setup_clouds(sky); + if(res != RES_OK) goto error; + +exit: *out_sky = sky; return res; error: diff --git a/src/htrdr_sky.h b/src/htrdr_sky.h @@ -47,6 +47,7 @@ extern LOCAL_SYM res_T htrdr_sky_create (struct htrdr* htrdr, const char* htcp_filename, + const char* htmie_filename, struct htrdr_sky** sky); extern LOCAL_SYM void