star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

commit 32fab332c807c21a470b8b8fd7d980ad553662d0
parent 47828fa38176281f606a1419e457b8cfc306350b
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Sat,  4 Oct 2025 17:17:58 +0200

Expose getter functions for volume, surface, and prop_rad names

The name of each of these structures is defined in the input file and
therefore forms part of the photoreactor system description. To make
this information accessible to client applications, the star-phor-input
API now provides getter functions to retrieve these names.

This commit additionally adds corresponding unit tests for volume,
surface, and prop_rad name getters and does minor formatting and comment
improvements in sphin.h.

Diffstat:
Msrc/sphin.h | 34+++++++++++++++++++++++++++-------
Msrc/sphin_prop_rad.c | 12++++++++++++
Msrc/sphin_surface.c | 12++++++++++++
Msrc/sphin_volume.c | 12++++++++++++
Msrc/test_sphin_load_prop_rad.c | 8+++++++-
Msrc/test_sphin_load_surface.c | 6++++++
Msrc/test_sphin_load_volume.c | 6++++++
7 files changed, 82 insertions(+), 8 deletions(-)

diff --git a/src/sphin.h b/src/sphin.h @@ -91,7 +91,7 @@ struct sphin_create_args { * override specific fields as needed. If the struct is created by sphin, it * will be initialized to its default value and the fields will be overwritten * during the parsing */ -#define SPHIN_CREATE_ARGS_DEFAULT__ {NULL, NULL, 0} /* We define a constant to */ +#define SPHIN_CREATE_ARGS_DEFAULT__ {NULL, NULL, 0} static const struct sphin_create_args SPHIN_CREATE_ARGS_DEFAULT = SPHIN_CREATE_ARGS_DEFAULT__; @@ -117,11 +117,16 @@ static const struct sphin_brdf_specular SPHIN_BRDF_SPECULAR_NULL = struct sphin_source_surface_flux_density { double flux_density; /* either [umol/m^2/s] or [W/m^2] */ - struct sphin_spectral_property* emission_spectrum; + struct sphin_spectral_property* emission_spectrum; /* Normalized */ enum sphin_photon_unit unit; }; -#define SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL__ {0, NULL, SPHIN_PHOTON_UNIT_NONE__} -static const struct sphin_source_surface_flux_density SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL = +#define SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL__ { \ + 0, \ + NULL, \ + SPHIN_PHOTON_UNIT_NONE__\ +} +static const struct sphin_source_surface_flux_density + SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL = SPHIN_SOURCE_SURFACE_FLUX_DENSITY_NULL__; struct sphin_source_surface_direction_distribution_cos_pow_n { @@ -180,8 +185,8 @@ struct sphin_geometry_descriptor { * direction of the normal. * It determines which of the sides of a given geometry * must be decorated with physical properties. - * Moreover, when used in a sphin_volume, it determine how the - * enclosure is formed. */ + * Moreover, when used in a sphin_volume, it determine + * how the enclosure is formed. */ struct sphin_mesh mesh; }; #define SPHIN_GEOMETRY_DESCRIPTOR_NULL__ { \ @@ -301,6 +306,11 @@ sphin_volume_ref_put (struct sphin_volume* volume); SPHIN_API res_T +sphin_volume_get_name + (struct sphin_volume* volume, + char** name); + +SPHIN_API res_T sphin_volume_get_ka (struct sphin_volume* volume, double* ka); @@ -344,6 +354,11 @@ sphin_prop_rad_ref_put (struct sphin_prop_rad* prop_rad); SPHIN_API res_T +sphin_prop_rad_get_name + (struct sphin_prop_rad* prop_rad, + char** name); + +SPHIN_API res_T sphin_prop_rad_get_scatterer (struct sphin_prop_rad* prop_rad, struct sphin_scatterer** scatterer); @@ -381,6 +396,11 @@ sphin_surface_ref_put (struct sphin_surface* surface); SPHIN_API res_T +sphin_surface_get_name + (struct sphin_surface* surface, + char** name); + +SPHIN_API res_T sphin_surface_get_brdf (const struct sphin_surface* surface, struct sphin_brdf** brdf); /* May be NULL <=> no brdf */ @@ -388,7 +408,7 @@ sphin_surface_get_brdf SPHIN_API res_T sphin_surface_get_source (const struct sphin_surface* surface, - struct sphin_source_surface** source_surface); /* May be NULL <=> no source */ + struct sphin_source_surface** source_surface); /* May be NULL <=> no src */ SPHIN_API res_T sphin_surface_get_geometry_count diff --git a/src/sphin_prop_rad.c b/src/sphin_prop_rad.c @@ -197,6 +197,18 @@ sphin_prop_rad_ref_put } res_T +sphin_prop_rad_get_name + (struct sphin_prop_rad* prop_rad, + char** name) +{ + if (NULL == prop_rad || NULL == name) { + return RES_BAD_ARG; + } + *name = (char*)str_get((struct str*)&prop_rad->name); + return RES_OK; +} + +res_T sphin_prop_rad_get_scatterer (struct sphin_prop_rad* prop_rad, struct sphin_scatterer** scatterer) diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -279,6 +279,18 @@ sphin_surface_ref_put } res_T +sphin_surface_get_name + (struct sphin_surface* surface, + char** name) +{ + if (NULL == surface || NULL == name) { + return RES_BAD_ARG; + } + *name = (char*)str_get((struct str*)&surface->name); + return RES_OK; +} + +res_T sphin_surface_get_brdf (const struct sphin_surface* surface, struct sphin_brdf** brdf) diff --git a/src/sphin_volume.c b/src/sphin_volume.c @@ -317,6 +317,18 @@ sphin_volume_ref_put } res_T +sphin_volume_get_name + (struct sphin_volume* volume, + char** name) +{ + if (NULL == volume || NULL == name) { + return RES_BAD_ARG; + } + *name = (char*)str_get((struct str*)&volume->name); + return RES_OK; +} + +res_T sphin_volume_get_ka (struct sphin_volume* volume, double* ka) diff --git a/src/test_sphin_load_prop_rad.c b/src/test_sphin_load_prop_rad.c @@ -93,6 +93,7 @@ test_prop_rad_api { struct sphin_config* config = NULL; const char* path = "file.txt"; + char* name = NULL; struct sphin_volume* volume = NULL; struct sphin_prop_rad* prop_rad = NULL; struct sphin_scatterer* scatterer = NULL; @@ -105,7 +106,7 @@ test_prop_rad_api CHK(fp = fopen(path, "w+")); fprintf(fp, "#Mot Clé Nom\n"); fprintf(fp, "volume: \"reaction volume\"\n"); - fprintf(fp, "\tprop_rad: \"name\" SCATTERER\n"); + fprintf(fp, "\tprop_rad:\"my prop_rad\" SCATTERER\n"); fprintf(fp, "\t\tconcentration: 1.935 mol/m^3\n"); fprintf(fp, "\t\tcross_sections:\n"); fprintf(fp, "\t\t\tabs_cross_sec: abs_cross_sec_0.txt nm m^2/part\n"); @@ -124,6 +125,11 @@ test_prop_rad_api CHK(sphin_volume_get_prop_rad(volume, (size_t)-1, &prop_rad) == RES_BAD_ARG); CHK(sphin_volume_get_prop_rad(volume, 10, &prop_rad) == RES_BAD_ARG); CHK(sphin_volume_get_prop_rad(volume, 0, &prop_rad) == RES_OK); + CHK(sphin_prop_rad_get_name(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_prop_rad_get_name(prop_rad, NULL) == RES_BAD_ARG); + CHK(sphin_prop_rad_get_name(NULL, &name) == RES_BAD_ARG); + CHK(sphin_prop_rad_get_name(prop_rad, &name) == RES_OK); + CHK(strcmp(name, "my prop_rad") == 0); CHK(sphin_prop_rad_ref_get(prop_rad) == RES_OK); CHK(sphin_prop_rad_ref_get(NULL) == RES_BAD_ARG); CHK(sphin_prop_rad_ref_put(NULL) == RES_BAD_ARG); diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c @@ -91,6 +91,7 @@ test_surface_api { struct sphin_config* config = NULL; const char* path = "file.txt"; + char* name = NULL; double power, reflectivity; struct sphin_surface* surface = NULL; struct sphin_brdf* brdf = NULL; @@ -124,6 +125,11 @@ test_surface_api CHK(sphin_config_get_surface(config, 10, &surface) == RES_BAD_ARG); CHK(sphin_config_get_surface(config, (size_t)-1, &surface) == RES_BAD_ARG); CHK(sphin_config_get_surface(config, 0, &surface) == RES_OK); + CHK(sphin_surface_get_name(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_surface_get_name(surface, NULL) == RES_BAD_ARG); + CHK(sphin_surface_get_name(NULL, &name) == RES_BAD_ARG); + CHK(sphin_surface_get_name(surface, &name) == RES_OK); + CHK(strcmp(name, "tube walls") == 0); CHK(sphin_surface_get_brdf(NULL, NULL) == RES_BAD_ARG); CHK(sphin_surface_get_brdf(surface, NULL) == RES_BAD_ARG); CHK(sphin_surface_get_brdf(NULL, &brdf) == RES_BAD_ARG); diff --git a/src/test_sphin_load_volume.c b/src/test_sphin_load_volume.c @@ -108,6 +108,7 @@ test_volume_api { struct sphin_config* config = NULL; const char* path = "file.txt"; + char* name = NULL; struct sphin_volume* volume = NULL; struct sphin_sensor_volume* sensor_volume = NULL; struct sphin_prop_rad* prop_rad = NULL; @@ -149,6 +150,11 @@ test_volume_api CHK(sphin_config_get_volume(config, 10, &volume) == RES_BAD_ARG); CHK(sphin_config_get_volume(config, (size_t)-1, &volume) == RES_BAD_ARG); CHK(sphin_config_get_volume(config, 0, &volume) == RES_OK); + CHK(sphin_volume_get_name(NULL, NULL) == RES_BAD_ARG); + CHK(sphin_volume_get_name(volume, NULL) == RES_BAD_ARG); + CHK(sphin_volume_get_name(NULL, &name) == RES_BAD_ARG); + CHK(sphin_volume_get_name(volume, &name) == RES_OK); + CHK(strcmp(name, "reaction volume") == 0); CHK(sphin_volume_get_ka(NULL, NULL) == RES_BAD_ARG); CHK(sphin_volume_get_ka(NULL, &ka) == RES_BAD_ARG); CHK(sphin_volume_get_ka(volume, NULL) == RES_BAD_ARG);