atrstm

Load and structure a combustion gas mixture
git clone git://git.meso-star.fr/atrstm.git
Log | Files | Refs | README | LICENSE

commit f72601ab438d7b0ab11f00c0fa005df54e067d25
parent 93a23f206fd9258a1c3304c2e05dadd0d09865f5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 25 Jan 2021 21:36:42 +0100

Add the '-d OCTREE' option to the test_atrstm program

Write the built octree to the OCTREE file following the VTK fileformat.

Diffstat:
Msrc/test_atrstm.c | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 62 insertions(+), 30 deletions(-)

diff --git a/src/test_atrstm.c b/src/test_atrstm.c @@ -21,6 +21,16 @@ #include <getopt.h> #include <stdio.h> +#include <string.h> + +struct args { + struct atrstm_args atrstm; + const char* dump_octree_filename; /* NULL <=> no dump */ + int quit; +}; + +#define ARGS_DEFAULT__ { ATRSTM_ARGS_DEFAULT__, NULL, 0 } +static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; /******************************************************************************* * Helper functions @@ -35,6 +45,8 @@ print_help(const char* cmd) cmd); printf("\n"); printf( +" -d OCTREE dump SVX octree to the OCTREE file.\n"); + printf( " -f FRACTAL_DIM fractal dimension. Its default value is %g.\n", ATRSTM_ARGS_DEFAULT.fractal_dimension); printf( @@ -115,57 +127,59 @@ error: } static void -args_release(struct atrstm_args* args) +args_release(struct args* args) { ASSERT(args); - *args = ATRSTM_ARGS_DEFAULT; + *args = ARGS_DEFAULT; } static res_T -args_init(struct atrstm_args* args, int argc, char** argv) +args_init(struct args* args, int argc, char** argv) { res_T res = RES_OK; int opt; ASSERT(args && argc && argv); - *args = ATRSTM_ARGS_DEFAULT; + *args = ARGS_DEFAULT; - while((opt = getopt(argc, argv, "f:g:hm:Nn:O:p:T:t:r:vV:w:")) != -1) { + while((opt = getopt(argc, argv, "d:f:g:hm:Nn:O:p:T:t:r:vV:w:")) != -1) { switch(opt) { + case 'd': args->dump_octree_filename = optarg; break; case 'f': - res = cstr_to_double(optarg, &args->fractal_dimension); - if(res == RES_OK && args->fractal_dimension <= 0) + res = cstr_to_double(optarg, &args->atrstm.fractal_dimension); + if(res == RES_OK && args->atrstm.fractal_dimension <= 0) res = RES_BAD_ARG; break; case 'g': - res = cstr_to_double(optarg, &args->gyration_radius_prefactor); - if(res == RES_OK && args->gyration_radius_prefactor <= 0) + res = cstr_to_double(optarg, &args->atrstm.gyration_radius_prefactor); + if(res == RES_OK && args->atrstm.gyration_radius_prefactor <= 0) res = RES_BAD_ARG; break; case 'h': print_help(argv[0]); args_release(args); + args->quit = 1; goto exit; - case 'm': args->sth_filename = optarg; break; - case 'N': args->precompute_normals = 1; break; - case 'n': args->name = optarg; break; - case 'O': args->cache_filename = optarg; break; - case 'p': args->atrtp_filename = optarg; break; - case 'r': args->atrri_filename = optarg; break; + case 'm': args->atrstm.sth_filename = optarg; break; + case 'N': args->atrstm.precompute_normals = 1; break; + case 'n': args->atrstm.name = optarg; break; + case 'O': args->atrstm.cache_filename = optarg; break; + case 'p': args->atrstm.atrtp_filename = optarg; break; + case 'r': args->atrstm.atrri_filename = optarg; break; case 'T': - res = cstr_to_double(optarg, &args->optical_thickness); - if(res == RES_OK && args->optical_thickness < 0) res = RES_BAD_ARG; + res = cstr_to_double(optarg, &args->atrstm.optical_thickness); + if(res == RES_OK && args->atrstm.optical_thickness<0) res = RES_BAD_ARG; break; case 't': - res = cstr_to_uint(optarg, &args->nthreads); - if(res == RES_OK && !args->nthreads) res = RES_BAD_ARG; + res = cstr_to_uint(optarg, &args->atrstm.nthreads); + if(res == RES_OK && !args->atrstm.nthreads) res = RES_BAD_ARG; break; - case 'V': res = parse_grid_definition(args, optarg); break; - case 'v': args->verbose = 1; break; + case 'V': res = parse_grid_definition(&args->atrstm, optarg); break; + case 'v': args->atrstm.verbose = 1; break; case 'w': - res = cstr_to_double(optarg, &args->wlen_range[0]); - if(res == RES_OK && args->wlen_range[0] < 0) res = RES_BAD_ARG; - args->wlen_range[1] = args->wlen_range[0]; + res = cstr_to_double(optarg, &args->atrstm.wlen_range[0]); + if(res == RES_OK && args->atrstm.wlen_range[0] < 0) res = RES_BAD_ARG; + args->atrstm.wlen_range[1] = args->atrstm.wlen_range[0]; break; default: res = RES_BAD_ARG; break; } @@ -179,19 +193,19 @@ args_init(struct atrstm_args* args, int argc, char** argv) } /* Check parsed arguments */ - if(!args->sth_filename) { + if(!args->atrstm.sth_filename) { fprintf(stderr, "Missing the path toward the volumetric mesh -- option '-m'\n"); res = RES_BAD_ARG; goto error; } - if(!args->atrtp_filename) { + if(!args->atrstm.atrtp_filename) { fprintf(stderr, "Missing the path of the thermodynamic properties -- option '-p'\n"); res = RES_BAD_ARG; goto error; } - if(!args->atrri_filename) { + if(!args->atrstm.atrri_filename) { fprintf(stderr, "Missing the path of the refractive indices -- option '-r'\n"); res = RES_BAD_ARG; @@ -211,21 +225,39 @@ error: int main(int argc, char** argv) { - struct atrstm_args args = ATRSTM_ARGS_DEFAULT; + struct args args = ARGS_DEFAULT; struct atrstm* atrstm = NULL; + FILE* fp_octree = NULL; res_T res = RES_OK; int err = 0; res = args_init(&args, argc, argv); if(res != RES_OK) goto error; - if(!args.sth_filename) goto exit; /* Quit */ + if(args.quit) goto exit; - res = atrstm_create(NULL, &mem_default_allocator, &args, &atrstm); + res = atrstm_create(NULL, &mem_default_allocator, &args.atrstm, &atrstm); if(res != RES_OK) goto error; + if(args.dump_octree_filename) { + const struct atrstm_dump_svx_octree_args dump_svx_octree_args = + ATRSTM_DUMP_SVX_OCTREE_ARGS_DEFAULT; + + fp_octree = fopen(args.dump_octree_filename, "w"); + if(!fp_octree) { + fprintf(stderr, "Could not open `%s' -- %s.", + args.dump_octree_filename, strerror(errno)); + res = RES_IO_ERR; + goto error; + } + + res = atrstm_dump_svx_octree(atrstm, &dump_svx_octree_args, fp_octree); + if(res != RES_OK) goto error; + } + exit: args_release(&args); if(atrstm) ATRSTM(ref_put(atrstm)); + if(fp_octree) fclose(fp_octree); if(MEM_ALLOCATED_SIZE(&mem_default_allocator) != 0) { fprintf(stderr, "Memory leaks: %lu bytes\n", (unsigned long)MEM_ALLOCATED_SIZE(&mem_default_allocator));