commit 241a8beb0e9453fcb2e1f95e6a13bea99cbd609e
parent 607ce0773e0e06d3e69a2848a513b20d3dee08d5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Tue, 5 Mar 2019 17:13:57 +0100
Add "heat path registration" support to the medium solver
Diffstat:
4 files changed, 37 insertions(+), 12 deletions(-)
diff --git a/src/sdis.h b/src/sdis.h
@@ -922,6 +922,7 @@ sdis_solve_medium
const double fp_to_meter, /* Scale from floating point units to meters */
const double ambient_radiative_temperature, /* In Kelvin */
const double reference_temperature, /* In Kelvin */
+ const int register_path, /* Combination of enum sdis_heat_path_flag */
struct sdis_estimator** estimator);
/*******************************************************************************
diff --git a/src/sdis_solve.c b/src/sdis_solve.c
@@ -445,16 +445,17 @@ sdis_solve_medium
const double fp_to_meter, /* Scale from floating point units to meters */
const double Tarad, /* In Kelvin */
const double Tref, /* In Kelvin */
+ const int register_paths, /* Combination of enum sdis_heat_path_flag */
struct sdis_estimator** estimator)
{
res_T res = RES_OK;
if(!scn) return RES_BAD_ARG;
if(scene_is_2d(scn)) {
res = solve_medium_2d(scn, nrealisations, medium, time_range, fp_to_meter, Tarad,
- Tref, estimator);
+ Tref, register_paths, estimator);
} else {
res = solve_medium_3d(scn, nrealisations, medium, time_range, fp_to_meter, Tarad,
- Tref, estimator);
+ Tref, register_paths, estimator);
}
return res;
}
diff --git a/src/sdis_solve_medium_Xd.h b/src/sdis_solve_medium_Xd.h
@@ -204,6 +204,7 @@ XD(solve_medium)
const double fp_to_meter,/* Scale factor from floating point unit to meter */
const double Tarad, /* Ambient radiative temperature */
const double Tref, /* Reference temperature */
+ const int register_paths, /* Combination of enum sdis_heat_path_flag */
struct sdis_estimator** out_estimator)
{
struct darray_enclosure_cumul cumul;
@@ -263,6 +264,8 @@ XD(solve_medium)
const struct enclosure* enc = NULL;
struct accum* accum = accums + ithread;
struct ssp_rng* rng = rngs[ithread];
+ struct sdis_heat_path* pheat_path = NULL;
+ struct sdis_heat_path heat_path;
double weight;
double time;
double pos[DIM];
@@ -273,6 +276,12 @@ XD(solve_medium)
/* Sample the time */
time = sample_time(rng, time_range);
+ /* Prepare path registration if necessary */
+ if(register_paths) {
+ heat_path_init(scn->dev->allocator, &heat_path);
+ pheat_path = &heat_path;
+ }
+
/* Uniformly Sample an enclosure that surround the submitted medium and
* uniformly sample a position into it */
enc = sample_medium_enclosure(&cumul, rng);
@@ -285,7 +294,7 @@ XD(solve_medium)
/* Run a probe realisation */
res_local = XD(probe_realisation)((size_t)irealisation, scn, rng, mdm, pos,
- time, fp_to_meter, Tarad, Tref, NULL, NULL, &weight);
+ time, fp_to_meter, Tarad, Tref, NULL, pheat_path, &weight);
if(res_local != RES_OK) {
if(res_local != RES_BAD_OP) { ATOMIC_SET(&res, res_local); continue; }
} else {
@@ -293,6 +302,21 @@ XD(solve_medium)
accum->sum2 += weight*weight;
++accum->naccums;
}
+
+ /* Finalize the registered path */
+ if(pheat_path) {
+ pheat_path->status = res_local == RES_OK
+ ? SDIS_HEAT_PATH_SUCCEED
+ : SDIS_HEAT_PATH_FAILED;
+
+ /* Check if the path must be saved regarding the register_paths mask */
+ if(!(register_paths & (int)pheat_path->status)) {
+ heat_path_release(pheat_path);
+ } else { /* Register the sampled path */
+ res_local = estimator_add_and_release_heat_path(estimator, pheat_path);
+ if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; }
+ }
+ }
}
if(res != RES_OK) goto error;
diff --git a/src/test_sdis_solve_medium.c b/src/test_sdis_solve_medium.c
@@ -313,19 +313,18 @@ main(int argc, char** argv)
MEM_RM(&allocator, vertices);
MEM_RM(&allocator, indices);
}
- exit(0);
#endif
OK(sdis_scene_create(dev, ntris, get_indices, get_interface, nverts,
get_position, &ctx, &scn));
- BA(sdis_solve_medium(NULL, N, solid0, trange, 1.f, -1, 0, &estimator));
- BA(sdis_solve_medium(scn, 0, solid0, trange, 1.f, -1, 0, &estimator));
- BA(sdis_solve_medium(scn, N, NULL, trange, 1.f, -1, 0, &estimator));
- BA(sdis_solve_medium(scn, N, solid0, NULL, 1.f, -1, 0, &estimator));
- BA(sdis_solve_medium(scn, N, solid0, trange, 0.f, -1, 0, &estimator));
- BA(sdis_solve_medium(scn, N, solid0, trange, 1.f, -1, 0, NULL));
- OK(sdis_solve_medium(scn, N, solid0, trange, 1.f, -1, 0, &estimator));
+ BA(sdis_solve_medium(NULL, N, solid0, trange, 1.f, -1, 0, 0, &estimator));
+ BA(sdis_solve_medium(scn, 0, solid0, trange, 1.f, -1, 0, 0, &estimator));
+ BA(sdis_solve_medium(scn, N, NULL, trange, 1.f, -1, 0, 0, &estimator));
+ BA(sdis_solve_medium(scn, N, solid0, NULL, 1.f, -1, 0, 0, &estimator));
+ BA(sdis_solve_medium(scn, N, solid0, trange, 0.f, -1, 0, 0, &estimator));
+ BA(sdis_solve_medium(scn, N, solid0, trange, 1.f, -1, 0, 0, NULL));
+ OK(sdis_solve_medium(scn, N, solid0, trange, 1.f, -1, 0, 0, &estimator));
OK(sdis_estimator_get_realisation_count(estimator, &nreals));
OK(sdis_estimator_get_failure_count(estimator, &nfails));
@@ -336,7 +335,7 @@ main(int argc, char** argv)
CHK(nreals + nfails == N);
OK(sdis_estimator_ref_put(estimator));
- OK(sdis_solve_medium(scn, N, solid1, trange, 1.f, -1, 0, &estimator));
+ OK(sdis_solve_medium(scn, N, solid1, trange, 1.f, -1, 0, 0, &estimator));
OK(sdis_estimator_get_realisation_count(estimator, &nreals));
OK(sdis_estimator_get_failure_count(estimator, &nfails));
OK(sdis_estimator_get_temperature(estimator, &T));