stardis-solver

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

commit 4efe0795c80d7d845fabfd0cd1aea28aa0d159db
parent 6f5cf8cbe0b39a670945ea9a92a06c3229fb212b
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 19 Jun 2024 17:50:17 +0200

Add public getters that retrieve a primitive from its key

These functions rely on new hash tables that associates a primkey with
its Star-<2|3>D primitive.

Diffstat:
Msrc/sdis.h | 14++++++++++++++
Msrc/sdis_scene.c | 34++++++++++++++++++++++++++++++++++
Msrc/sdis_scene_Xd.h | 107++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/sdis_scene_c.h | 32++++++++++++++++++++++++++++++++
4 files changed, 181 insertions(+), 6 deletions(-)

diff --git a/src/sdis.h b/src/sdis.h @@ -1404,6 +1404,20 @@ sdis_scene_get_radiative_env /* The returned pointer can be NULL, i.e. there is no radiative environement*/ struct sdis_radiative_env** radenv); +/* Get the internal Star-2D primitive corresponding to the primitive key */ +SDIS_API res_T +sdis_scene_get_s2d_primitive + (struct sdis_scene* scn, + const struct sdis_primkey* key, + struct s2d_primitive* primitive); + +/* Get the internal Star-3D primitive corresponding to the primitive key */ +SDIS_API res_T +sdis_scene_get_s3d_primitive + (struct sdis_scene* scn, + const struct sdis_primkey* key, + struct s3d_primitive* primitive); + /******************************************************************************* * An estimator stores the state of a simulation ******************************************************************************/ diff --git a/src/sdis_scene.c b/src/sdis_scene.c @@ -103,6 +103,8 @@ scene_release(ref_T * ref) darray_prim_prop_release(&scn->prim_props); htable_enclosure_release(&scn->enclosures); htable_d_release(&scn->tmp_hc_ub); + htable_key2prim2d_release(&scn->key2prim2d); + htable_key2prim3d_release(&scn->key2prim3d); if(scn->s2d_view) S2D(scene_view_ref_put(scn->s2d_view)); if(scn->s3d_view) S3D(scene_view_ref_put(scn->s3d_view)); if(scn->senc2d_scn) SENC2D(scene_ref_put(scn->senc2d_scn)); @@ -416,6 +418,38 @@ sdis_scene_get_radiative_env return RES_OK; } +res_T +sdis_scene_get_s2d_primitive + (struct sdis_scene* scn, + const struct sdis_primkey* key, + struct s2d_primitive* out_prim) +{ + struct s2d_primitive* prim = NULL; + + if(!scn || !key || !out_prim || !scene_is_2d(scn)) return RES_BAD_ARG; + + if((prim = htable_key2prim2d_find(&scn->key2prim2d, key)) == NULL) + return RES_BAD_ARG; + *out_prim = *prim; + return RES_OK; +} + +res_T +sdis_scene_get_s3d_primitive + (struct sdis_scene* scn, + const struct sdis_primkey* key, + struct s3d_primitive* out_prim) +{ + struct s3d_primitive* prim = NULL; + + if(!scn || !key || !out_prim || scene_is_2d(scn)) return RES_BAD_ARG; + + if((prim = htable_key2prim3d_find(&scn->key2prim3d, key)) == NULL) + return RES_BAD_ARG; + *out_prim = *prim; + return RES_OK; +} + /******************************************************************************* * Local miscellaneous function ******************************************************************************/ diff --git a/src/sdis_scene_Xd.h b/src/sdis_scene_Xd.h @@ -938,6 +938,89 @@ error: goto exit; } +#if DIM == 2 +static res_T +setup_primitive_keys_2d(struct sdis_scene* scn, struct senc2d_scene* senc_scn) +{ + unsigned iprim = 0; + unsigned nprims = 0; + res_T res = RES_OK; + ASSERT(scn && senc_scn); + + SENC2D(scene_get_primitives_count(senc_scn, &nprims)); + + FOR_EACH(iprim, 0, nprims) { + struct s2d_primitive prim = S2D_PRIMITIVE_NULL; + struct sdis_primkey key = SDIS_PRIMKEY_NULL; + unsigned ids[2] = {0,0}; + double v0[2] = {0,0}; + double v1[2] = {0,0}; + + /* Retrieve positions from Star-Enclosre, not Star-2D. Star-Enclosure keeps + * the positions submitted by the user as they are, without any + * transformation or conversion (Star-2D converts them to float). This + * ensures that the caller can construct the same key from his data */ + SENC2D(scene_get_primitive(senc_scn, iprim, ids)); + SENC2D(scene_get_vertex(senc_scn, ids[0], v0)); + SENC2D(scene_get_vertex(senc_scn, ids[1], v1)); + S2D(scene_view_get_primitive(scn->s2d_view, iprim, &prim)); + + sdis_primkey_2d_setup(&key, v0, v1); + + res = htable_key2prim2d_set(&scn->key2prim2d, &key, &prim); + if(res != RES_OK) goto error; + } + +exit: + return res; +error: + htable_key2prim2d_purge(&scn->key2prim2d); + goto exit; +} + +#elif DIM == 3 +static res_T +setup_primitive_keys_3d(struct sdis_scene* scn, struct senc3d_scene* senc_scn) +{ + unsigned iprim = 0; + unsigned nprims = 0; + res_T res = RES_OK; + ASSERT(scn && senc_scn); + + SENC3D(scene_get_primitives_count(senc_scn, &nprims)); + + FOR_EACH(iprim, 0, nprims) { + struct s3d_primitive prim = S3D_PRIMITIVE_NULL; + struct sdis_primkey key = SDIS_PRIMKEY_NULL; + unsigned ids[3] = {0}; + double v0[3] = {0}; + double v1[3] = {0}; + double v2[3] = {0}; + + /* Retrieve positions from Star-Enclosre, not Star-3D. Star-Enclosure keeps + * the positions submitted by the user as they are, without any + * transformation or conversion (Star-3D converts them to float). This + * ensures that the caller can construct the same key from his data */ + SENC3D(scene_get_primitive(senc_scn, iprim, ids)); + SENC3D(scene_get_vertex(senc_scn, ids[0], v0)); + SENC3D(scene_get_vertex(senc_scn, ids[1], v1)); + SENC3D(scene_get_vertex(senc_scn, ids[2], v2)); + S3D(scene_view_get_primitive(scn->s3d_view, iprim, &prim)); + + sdis_primkey_setup(&key, v0, v1, v2); + + res = htable_key2prim3d_set(&scn->key2prim3d, &key, &prim); + if(res != RES_OK) goto error; + } + +exit: + return res; +error: + htable_key2prim3d_purge(&scn->key2prim3d); + goto exit; +} +#endif + /* Create a Stardis scene */ static res_T XD(scene_create) @@ -956,8 +1039,9 @@ XD(scene_create) scn = MEM_CALLOC(dev->allocator, 1, sizeof(struct sdis_scene)); if(!scn) { - log_err(dev, "%s: could not allocate the Stardis scene.\n", FUNC_NAME); res = RES_MEM_ERR; + log_err(dev, "%s: unabale to allocate the scene -- %s\n", + FUNC_NAME, res_to_cstr(res)); goto error; } @@ -973,6 +1057,8 @@ XD(scene_create) darray_prim_prop_init(dev->allocator, &scn->prim_props); htable_enclosure_init(dev->allocator, &scn->enclosures); htable_d_init(dev->allocator, &scn->tmp_hc_ub); + htable_key2prim2d_init(dev->allocator, &scn->key2prim2d); + htable_key2prim3d_init(dev->allocator, &scn->key2prim3d); if(args->source) { SDIS(source_ref_get(args->source)); @@ -994,23 +1080,32 @@ XD(scene_create) args->context, &senc_scn); if(res != RES_OK) { - log_err(dev, "%s: error during the scene analysis.\n", FUNC_NAME); + log_err(dev, "%s: unable to analyze the scene -- %s\n", + FUNC_NAME, res_to_cstr(res)); goto error; } res = XD(setup_properties)(scn, senc_scn, args->get_interface, args->context); if(res != RES_OK) { - log_err(dev, "%s: could not setup the scene interfaces and their media.\n", - FUNC_NAME); + log_err(dev, "%s: unable to configure interfaces and media -- %s\n", + FUNC_NAME, res_to_cstr(res)); goto error; } res = XD(setup_scene_geometry)(scn, senc_scn); if(res != RES_OK) { - log_err(dev, "%s: could not setup the scene geometry.\n", FUNC_NAME); + log_err(dev, "%s: unable to configure scene geometry -- %s\n", + FUNC_NAME, res_to_cstr(res)); goto error; } res = XD(setup_enclosures)(scn, senc_scn); if(res != RES_OK) { - log_err(dev, "%s: could not setup the enclosures.\n", FUNC_NAME); + log_err(dev, "%s: unable to configure enclosures -- %s\n", + FUNC_NAME, res_to_cstr(res)); + goto error; + } + res = XD(setup_primitive_keys)(scn, senc_scn); + if(res != RES_OK) { + log_err(dev, "%s: unable to configure primitive keys -- %s\n", + FUNC_NAME, res_to_cstr(res)); goto error; } scn->sencXd(scn) = senc_scn; diff --git a/src/sdis_scene_c.h b/src/sdis_scene_c.h @@ -159,6 +159,16 @@ enclosure_local2global_prim_id return darray_uint_cdata_get(&enc->local2global)[local_prim_id]; } +static INLINE void +primkey_init + (const struct mem_allocator* allocator, + struct sdis_primkey* key) +{ + ASSERT(allocator && key); + (void)allocator; + *key = SDIS_PRIMKEY_NULL; +} + /* Declare the array of interfaces */ #define DARRAY_NAME interf #define DARRAY_DATA struct sdis_interface* @@ -193,6 +203,24 @@ enclosure_local2global_prim_id #define HTABLE_DATA double #include <rsys/hash_table.h> +/* Declare the hash table that maps the primitive key to its 2D primitve */ +#define HTABLE_NAME key2prim2d +#define HTABLE_KEY struct sdis_primkey +#define HTABLE_KEY_FUNCTOR_INIT primkey_init +#define HTABLE_KEY_FUNCTOR_HASH sdis_primkey_hash +#define HTABLE_KEY_FUNCTOR_EQ sdis_primkey_eq +#define HTABLE_DATA struct s2d_primitive +#include <rsys/hash_table.h> + +/* Declare the hash table that maps the primitive key to its 3D primitive */ +#define HTABLE_NAME key2prim3d +#define HTABLE_KEY struct sdis_primkey +#define HTABLE_KEY_FUNCTOR_INIT primkey_init +#define HTABLE_KEY_FUNCTOR_HASH sdis_primkey_hash +#define HTABLE_KEY_FUNCTOR_EQ sdis_primkey_eq +#define HTABLE_DATA struct s3d_primitive +#include <rsys/hash_table.h> + struct sdis_scene { struct darray_interf interfaces; /* List of interfaces own by the scene */ struct darray_medium media; /* List of media own by the scene */ @@ -206,6 +234,10 @@ struct sdis_scene { struct htable_enclosure enclosures; /* Map an enclosure id to its data */ unsigned outer_enclosure_id; + /* Map a primivei key to its Star-2D/Star-3D primitive */ + struct htable_key2prim2d key2prim2d; + struct htable_key2prim3d key2prim3d; + double fp_to_meter; double tmin; /* Minimum temperature of the system (In Kelvin) */ double tmax; /* Maximum temperature of the system (In Kelvin) */