stardis-solver

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

commit 252fdf5a9c1e14aadbd66df847f60e91398a13a9
parent def3a4cdde0f1e5f99b567edd8ba7643a960afdd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 10 Apr 2024 10:57:39 +0200

Add a unique identifier to external sources

Use the same internal mechanism as for media and interfaces. It uses a
free list to guarantee the compactness of identifiers, allowing the
caller to use a simple array to manage associativity between the source
and its caller-side data (e.g. the source name). A source whose
identifier the caller can retrieve using the new sdis_source_get_id
function.

This identifier has been added mainly to prepare the API update for
radiative properties that will depend on the source. Consequently,
functors that query these properties will have the source identifier as
an input parameter.

Diffstat:
Msrc/sdis.h | 4++++
Msrc/sdis_device.c | 3+++
Msrc/sdis_device_c.h | 1+
Msrc/sdis_source.c | 12++++++++++++
Msrc/test_sdis_source.c | 4++++
5 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/src/sdis.h b/src/sdis.h @@ -1064,6 +1064,10 @@ sdis_source_get_power (struct sdis_source* source, const double time); /* [s] */ +SDIS_API unsigned +sdis_source_get_id + (const struct sdis_source* source); + /******************************************************************************* * A scene is a collection of primitives. Each primitive is the geometric * support of the interface between 2 media. diff --git a/src/sdis_device.c b/src/sdis_device.c @@ -316,8 +316,10 @@ device_release(ref_T* ref) if(dev->logger == &dev->logger__) logger_release(&dev->logger__); ASSERT(flist_name_is_empty(&dev->interfaces_names)); ASSERT(flist_name_is_empty(&dev->media_names)); + ASSERT(flist_name_is_empty(&dev->source_names)); flist_name_release(&dev->interfaces_names); flist_name_release(&dev->media_names); + flist_name_release(&dev->source_names); #ifdef SDIS_ENABLE_MPI if(dev->mpi_mutex) mutex_destroy(dev->mpi_mutex); str_release(&dev->mpi_err_str); @@ -366,6 +368,7 @@ sdis_device_create ref_init(&dev->ref); flist_name_init(allocator, &dev->interfaces_names); flist_name_init(allocator, &dev->media_names); + flist_name_init(allocator, &dev->source_names); #ifdef SDIS_ENABLE_MPI str_init(allocator, &dev->mpi_err_str); #endif diff --git a/src/sdis_device_c.h b/src/sdis_device_c.h @@ -61,6 +61,7 @@ struct sdis_device { struct flist_name interfaces_names; struct flist_name media_names; + struct flist_name source_names; struct s2d_device* s2d_dev; struct s3d_device* s3d_dev; diff --git a/src/sdis_source.c b/src/sdis_source.c @@ -18,6 +18,7 @@ #include "sdis_log.h" #include "sdis_source_c.h" +#include <rsys/free_list.h> #include <rsys/mem_allocator.h> #include <rsys/ref_count.h> @@ -26,6 +27,7 @@ struct sdis_source { struct sdis_spherical_source_create_args spherical; + struct fid id; /* Unique identifier of the source */ struct sdis_device* dev; ref_T ref; }; @@ -69,6 +71,7 @@ release_source(ref_T* ref) ASSERT(ref); dev = src->dev; if(src->spherical.data) SDIS(data_ref_put(src->spherical.data)); + flist_name_del(&dev->source_names, src->id); MEM_RM(dev->allocator, src); SDIS(device_ref_put(dev)); } @@ -100,6 +103,8 @@ sdis_spherical_source_create if(args->data) SDIS(data_ref_get(args->data)); src->spherical = *args; src->dev = dev; + src->id = flist_name_add(&dev->source_names); + flist_name_get(&dev->source_names, src->id)->mem = src; exit: if(out_src) *out_src = src; @@ -132,6 +137,13 @@ sdis_source_get_power(struct sdis_source* src, const double time /* [s] */) return source_get_power(src, time); } +unsigned +sdis_source_get_id(const struct sdis_source* source) +{ + ASSERT(source); + return source->id.index; +} + /******************************************************************************* * Local functions ******************************************************************************/ diff --git a/src/test_sdis_source.c b/src/test_sdis_source.c @@ -44,6 +44,7 @@ check_spherical_source(struct sdis_device* dev) struct sdis_spherical_source_create_args args = SDIS_SPHERICAL_SOURCE_CREATE_ARGS_NULL; struct sdis_source* src = NULL; + struct sdis_source* src2 = NULL; struct sdis_data* data = NULL; /* Create a data to check its memory management */ @@ -71,7 +72,10 @@ check_spherical_source(struct sdis_device* dev) args.data = NULL; OK(sdis_spherical_source_create(dev, &args, &src)); + OK(sdis_spherical_source_create(dev, &args, &src2)); + CHK(sdis_source_get_id(src) != sdis_source_get_id(src2)); OK(sdis_source_ref_put(src)); + OK(sdis_source_ref_put(src2)); args.position = NULL; BA(sdis_spherical_source_create(dev, &args, &src));