stardis

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

commit 4acde1d9c3798aa01d9acf822e7f4f0bc2996b5c
parent dea48b5c6cda963dca5b4709b68315d39829f909
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 20 Aug 2020 18:02:18 +0200

Use new 0.9.1 rsys/str feature instead of custom code

Diffstat:
Mcmake/CMakeLists.txt | 2+-
Msrc/stardis-app.c | 82++++++++++++++++---------------------------------------------------------------
Msrc/stardis-app.h | 54++++++++++++++++++++++++++----------------------------
Msrc/stardis-parsing.c | 2+-
4 files changed, 44 insertions(+), 96 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -68,7 +68,7 @@ configure_file(${SDIS_SOURCE_DIR}/stardis-version.h.in # Check dependencies ############################################################################### find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.9 REQUIRED) +find_package(RSys 0.9.1 REQUIRED) find_package(StarGeom3D 0.1 REQUIRED) find_package(Star3D 0.7.1 REQUIRED) find_package(StarEnc3D 0.4.2 REQUIRED) diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -24,6 +24,7 @@ #include <star/sg3d_sencXd_helper.h> #include <star/sg3d_sdisXd_helper.h> +#include <rsys/str.h> #include <rsys/text_reader.h> #include <rsys/logger.h> @@ -459,9 +460,7 @@ stardis_init res = tmp_res; goto error; } - str_clear(&str); - ERR(str_printf(&str, "Description %d: ", i)); - ERR(str_print_description(&str, + ERR(str_print_description(&str, i, darray_descriptions_cdata_get(&stardis->descriptions) + i)); logger_print(stardis->logger, LOG_OUTPUT, "%s\n", str_cget(&str)); } @@ -718,74 +717,25 @@ end: return res; } -#undef COUNT_SIDE - -/******************************************************************************* - * rsys/str additions - ******************************************************************************/ -static res_T -ensure_allocated(struct str* str, const size_t len, const char keep_old) -{ - char* buf = NULL; - const size_t alloc_granularity = 32; - size_t mod = 0; - size_t new_len = 0; - size_t new_size = 0; - ASSERT(str); - - if(len * sizeof(char) <= str->allocated) - return RES_OK; - - mod = len % alloc_granularity; - new_len = !mod ? len : len - mod + alloc_granularity; - new_size = new_len * sizeof(char); - buf = MEM_ALLOC(str->allocator, new_size); - if(!buf) - return RES_MEM_ERR; - - if(keep_old) { - strncpy(buf, str->cstr, new_len - 1); - buf[new_len - 1] = '\0'; - } - - str->allocated = new_len * sizeof(char); - if(str->cstr != str->buffer) - MEM_RM(str->allocator, str->cstr); - - str->cstr = buf; - return RES_OK; -} - res_T -str_printf - (struct str* str, - const char* fmt, ...) +str_append_printf + (struct str* accum, const char* fmt, ...) { + struct str tmp; + va_list ap; res_T res = RES_OK; - size_t initial_len, left; - va_list args_cp; - size_t needed = 0; - va_list args; - ASSERT(str && fmt); - va_start(args, fmt); - - initial_len = str_len(str); - ASSERT(str->allocated >= initial_len); - left = str->allocated - initial_len; - if(left) { - VA_COPY(args_cp, args); - needed = (size_t)vsnprintf(str->cstr + initial_len, left, fmt, args_cp); - } - if(needed >= left) { - ERR(ensure_allocated(str, initial_len + needed + 1, 1)); - ASSERT(str->allocated >= initial_len); - left = str->allocated - initial_len; - needed = (size_t)vsnprintf(str->cstr + initial_len, left, fmt, args); - CHK(needed < left); - } - va_end(args); + ASSERT(accum && fmt); + str_init(accum->allocator, &tmp); + va_start(ap, fmt); + ERR(str_printf(&tmp, fmt, ap)); + va_end(ap); + ERR(str_append(accum, str_cget(&tmp))); + end: + str_release(&tmp); return res; error: goto end; } + +#undef COUNT_SIDE diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -172,17 +172,10 @@ error: goto exit; } -/******************************************************************************* - * rsys/str addition - ******************************************************************************/ extern LOCAL_SYM res_T -str_printf - (struct str* str, - const char* fmt, ...) -#ifdef COMPILER_GCC - __attribute((format(printf, 2, 3))) -#endif - ; +str_append_printf +(struct str* accum, const char* fmt, ...); + /******************************************************************************/ struct mat_fluid { @@ -219,15 +212,15 @@ str_print_fluid { res_T res = RES_OK; ASSERT(str && f); - ERR(str_printf(str, "Fluid '%s': rho=%g cp=%g", + ERR(str_append_printf(str, "Fluid '%s': rho=%g cp=%g", str_cget(&f->name), f->rho, f->cp)); if(f->tinit >= 0) { - ERR(str_printf(str, " Tinit=%g", f->tinit)); + ERR(str_append_printf(str, " Tinit=%g", f->tinit)); } if(f->imposed_temperature >= 0) { - ERR(str_printf(str, " Temp=%g", f->imposed_temperature)); + ERR(str_append_printf(str, " Temp=%g", f->imposed_temperature)); } - ERR(str_printf(str, " (it is medium %u)", f->fluid_id)); + ERR(str_append_printf(str, " (it is medium %u)", f->fluid_id)); end: return res; error: @@ -286,18 +279,18 @@ str_print_solid { res_T res = RES_OK; ASSERT(str && s); - ERR(str_printf(str, "Solid '%s': lambda=%g rho=%g cp=%g delta=%g", + ERR(str_append_printf(str, "Solid '%s': lambda=%g rho=%g cp=%g delta=%g", str_cget(&s->name), s->lambda, s->rho, s->cp, s->delta)); if(s->vpower != 0) { - ERR(str_printf(str, " VPower=%g", s->vpower)); + ERR(str_append_printf(str, " VPower=%g", s->vpower)); } if(s->tinit >= 0) { - ERR(str_printf(str, " Tinit=%g", s->tinit)); + ERR(str_append_printf(str, " Tinit=%g", s->tinit)); } if(s->imposed_temperature >= 0) { - ERR(str_printf(str, " Temp=%g", s->imposed_temperature)); + ERR(str_append_printf(str, " Temp=%g", s->imposed_temperature)); } - ERR(str_printf(str, " (it is medium %u)", s->solid_id)); + ERR(str_append_printf(str, " (it is medium %u)", s->solid_id)); end: return res; error: @@ -354,7 +347,7 @@ str_print_h_boundary { res_T res = RES_OK; ASSERT(str && b && DESC_IS_H(type)); - ERR(str_printf(str, + ERR(str_append_printf(str, "H boundary for %s '%s': emissivity=%g specular_fraction=%g hc=%g T=%g " "(using medium %u as external medium)", (type == DESC_BOUND_H_FOR_SOLID ? "solid" : "fluid"), str_cget(&b->name), @@ -412,15 +405,15 @@ str_print_t_boundary { res_T res = RES_OK; ASSERT(str && b && DESC_IS_T(type)); - ERR(str_printf(str, "T boundary for %s' %s': T=%g ", + ERR(str_append_printf(str, "T boundary for %s' %s': T=%g ", (type == DESC_BOUND_T_FOR_SOLID ? "solid" : "fluid"), str_cget(&b->name), b->imposed_temperature)); if(type == DESC_BOUND_T_FOR_FLUID) { - ERR(str_printf(str, "emissivity=%g, specular_fraction=%g hc=%g ", + ERR(str_append_printf(str, "emissivity=%g, specular_fraction=%g hc=%g ", b->emissivity, b->specular_fraction, b->hc)); } - ERR(str_printf(str, "(using medium %u as external medium)", b->mat_id)); + ERR(str_append_printf(str, "(using medium %u as external medium)", b->mat_id)); end: return res; error: @@ -467,7 +460,7 @@ str_print_f_boundary { res_T res = RES_OK; ASSERT(str && b); - ERR(str_printf(str, + ERR(str_append_printf(str, "F boundary for SOLID '%s': flux=%g (using medium %u as external medium)", str_cget(&b->name), b->imposed_flux, b->mat_id)); end: @@ -517,8 +510,8 @@ str_print_sf_connect { res_T res = RES_OK; ASSERT(str && c); - ERR(str_printf(str, "Solid-Fluid connection '%s':", str_cget(&c->name))); - ERR(str_printf(str, " emissivity=%g, specular_fraction=%g hc=%g", + ERR(str_append_printf(str, "Solid-Fluid connection '%s':", str_cget(&c->name))); + ERR(str_append_printf(str, " emissivity=%g, specular_fraction=%g hc=%g", c->emissivity, c->specular_fraction, c->hc)); end: return res; @@ -527,7 +520,8 @@ error: } static FINLINE res_T -cp_sf_connect(struct solid_fluid_connect* dst, const struct solid_fluid_connect* src) +cp_sf_connect + (struct solid_fluid_connect* dst, const struct solid_fluid_connect* src) { str_copy(&dst->name, &src->name); dst->connection_id = src->connection_id; @@ -538,7 +532,8 @@ cp_sf_connect(struct solid_fluid_connect* dst, const struct solid_fluid_connect* } static FINLINE res_T -cp_release_sf_connect(struct solid_fluid_connect* dst, struct solid_fluid_connect* src) +cp_release_sf_connect + (struct solid_fluid_connect* dst, struct solid_fluid_connect* src) { return cp_sf_connect(dst, src); } @@ -596,10 +591,13 @@ release_description(struct description* desc) static INLINE res_T str_print_description (struct str* str, + const unsigned rank, const struct description* desc) { res_T res = RES_OK; ASSERT(str && desc); + str_clear(str); + ERR(str_printf(str, "Description %u: ", rank)); switch (desc->type) { case DESC_MAT_SOLID: ERR(str_print_solid(str, &desc->d.solid)); diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -281,7 +281,7 @@ read_sides_and_files logger_print(stardis->logger, LOG_WARNING, "File '%s' included %zu degenerated triangles (removed)\n", tk, c); ERR(str_printf(&str, "Degenerated triangles IDs: %u", ids[0])); - FOR_EACH(n, 1, c) ERR(str_printf(&str, ", %u", ids[n])); + FOR_EACH(n, 1, c) ERR(str_append_printf(&str, ", %u", ids[n])); logger_print(stardis->logger, LOG_OUTPUT, "%s\n", str_cget(&str)); darray_uint_clear(&degenerated); }