stardis-solver

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

commit 7b6f77a675cccef5b934ac5467072b0e0d1fb20f
parent 4ebfc0ae8f35a4b57ba0e0efbd8b673f049da7fa
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 24 Aug 2023 15:49:44 +0200

Rejection positions in enclosures with multiple media

A multi-medium enclosure is a convenient way of describing boundary
conditions on system boundaries without having to describe the geometry
of the boundary media. Consequently, such enclosures are outside the
system to be simulated, and can only be interrogated via their
interfaces. This commit ensures this by returning an error if the
medium of such an enclosure is interrogated at a given position. Until
now, this was not the case, leading either to a crash when trying to
calculate the enclosure temperature, or to unexpected results.

Diffstat:
Msrc/sdis_heat_path_boundary_Xd_c.h | 8++++----
Msrc/sdis_heat_path_boundary_c.h | 8++++----
Msrc/sdis_heat_path_convective_Xd.h | 15+--------------
Msrc/sdis_scene.c | 4++--
Msrc/sdis_scene_Xd.h | 57++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/sdis_scene_c.h | 8+++++---
6 files changed, 58 insertions(+), 42 deletions(-)

diff --git a/src/sdis_heat_path_boundary_Xd_c.h b/src/sdis_heat_path_boundary_Xd_c.h @@ -302,7 +302,7 @@ XD(move_away_primitive_boundaries) static res_T XD(find_reinjection_ray) - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct XD(find_reinjection_ray_args)* args, struct XD(reinjection_ray)* ray) { @@ -498,7 +498,7 @@ error: static res_T XD(find_reinjection_ray_and_check_validity) - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct XD(find_reinjection_ray_args)* args, struct XD(reinjection_ray)* ray) { @@ -591,7 +591,7 @@ error: ******************************************************************************/ res_T XD(sample_reinjection_step_solid_fluid) - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct XD(sample_reinjection_step_args)* args, struct XD(reinjection_step)* step) { @@ -673,7 +673,7 @@ error: res_T XD(sample_reinjection_step_solid_solid) - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct XD(sample_reinjection_step_args)* args_frt, const struct XD(sample_reinjection_step_args)* args_bck, struct XD(reinjection_step)* step_frt, diff --git a/src/sdis_heat_path_boundary_c.h b/src/sdis_heat_path_boundary_c.h @@ -75,19 +75,19 @@ REINJECTION_STEP_NULL_3d = REINJECTION_STEP_NULL___3d; extern LOCAL_SYM res_T sample_reinjection_step_solid_fluid_2d - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct sample_reinjection_step_args_2d* args, struct reinjection_step_2d* step); extern LOCAL_SYM res_T sample_reinjection_step_solid_fluid_3d - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct sample_reinjection_step_args_3d* args, struct reinjection_step_3d *step); extern LOCAL_SYM res_T sample_reinjection_step_solid_solid_2d - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct sample_reinjection_step_args_2d* args_front, const struct sample_reinjection_step_args_2d* args_back, struct reinjection_step_2d* step_front, @@ -95,7 +95,7 @@ sample_reinjection_step_solid_solid_2d extern LOCAL_SYM res_T sample_reinjection_step_solid_solid_3d - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const struct sample_reinjection_step_args_3d* args_front, const struct sample_reinjection_step_args_3d* args_back, struct reinjection_step_3d* step_front, diff --git a/src/sdis_heat_path_convective_Xd.h b/src/sdis_heat_path_convective_Xd.h @@ -210,23 +210,10 @@ XD(fetch_fluid_enclosure) /* Fetch the enclosure data */ enc = scene_get_enclosure(scn, enc_id); - if(!enc) { - /* The possibility for a fluid enclosure to be unregistred is that it is - * the external enclosure. In this situation unknown temperature is - * forbidden. */ - log_err(scn->dev, - "%s: invalid enclosure. The surrounding fluid has an unset temperature.\n", - FUNC_NAME); - res = RES_BAD_ARG; - goto error; - } + ASSERT(enc != NULL && enc->medium_id != ENCLOSURE_MULTI_MEDIA); -exit: *out_enclosure = enc; return res; -error: - enc = NULL; - goto exit; } /******************************************************************************* diff --git a/src/sdis_scene.c b/src/sdis_scene.c @@ -422,7 +422,7 @@ scene_get_interface(const struct sdis_scene* scn, const unsigned iprim) res_T scene_get_medium - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const double pos[], struct get_medium_info* info, struct sdis_medium** out_medium) @@ -434,7 +434,7 @@ scene_get_medium res_T scene_get_medium_in_closed_boundaries - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const double pos[], struct sdis_medium** out_medium) { diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h @@ -741,7 +741,7 @@ error: /* Build the Star-XD scene view of a specific enclosure and map their local * primitive id to their primitive id in the whole scene */ static res_T -XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* enc) +XD(register_enclosure)(struct sdis_scene* scn, struct sencXd(enclosure)* enc) { struct sXd(device)* sXd_dev = NULL; struct sXd(scene)* sXd_scn = NULL; @@ -775,7 +775,19 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e enc_data = htable_enclosure_find(&scn->enclosures, &header.enclosure_id); ASSERT(enc_data != NULL); - /* Setup the vertex data */ + /* Setup the medium id of the enclosure */ + if(header.enclosed_media_count > 1) { + enc_data->medium_id = ENCLOSURE_MULTI_MEDIA; + } else { + SENCXD(enclosure_get_medium(enc, 0, &enc_data->medium_id)); + } + + /* Do not configure the enclosure geometry for enclosures that are infinite + * or composed of several media, i.e. that define boundary conditions */ + if(header.is_infinite || header.enclosed_media_count > 1) + goto exit; + + /* Setup the vertex data */ vdata.usage = SXD_POSITION; vdata.type = SXD_FLOATX; vdata.get = XD(enclosure_position); @@ -808,7 +820,7 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e ASSERT(enc_data->S_over_V >= 0); #undef CALL - /* Set enclosure hc upper bound regardless of its media being a fluid */ + /* Set enclosure hc upper bound regardless of its media being a fluid */ p_ub = htable_d_find(&scn->tmp_hc_ub, &header.enclosure_id); ASSERT(p_ub); enc_data->hc_upper_bound = *p_ub; @@ -822,9 +834,6 @@ XD(setup_enclosure_geometry)(struct sdis_scene* scn, struct sencXd(enclosure)* e (enc, iprim, darray_uint_data_get(&enc_data->local2global)+iprim, &side)); } - /* Setup the medium id of the enclosure */ - SENCXD(enclosure_get_medium(enc, 0, &enc_data->medium_id)); - exit: enclosure_release(&enc_dummy); if(sXd_shape) SXD(shape_ref_put(sXd_shape)); @@ -861,11 +870,9 @@ XD(setup_enclosures)(struct sdis_scene* scn, struct sencXd(scene)* senc_scn) if(header.enclosed_media_count != 1 && !header.is_infinite) inner_multi++; - /* Silently discard infinite enclosures */ - if(!header.is_infinite) { - res = XD(setup_enclosure_geometry)(scn, enc); - if(res != RES_OK) goto error; - } + res = XD(register_enclosure)(scn, enc); + if(res != RES_OK) goto error; + SENCXD(enclosure_ref_put(enc)); enc = NULL; } @@ -1028,7 +1035,7 @@ error: ******************************************************************************/ static INLINE res_T XD(scene_get_medium) - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const double pos[DIM], struct get_medium_info* info, /* May be NULL */ struct sdis_medium** out_medium) @@ -1104,10 +1111,30 @@ XD(scene_get_medium) /* Not too close and not roughly orthognonal */ if(hit.distance > 1.e-6 && absf(cos_N_dir) > 1.e-2f) { + const struct enclosure* enclosure = NULL; + unsigned enc_ids[2]; const struct sdis_interface* interf; + interf = scene_get_interface(scn, hit.prim.prim_id); - medium = interface_get_medium - (interf, cos_N_dir < 0 ? SDIS_FRONT : SDIS_BACK); + scene_get_enclosure_ids(scn, hit.prim.prim_id, enc_ids); + + if(cos_N_dir < 0) { + medium = interface_get_medium(interf, SDIS_FRONT); + enclosure = scene_get_enclosure(scn, enc_ids[0]); + } else { + medium = interface_get_medium(interf, SDIS_BACK); + enclosure = scene_get_enclosure(scn, enc_ids[1]); + } + + if(enclosure->medium_id == ENCLOSURE_MULTI_MEDIA) { + log_err + (scn->dev, + "%s: invalid medium request at {%g, %g, %g}. " + "The position is located in an enclosure comprising several media.\n", + FUNC_NAME, P[0], P[1], DIM == 3 ? P[3] : 0); + res = RES_BAD_ARG; + goto error; + } /* Register the get_medium_info */ if(info) { @@ -1163,7 +1190,7 @@ error: static INLINE res_T XD(scene_get_medium_in_closed_boundaries) - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const double pos[DIM], struct sdis_medium** out_medium) { diff --git a/src/sdis_scene_c.h b/src/sdis_scene_c.h @@ -76,6 +76,8 @@ medium_init(struct mem_allocator* allocator, struct sdis_medium** medium) *medium = NULL; } +#define ENCLOSURE_MULTI_MEDIA UINT_MAX + struct enclosure { struct s2d_scene_view* s2d_view; struct s3d_scene_view* s3d_view; @@ -100,7 +102,7 @@ enclosure_init(struct mem_allocator* allocator, struct enclosure* enc) enc->S_over_V = 0; enc->V = 0; enc->hc_upper_bound = 0; - enc->medium_id = UINT_MAX; + enc->medium_id = ENCLOSURE_MULTI_MEDIA; } static INLINE void @@ -231,7 +233,7 @@ scene_get_interface extern LOCAL_SYM res_T scene_get_medium - (const struct sdis_scene* scene, + (struct sdis_scene* scene, const double position[], struct get_medium_info* info, /* May be NULL */ struct sdis_medium** medium); @@ -248,7 +250,7 @@ scene_get_medium * are opened to infinity). */ extern LOCAL_SYM res_T scene_get_medium_in_closed_boundaries - (const struct sdis_scene* scn, + (struct sdis_scene* scn, const double position[], struct sdis_medium** medium);