stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit 774616f38d30aeec08a3c5f73aad8f897509a569
parent f743334a1b31a1628074e15b64c60c765db9ab20
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 25 Jun 2024 12:57:36 +0200

Add support of customize conductive path sampling

On programmable solids, users can now define the new
Stardis_sampling_conductive_path function, in which they can write their
own sampling process. As input, the function takes a path whose
spatio-temporal position lies within the programmable solid. Once the
path has been sampled, this position is updated and can be either within
the solid if the initial condition is reached, or at the boundary, i.e.
at a boundary condition. Stardis then continues the path sampling
procedure in relation to the returned state.

To perform coupling with a boundary condition, we need to match the
boundary of the user-side sampling procedure to the geometry of Stardis.
To do this, the caller must define the three vertices of the
intersecting primitive as they are exactly defined (i.e. bitwise) on the
Stardis side. In this way, Stardis can internally construct a key that
associates these vertices with the corresponding primitive on the solver
side.

Diffstat:
Msrc/stardis-parsing.c | 4++++
Msrc/stardis-prog-properties.h.in | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/stardis-solid-prog.c | 50+++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/stardis-solid-prog.h | 8++++++++
4 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -1804,6 +1804,10 @@ process_solid_prog GET_LIB_SYMBOL(solid_prog, delta, stardis_delta_solid); GET_LIB_SYMBOL(solid_prog, temp, stardis_medium_temperature); GET_LIB_SYMBOL(solid_prog, vpower, stardis_volumic_power); + + GET_LIB_SYMBOL_BASE(&solid_prog->sample_path, solid_prog->program->lib_handle, + stardis_sample_conductive_path, 1); + /* create and init custom data */ ctx.name = desc_name; CREATE_DESC_DATA(solid_prog); diff --git a/src/stardis-prog-properties.h.in b/src/stardis-prog-properties.h.in @@ -45,6 +45,10 @@ /* Indentifier of the internal source of radiation */ #define STARDIS_INTERN_SOURCE_ID UINT_MAX +/* Forward declaration of external data types */ +struct sdis_scene; +struct ssp_rng; + /******************************************************************************* * API types. * The various functions defining programmed descriptions receive arguments @@ -91,6 +95,42 @@ struct stardis_description_create_context { const char* name; /* Description name */ }; +struct stardis_triangle { + double vtx0[3]; + double vtx1[3]; + double vtx2[3]; +}; +#define STARDIS_TRIANGLE_NULL__ {{0,0,0}, {0,0,0}, {0,0,0}} +static const struct stardis_triangle STARDIS_TRIANGLE_NULL = + STARDIS_TRIANGLE_NULL__; + +/* Helper macro that check if the triangle is NULL */ +#define STARDIS_TRIANGLE_NONE(T) \ + ( (T)->vtx0[0] == 0 && (T)->vtx0[1] == 0 && (T)->vtx0[2] == 0 \ + && (T)->vtx1[0] == 0 && (T)->vtx1[1] == 0 && (T)->vtx1[2] == 0 \ + && (T)->vtx2[0] == 0 && (T)->vtx2[1] == 0 && (T)->vtx2[2] == 0) + +/* A sampled path */ +struct stardis_path { + struct stardis_vertex vtx; /* Current position and time */ + + /* Triangle intersected by the path. When defined, the path is on a border */ + struct stardis_triangle tri; + + double weight; /* Monte Carlo weight update along the path */ + + /* Define whether the path has reached a boundary conduction in time/space */ + int at_limit; +}; +#define STARDIS_PATH_NULL__ { \ + STARDIS_VERTEX_NULL__, \ + STARDIS_TRIANGLE_NULL__, \ + 0, /* MC weight */ \ + 0 /* At limit */ \ +} +static const struct stardis_path STARDIS_PATH_NULL = + STARDIS_PATH_NULL__; + #ifdef __cplusplus extern "C" { #endif @@ -240,6 +280,19 @@ stardis_medium_temperature void* data); /******************************************************************************* + * Optional function for a solid + ******************************************************************************/ + +/* Function used to sample a conductive path. When defined, it is no + * longer Stardis that samples the path, but the user via this function */ +STARDIS_API int /* Error code */ +stardis_sample_conductive_path + (struct sdis_scene* scn, + struct ssp_rng* rng, + struct stardis_path* path, + void* data); + +/******************************************************************************* * Mandatory functions for a fluid ******************************************************************************/ diff --git a/src/stardis-solid-prog.c b/src/stardis-solid-prog.c @@ -103,6 +103,51 @@ solid_prog_get_temperature return STARDIS_TEMPERATURE_IS_KNOWN(temp) ? temp : SDIS_TEMPERATURE_NONE; } +static res_T +solid_prog_sample_path + (struct sdis_scene* scn, + struct ssp_rng* rng, + struct sdis_path* path, + struct sdis_data* data) +{ + const struct solid_prog* const* solid_props = sdis_data_cget(data); + struct stardis_path p = STARDIS_PATH_NULL; + int err = 0; + res_T res = RES_OK; + + d3_set(p.vtx.P, path->vtx.P); + p.vtx.time = path->vtx.time; + + err = (*solid_props)->sample_path(scn, rng, &p, (*solid_props)->prog_data); + if(err) { res = RES_UNKNOWN_ERR; goto error; } + + d3_set(path->vtx.P, p.vtx.P); + path->vtx.time = p.vtx.time; + path->weight = p.weight; + path->at_limit = p.at_limit; + + if(!STARDIS_TRIANGLE_NONE(&p.tri)) { + struct sdis_primkey key = SDIS_PRIMKEY_NULL; + + sdis_primkey_setup(&key, p.tri.vtx0, p.tri.vtx1, p.tri.vtx2); + res = sdis_scene_get_s3d_primitive(scn, &key, &path->prim_3d); + + /* In fact, we'd like to log an error notifying us that the returned + * triangle doesn't exist in Stardis. But there's no easy way to retrieve + * the logger since the program has no reference to Stardis. This lack stems + * from design choices where internal data structures are not managed by + * reference and don't take a reference on the Stardis structure. In any + * case, until stardis' internal data structures have been thoroughly + * redesigned, we're only returning an error */ + if(res != RES_OK) goto error; + } + +exit: + return res; +error: + goto exit; +} + /******************************************************************************* * Public Functions ******************************************************************************/ @@ -121,10 +166,13 @@ create_solver_solid_prog solid_shader.calorific_capacity = solid_prog_get_calorific_capacity; solid_shader.thermal_conductivity = solid_prog_get_thermal_conductivity; solid_shader.volumic_mass = solid_prog_get_volumic_mass; - solid_shader.delta= solid_prog_get_delta; + solid_shader.delta = solid_prog_get_delta; solid_shader.volumic_power = solid_prog_get_volumic_power; solid_shader.temperature = solid_prog_get_temperature; solid_shader.t0 = stardis->initial_time; + if(solid_props->sample_path) { + solid_shader.sample_path = solid_prog_sample_path; + } ERR(sdis_data_create(stardis->dev, sizeof(struct solid_prog*), ALIGNOF(struct solid_prog*), NULL, &data)); diff --git a/src/stardis-solid-prog.h b/src/stardis-solid-prog.h @@ -48,6 +48,14 @@ struct solid_prog { double (*delta)(const struct stardis_vertex*, void*); double (*temp)(const struct stardis_vertex*, void*); double (*vpower)(const struct stardis_vertex*, void*); + + /* User-defined function for sampling a conductive path */ + int + (*sample_path) + (struct sdis_scene*, + struct ssp_rng*, + struct stardis_path*, + void*); }; res_T