rnatm

Load and structure data describing an atmosphere
git clone git://git.meso-star.fr/rnatm.git
Log | Files | Refs | README | LICENSE

commit 20b47b39738400cabb3dc3c246639a8a1f5fb4b0
parent bb92a7fe3a83bc25f8c741e5f5c37ea5c4137952
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 26 Jul 2022 18:39:35 +0200

Add octree writing to test_rnatm

Diffstat:
Msrc/test_rnatm.c | 52+++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/test_rnatm.c b/src/test_rnatm.c @@ -32,9 +32,10 @@ struct args { struct rnatm_create_args rnatm; + const char* vtk_filename; int quit; }; -#define ARGS_DEFAULT__ { RNATM_CREATE_ARGS_DEFAULT__, 0 } +#define ARGS_DEFAULT__ { RNATM_CREATE_ARGS_DEFAULT__, NULL, 0 } static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; /******************************************************************************* @@ -49,6 +50,9 @@ print_help(const char* cmd) "Test the Rad-Net ATMosphere library\n\n", cmd); printf( +" -d file write the builded octree to file according to the\n" +" VTK file format\n"); + printf( " -g gas Atmospheric gas mixture. This mixture is defined by\n" " the following list of parameters, each parameter\n" " separated from the previous one by the character ':'\n\n"); @@ -61,6 +65,10 @@ print_help(const char* cmd) printf( " -N precompute_normals the tetrahedra normals\n"); printf( +" -T threshold optical thickness criteria for octree building.\n" +" Default is %g\n", + ARGS_DEFAULT.rnatm.optical_thickness); + printf( " -t nthreads hint on the number of threads to use. By default use\n" " as many threads as CPU cores\n"); printf( @@ -161,8 +169,9 @@ args_init(struct args* args, int argc, char** argv) *args = ARGS_DEFAULT; - while((opt = getopt(argc, argv, "g:hN:t:V:v")) != -1) { + while((opt = getopt(argc, argv, "d:g:hN:T:t:V:v")) != -1) { switch(opt) { + case 'd': args->vtk_filename = optarg; break; case 'g': res = cstr_parse_list(optarg, ':', parse_gas_parameters, args); break; @@ -172,6 +181,10 @@ args_init(struct args* args, int argc, char** argv) args->quit = 1; goto exit; case 'N': args->rnatm.precompute_normals = 1; break; + case 'T': + res = cstr_to_double(optarg, &args->rnatm.optical_thickness); + if(res != RES_OK && args->rnatm.optical_thickness<=0) res = RES_BAD_ARG; + break; case 't': res = cstr_to_uint(optarg, &args->rnatm.nthreads); if(res == RES_OK && !args->rnatm.nthreads) res = RES_BAD_ARG; @@ -208,6 +221,30 @@ error: goto exit; } +static res_T +write_vtk_octree(struct rnatm* atm, const char* filename) +{ + FILE* fp = NULL; + res_T res = RES_OK; + ASSERT(atm && filename); + + fp = fopen(filename, "w"); + if(!fp) { + fprintf(stderr, "Could not open `%s' -- %s\n", filename, strerror(errno)); + res = RES_IO_ERR; + goto error; + } + + res = rnatm_write_vtk_octree(atm, fp); + if(res != RES_OK) goto error; + +exit: + if(fp) CHK(fclose(fp) == 0); + return res; +error: + goto exit; +} + /******************************************************************************* * Main function ******************************************************************************/ @@ -215,19 +252,24 @@ int main(int argc, char** argv) { struct args args = ARGS_DEFAULT; - struct rnatm* rnatm = NULL; + struct rnatm* atm = NULL; res_T res = RES_OK; int err = 0; res = args_init(&args, argc, argv); if(res != RES_OK) goto error; - res = rnatm_create(&args.rnatm, &rnatm); + res = rnatm_create(&args.rnatm, &atm); if(res != RES_OK) goto error; + if(args.vtk_filename) { + res = write_vtk_octree(atm, args.vtk_filename); + if(res != RES_OK) goto error; + } + exit: args_release(&args); - if(rnatm) RNATM(ref_put(rnatm)); + if(atm) RNATM(ref_put(atm)); if(mem_allocated_size() != 0) { fprintf(stderr, "Memory leaks: %lu bytes\n", (unsigned long)mem_allocated_size());