stardis-green

Post-processing of green functions
git clone git://git.meso-star.fr/stardis-green.git
Log | Files | Refs | README | LICENSE

commit 13691c3e42f906d8c6aa137d1d8638ecc86bf96d
parent 7de5dcd6f96e1e5dbea83e99b1924bf9d2eb9823
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 30 Jun 2021 15:37:54 +0200

Merge branch 'release_0.2'

Diffstat:
MREADME.md | 6++++++
Mcmake/CMakeLists.txt | 4++--
Mdoc/sgreen-output.5.txt | 53+++++++++++++++++++++++++++++++++++++++--------------
Msrc/green-compute.c | 25++++++++++++++++---------
Msrc/green-input.c | 30+++++++++++++++++++++++++-----
Msrc/green-main.c | 48++++++++++++++++++++++++++++++++++++++++++++----
Msrc/green-output.c | 56+++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/green-types.h | 70+++++++++++++++++++++++++++++++++++++++++++++++++---------------------
8 files changed, 236 insertions(+), 56 deletions(-)

diff --git a/README.md b/README.md @@ -24,6 +24,12 @@ variable the install directories of its dependencies. ## Release notes +### Version 0.2 + +- Add connections to html output. +- Add compute time information to output. +- Adapt to new file format from stardis. + ### Version 0.1.1 - Check binary Green file format version (this require stardis 0.5.1). diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -41,8 +41,8 @@ configure_file(${GREEN_SOURCE_DIR}/../doc/sgreen.1.txt.in ${CMAKE_CURRENT_BINARY_DIR}/doc/sgreen.1.txt @ONLY) set(GREEN_VERSION_MAJOR 0) -set(GREEN_VERSION_MINOR 1) -set(GREEN_VERSION_PATCH 1) +set(GREEN_VERSION_MINOR 2) +set(GREEN_VERSION_PATCH 0) set(GREEN_VERSION ${GREEN_VERSION_MAJOR}.${GREEN_VERSION_MINOR}.${GREEN_VERSION_PATCH}) configure_file(${GREEN_SOURCE_DIR}/green-default.h.in diff --git a/doc/sgreen-output.5.txt b/doc/sgreen-output.5.txt @@ -27,8 +27,8 @@ DESCRIPTION The type of the data that are generated depends on the options used when *sgreen*(1) is invoked. When invoked with option *-a*, *sgreen*(1) outputs Monte-Carlo results, either in extended or compact format, whether option *-e* -is used or not. Also, when invoked whith option *-s* *sgreen*(1) outputs an -HTML file contening a summary of the Green function used. +is used or not. Also, when invoked whith option *-s* *sgreen*(1) silently +creates an HTML file contening a summary of the Green function used. GRAMMAR ------- @@ -43,25 +43,46 @@ in a description is a comment and is not part of the output. [verse] _______ -<output> ::= <MC-result> - <output> # as many ouput lines as provided setting - # lines +<output> ::= <compact-results> + | <extended-results> -<MC-result> ::= <compact-MC-result> - | <extended-MC-result> +<compact-results> ::= <compact-MC-result> # as many results as provided + <compact-results> # setting lines + +<extended-results> ::= "message: Initialisation time = " <time value> + "message: Computation time = " <time value> + <extended-MC-results> + +------------------------------------- + +<compact-MC-result> ::= <estimate> <standard-deviation> + +<extended-MC-results> ::= <extended-MC-result> # as many results as provided + | <extended-MC-results> # setting lines + +<time value> ::= [<h> "hour"] [<m> "min"] [<s> "sec"] \ + [<ms> "msec"] [<us> "usec"] + +<extended-MC-result> ::= <estimate> "K +/-" <standard-deviation> \ + ";" <applied-settings> + +<estimate> ::= REAL + +<standard-deviation> ::= REAL # in [0, INF) ------------------------------------- -<compact-MC-result> ::= <estimate> <standard-deviation> +<applied-settings> ::= ASCII TEXT # verbatim from the settings file -<extended-MC-result> ::= <estimate> "+/-" <standard-deviation> \ - ";" <applied-settings> +<h> ::= INTEGER # in [1 INF) -<estimate> ::= REAL +<m> ::= INTEGER # in [1 59] -<standard-deviation> ::= REAL # in [0, INF) +<s> ::= INTEGER # in [1 59] -<applied-settings> ::= ASCII TEXT # verbatim from the settings file +<ms> ::= INTEGER # in [1 999] + +<us> ::= INTEGER # in [1 999] _______ HTML SUMMARY @@ -87,7 +108,11 @@ HTML format. This document contains the following sections: * H boundaries for fluids -* F boundaries for dolids +* F boundaries for solids + +* Solid-Fluid connections + +* Solid-Solid connections * Radiative temperatures diff --git a/src/green-compute.c b/src/green-compute.c @@ -129,8 +129,13 @@ check_green_table_variables_use if(vd___.unknown) green->unknown_variables = 1; \ else if(!vd___.used) green->unused_variables = 1; \ if(htable_variable_ptr_find(&green->variable_ptrs, \ - &(green->table[Elt].Field ## _name))) \ - FATAL("Name already known"); /* Should have been detected by stardis */ \ + &(green->table[Elt].Field ## _name))) {\ + /* Should have been detected by stardis: corrupted file??? */ \ + logger_print(green->logger, LOG_ERROR, \ + "Duplicate description name found.\n"); \ + res = RES_BAD_ARG; \ + goto error; \ + } \ ERR(htable_variable_ptr_set(&green->variable_ptrs, \ &(green->table[Elt].Field ## _name), &vd___)); \ } (void)0 @@ -149,8 +154,6 @@ build_green_table { res_T res = RES_OK; size_t i, ambient_id; - struct description* desc = NULL; - const struct str* name = NULL; char* buf = NULL; size_t bufsz = 32; @@ -169,8 +172,9 @@ build_green_table check_green_table_variables_use(green); FOR_EACH(i, 0, green->counts.desc_count) { - desc = green->descriptions + i; - name = get_description_name(desc); + struct description* desc = green->descriptions + i; + struct str* name; + ERR(get_description_name(desc, &name)); if(DESC_IS_T(desc->type)) { MK_VAR("%s.T"); ERR(str_set(&green->table[i].imposed_T_name, buf)); @@ -232,14 +236,17 @@ build_green_table INSERT(i, initial_T); } } - else if(desc->type == DESC_SOLID_FLUID_CONNECT) { + else if(DESC_IS_CONNECTION(desc->type)) { /* No variables here */ } - else FATAL("Invalid desc type."); /* Should have been detected by stardis */ + else { /*Corrupted file??? */ + logger_print(green->logger, LOG_ERROR, "Invalid description type.\n"); + res = RES_BAD_ARG; + goto error; + } } /* Ambient ID is desc_count */ ambient_id = green->counts.desc_count; - desc = green->descriptions + ambient_id; ERR(str_set(&green->table[ambient_id].imposed_T_name, "AMBIENT")); green->table[ambient_id].imposed_T_value = green->ambient_temp; green->table[ambient_id].imposed_T_defined = 1; diff --git a/src/green-input.c b/src/green-input.c @@ -26,6 +26,8 @@ #define FR(Ptr, Count) \ if((Count) != fread((Ptr), sizeof(*(Ptr)), (Count), stream)) { \ + logger_print(green->logger, LOG_ERROR, \ + "Could not read expected data.\n"); \ res = RES_IO_ERR; \ goto error; \ } @@ -34,6 +36,7 @@ static res_T read_sample (struct sample* sample, struct mem_allocator* alloc, + struct green* green, FILE* stream) { res_T res = RES_OK; @@ -44,7 +47,7 @@ read_sample /* Alloc buffers */ ERR(alloc_sample_buffers(alloc, sample)); /* Read Ids and weights */ - read_sample_buffers(sample); + READ_SAMPLE_BUFFER(sample); end: return res; @@ -62,7 +65,7 @@ read_green_function unsigned i; char* pool_ptr; const char expected_green_string[] = "GREEN_BIN_FILE:"; - const unsigned expected_file_fmt_version = 1; + const unsigned expected_file_fmt_version = 2; char green_string[sizeof(expected_green_string)]; unsigned file_fmt_version; @@ -87,6 +90,18 @@ read_green_function /* Read counts */ FR(&green->counts, 1); + if(green->counts.desc_count != + (green->counts.smed_count + green->counts.fmed_count + + green->counts.tbound_count + green->counts.hbound_count + + green->counts.fbound_count + green->counts.sfconnect_count + + green->counts.ssconnect_count)) + { + logger_print(green->logger, LOG_ERROR, + "Inconsistant description counts (%u).\n", + green->counts.desc_count); + res = RES_BAD_ARG; + goto error; + } /* Read descriptions*/ green->descriptions = MEM_CALLOC(green->allocator, green->counts.desc_count, @@ -107,8 +122,13 @@ read_green_function FR(green->names_pool, green->counts.name_pool_sz); FOR_EACH(i, 0, green->counts.desc_count) { struct description* desc = green->descriptions + i; - struct str* name = get_description_name(desc); + struct str* name; const size_t len = strlen(pool_ptr); + res = get_description_name(desc, &name); + if(res != RES_OK) { + logger_print(green->logger, LOG_ERROR, "Invalid description type.\n"); + goto error; + } name->cstr = pool_ptr; pool_ptr += len + 1; } @@ -129,7 +149,7 @@ read_green_function goto error; } FOR_EACH(i, 0, green->counts.ok_count) { - ERR(read_sample(green->samples + i, green->allocator, stream)); + ERR(read_sample(green->samples + i, green->allocator, green, stream)); } /* Build table */ @@ -155,7 +175,7 @@ green_read_settings stream = fopen(in_name, "r"); if(!stream) { logger_print(green->logger, LOG_ERROR, - "Cannot open model file '%s'\n", + "Cannot open settings file '%s'\n", in_name); res = RES_IO_ERR; goto error; diff --git a/src/green-main.c b/src/green-main.c @@ -21,6 +21,7 @@ #include <rsys/rsys.h> #include <rsys/mem_allocator.h> #include <rsys/logger.h> +#include <rsys/clock_time.h> #include <stdlib.h> #include <omp.h> @@ -37,8 +38,13 @@ main struct logger logger; struct green green; struct args args; + struct time init_start, tmp; + char buf[128]; + const int flag = TIME_USEC | TIME_MSEC | TIME_SEC | TIME_MIN | TIME_HOUR ; FILE* stream = NULL; + time_current(&init_start); + ERR(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); allocator_initialized = 1; @@ -82,20 +88,46 @@ main "Cannot open model file '%s'\n", args.green_filename); res = RES_IO_ERR; } else { - res_T tmp_err; - tmp_err = read_green_function(&green, stream); + res_T tmp_res; + tmp_res = read_green_function(&green, stream); fclose(stream); - if(tmp_err != RES_OK) res = tmp_err; + if(tmp_res == RES_MEM_ERR) { + logger_print(&logger, LOG_ERROR, "Could not allocate memory.\n"); + res = tmp_res; + } + else if(tmp_res != RES_OK) { + logger_print(&logger, LOG_ERROR, + "Cannot read model file '%s' (file could be corrupted).\n", + args.green_filename); + res = tmp_res; + } } } #pragma omp section if(args.mode & MODE_APPLY_GREEN) { res_T tmp_res; tmp_res = green_read_settings(&green, args.command_filename); - if(tmp_res != RES_OK) res = tmp_res; + if(tmp_res == RES_MEM_ERR) { + logger_print(&logger, LOG_ERROR, "Could not allocate memory.\n"); + res = tmp_res; + } + else if(tmp_res != RES_OK) { + logger_print(&logger, LOG_ERROR, + "Cannot read settings file '%s' (file could be corrupted).\n", + args.green_filename); + res = tmp_res; + } } } /* Implicit barrier */ if(res != RES_OK) goto error; + if(args.mode & MODE_EXTENTED_RESULTS) { + struct time init_end; + time_current(&init_end); + time_sub(&tmp, &init_end, &init_start); + time_dump(&tmp, flag, NULL, buf, sizeof(buf)); + logger_print(&logger, LOG_OUTPUT, "Initialisation time = %s\n", buf); + } + if(args.mode & MODE_HTML_SUMMARY) { ASSERT(args.info_filename); stream = fopen(args.info_filename, "w"); @@ -110,7 +142,15 @@ main } if(args.mode & MODE_APPLY_GREEN) { + struct time compute_start, compute_end; + time_current(&compute_start); ERR(green_compute(&green, args.command_filename)); + if(args.mode & MODE_EXTENTED_RESULTS) { + time_current(&compute_end); + time_sub(&tmp, &compute_end, &compute_start); + time_dump(&tmp, flag, NULL, buf, sizeof(buf)); + logger_print(&logger, LOG_OUTPUT, "Computation time = %s\n", buf); + } green_print_result(&green, args.mode, stdout); } diff --git a/src/green-output.c b/src/green-output.c @@ -114,7 +114,7 @@ green_print_result struct result* result = darray_result_data_get(&green->results) + i; const char* line = str_cget(darray_str_data_get(&green->settings) + i); if(mode & MODE_EXTENTED_RESULTS) - fprintf(out_stream, "%g +/- %g ; %s\n", result->E, result->STD, line); + fprintf(out_stream, "%g K +/- %g ; %s\n", result->E, result->STD, line); else fprintf(out_stream, "%g %g\n", result->E, result->STD); } } @@ -314,6 +314,8 @@ dump_green_info fprintf(stream, " <th>T Boundaries</th>\n"); fprintf(stream, " <th>H Boundaries</th>\n"); fprintf(stream, " <th>F Boundaries</th>\n"); + fprintf(stream, " <th>Solid-Fluid Connections</th>\n"); + fprintf(stream, " <th>Solid-Solid Connections</th>\n"); fprintf(stream, " <th>OK Samples</th>\n"); fprintf(stream, " <th>Failures</th>\n"); fprintf(stream, "</tr>\n"); @@ -323,6 +325,8 @@ dump_green_info CELL(u, green->counts.tbound_count); CELL(u, green->counts.hbound_count); CELL(u, green->counts.fbound_count); + CELL(u, green->counts.sfconnect_count); + CELL(u, green->counts.ssconnect_count); CELL(lu, (long unsigned)green->counts.ok_count); CELL(lu, (long unsigned)green->counts.failed_count); fprintf(stream, "</tr>\n"); @@ -526,6 +530,56 @@ dump_green_info } if(local_count) fprintf(stream, "</table>\n"); + /* S-F connection table */ + local_count = 0; + FOR_EACH(i, 0, green->counts.desc_count) { + const struct description* desc = green->descriptions + i; + const struct solid_fluid_connect* sf; + if(desc->type != DESC_SOLID_FLUID_CONNECT) continue; + if(!local_count) { + fprintf(stream, "<h2>Solid-Fluid connections</h2>\n"); + fprintf(stream, "<table>\n"); + fprintf(stream, "<tr>\n"); + fprintf(stream, " <th>Name</th>\n"); + fprintf(stream, " <th>Emissivity</th>\n"); + fprintf(stream, " <th>Specular Fraction</th>\n"); + fprintf(stream, " <th>Hc</th>\n"); + fprintf(stream, "</tr>\n"); + } + sf = &desc->d.sf_connect; + fprintf(stream, "<tr>\n"); + CELL(s, str_cget(&sf->name)); + CELL(g, sf->emissivity); + CELL(g, sf->specular_fraction); + CELL(g, sf->hc); + fprintf(stream, "</tr>\n"); + local_count++; + } + if(local_count) fprintf(stream, "</table>\n"); + + /* S-S connection table */ + local_count = 0; + FOR_EACH(i, 0, green->counts.desc_count) { + const struct description* desc = green->descriptions + i; + const struct solid_solid_connect* ss; + if(desc->type != DESC_SOLID_SOLID_CONNECT) continue; + if(!local_count) { + fprintf(stream, "<h2>Solid-Solid connections</h2>\n"); + fprintf(stream, "<table>\n"); + fprintf(stream, "<tr>\n"); + fprintf(stream, " <th>Name</th>\n"); + fprintf(stream, " <th>Thermal Contact Resistance</th>\n"); + fprintf(stream, "</tr>\n"); + } + ss = &desc->d.ss_connect; + fprintf(stream, "<tr>\n"); + CELL(s, str_cget(&ss->name)); + CELL(g, ss->tcr); + fprintf(stream, "</tr>\n"); + local_count++; + } + if(local_count) fprintf(stream, "</table>\n"); + /* Radiative temperatures table */ fprintf(stream, "<h2>Radiative temperatures</h2>\n"); fprintf(stream, "<table>\n"); diff --git a/src/green-types.h b/src/green-types.h @@ -79,15 +79,15 @@ log_prt(const char* msg, void* ctx) /* * Counts read from the binary file */ -struct green_counts { +struct bfile_green_counts { unsigned desc_count, smed_count, fmed_count, tbound_count, hbound_count, - fbound_count, sfconnect_count, name_pool_sz; + fbound_count, sfconnect_count, ssconnect_count, name_pool_sz; size_t ok_count, failed_count; }; static INLINE void init_green_counts - (struct green_counts* counts) + (struct bfile_green_counts* counts) { ASSERT(counts); counts->desc_count = 0; @@ -97,6 +97,7 @@ init_green_counts counts->hbound_count = 0; counts->fbound_count = 0; counts->sfconnect_count = 0; + counts->ssconnect_count = 0; counts->name_pool_sz = 0; counts->ok_count = 0; counts->failed_count = 0; @@ -162,7 +163,7 @@ alloc_sample_buffers return RES_OK; } -#define read_sample_buffers(Sample) { \ +#define READ_SAMPLE_BUFFER(Sample) { \ size_t count = (Sample)->header.pw_count + (Sample)->header.fx_count; \ FR((Sample)->pw_ids, count); \ FR((Sample)->pw_weights, count); \ @@ -262,7 +263,7 @@ struct result { struct green { struct mem_allocator* allocator; struct logger* logger; - struct green_counts counts; + struct bfile_green_counts counts; char* names_pool; struct description* descriptions; double ambient_temp, ref_temp; @@ -311,12 +312,16 @@ green_release MEM_RM(green->allocator, green->names_pool); MEM_RM(green->allocator, green->descriptions); - FOR_EACH(i, 0, green->counts.ok_count) - release_sample(green->allocator, green->samples + i); - FOR_EACH(i, 0, 1 + green->counts.desc_count) - if(&green->table[i]) release_table_elt(&green->table[i]); - MEM_RM(green->allocator, green->table); - MEM_RM(green->allocator, green->samples); + if(green->samples) { /* On error, samples could be not yet allocated */ + FOR_EACH(i, 0, green->counts.ok_count) + release_sample(green->allocator, green->samples + i); + MEM_RM(green->allocator, green->samples); + } + if(green->table) { /* On error, table could be not yet allocated */ + FOR_EACH(i, 0, 1 + green->counts.desc_count) + if(&green->table[i]) release_table_elt(&green->table[i]); + MEM_RM(green->allocator, green->table); + } green->allocator = NULL; htable_variable_ptr_release(&green->variable_ptrs); darray_str_release(&green->settings); @@ -345,6 +350,7 @@ enum description_type { DESC_BOUND_T_FOR_SOLID, DESC_BOUND_F_FOR_SOLID, DESC_SOLID_FLUID_CONNECT, + DESC_SOLID_SOLID_CONNECT, DESCRIPTION_TYPE_COUNT__, DESC_OUTSIDE }; @@ -359,6 +365,10 @@ enum description_type { ((D) == DESC_BOUND_F_FOR_SOLID) #define DESC_IS_SF(D) \ ((D) == DESC_SOLID_FLUID_CONNECT) +#define DESC_IS_SS(D) \ + ((D) == DESC_SOLID_SOLID_CONNECT) +#define DESC_IS_CONNECTION(D) \ + (DESC_IS_SS(D) || DESC_IS_SF(D)) #define DESC_HOLDS_T(D) \ (DESC_IS_MEDIUM(D) || DESC_IS_H(D) || DESC_IS_T(D)) @@ -423,6 +433,12 @@ struct solid_fluid_connect { unsigned connection_id; }; +struct solid_solid_connect { + struct str name; + double tcr; + unsigned connection_id; +}; + struct description { enum description_type type; union { @@ -432,32 +448,44 @@ struct description { struct f_boundary f_boundary; struct h_boundary h_boundary; struct solid_fluid_connect sf_connect; + struct solid_solid_connect ss_connect; } d; }; -static INLINE struct str* +static INLINE res_T get_description_name - (struct description* desc) + (struct description* desc, + struct str** name) { - ASSERT(desc); + ASSERT(desc && name); switch (desc->type) { case DESC_MAT_SOLID: - return &desc->d.solid.name; + *name = &desc->d.solid.name; + break; case DESC_MAT_FLUID: - return &desc->d.fluid.name; + *name = &desc->d.fluid.name; + break; case DESC_BOUND_T_FOR_SOLID: case DESC_BOUND_T_FOR_FLUID: - return &desc->d.t_boundary.name; + *name = &desc->d.t_boundary.name; + break; case DESC_BOUND_H_FOR_SOLID: case DESC_BOUND_H_FOR_FLUID: - return &desc->d.h_boundary.name; + *name = &desc->d.h_boundary.name; + break; case DESC_BOUND_F_FOR_SOLID: - return &desc->d.f_boundary.name; + *name = &desc->d.f_boundary.name; + break; case DESC_SOLID_FLUID_CONNECT: - return &desc->d.sf_connect.name; + *name = &desc->d.sf_connect.name; + break; + case DESC_SOLID_SOLID_CONNECT: + *name = &desc->d.ss_connect.name; + break; default: - FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); + return RES_BAD_ARG; } + return RES_OK; } #endif /* GREEN_TYPES_H */