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 b92b25b4462cea91346d039f7a807094e3797b34
parent c26ec63e7dbcfe19a769b5cc50f6f7af2e69025e
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Thu, 29 Jan 2026 12:12:27 +0100

Expose total surface area function in public sphin API

The function that computes the total surface area may be useful to sphin
API users. This change moves it from internal use to the public API,
making it reusable by external clients.

Also adds a corresponding test in test_sphin_load_surface

Diffstat:
Msrc/sphin.h | 5+++++
Msrc/sphin_surface.c | 22++++++++++++++++++++++
Msrc/test_sphin_load_surface.c | 15+++++++++------
3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/src/sphin.h b/src/sphin.h @@ -433,6 +433,11 @@ sphin_surface_get_name char** name); SPHIN_API res_T +sphin_surface_compute_total_area + (struct sphin_surface* surface, + double* area); + +SPHIN_API res_T sphin_surface_get_sensor (struct sphin_surface* surface, struct sphin_sensor_surface** sensor_surface); /* May be NULL <=> no diff --git a/src/sphin_surface.c b/src/sphin_surface.c @@ -371,6 +371,28 @@ sphin_surface_get_geometry } res_T +sphin_surface_compute_total_area + (struct sphin_surface* surface, + double* area) +{ + double total_geometry_area = 0; + size_t geometry_count = 0; + size_t i = 0; + struct sphin_geometry* geometry = NULL; + res_T res = RES_OK; + + geometry_count = darray_sphin_geometry_ptr_size_get(&surface->geometries); + + FOR_EACH(i, 0, geometry_count) { + geometry = darray_sphin_geometry_ptr_data_get(&surface->geometries)[i]; + total_geometry_area += geometry_compute_area(geometry); + } + + *area = total_geometry_area; + return res; +} + +res_T sphin_surface_source_get_power (struct sphin_surface* surface, double* power) diff --git a/src/test_sphin_load_surface.c b/src/test_sphin_load_surface.c @@ -95,15 +95,15 @@ static void test_surface_api (struct sphin* sphin) { - struct sphin_config* config = NULL; - const char* path = "file.txt"; char* name = NULL; - double power, reflectivity, response_function; - struct sphin_surface* surface = NULL; - struct sphin_brdf* brdf = NULL; - struct sphin_sensor_surface* sensor_surface = NULL; + const char* path = "file.txt"; + double area, power, reflectivity, response_function; enum sphin_brdf_type brdf_type = SPHIN_BRDF_NONE__; size_t nsurfaces; + struct sphin_brdf* brdf = NULL; + struct sphin_config* config = NULL; + struct sphin_sensor_surface* sensor_surface = NULL; + struct sphin_surface* surface = NULL; FILE* fp = NULL; CHK(fp = fopen(path, "w+")); @@ -116,6 +116,7 @@ test_surface_api fprintf(fp, " # A line with a comment\n"); fprintf(fp, " \n"); fprintf(fp, "surface: \"other_tube walls\"\n"); + fprintf(fp, "\tgeometry: FRONT test_0.stl\n"); fprintf(fp, "\tbrdf\t : SPECULAR 0.1935 \n"); fprintf(fp, "\tsensor: \n"); fprintf(fp, "\t\tresponse_function: 1\n"); @@ -169,6 +170,8 @@ test_surface_api CHK(sphin_brdf_specular_get_reflectivity(brdf, &reflectivity) == RES_OK); CHK(sphin_surface_source_get_power(surface, &power) == RES_BAD_ARG); CHK(eq_eps(reflectivity, 0.1935, 1e-15)); + CHK(sphin_surface_compute_total_area(surface, &area) == RES_OK); + CHK(eq_eps(area, 0.5, 1e-15)); CHK(sphin_brdf_ref_get(brdf) == RES_OK); CHK(sphin_brdf_ref_put(brdf) == RES_OK); CHK(sphin_surface_get_sensor(NULL, NULL) == RES_BAD_ARG);