stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit 2ee2022a912bf5dcbb642afc4ae9a2ba9581dd17
parent 5c0cffefa4c3fb655bab7fb474600aebac0ce119
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 29 Jun 2020 15:11:35 +0200

Update the API of sdis_solve_camera

Diffstat:
Msrc/sdis.h | 33++++++++++++++++++++++++---------
Msrc/sdis_solve.c | 63+++++++++++++++++++++++++++++++++------------------------------
Msrc/test_sdis_solve_camera.c | 77++++++++++++++++++++++++++++++++++++++++-------------------------------------
3 files changed, 97 insertions(+), 76 deletions(-)

diff --git a/src/sdis.h b/src/sdis.h @@ -478,6 +478,29 @@ static const struct sdis_solve_boundary_flux_args SDIS_SOLVE_BOUNDARY_FLUX_ARGS_DEFAULT = SDIS_SOLVE_BOUNDARY_FLUX_ARGS_DEFAULT__; +struct sdis_solve_camera_args { + struct sdis_camera* cam; /* Point of view */ + double time_range[2]; /* Observation time */ + double fp_to_meter; /* Scale from floating point units to meters */ + double ambient_radiative_temperature; /* In Kelvin */ + double reference_temperature; /* In Kelvin */ + size_t image_resolution[2]; /* Image resolution */ + size_t spp; /* #samples per pixel */ + int register_paths; /* Combination of enum sdis_heat_path_flag */ +}; +#define SDIS_SOLVE_CAMERA_ARGS_DEFAULT__ { \ + NULL, /* Camera */ \ + {DBL_MAX,DBL_MAX}, /* Time range */ \ + 1, /* FP to meter */ \ + -1, /* Ambient radiative temperature */ \ + -1, /* Reference temperature */ \ + {512,512}, /* Image resolution */ \ + 256, /* #realisations per pixel */ \ + SDIS_HEAT_PATH_NONE \ +} +static const struct sdis_solve_camera_args SDIS_SOLVE_CAMERA_ARGS_DEFAULT = + SDIS_SOLVE_CAMERA_ARGS_DEFAULT__; + BEGIN_DECLS /******************************************************************************* @@ -1044,15 +1067,7 @@ sdis_solve_boundary_flux SDIS_API res_T sdis_solve_camera (struct sdis_scene* scn, - const struct sdis_camera* cam, /* Point of view */ - const double time_range[2], /* Observation time */ - const double fp_to_meter, /* Scale from floating point units to meters */ - const double ambient_radiative_temperature, /* In Kelvin */ - const double reference_temperature, /* In Kelvin */ - const size_t width, /* Image definition in in X */ - const size_t height, /* Image definition in Y */ - const size_t spp, /* #samples per pixel */ - const int register_paths, /* Combination of enum sdis_heat_path_flag */ + const struct sdis_solve_camera_args* args, struct sdis_estimator_buffer** buf); SDIS_API res_T diff --git a/src/sdis_solve.c b/src/sdis_solve.c @@ -332,15 +332,7 @@ sdis_solve_boundary_flux res_T sdis_solve_camera (struct sdis_scene* scn, - const struct sdis_camera* cam, - const double time_range[2], - const double fp_to_meter, /* Scale from floating point units to meters */ - const double Tarad, /* In Kelvin */ - const double Tref, /* In Kelvin */ - const size_t width, /* #pixels in X */ - const size_t height, /* #pixels in Y */ - const size_t spp, /* #samples per pixel */ - const int register_paths, /* Combination of enum sdis_heat_path_flag */ + const struct sdis_solve_camera_args* args, struct sdis_estimator_buffer** out_buf) { #define TILE_SIZE 32 /* definition in X & Y of a tile */ @@ -363,28 +355,36 @@ sdis_solve_camera ATOMIC nsolved_tiles = 0; ATOMIC res = RES_OK; - if(!scn || !cam || fp_to_meter <= 0 || Tref < 0 || !width || !height || !spp - || !out_buf) { + if(!scn + || !args + || !out_buf + || !args->cam + || args->fp_to_meter <= 0 + || !args->image_resolution[0] + || !args->image_resolution[1] + || !args->spp + || args->ambient_radiative_temperature < 0 + || args->reference_temperature < 0 + || args->time_range[0] < 0 + || args->time_range[1] < args->time_range[0] + || ( args->time_range[1] > DBL_MAX + && args->time_range[0] != args->time_range[1])) { res = RES_BAD_ARG; goto error; } + if(scene_is_2d(scn)) { log_err(scn->dev, "%s: 2D scene are not supported.\n", FUNC_NAME); goto error; } - if(!time_range || time_range[0] < 0 || time_range[1] < time_range[0] - || (time_range[1] > DBL_MAX && time_range[0] != time_range[1])) { - res = RES_BAD_ARG; - goto error; - } /* Retrieve the medium in which the submitted position lies */ - res = scene_get_medium(scn, cam->position, NULL, &medium); + res = scene_get_medium(scn, args->cam->position, NULL, &medium); if(res != RES_OK) goto error; if(medium->type != SDIS_FLUID) { log_err(scn->dev, "%s: the camera position `%g %g %g' is not in a fluid.\n", - FUNC_NAME, SPLIT3(cam->position)); + FUNC_NAME, SPLIT3(args->cam->position)); res = RES_BAD_ARG; goto error; } @@ -406,16 +406,17 @@ sdis_solve_camera if(res != RES_OK) goto error; } - ntiles_x = (width + (TILE_SIZE-1)/*ceil*/)/TILE_SIZE; - ntiles_y = (height + (TILE_SIZE-1)/*ceil*/)/TILE_SIZE; + ntiles_x = (args->image_resolution[0] + (TILE_SIZE-1)/*ceil*/)/TILE_SIZE; + ntiles_y = (args->image_resolution[1] + (TILE_SIZE-1)/*ceil*/)/TILE_SIZE; ntiles = round_up_pow2(MMAX(ntiles_x, ntiles_y)); ntiles *= ntiles; - pix_sz[0] = 1.0 / (double)width; - pix_sz[1] = 1.0 / (double)height; + pix_sz[0] = 1.0 / (double)args->image_resolution[0]; + pix_sz[1] = 1.0 / (double)args->image_resolution[1]; /* Create the global estimator */ - res = estimator_buffer_create(scn->dev, width, height, &buf); + res = estimator_buffer_create + (scn->dev, args->image_resolution[0], args->image_resolution[1], &buf); if(res != RES_OK) goto error; omp_set_num_threads((int)scn->dev->nthreads); @@ -439,12 +440,14 @@ sdis_solve_camera /* Setup the tile coordinates in the image plane */ tile_org[0] *= TILE_SIZE; tile_org[1] *= TILE_SIZE; - tile_sz[0] = MMIN(TILE_SIZE, width - tile_org[0]); - tile_sz[1] = MMIN(TILE_SIZE, height - tile_org[1]); + tile_sz[0] = MMIN(TILE_SIZE, args->image_resolution[0] - tile_org[0]); + tile_sz[1] = MMIN(TILE_SIZE, args->image_resolution[1] - tile_org[1]); /* Draw the tile */ - res_local = solve_tile(scn, rng, medium, cam, time_range, fp_to_meter, - Tarad, Tref, tile_org, tile_sz, spp, register_paths, pix_sz, buf); + res_local = solve_tile(scn, rng, medium, args->cam, args->time_range, + args->fp_to_meter, args->ambient_radiative_temperature, + args->reference_temperature, tile_org, tile_sz, args->spp, + args->register_paths, pix_sz, buf); if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; @@ -468,8 +471,8 @@ sdis_solve_camera acc_temp = ACCUM_NULL; acc_time = ACCUM_NULL; nsuccesses = 0; - FOR_EACH(iy, 0, height) { - FOR_EACH(ix, 0, width) { + FOR_EACH(iy, 0, args->image_resolution[1]) { + FOR_EACH(ix, 0, args->image_resolution[0]) { const struct sdis_estimator* estimator; SDIS(estimator_buffer_at(buf, ix, iy, &estimator)); acc_temp.sum += estimator->temperature.sum; @@ -482,7 +485,7 @@ sdis_solve_camera } } - nrealisations = width*height*spp; + nrealisations = args->image_resolution[0]*args->image_resolution[1]*args->spp; ASSERT(acc_temp.count == acc_time.count); ASSERT(acc_temp.count == nsuccesses); estimator_buffer_setup_realisations_count(buf, nrealisations, nsuccesses); diff --git a/src/test_sdis_solve_camera.c b/src/test_sdis_solve_camera.c @@ -35,7 +35,7 @@ /* * The scene is composed of a solid cube whose temperature is unknown. The * emissivity of the cube is 1 and its convection coefficient with the - * surrounding fluid is null. At the center of the cube there is a spherical + * surrounding fluid at 290Kk is 0.1. At the center of the cube there is a spherical * fluid cavity whose temperature is 350K. The convection coefficient between * the solid and the cavity is 1 and the emissivity of this interface is null. * The ambient radiative temperature of the system is 300K. @@ -540,16 +540,17 @@ main(int argc, char** argv) struct sdis_interface* interf0 = NULL; struct sdis_interface* interf1 = NULL; struct sdis_scene* scn = NULL; + struct sdis_solve_camera_args solve_args = SDIS_SOLVE_CAMERA_ARGS_DEFAULT; struct fluid fluid_param = FLUID_NULL; struct solid solid_param = SOLID_NULL; struct interf interface_param = INTERF_NULL; + struct fluid* pfluid_param = NULL; size_t ntris, npos; size_t nreals, nfails; size_t definition[2]; double pos[3]; double tgt[3]; double up[3]; - double trange[2] = {INF, INF}; (void)argc, (void)argv; OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); @@ -562,7 +563,7 @@ main(int argc, char** argv) create_fluid(dev, &fluid_param, &fluid0); /* Create the fluid1 */ - fluid_param.temperature = UNKOWN_TEMPERATURE; + fluid_param.temperature = 290; fluid_param.rho = 0; fluid_param.cp = 0; create_fluid(dev, &fluid_param, &fluid1); @@ -583,17 +584,12 @@ main(int argc, char** argv) create_interface(dev, solid, fluid0, &interface_param, &interf0); /* Create the fluid1/solid interface */ - interface_param.hc = 0; + interface_param.hc = 0.1; interface_param.epsilon = 1; interface_param.specular_fraction = 1; interface_param.temperature = UNKOWN_TEMPERATURE; create_interface(dev, fluid1, solid, &interface_param, &interf1); - /* Release the ownership onto the media */ - OK(sdis_medium_ref_put(solid)); - OK(sdis_medium_ref_put(fluid0)); - OK(sdis_medium_ref_put(fluid1)); - /* Setup the cube geometry */ OK(s3dut_create_cuboid(&allocator, 2, 2, 2, &msh)); OK(s3dut_mesh_get_data(msh, &msh_data)); @@ -633,36 +629,40 @@ main(int argc, char** argv) dump_mesh(stdout, geom.positions, npos, geom.indices, ntris); exit(0); #endif - BA(sdis_solve_camera(NULL, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, NULL, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, NULL, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, trange, 0, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, trange, 1, 300, -1, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, trange, 1, 300, 300, 0, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, 0, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - 0, SDIS_HEAT_PATH_NONE, &buf)); - BA(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, NULL)); - - trange[0] = -1; - BA(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - trange[0] = 10; trange[1] = 1; - BA(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); - trange[0] = trange[1] = INF; + solve_args.cam = cam; + solve_args.time_range[0] = INF; + solve_args.time_range[0] = INF; + solve_args.image_resolution[0] = IMG_WIDTH; + solve_args.image_resolution[1] = IMG_HEIGHT; + solve_args.ambient_radiative_temperature = 300; + solve_args.reference_temperature = 300; + solve_args.spp = SPP; + + BA(sdis_solve_camera(NULL, &solve_args, &buf)); + BA(sdis_solve_camera(scn, NULL, &buf)); + BA(sdis_solve_camera(scn, &solve_args, NULL)); + solve_args.cam = NULL; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.cam = cam; + solve_args.fp_to_meter = 0; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.fp_to_meter = 1; + solve_args.ambient_radiative_temperature = -1; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.ambient_radiative_temperature = 300; + solve_args.reference_temperature = -1; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.reference_temperature = 300; + solve_args.time_range[0] = solve_args.time_range[1] = -1; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.time_range[0] = 1; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.time_range[1] = 0; + BA(sdis_solve_camera(scn, &solve_args, &buf)); + solve_args.time_range[0] = solve_args.time_range[1] = INF; /* Launch the simulation */ - OK(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); + OK(sdis_solve_camera(scn, &solve_args, &buf)); BA(sdis_estimator_buffer_get_realisation_count(NULL, &nreals)); BA(sdis_estimator_buffer_get_realisation_count(buf, NULL)); @@ -698,6 +698,9 @@ main(int argc, char** argv) /* Release memory */ OK(sdis_estimator_buffer_ref_put(buf)); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(fluid0)); + OK(sdis_medium_ref_put(fluid1)); OK(sdis_scene_ref_put(scn)); OK(sdis_camera_ref_put(cam)); OK(sdis_interface_ref_put(interf0));