stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit 9a84d377dbbf5711651dc0768d96d26b507fa53f
parent 8bcedc68395190ee034c13cbe2fa071d0c5ce5e7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 21 May 2019 10:12:49 +0200

Add global estimation to the estimator buffer

Diffstat:
Msrc/sdis.h | 20++++++++++++++++++++
Msrc/sdis_estimator.c | 10+++++-----
Msrc/sdis_estimator_buffer.c | 87++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/sdis_estimator_buffer_c.h | 18++++++++++++++++++
Msrc/sdis_estimator_c.h | 4++--
Msrc/sdis_solve.c | 30++++++++++++++++++++++++++++++
Msrc/test_sdis_solve_camera.c | 31++++++++++++++++++++++++-------
Msrc/test_sdis_utils.c | 2+-
Msrc/test_sdis_utils.h | 2+-
9 files changed, 187 insertions(+), 17 deletions(-)

diff --git a/src/sdis.h b/src/sdis.h @@ -416,6 +416,26 @@ sdis_estimator_buffer_at const size_t y, const struct sdis_estimator** estimator); +SDIS_API res_T +sdis_estimator_buffer_get_realisation_count + (const struct sdis_estimator_buffer* buf, + size_t* nrealisations); /* Successful ones */ + +SDIS_API res_T +sdis_estimator_buffer_get_failure_count + (const struct sdis_estimator_buffer* buf, + size_t* nfailures); + +SDIS_API res_T +sdis_estimator_buffer_get_temperature + (const struct sdis_estimator_buffer* buf, + struct sdis_mc* temperature); + +SDIS_API res_T +sdis_estimator_buffer_get_realisation_time + (const struct sdis_estimator_buffer* buf, + struct sdis_mc* time); + /******************************************************************************* * A medium encapsulates the properties of either a fluid or a solid. ******************************************************************************/ diff --git a/src/sdis_estimator.c b/src/sdis_estimator.c @@ -82,11 +82,11 @@ sdis_estimator_get_failure_count return RES_OK; } -#define SETUP_MC(McName, Acc) { \ - (McName)->E = (Acc)->sum / (double)(Acc)->count; \ - (McName)->V = (Acc)->sum2 / (double)(Acc)->count - (McName)->E*(McName)->E; \ - (McName)->V = MMAX((McName)->V, 0); \ - (McName)->SE = sqrt((McName)->V / (double)(Acc)->count); \ +#define SETUP_MC(Mc, Acc) { \ + (Mc)->E = (Acc)->sum / (double)(Acc)->count; \ + (Mc)->V = (Acc)->sum2 / (double)(Acc)->count - (Mc)->E*(Mc)->E; \ + (Mc)->V = MMAX((Mc)->V, 0); \ + (Mc)->SE = sqrt((Mc)->V / (double)(Acc)->count); \ } (void)0 res_T diff --git a/src/sdis_estimator_buffer.c b/src/sdis_estimator_buffer.c @@ -19,10 +19,15 @@ #include "sdis_estimator_buffer_c.h" struct sdis_estimator_buffer { - struct sdis_estimator** estimators; /* Row major estimators list */ + struct sdis_estimator** estimators; /* Row major per pixe lestimators */ size_t width; size_t height; + struct accum temperature; + struct accum realisation_time; + size_t nrealisations; /* #successes */ + size_t nfailures; + ref_T ref; struct sdis_device* dev; }; @@ -94,6 +99,51 @@ sdis_estimator_buffer_at return RES_OK; } +res_T +sdis_estimator_buffer_get_realisation_count + (const struct sdis_estimator_buffer* buf, size_t* nrealisations) +{ + if(!buf || !nrealisations) return RES_BAD_ARG; + *nrealisations = buf->nrealisations; + return RES_OK; +} + +res_T +sdis_estimator_buffer_get_failure_count + (const struct sdis_estimator_buffer* buf, size_t* nfailures) +{ + if(!buf || !nfailures) return RES_BAD_ARG; + *nfailures = buf->nfailures; + return RES_OK; +} + +#define SETUP_MC(Mc, Acc) { \ + (Mc)->E = (Acc)->sum / (double)(Acc)->count; \ + (Mc)->V = (Acc)->sum2 / (double)(Acc)->count - (Mc)->E*(Mc)->E; \ + (Mc)->V = MMAX((Mc)->V, 0); \ + (Mc)->SE = sqrt((Mc)->V / (double)(Acc)->count); \ +} (void)0 + +res_T +sdis_estimator_buffer_get_temperature + (const struct sdis_estimator_buffer* buf, struct sdis_mc* mc) +{ + if(!buf || !mc) return RES_BAD_ARG; + SETUP_MC(mc, &buf->temperature); + return RES_OK; +} + +res_T +sdis_estimator_buffer_get_realisation_time +(const struct sdis_estimator_buffer* buf, struct sdis_mc* mc) +{ + if(!buf || !mc) return RES_BAD_ARG; + SETUP_MC(mc, &buf->realisation_time); + return RES_OK; +} + +#undef SETUP_MC + /******************************************************************************* * Local functions ******************************************************************************/ @@ -157,3 +207,38 @@ estimator_buffer_grab return buf->estimators[y*buf->width + x]; } +void +estimator_buffer_setup_realisations_count + (struct sdis_estimator_buffer* buf, + const size_t nrealisations, + const size_t nsuccesses) +{ + ASSERT(buf && nrealisations && nsuccesses && nsuccesses<=nrealisations); + buf->nrealisations = nsuccesses; + buf->nfailures = nrealisations - nsuccesses; +} + +void +estimator_buffer_setup_temperature + (struct sdis_estimator_buffer* buf, + const double sum, + const double sum2) +{ + ASSERT(buf && buf->nrealisations); + buf->temperature.sum = sum; + buf->temperature.sum2 = sum2; + buf->temperature.count = buf->nrealisations; +} + +void +estimator_buffer_setup_realisation_time + (struct sdis_estimator_buffer* buf, + const double sum, + const double sum2) +{ + ASSERT(buf && buf->nrealisations); + buf->realisation_time.sum = sum; + buf->realisation_time.sum2 = sum2; + buf->realisation_time.count = buf->nrealisations; +} + diff --git a/src/sdis_estimator_buffer_c.h b/src/sdis_estimator_buffer_c.h @@ -36,5 +36,23 @@ estimator_buffer_grab const size_t x, const size_t y); +extern LOCAL_SYM void +estimator_buffer_setup_realisations_count + (struct sdis_estimator_buffer* buf, + const size_t nrealisations, + const size_t nsuccesses); + +extern LOCAL_SYM void +estimator_buffer_setup_temperature + (struct sdis_estimator_buffer* buf, + const double sum, + const double sum2); + +extern LOCAL_SYM void +estimator_buffer_setup_realisation_time + (struct sdis_estimator_buffer* buf, + const double sum, + const double sum2); + #endif /* SDIS_ESTIMATOR_BUFFER_C_H */ diff --git a/src/sdis_estimator_c.h b/src/sdis_estimator_c.h @@ -37,8 +37,8 @@ enum flux_name { struct sdis_estimator { struct accum temperature; struct accum realisation_time; - struct accum fluxes[FLUX_NAMES_COUNT__]; - size_t nrealisations; + struct accum fluxes[FLUX_NAMES_COUNT__]; + size_t nrealisations; /* #successes */ size_t nfailures; struct mutex* mutex; diff --git a/src/sdis_solve.c b/src/sdis_solve.c @@ -416,11 +416,16 @@ sdis_solve_camera struct sdis_estimator_buffer* buf = NULL; struct sdis_medium* medium = NULL; + struct accum acc_temp = ACCUM_NULL; + struct accum acc_time = ACCUM_NULL; struct ssp_rng_proxy* rng_proxy = NULL; struct ssp_rng** rngs = NULL; size_t ntiles_x, ntiles_y, ntiles; double pix_sz[2]; /* Size of a pixel in the normalized image plane */ int64_t mcode; /* Morton code of a tile */ + size_t nrealisations; + size_t nsuccesses; + size_t ix, iy; size_t i; ATOMIC res = RES_OK; @@ -510,6 +515,31 @@ sdis_solve_camera } } + /* Setup the accumulators of the whole estimator buffer */ + acc_temp = ACCUM_NULL; + acc_time = ACCUM_NULL; + nsuccesses = 0; + FOR_EACH(iy, 0, height) { + FOR_EACH(ix, 0, width) { + const struct sdis_estimator* estimator; + SDIS(estimator_buffer_at(buf, ix, iy, &estimator)); + acc_temp.sum += estimator->temperature.sum; + acc_temp.sum2 += estimator->temperature.sum2; + acc_temp.count += estimator->temperature.count; + acc_time.sum += estimator->realisation_time.sum; + acc_time.sum2 += estimator->realisation_time.sum2; + acc_time.count += estimator->realisation_time.count; + nsuccesses += estimator->nrealisations; + } + } + + nrealisations = width*height*spp; + ASSERT(acc_temp.count == acc_time.count); + ASSERT(acc_temp.count == nsuccesses); + estimator_buffer_setup_realisations_count(buf, nrealisations, nsuccesses); + estimator_buffer_setup_temperature(buf, acc_temp.sum, acc_temp.sum2); + estimator_buffer_setup_realisation_time(buf, acc_time.sum, acc_time.sum2); + exit: if(rngs) { FOR_EACH(i, 0, scn->dev->nthreads) { diff --git a/src/test_sdis_solve_camera.c b/src/test_sdis_solve_camera.c @@ -474,7 +474,7 @@ dump_image(const struct sdis_estimator_buffer* buf) CHK(time.E > 0); } } - + /* Compute the per pixel temperature */ FOR_EACH(iy, 0, definition[1]) { double* row = temps + iy * definition[0]; @@ -615,6 +615,11 @@ main(int argc, char** argv) geometry_get_interface, npos, geometry_get_position, &geom, &scn)); +#if 0 + dump_mesh(stdout, geom.positions, sa_size(geom.positions)/3, geom.indices, + sa_size(geom.indices)/3); +#endif + /* Setup the camera */ d3(pos, 3, 3, 3); d3(tgt, 0, 0, 0); @@ -657,19 +662,31 @@ main(int argc, char** argv) /* Launch the simulation */ OK(sdis_solve_camera(scn, cam, trange, 1, 300, 300, IMG_WIDTH, IMG_HEIGHT, - SPP, SDIS_HEAT_PATH_NONE, &buf)); + SPP, SDIS_HEAT_PATH_SUCCEED, &buf)); - /*OK(sdis_estimator_get_realisation_count(estimator, &nreals)); - OK(sdis_estimator_get_failure_count(estimator, &nfails)); - OK(sdis_estimator_get_temperature(estimator, &T)); - OK(sdis_estimator_get_realisation_time(estimator, &time)); + BA(sdis_estimator_buffer_get_realisation_count(NULL, &nreals)); + BA(sdis_estimator_buffer_get_realisation_count(buf, NULL)); + OK(sdis_estimator_buffer_get_realisation_count(buf, &nreals)); + + BA(sdis_estimator_buffer_get_failure_count(NULL, &nfails)); + BA(sdis_estimator_buffer_get_failure_count(buf, NULL)); + OK(sdis_estimator_buffer_get_failure_count(buf, &nfails)); + + BA(sdis_estimator_buffer_get_temperature(NULL, &T)); + BA(sdis_estimator_buffer_get_temperature(buf, NULL)); + OK(sdis_estimator_buffer_get_temperature(buf, &T)); + + BA(sdis_estimator_buffer_get_realisation_time(NULL, &time)); + BA(sdis_estimator_buffer_get_realisation_time(buf, NULL)); + OK(sdis_estimator_buffer_get_realisation_time(buf, &time)); CHK(nreals + nfails == IMG_WIDTH*IMG_HEIGHT*SPP); fprintf(stderr, "Overall temperature ~ %g +/- %g\n", T.E, T.SE); fprintf(stderr, "Time per realisation (in usec) ~ %g +/- %g\n", time.E, time.SE); fprintf(stderr, "#failures = %lu/%lu\n", - (unsigned long)nfails, (unsigned long)(IMG_WIDTH*IMG_HEIGHT*SPP));*/ + (unsigned long)nfails, (unsigned long)(IMG_WIDTH*IMG_HEIGHT*SPP)); + BA(sdis_estimator_buffer_get_definition(NULL, definition)); BA(sdis_estimator_buffer_get_definition(buf, NULL)); OK(sdis_estimator_buffer_get_definition(buf, definition)); diff --git a/src/test_sdis_utils.c b/src/test_sdis_utils.c @@ -270,7 +270,7 @@ check_green_function(struct sdis_green_function* green) } void -dump_heat_paths(FILE* stream, struct sdis_estimator* estimator) +dump_heat_paths(FILE* stream, const struct sdis_estimator* estimator) { const struct sdis_heat_path* path; size_t ipath; diff --git a/src/test_sdis_utils.h b/src/test_sdis_utils.h @@ -292,7 +292,7 @@ check_green_function extern LOCAL_SYM void dump_heat_paths (FILE* stream, - struct sdis_estimator* estimator); + const struct sdis_estimator* estimator); #endif /* TEST_SDIS_UTILS_H */