commit fb059f60897866eedc4aacf281c9fd71fe2c98fe
parent 086bfbe04ddee1765bdfe59541b5377f56bb13d3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 20 Dec 2023 19:00:25 +0100
Add a functor to trace a ray to external sources
Like the functor used to sample an external source, it returns a sample
on a source, which in this case refers to "the source hit by the ray".
This functor is actually needed to check whether a specular bounce
targets an external source.
In any case, defining external sources by means of functors is a bit of
a shame. First of all, describing them at the interface level is
bizarre. What's more, while the API seems to provide complete
genericity, the caller has to handle a lot of data to even describe a
single spherical source, which is actually the main situation we want to
handle. As a result, the way in which external sources are handled will
certainly change.
Diffstat:
4 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/src/sdis.h b/src/sdis.h
@@ -192,15 +192,26 @@ struct sdis_external_sources_sample {
static const struct sdis_external_sources_sample
SDIS_EXTERNAL_SOURCES_SAMPLE_NULL = SDIS_EXTERNAL_SOURCES_SAMPLE_NULL__;
+/* Is the sample valid */
+#define SDIS_EXTERNAL_SOURCES_SAMPLE_NONE(Sample) ((Sample)->pdf != 0)
+
/* Functor for sampling external sources. The returned sample is used to
* evaluate an external flux at the interface. */
typedef res_T
-(*sdis_interface_sample_external_sources_T)
+(*sdis_sample_external_sources_T)
(const struct sdis_interface_fragment* frag, /* Interface position */
struct ssp_rng* rng, /* Random Number Generator to use */
struct sdis_external_sources_sample* sample, /* Returned sample */
struct sdis_data* data); /* User data */
+/* Functor returning the external sources hit by a ray */
+typedef res_T
+(*sdis_trace_external_sources_T)
+ (const struct sdis_interface_fragment* frag, /* Interface position */
+ const double dir[3], /* Ray direction */
+ struct sdis_external_sources_sample* sample, /* Hit source */
+ struct sdis_data* data); /* User data */
+
/* Define the physical properties of a solid */
struct sdis_solid_shader {
/* Properties */
@@ -261,10 +272,14 @@ struct sdis_interface_side_shader {
sdis_interface_getter_T reference_temperature;
/* Manage external sources, i.e. sample them to evaluate the corresponding
- * external flow. Can be NULL <=> no external source */
- sdis_interface_sample_external_sources_T sample_external_sources;
+ * external flux. Can be NULL <=> no external source */
+ sdis_sample_external_sources_T sample_external_sources;
+
+ /* Does the ray target an external source? Can only be NULL if
+ * sample_external_sources is also NULL */
+ sdis_trace_external_sources_T trace_external_sources;
};
-#define SDIS_INTERFACE_SIDE_SHADER_NULL__ { NULL, NULL, NULL, NULL, NULL, NULL }
+#define SDIS_INTERFACE_SIDE_SHADER_NULL__ { NULL, NULL, NULL, NULL, NULL, NULL, NULL }
static const struct sdis_interface_side_shader SDIS_INTERFACE_SIDE_SHADER_NULL =
SDIS_INTERFACE_SIDE_SHADER_NULL__;
diff --git a/src/sdis_heat_path_boundary_Xd_handle_external_net_flux.h b/src/sdis_heat_path_boundary_Xd_handle_external_net_flux.h
@@ -31,7 +31,7 @@ XD(check_handle_external_net_flux_args)
const char* func_name,
const struct XD(handle_external_net_flux_args)* args)
{
- sdis_interface_sample_external_sources_T functor = NULL;
+ sdis_sample_external_sources_T functor = NULL;
res_T res = RES_OK;
/* Handle bugs */
@@ -66,7 +66,7 @@ XD(handle_external_net_flux)
{
/* Sampling external sources */
struct sdis_external_sources_sample sample = SDIS_EXTERNAL_SOURCES_SAMPLE_NULL;
- sdis_interface_sample_external_sources_T sample_sources = NULL;
+ sdis_sample_external_sources_T sample_sources = NULL;
/* Ray tracing */
struct hit_filter_data filter_data = HIT_FILTER_DATA_NULL;
diff --git a/src/sdis_interface_c.h b/src/sdis_interface_c.h
@@ -183,7 +183,7 @@ interface_side_get_reference_temperature
? shader->reference_temperature(frag, interf->data) : -1;
}
-static INLINE sdis_interface_sample_external_sources_T
+static INLINE sdis_sample_external_sources_T
interface_side_get_external_sources_sampling_functor
(const struct sdis_interface* interf,
const struct sdis_interface_fragment* frag)
@@ -198,5 +198,19 @@ interface_side_get_external_sources_sampling_functor
return shader->sample_external_sources;
}
-#endif /* SDIS_INTERFACE_C_H */
+static INLINE sdis_trace_external_sources_T
+interface_side_get_external_sources_tracing_functor
+ (const struct sdis_interface* interf,
+ const struct sdis_interface_fragment* frag)
+{
+ const struct sdis_interface_side_shader* shader;
+ ASSERT(interf && frag);
+ switch(frag->side) {
+ case SDIS_BACK: shader = &interf->shader.back; break;
+ case SDIS_FRONT: shader = &interf->shader.front; break;
+ default: FATAL("Unreachable code\n"); break;
+ }
+ return shader->trace_external_sources;
+}
+#endif /* SDIS_INTERFACE_C_H */
diff --git a/src/test_sdis_utils.h b/src/test_sdis_utils.h
@@ -193,7 +193,8 @@ static const struct sdis_fluid_shader DUMMY_FLUID_SHADER = {
dummy_interface_getter, /* Emissivity */ \
dummy_interface_getter, /* Specular fraction */ \
dummy_interface_getter, /* Reference temperature */ \
- NULL, /* External sources */ \
+ NULL, /* Sample external sources */ \
+ NULL, /* Trace externa sources */ \
}
static const struct sdis_interface_shader DUMMY_INTERFACE_SHADER = {
dummy_interface_getter, /* Convection coef */