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 d31b4a80a95f36c06985aaf646fad80860b81c69
parent de49cd3e8a2cf59641477c0ad75784e68a791c6a
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Tue, 25 Feb 2025 19:12:54 +0100

Continue the implementation of lib_sphin

- Implement new api functions
- Ensure consistency of style

Diffstat:
Msrc/sphin.h | 20+++++++++++---------
Msrc/sphin_brdf.c | 23++++++++++++++++++++---
Msrc/sphin_c.h | 2+-
Msrc/sphin_config.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Msrc/sphin_source.c | 34+++++++++++++++++++++++++++++++---
Msrc/sphin_surface.c | 24++++++++++++++++++------
Msrc/sphin_volume.c | 6+++---
7 files changed, 158 insertions(+), 29 deletions(-)

diff --git a/src/sphin.h b/src/sphin.h @@ -47,17 +47,17 @@ enum sphin_side { SPHIN_SIDE_BACK, /* 0 */ SPHIN_SIDE_FRONT, /* 1 */ - SPHIN_SIDE_NONE__ /* 2 */ + SPHIN_SIDE_NONE__ /* 2 */ }; enum sphin_brdf_type { SPHIN_BRDF_LAMBERT, /* 0 */ SPHIN_BRDF_SPECULAR, /* 1 */ - SPHIN_BRDF_NONE__ /* 2 */ + SPHIN_BRDF_NONE__ /* 2 */ }; enum sphin_photon_unit { - SPHIN_PHOTON_UNIT_MOL, /* [mol hv] */ + SPHIN_PHOTON_UNIT_MOL, /* [mol] */ SPHIN_PHOTON_UNIT_JOULE, /* [J] */ SPHIN_PHOTON_UNIT_NONE__ }; @@ -144,6 +144,7 @@ struct sphin; /* Library handler */ struct sphin_brdf; struct sphin_config; /* Physical configuration */ struct sphin_source; +struct sphin_source_power; struct sphin_surface; struct sphin_volume; @@ -236,7 +237,7 @@ sphin_surface_ref_put SPHIN_API res_T sphin_surface_get_brdf (const struct sphin_surface* surface, - struct sphin_brdf* brdf); + struct sphin_brdf** brdf); SPHIN_API res_T sphin_surface_get_source @@ -259,16 +260,17 @@ sphin_source_get_direction_distribution (const struct sphin_source* source, struct sphin_source_direction_distribution* distrib); -/* SPHIN_API res_T -sphin_source_get_power - (const struct sphin_source* source, - struct sphin_source_power* power);*/ - SPHIN_API res_T sphin_source_surface_get_flux_density (const struct sphin_source* source, struct sphin_source_flux_density* density); +/* TODO */ +SPHIN_API res_T +sphin_source_get_power + (const struct sphin_source* source, + struct sphin_source_power* power); + /******************************************************************************* * API of the source ******************************************************************************/ diff --git a/src/sphin_brdf.c b/src/sphin_brdf.c @@ -152,7 +152,7 @@ error: res_T sphin_brdf_ref_get(struct sphin_brdf* brdf) { - if(NULL == brdf) { + if (NULL == brdf) { return RES_BAD_ARG; } ref_get(&brdf->ref); @@ -162,7 +162,7 @@ sphin_brdf_ref_get(struct sphin_brdf* brdf) res_T sphin_brdf_ref_put(struct sphin_brdf* brdf) { - if(NULL == brdf) { + if (NULL == brdf) { return RES_BAD_ARG; } ref_put(&brdf->ref, release_brdf); @@ -182,6 +182,23 @@ sphin_brdf_lambertian_get_reflectivity if (SPHIN_BRDF_SPECULAR == brdf->type) { return RES_BAD_ARG; } - reflectivity = &brdf->specular.reflectivity; + *reflectivity = brdf->specular.reflectivity; + return res; +} + +res_T +sphin_brdf_specular_get_reflectivity + (struct sphin_brdf* brdf, + double* reflectivity) +{ + res_T res = RES_OK; + + if (NULL == brdf) { + return RES_BAD_ARG; + } + if (SPHIN_BRDF_LAMBERT == brdf->type) { + return RES_BAD_ARG; + } + *reflectivity = brdf->lambertian.reflectivity; return res; } diff --git a/src/sphin_c.h b/src/sphin_c.h @@ -30,7 +30,7 @@ /* Helper macros for logging */ #define LOG__(Dev, Lvl, Type, ...) { \ - if((Dev)->verbose >= (Lvl)) \ + if ((Dev)->verbose >= (Lvl)) \ logger_print((Dev)->logger, Type, __VA_ARGS__); \ } (void)0 #define ERROR(Dev, ...) LOG__(Dev, 1, LOG_ERROR, __VA_ARGS__) diff --git a/src/sphin_config.c b/src/sphin_config.c @@ -160,7 +160,7 @@ load_stream /* parse value (name) */ token = strtok_r(NULL, "", &token_ptr); - if(NULL != token){ res = RES_BAD_ARG; goto error; } + if (NULL != token){ res = RES_BAD_ARG; goto error; } name = trim_string(token); if (NULL == name){ res = RES_BAD_ARG; goto error; } @@ -319,7 +319,7 @@ sphin_load_stream const char* streamname, struct sphin_config** config) { - if(NULL == sphin + if (NULL == sphin || NULL == stream || NULL == streamname || NULL == config) { @@ -331,7 +331,7 @@ sphin_load_stream res_T sphin_config_ref_get(struct sphin_config* config) { - if(NULL == config) { + if (NULL == config) { return RES_BAD_ARG; } ref_get(&config->ref); @@ -341,9 +341,79 @@ sphin_config_ref_get(struct sphin_config* config) res_T sphin_config_ref_put(struct sphin_config* config) { - if(NULL == config) { + if (NULL == config) { return RES_BAD_ARG; } ref_put(&config->ref, release_config); return RES_OK; } + +res_T +sphin_config_get_volume_count + (struct sphin_config* config, + size_t* nvolumes) +{ + res_T res = RES_OK; + if (NULL == config) { + return RES_BAD_ARG; + } + *nvolumes = darray_sphin_volume_ptr_size_get(&config->volumes); + return res; +} + +res_T +sphin_config_get_volume + (struct sphin_config* config, + size_t ivolume, + struct sphin_volume** volume) +{ + res_T res = RES_OK; + size_t nvolumes; + + if (NULL == config) { + return RES_BAD_ARG; + } + + res = sphin_config_get_volume_count(config, &nvolumes); + if (RES_OK != res || ivolume > nvolumes) { + return RES_BAD_ARG; + } + + *volume = darray_sphin_volume_ptr_data_get(&config->volumes)[ivolume]; + return res; +} + +res_T +sphin_config_get_surface_count + (struct sphin_config* config, + size_t* nsurfaces) +{ + res_T res = RES_OK; + if (NULL == config) { + return RES_BAD_ARG; + } + *nsurfaces = darray_sphin_surface_ptr_size_get(&config->surfaces); + return res; +} + +res_T +sphin_config_get_surface + (struct sphin_config* config, + size_t isurface, + struct sphin_surface** surface) +{ + res_T res = RES_OK; + size_t nsurfaces; + + if (NULL == config) { + return RES_BAD_ARG; + } + + res = sphin_config_get_surface_count(config, &nsurfaces); + if (RES_OK != res || isurface > nsurfaces) { + return RES_BAD_ARG; + } + + *surface = darray_sphin_surface_ptr_data_get(&config->surfaces)[isurface]; + return res; +} diff --git a/src/sphin_source.c b/src/sphin_source.c @@ -129,7 +129,7 @@ parse_direction_distribution else if (0 == strcmp(direction_distribution_type, "COLLIM")){ source->direction_distribution.type = SPHIN_SOURCE_DIRECTION_COLLIM; str_direction = strtok_r(NULL, " \t", &token_ptr); - if(0 == strcmp(str_direction, "NORMAL")){ + if (0 == strcmp(str_direction, "NORMAL")){ direction[0] = direction[1] = direction[2] = 0; } else{ @@ -181,6 +181,7 @@ parse_flux_density /* Parse unit */ flux_density_unit = strtok_r(value, " \t", &token_ptr); if (NULL == flux_density_unit){ res = RES_BAD_ARG; goto error; } + /* Kinetic flux density unit */ if (0 == strcmp(flux_density_unit, "mol/m^2/s") || 0 == strcmp(flux_density_unit, "mol.m^-2.s^-1")) { @@ -192,6 +193,7 @@ parse_flux_density source->flux_density.unit= SPHIN_PHOTON_UNIT_MOL; source->flux_density.flux_density *= 1; /* No conversion */ } + /* Energy flux density energy */ else if (0 == strcmp(flux_density_unit, "W/m^2") || 0 == strcmp(flux_density_unit, "W.s^-1")) { @@ -280,7 +282,7 @@ error: res_T sphin_source_ref_get(struct sphin_source* source) { - if(NULL == source) { + if (NULL == source) { return RES_BAD_ARG; } ref_get(&source->ref); @@ -290,9 +292,35 @@ sphin_source_ref_get(struct sphin_source* source) res_T sphin_source_ref_put(struct sphin_source* source) { - if(NULL == source) { + if (NULL == source) { return RES_BAD_ARG; } ref_put(&source->ref, release_source); return RES_OK; } + +res_T +sphin_source_get_direction_distribution + (const struct sphin_source* source, + struct sphin_source_direction_distribution* distrib) +{ + if (NULL == source) { + return RES_BAD_ARG; + } + + *distrib = source->direction_distribution; + return RES_OK; +} + +res_T +sphin_source_surface_get_flux_density + (const struct sphin_source* source, + struct sphin_source_flux_density* density) +{ + if (NULL == source) { + return RES_BAD_ARG; + } + + *density = source->flux_density; + return RES_OK; +} diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -205,7 +205,7 @@ error: res_T sphin_surface_ref_get(struct sphin_surface* surface) { - if(NULL == surface) { + if (NULL == surface) { return RES_BAD_ARG; } ref_get(&surface->ref); @@ -215,21 +215,33 @@ sphin_surface_ref_get(struct sphin_surface* surface) res_T sphin_surface_ref_put(struct sphin_surface* surface) { - if(NULL == surface) { + if (NULL == surface) { return RES_BAD_ARG; } ref_put(&surface->ref, release_surface); return RES_OK; } -/* res_T +res_T sphin_surface_get_brdf (const struct sphin_surface* surface, - struct sphin_brdf* brdf) + struct sphin_brdf** brdf) { - if(NULL == surface || NULL ==brdf) { + if (NULL == surface || NULL == brdf) { return RES_BAD_ARG; } *brdf = surface->brdf; return RES_OK; -} */ +} + +res_T +sphin_surface_get_source + (const struct sphin_surface* surface, + struct sphin_source** source) +{ + if (NULL == surface || NULL == source) { + return RES_BAD_ARG; + } + *source = surface->source; + return RES_OK; +} diff --git a/src/sphin_volume.c b/src/sphin_volume.c @@ -147,7 +147,7 @@ parse_ka volume->ka = ka; token = strtok_r(NULL, " \t", &token_ptr); - if(NULL != token) { res = RES_BAD_ARG; goto error; } + if (NULL != token) { res = RES_BAD_ARG; goto error; } exit: return res; @@ -227,7 +227,7 @@ error: res_T sphin_volume_ref_get(struct sphin_volume* volume) { - if(NULL == volume) { + if (NULL == volume) { return RES_BAD_ARG; } ref_get(&volume->ref); @@ -237,7 +237,7 @@ sphin_volume_ref_get(struct sphin_volume* volume) res_T sphin_volume_ref_put(struct sphin_volume* volume) { - if(NULL == volume) { + if (NULL == volume) { return RES_BAD_ARG; } ref_put(&volume->ref, release_volume);