stardis

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

commit 16cf1bc4bca1529476780d6005051919a72ee73f
parent eb03f4a414f72da4144e0b2c3c4c99dfe8bacacb
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 23 Feb 2024 15:58:06 +0100

Preparing to print the results of multiple probe calculations

The print_single_MC_result function assumes that a single calculation
has been performed and that it has retrieved the calculation parameters
from the stardis structure. This commit adds the
print_single_MC_result_probe_boundary function, which adds the probe
associated with the result as an input argument. This function can be
called to display the results of multiple boundary probe calculations.

This new function is called internally by the print_single_MC_result
function when the result comes from a probe calculation on a boundary.
It reduces the size of this function while simplifying its reading.
Nevertheless, this function is still too long, with a large number of
case instructions that could be simplified by refactoring the code into
sub-functions, as this commit does with the probe calculation on a
boundary. And perhaps once this refactoring has been carried out, this
"generic" function will then appear dispensable, since when we want to
print a result, the caller knows what type of calculation he has just
carried out. He can then directly call the function that displays the
result of the calculation he has just performed. In other words, this
genericity doesn't seem necessary.

The print_computation_time function has also been updated. It no longer
takes an estimator as an input argument. It now takes a Monte Carlo
estimate of time per realization. This change was necessary because time
per realization was not necessarily defined on a single estimator. When
calculating multiple probes, the total estimate of time per realization
is saved in an estimator buffer.

Diffstat:
Msrc/stardis-compute-probe-boundary.c | 5++++-
Msrc/stardis-compute.c | 25+++++++++++++++++--------
Msrc/stardis-output.c | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/stardis-output.h | 43++++++++++++++++++++++++++-----------------
4 files changed, 111 insertions(+), 55 deletions(-)

diff --git a/src/stardis-compute-probe-boundary.c b/src/stardis-compute-probe-boundary.c @@ -629,6 +629,7 @@ solve res_T output[2]) { struct time t0, t1; + struct sdis_mc time = SDIS_MC_NULL; struct dump_path_context ctx = DUMP_PATH_CONTEXT_NULL; struct sdis_estimator* estimator = NULL; const struct str* rng_in = NULL; @@ -658,7 +659,9 @@ solve /* No more to do for non master processes */ if(!is_master_process) goto exit; - ERR(print_computation_time(estimator, stardis, start, &t0, &t1, NULL)); + /* Per per realisation time */ + ERR(sdis_estimator_get_realisation_time(estimator, &time)); + ERR(print_computation_time(&time, stardis, start, &t0, &t1, NULL)); /* Write outputs and save their status */ ctx.stardis = stardis; diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -456,12 +456,14 @@ compute_probe(struct stardis* stardis, struct time* start) if(stardis->mpi_initialized && stardis->mpi_rank != 0) { ERR(sdis_solve_probe(stardis->sdis_scn, &args, &estimator)); } else { + struct sdis_mc time = SDIS_MC_NULL; res_T tmp_res1, tmp_res2; time_current(&compute_start); ERR(sdis_solve_probe(stardis->sdis_scn, &args, &estimator)); time_current(&compute_end); - ERR(print_computation_time(estimator, stardis, - start, &compute_start, &compute_end, NULL)); + ERR(sdis_estimator_get_realisation_time(estimator, &time)); + ERR(print_computation_time + (&time, stardis, start, &compute_start, &compute_end, NULL)); tmp_res1 = print_single_MC_result(estimator, stardis, stdout); /* Dump recorded paths according to user settings */ @@ -751,12 +753,15 @@ compute_medium(struct stardis* stardis, struct time* start) if(stardis->mpi_initialized && stardis->mpi_rank != 0) { ERR(sdis_solve_medium(stardis->sdis_scn, &args, &estimator)); } else { + struct sdis_mc time = SDIS_MC_NULL; res_T tmp_res1, tmp_res2; time_current(&compute_start); ERR(sdis_solve_medium(stardis->sdis_scn, &args, &estimator)); time_current(&compute_end); - ERR(print_computation_time(estimator, stardis, - start, &compute_start, &compute_end, NULL)); + + ERR(sdis_estimator_get_realisation_time(estimator, &time)); + ERR(print_computation_time + (&time, stardis, start, &compute_start, &compute_end, NULL)); tmp_res1 = print_single_MC_result(estimator, stardis, stdout); /* Dump recorded paths according to user settings */ dump_ctx.stardis = stardis; @@ -908,12 +913,14 @@ compute_boundary(struct stardis* stardis, struct time* start) if(stardis->mpi_initialized && stardis->mpi_rank != 0) { ERR(sdis_solve_boundary(stardis->sdis_scn, &args, &estimator)); } else { + struct sdis_mc time = SDIS_MC_NULL; res_T tmp_res1, tmp_res2; time_current(&compute_start); ERR(sdis_solve_boundary(stardis->sdis_scn, &args, &estimator)); time_current(&compute_end); - ERR(print_computation_time(estimator, stardis, - start, &compute_start, &compute_end, NULL)); + ERR(sdis_estimator_get_realisation_time(estimator, &time)); + ERR(print_computation_time + (&time, stardis, start, &compute_start, &compute_end, NULL)); tmp_res1 = print_single_MC_result(estimator, stardis, stdout); /* Dump recorded paths according to user settings */ dump_ctx.stardis = stardis; @@ -967,12 +974,14 @@ compute_flux_boundary(struct stardis* stardis, struct time* start) if(stardis->mpi_initialized && stardis->mpi_rank != 0) { ERR(sdis_solve_boundary_flux(stardis->sdis_scn, &args, &estimator)); } else { + struct sdis_mc time = SDIS_MC_NULL; res_T tmp_res1, tmp_res2; time_current(&compute_start); ERR(sdis_solve_boundary_flux(stardis->sdis_scn, &args, &estimator)); time_current(&compute_end); - ERR(print_computation_time(estimator, stardis, - start, &compute_start, &compute_end, NULL)); + ERR(sdis_estimator_get_realisation_time(estimator, &time)); + ERR(print_computation_time + (&time, stardis, start, &compute_start, &compute_end, NULL)); tmp_res1 = print_single_MC_result(estimator, stardis, stdout); /* Dump recorded paths according to user settings */ diff --git a/src/stardis-output.c b/src/stardis-output.c @@ -1551,15 +1551,13 @@ error: res_T print_computation_time - (struct sdis_estimator* estimator, + (struct sdis_mc* time_per_realisation, struct stardis* stardis, struct time* start, struct time* compute_start, struct time* compute_end, struct time* output_end) { - res_T res = RES_OK; - struct sdis_mc time; struct time tmp; char buf[128]; const int flag = TIME_MSEC | TIME_SEC | TIME_MIN | TIME_HOUR | TIME_DAY; @@ -1584,16 +1582,13 @@ print_computation_time "Result output time = %s\n", buf); } - if(estimator) { - ERR(sdis_estimator_get_realisation_time(estimator, &time)); + if(time_per_realisation) { logger_print(stardis->logger, LOG_OUTPUT, - "Time per realisation (in usec) = %g +/- %g\n", time.E, time.SE); + "Time per realisation (in usec) = %g +/- %g\n", + time_per_realisation->E, time_per_realisation->SE); } -exit: - return res; -error: - goto exit; + return RES_OK; } res_T @@ -1644,28 +1639,13 @@ print_single_MC_result else fprintf(stream, "%g %g %lu %lu\n", result.E, result.SE, nfailures, nsamples); break; - case MODE_PROBE_COMPUTE_ON_INTERFACE: - if(stardis->mode & MODE_EXTENDED_RESULTS) { + case MODE_PROBE_COMPUTE_ON_INTERFACE: { const struct stardis_probe_boundary* probe = NULL; - ASSERT(darray_probe_boundary_size_get(&stardis->probe_boundary_list) == 1); probe = darray_probe_boundary_cdata_get(&stardis->probe_boundary_list); - if(stardis->time_range[0] == stardis->time_range[1]) - fprintf(stream, - "Boundary temperature at [%g, %g, %g] at t=%g = %g K +/- %g\n", - SPLIT3(probe->position), - probe->time[0], - result.E, /* Expected value */ - result.SE); /* Standard error */ - else - fprintf(stream, - "Boundary temperature at [%g, %g, %g] with t in [%g %g] = %g K +/- %g\n", - SPLIT3(probe->position), SPLIT2(probe->time), - result.E, /* Expected value */ - result.SE); /* Standard error */ + ERR(print_single_MC_result_probe_boundary + (stardis, probe, estimator, stream)); + break; } - else fprintf(stream, "%g %g %lu %lu\n", - result.E, result.SE, nfailures, nsamples); - break; case MODE_MEDIUM_COMPUTE: if(stardis->mode & MODE_EXTENDED_RESULTS) { if(stardis->time_range[0] == stardis->time_range[1]) @@ -1805,6 +1785,61 @@ abort: } res_T +print_single_MC_result_probe_boundary + (struct stardis* stardis, + const struct stardis_probe_boundary* probe, + const struct sdis_estimator* estimator, + FILE* stream) +{ + struct sdis_mc result = SDIS_MC_NULL; + size_t nfailures = 0; + size_t nsamples = 0; + res_T res = RES_OK; + + ASSERT(stardis && probe && estimator); + ASSERT((stardis->mode & MODE_PROBE_COMPUTE_ON_INTERFACE) + || (stardis->mode & MODE_PROBE_LIST_COMPUTE_ON_INTERFACE)); + + /* Only master prints or reads estimators */ + ASSERT(!stardis->mpi_initialized || stardis->mpi_rank == 0); + + /* Fetch the estimation data */ + ERR(sdis_estimator_get_temperature(estimator, &result)); + ERR(sdis_estimator_get_failure_count(estimator, &nfailures)); + nsamples = stardis->samples; + + if(nfailures == nsamples) { + logger_print(stardis->logger, LOG_ERROR, + "All the %lu samples failed. No result to display.\n", nsamples); + res = RES_BAD_OP; + goto error; + } + + /* Raw output */ + if((stardis->mode & MODE_EXTENDED_RESULTS) == 0) { + fprintf(stream, "%g %g %lu %lu\n", + result.E, result.SE, (unsigned long)nfailures, (unsigned long)nsamples); + + /* Extended output */ + } else if(stardis->time_range[0] == stardis->time_range[1]) { + fprintf(stream, + "Boundary temperature at [%g, %g, %g] at t=%g = %g K +/- %g\n", + SPLIT3(probe->position), probe->time[0], result.E, result.SE); + + /* Extended output with time range */ + } else { + fprintf(stream, + "Boundary temperature at [%g, %g, %g] with t in [%g %g] = %g K +/- %g\n", + SPLIT3(probe->position), SPLIT2(probe->time), result.E, result.SE); + } + +exit: + return res; +error: + goto exit; +} + +res_T dump_map (const struct stardis* stardis, const struct darray_estimators* estimators, diff --git a/src/stardis-output.h b/src/stardis-output.h @@ -23,11 +23,13 @@ struct sdis_green_path; struct sdis_heat_path; struct sdis_estimator_buffer; struct sdis_green_function; +struct sdis_mc; struct counts; struct description; struct mem_allocator; struct sdis_estimator; struct stardis; +struct stardis_probe_boundary; struct geometry; struct vertex; struct darray_estimators; @@ -42,71 +44,78 @@ struct dump_path_context { static const struct dump_path_context DUMP_PATH_CONTEXT_NULL = DUMP_PATH_CONTEXT_NULL__; -res_T +extern LOCAL_SYM res_T dump_path (const struct sdis_heat_path* path, void* context); -res_T +extern LOCAL_SYM res_T print_sample (struct sdis_green_path* path, void* ctx); -res_T +extern LOCAL_SYM res_T dump_vtk_image (const struct sdis_estimator_buffer* buf, FILE* stream); -res_T +extern LOCAL_SYM res_T dump_ht_image (const struct sdis_estimator_buffer* buf, FILE* stream); -res_T +extern LOCAL_SYM res_T dump_green_ascii (struct sdis_green_function* green, const struct stardis* stardis, FILE* stream); -res_T +extern LOCAL_SYM res_T dump_green_bin (struct sdis_green_function* green, const struct stardis* stardis, FILE* stream); -res_T +extern LOCAL_SYM res_T dump_paths_end (struct sdis_green_function* green, const struct stardis* stardis, FILE* stream); -res_T +extern LOCAL_SYM res_T dump_enclosure_related_stuff_at_the_end_of_vtk (struct stardis* stardis, FILE* stream); -res_T +extern LOCAL_SYM res_T print_computation_time - (struct sdis_estimator* estimator, /* Can be NULL */ + (struct sdis_mc* time_per_realisation, /* Can be NULL */ struct stardis* stardis, - struct time* start, - struct time* computation_start, - struct time* computation_end, - struct time* output_end); /* Can be NULL */ + struct time* start, + struct time* computation_start, + struct time* computation_end, + struct time* output_end); /* Can be NULL */ -res_T +extern LOCAL_SYM res_T print_single_MC_result (struct sdis_estimator* estimator, struct stardis* stardis, FILE* stream); -res_T +extern LOCAL_SYM res_T +print_single_MC_result_probe_boundary + (struct stardis* stardis, + const struct stardis_probe_boundary* probe, + const struct sdis_estimator* estimator, + FILE* stream); + +extern LOCAL_SYM res_T dump_map (const struct stardis* stardis, const struct darray_estimators* estimators, FILE* stream); -res_T +extern LOCAL_SYM res_T dump_boundaries_at_the_end_of_vtk (const struct stardis* stardis, FILE* stream);