star-phor

Radiative transfer solver for photoreactors.
git clone https://www.edstar.cnrs.fr/git/star-phor.git
Log | Files | Refs | README | LICENSE

commit 10a6ce8ccb080889a085891725a57ebce05ba3f4
parent b7504bb3d4c029ffb3c32116302fc52f7435a116
Author: Eduardo Fontana Lazzari <edufonlaz@gmail.com>
Date:   Wed,  7 May 2025 16:49:37 +0200

Refactor struct interface: remove front/back from member names

Once the correspondence between geometrical and physical data has been
established, the notion of "front" and "back" from star-phor-input
becomes irrelevant. Triangle orientations may be reversed during this
process, making those original labels misleading.

This refactoring also makes the data more suitable for Monte Carlo
sampling, where orientation semantics are mostly unnecessary except in a
few specific cases. Using static arrays to store volumes and
surfaces—indexed by a symbolic constant for each side—provides a good
compromise: it removes hardcoded orientation assumptions while
preserving the ability to reinterpret the data where necessary (e.g.,
using SPHIN_SIDE_FRONT, SPHIN_SIDE_BACK).

Diffstat:
Msrc/sphor_config.c | 54++++++++++++++++++++++--------------------------------
Msrc/sphor_interface.h | 21+++++++++++++--------
2 files changed, 35 insertions(+), 40 deletions(-)

diff --git a/src/sphor_config.c b/src/sphor_config.c @@ -119,8 +119,7 @@ are_triangles_reversed /* Check the order of the next vertex: * If tri0->v1 matches the next vertex in tri1 (cyclically), * the triangles have the same orientation (not reversed). - * Otherwise, the vertex order has been reversed - * (due to lexicographical sorting in the key struct). */ + * Otherwise, the vertex order has been reversed. */ if(0 == vec3_cmp(tri0->v1, tri1_verts[(i+1)%3])) { return 0; /* Same orientation */ } else { @@ -185,7 +184,7 @@ setup_interface_volume_geometry_triangle struct interface* interface = NULL; size_t ids[3] = {0, 0, 0}; const double* coords[3] = {NULL, NULL, NULL}; - size_t* pvolume_id = NULL; + enum sphin_side side = SPHIN_SIDE_NONE__; int flip = 0; res_T res = RES_OK; @@ -234,21 +233,13 @@ setup_interface_volume_geometry_triangle flip = are_triangles_reversed(&tri, tri_sphor); - switch (geom_desc->side) { - case SPHIN_SIDE_FRONT: - pvolume_id = flip ? &interface->volume_back : &interface->volume_front; - break; - case SPHIN_SIDE_BACK: - pvolume_id = flip ? &interface->volume_front : &interface->volume_back; - break; - default: FATAL("Unreachable code\n"); break; + side = (size_t) flip ^ geom_desc->side; + if(INVALID_ID != interface->volumes[side]) { + ERROR(sphor, + "Redefinition of volume side in triangle from file '%s'.\n", + geom_desc->filename); } - - if(*pvolume_id != INVALID_ID) { - /* TODO return an error and log a message */ - } - - *pvolume_id = ivolume; + interface->volumes[side] = ivolume; exit: return res; @@ -356,7 +347,8 @@ setup_interface_surface_geometry_triangle size_t ids[3] = {0, 0, 0}; const double* coords[3] = {NULL, NULL, NULL}; int flip = 0; - int is_back = 0; + short surf_count = 0; + enum sphin_side side = SPHIN_SIDE_NONE__; res_T res = RES_OK; ASSERT(NULL != sphor); @@ -417,21 +409,19 @@ setup_interface_surface_geometry_triangle * +------+-----+-----+-----+ */ flip = are_triangles_reversed(&tri, tri_sphor); - is_back = flip ^ (geom_desc->side == SPHIN_SIDE_BACK); - - if (is_back) { - if ( MAX_SURFACE_COUNT <= interface->surface_back_count+1){ - /* TODO Error message and exit */ - } - interface->surfaces_back[interface->surface_back_count] = isurface; - interface->surface_back_count++; - } else { - if ( MAX_SURFACE_COUNT <= interface->surface_front_count+1){ - /* TODO Error message and exit */ - } - interface->surfaces_front[interface->surface_front_count] = isurface; - interface->surface_front_count++; + + side = (size_t) flip ^ geom_desc->side; + + surf_count = interface->surface_count[side]; + + if(MAX_SURFACE_COUNT <= surf_count) { + ERROR(sphor, + "Too many surfaces on the same side of interface defined by triangle from file '%s'. " + "Maximum allowed: %d\n", + geom_desc->filename, MAX_SURFACE_COUNT); + goto error; } + interface->surfaces[side][surf_count] = isurface; exit: return res; diff --git a/src/sphor_interface.h b/src/sphor_interface.h @@ -27,19 +27,24 @@ #include <rsys/dynamic_array.h> -/* Maximal amount of surfaces that the same triangle can be part of. */ +/* Maximum number of surfaces a single triangle can be part of (per side). + * We use a constant to avoid dynamic memory allocation. + * 4 is chosen as a good balance between efficiency and possibility. + * This value can be adjusted as needed. */ #define MAX_SURFACE_COUNT 4 #define INVALID_ID SIZE_MAX struct interface { - size_t volume_front; - size_t volume_back; - size_t surfaces_back[MAX_SURFACE_COUNT]; - size_t surfaces_front[MAX_SURFACE_COUNT]; - short surface_back_count; - short surface_front_count; + /* Interface side; FRONT and BACK */ + size_t volumes[2/*#sides*/]; + size_t surfaces[2/*#sides*/][MAX_SURFACE_COUNT]; + short surface_count[2]; }; -#define INTERFACE_NULL__ {INVALID_ID, INVALID_ID, {INVALID_ID}, {INVALID_ID}, 0, 0} +#define INTERFACE_NULL__ { \ + {INVALID_ID, INVALID_ID}, /* volumes */ \ + {{INVALID_ID}, {INVALID_ID}}, /* surfaces*/ \ + {0, 0} /* surface_count*/ \ +} static const struct interface INTERFACE_NULL = INTERFACE_NULL__; #define DARRAY_NAME interface