stardis

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

commit e169b9c67b324875bff32f6611229e9feb7e8060
parent 71702a3911f79cd5aad5788096553020a5a6f23f
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 18 Nov 2020 10:22:27 +0100

Ensure C89 compliance

Diffstat:
Mcmake/CMakeLists.txt | 10++++------
Msrc/stardis-app.h | 36+++++++++++++++++++++++-------------
Msrc/stardis-fluid.c | 8++++----
Msrc/stardis-main.c | 4++--
Msrc/stardis-output.c | 85++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
Msrc/stardis-output.h | 2+-
Msrc/stardis-parsing.c | 8+++++---
Msrc/stardis-parsing.h | 2+-
Msrc/stardis-solid.c | 10+++++-----
9 files changed, 97 insertions(+), 68 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -69,7 +69,7 @@ configure_file(${SDIS_SOURCE_DIR}/stardis-version.h.in # Check dependencies ############################################################################### find_package(RCMake 0.4 REQUIRED) -find_package(RSys 0.9.1 REQUIRED) +find_package(RSys 0.11 REQUIRED) find_package(StarGeom3D 0.1 REQUIRED) find_package(Star3D 0.7.1 REQUIRED) find_package(StarEnc3D 0.4.2 REQUIRED) @@ -148,15 +148,13 @@ add_executable(stardis if(CMAKE_COMPILER_IS_GNUCC) set(MATH_LIB m) - set_target_properties(stardis PROPERTIES - COMPILE_FLAGS "-std=c99" - VERSION ${SDIS_VERSION}) elseif(MSVC) set(GETOPT_LIB MuslGetopt) - set_target_properties(stardis PROPERTIES - VERSION ${SDIS_VERSION}) endif() +set_target_properties(stardis + PROPERTIES VERSION ${SDIS_VERSION}) + target_link_libraries(stardis Stardis Star3D StarGeom3D StarEnc3D StarSTL RSys ${GETOPT_LIB} ${MATH_LIB}) diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -45,16 +45,25 @@ struct sdis_medium; /* Utility macros */ #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; else (void)0 -#define STR_APPEND_PRINTF(accum, fmt, ...) \ +#define STR_APPEND_PRINTF(Accum, Fmt, Args) \ { \ struct str tmp; \ - str_init((accum)->allocator, &tmp); \ - res = str_printf(&tmp, (fmt), ##__VA_ARGS__);\ - if(res == RES_OK) res = str_append((accum), str_cget(&tmp)); \ + str_init((Accum)->allocator, &tmp); \ + res = str_printf(&tmp, Fmt COMMA_##Args LIST_##Args); \ + if(res == RES_OK) res = str_append((Accum), str_cget(&tmp)); \ str_release(&tmp); \ if(res != RES_OK) goto error; \ } (void)0 + +#define VFATAL(Fmt, Args) \ + { \ + fprintf(stderr, Fmt COMMA_##Args LIST_##Args); \ + ASSERT(0); \ + abort(); \ + } (void)0 + + #define DELTA_AUTO INF /* Placeholder until actual value is substituted */ #define UNKNOWN_MEDIUM_TEMPERATURE -1 /* Unknown for stadis solver is -1 */ @@ -224,8 +233,8 @@ str_print_h_boundary 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), - b->emissivity, b->specular_fraction, b->hc, b->imposed_temperature, b->mat_id); + ARG7( (type == DESC_BOUND_H_FOR_SOLID ? "solid" : "fluid"), str_cget(&b->name), + b->emissivity, b->specular_fraction, b->hc, b->imposed_temperature, b->mat_id ) ); end: return res; error: @@ -278,14 +287,15 @@ str_print_t_boundary res_T res = RES_OK; ASSERT(str && b && DESC_IS_T(type)); 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); + ARG3( (type == DESC_BOUND_T_FOR_SOLID ? "solid" : "fluid"), + str_cget(&b->name), b->imposed_temperature ) ); if(type == DESC_BOUND_T_FOR_FLUID) { STR_APPEND_PRINTF(str, "emissivity=%g, specular_fraction=%g hc=%g ", - b->emissivity, b->specular_fraction, b->hc); + ARG3( b->emissivity, b->specular_fraction, b->hc ) ); } - STR_APPEND_PRINTF(str, "(using medium %u as external medium)", b->mat_id); + STR_APPEND_PRINTF(str, "(using medium %u as external medium)", + ARG1( b->mat_id ) ); end: return res; error: @@ -332,7 +342,7 @@ str_print_f_boundary ASSERT(str && b); 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); + ARG3( str_cget(&b->name), b->imposed_flux, b->mat_id ) ); end: return res; error: @@ -378,9 +388,9 @@ str_print_sf_connect { res_T res = RES_OK; ASSERT(str && c); - STR_APPEND_PRINTF(str, "Solid-Fluid connection '%s':", str_cget(&c->name)); + STR_APPEND_PRINTF(str, "Solid-Fluid connection '%s':", ARG1( str_cget(&c->name) ) ); STR_APPEND_PRINTF(str, " emissivity=%g, specular_fraction=%g hc=%g", - c->emissivity, c->specular_fraction, c->hc); + ARG3( c->emissivity, c->specular_fraction, c->hc ) ); end: return res; error: diff --git a/src/stardis-fluid.c b/src/stardis-fluid.c @@ -134,14 +134,14 @@ str_print_fluid(struct str* str, const struct fluid* f) res_T res = RES_OK; ASSERT(str && f); STR_APPEND_PRINTF(str, "Fluid '%s': rho=%g cp=%g", - str_cget(&f->name), f->rho, f->cp); + ARG3( str_cget(&f->name), f->rho, f->cp ) ); if(f->tinit >= 0) { - STR_APPEND_PRINTF(str, " Tinit=%g", f->tinit); + STR_APPEND_PRINTF(str, " Tinit=%g", ARG1( f->tinit ) ); } if(f->imposed_temperature >= 0) { - STR_APPEND_PRINTF(str, " Temp=%g", f->imposed_temperature); + STR_APPEND_PRINTF(str, " Temp=%g", ARG1( f->imposed_temperature ) ); } - STR_APPEND_PRINTF(str, " (it is medium %u)", f->fluid_id); + STR_APPEND_PRINTF(str, " (it is medium %u)", ARG1( f->fluid_id ) ); end: return res; error: diff --git a/src/stardis-main.c b/src/stardis-main.c @@ -110,8 +110,8 @@ exit: char dump[4096] = { '\0' }; MEM_DUMP(&allocator, dump, sizeof(dump)); fprintf(stderr, "%s\n", dump); - fprintf(stderr, "\nMemory leaks: %zu Bytes\n", - MEM_ALLOCATED_SIZE(&allocator)); + fprintf(stderr, "\nMemory leaks: %lu Bytes\n", + (unsigned long)MEM_ALLOCATED_SIZE(&allocator)); } mem_shutdown_proxy_allocator(&allocator); } diff --git a/src/stardis-output.c b/src/stardis-output.c @@ -13,6 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define _POSIX_C_SOURCE 200112L /* snprintf */ #include "stardis-output.h" #include "stardis-compute.h" #include "stardis-fluid.h" @@ -163,7 +164,8 @@ dump_path FILE* stream = NULL; char* name = NULL; enum sdis_heat_path_flag status = SDIS_HEAT_PATH_NONE; - size_t i, vcount, name_sz; + size_t vcount_, name_sz; + unsigned long i, vcount; ASSERT(path && dump_ctx && dump_ctx->stardis @@ -177,7 +179,7 @@ dump_path res = RES_MEM_ERR; goto error; } - snprintf(name, name_sz, "%s%08zu%s.vtk", + snprintf(name, name_sz, "%s%08lu%s.vtk", str_cget(&dump_ctx->stardis->paths_filename), dump_ctx->rank++, (status == SDIS_HEAT_PATH_FAILURE ? "_err" : "")); @@ -192,17 +194,19 @@ dump_path fprintf(stream, "ASCII\n"); fprintf(stream, "DATASET POLYDATA\n"); /* Write path positions */ - sdis_heat_path_get_vertices_count(path, &vcount); - fprintf(stream, "POINTS %zu double\n", vcount); + sdis_heat_path_get_vertices_count(path, &vcount_); + ASSERT(vcount_ < ULONG_MAX); + vcount = (unsigned long)vcount_; + fprintf(stream, "POINTS %lu double\n", vcount); FOR_EACH(i, 0, vcount) { struct sdis_heat_vertex vtx; ERR(sdis_heat_path_get_vertex(path, i, &vtx)); fprintf(stream, "%g %g %g\n", SPLIT3(vtx.P)); } /* Write the segment of the path */ - fprintf(stream, "LINES %d %zu\n", 1, 1 + vcount); - fprintf(stream, "%zu", vcount); - FOR_EACH(i, 0, vcount) fprintf(stream, " %zu", i); + fprintf(stream, "LINES %d %lu\n", 1, 1 + vcount); + fprintf(stream, "%lu", vcount); + FOR_EACH(i, 0, vcount) fprintf(stream, " %lu", i); fprintf(stream, "\n"); /* Write path type */ @@ -215,7 +219,7 @@ dump_path default: FATAL("Unreachable code.\n"); break; } - fprintf(stream, "POINT_DATA %zu\n", vcount); + fprintf(stream, "POINT_DATA %lu\n", vcount); /* Write the type of the random walk vertices */ fprintf(stream, "SCALARS Vertex_Type unsigned_char 1\n"); fprintf(stream, "LOOKUP_TABLE default\n"); @@ -261,12 +265,16 @@ dump_vtk_image FILE* stream) { res_T res = RES_OK; - size_t definition[2]; + size_t def[2]; + unsigned long definition[2]; double* temps = NULL; size_t ix, iy; ASSERT(buf && stream); - ERR(sdis_estimator_buffer_get_definition(buf, definition)); + ERR(sdis_estimator_buffer_get_definition(buf, def)); + ASSERT(def[0] != 0 && def[1] != 0 && def[0] * def[1] <= ULONG_MAX); + definition[0] = (unsigned long)def[0]; + definition[1] = (unsigned long)def[1]; temps = mem_alloc(definition[0] * definition[1] * sizeof(double)); if(temps == NULL) { @@ -279,10 +287,10 @@ dump_vtk_image fprintf(stream, "Infrared Image\n"); fprintf(stream, "ASCII\n"); fprintf(stream, "DATASET STRUCTURED_POINTS\n"); - fprintf(stream, "DIMENSIONS %zu %zu 1\n", definition[0], definition[1]); + fprintf(stream, "DIMENSIONS %lu %lu 1\n", definition[0], definition[1]); fprintf(stream, "ORIGIN 0 0 0\n"); fprintf(stream, "SPACING 1 1 1\n"); - fprintf(stream, "POINT_DATA %zu\n", definition[0] * definition[1]); + fprintf(stream, "POINT_DATA %lu\n", definition[0] * definition[1]); fprintf(stream, "SCALARS temperature_estimate float 1\n"); fprintf(stream, "LOOKUP_TABLE default\n"); FOR_EACH(iy, 0, definition[1]) { @@ -335,7 +343,8 @@ dump_vtk_image size_t nfails; ERR(sdis_estimator_buffer_at(buf, ix, iy, &estimator)); ERR(sdis_estimator_get_failure_count(estimator, &nfails)); - fprintf(stream, "%zu\n", nfails); + ASSERT(nfails <= ULONG_MAX); + fprintf(stream, "%lu\n", (unsigned long)nfails); } } mem_rm(temps); @@ -352,13 +361,17 @@ dump_ht_image FILE* stream) { res_T res = RES_OK; - size_t definition[2]; + size_t def[2]; + unsigned long definition[2]; size_t ix, iy; ASSERT(buf && stream); - ERR(sdis_estimator_buffer_get_definition(buf, definition)); + ERR(sdis_estimator_buffer_get_definition(buf, def)); + ASSERT(def[0] <= ULONG_MAX && def[1] <= ULONG_MAX); + definition[0] = (unsigned long)def[0]; + definition[1] = (unsigned long)def[1]; - fprintf(stream, "%zu %zu\n", definition[0], definition[1]); + fprintf(stream, "%lu %lu\n", definition[0], definition[1]); FOR_EACH(iy, 0, definition[1]) { FOR_EACH(ix, 0, definition[0]) { const struct sdis_estimator* estimator; @@ -403,8 +416,8 @@ medium_get_t0 const struct fluid* fluid_props = sdis_data_cget(data); return fluid_props->t0; } else { - ASSERT(type == SDIS_SOLID); const struct solid* solid_props = sdis_data_cget(data); + ASSERT(type == SDIS_SOLID); return solid_props->t0; } } @@ -808,7 +821,9 @@ print_sample ERR(sdis_green_path_for_each_flux_term(path, merge_flux_terms, w_ctx)); fcount = htable_weigth_size_get(&w_ctx->flux); - fprintf(w_ctx->stream, "\t%zu\t%zu", pcount, fcount); + ASSERT(pcount <= ULONG_MAX && fcount <= ULONG_MAX); + fprintf(w_ctx->stream, "\t%lu\t%lu", + (unsigned long)pcount, (unsigned long)fcount); htable_weigth_begin(&w_ctx->pw, &it); htable_weigth_end(&w_ctx->pw, &end); @@ -1290,16 +1305,20 @@ print_single_MC_result { res_T res = RES_OK; struct sdis_mc result; - size_t nfailures; + size_t nfailures_; + unsigned long nfailures, nsamples; ASSERT(estimator && stardis && stream); /* Fetch the estimation data */ ERR(sdis_estimator_get_temperature(estimator, &result)); - ERR(sdis_estimator_get_failure_count(estimator, &nfailures)); - if(nfailures == stardis->samples) { + ERR(sdis_estimator_get_failure_count(estimator, &nfailures_)); + ASSERT(nfailures_ <= ULONG_MAX && stardis->samples <= ULONG_MAX); + nfailures = (unsigned long)nfailures_; + nsamples = (unsigned long)stardis->samples; + if(nfailures == nsamples) { logger_print(stardis->logger, LOG_ERROR, - "All the %zu samples failed. No result to display.\n", nfailures); + "All the %lu samples failed. No result to display.\n", nsamples); res = RES_BAD_OP; goto error; } @@ -1319,8 +1338,8 @@ print_single_MC_result result.E, /* Expected value */ result.SE); /* Standard error */ } - else fprintf(stream, "%g %g %zu %zu\n", - result.E, result.SE, nfailures, stardis->samples); + 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) { @@ -1335,8 +1354,8 @@ print_single_MC_result result.E, /* Expected value */ result.SE); /* Standard error */ } - else fprintf(stream, "%g %g %zu %zu\n", - result.E, result.SE, nfailures, stardis->samples); + 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) { @@ -1351,8 +1370,8 @@ print_single_MC_result result.E, /* Expected value */ result.SE); /* Standard error */ } - else fprintf(stream, "%g %g %zu %zu\n", - result.E, result.SE, nfailures, stardis->samples); + else fprintf(stream, "%g %g %lu %lu\n", + result.E, result.SE, nfailures, nsamples); break; case MODE_BOUNDARY_COMPUTE: if(stardis->mode & MODE_EXTENDED_RESULTS) { @@ -1367,8 +1386,8 @@ print_single_MC_result result.E, /* Expected value */ result.SE); /* Standard error */ } - else fprintf(stream, "%g %g %zu %zu\n", - result.E, result.SE, nfailures, stardis->samples); + else fprintf(stream, "%g %g %lu %lu\n", + result.E, result.SE, nfailures, nsamples); break; case MODE_FLUX_BOUNDARY_COMPUTE: { enum sdis_estimator_type type; @@ -1440,17 +1459,17 @@ print_single_MC_result fprintf(stream, "%g %g ", result.E, result.SE); ERR(sdis_estimator_get_total_flux(estimator, &result)); fprintf(stream, "%g %g ", result.E, result.SE); - fprintf(stream, "%zu %zu\n", nfailures, stardis->samples); + fprintf(stream, "%lu %lu\n", nfailures, nsamples); } break; } default: FATAL("Invalid mode."); } if(stardis->mode & MODE_EXTENDED_RESULTS) - fprintf(stream, "#failures: %zu/%zu\n", nfailures, stardis->samples); + fprintf(stream, "#failures: %lu/%lu\n", nfailures, nsamples); if(nfailures) logger_print(stardis->logger, LOG_ERROR, - "#failures: %zu/%zu\n", nfailures, stardis->samples); + "#failures: %lu/%lu\n", nfailures, nsamples); end: return res; diff --git a/src/stardis-output.h b/src/stardis-output.h @@ -33,7 +33,7 @@ struct vertex; struct darray_estimators; struct dump_path_context { - size_t rank; + unsigned long rank; struct stardis* stardis; }; diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define _GNU_SOURCE 1 +#define _POSIX_C_SOURCE 200809L /* strdup */ #include "stardis-parsing.h" #include "stardis-app.h" #include "stardis-default.h" @@ -279,10 +279,12 @@ read_sides_and_files size_t c, n; const unsigned* ids = darray_uint_cdata_get(&degenerated); c = darray_uint_size_get(&degenerated); + ASSERT(c <= ULONG_MAX); logger_print(stardis->logger, LOG_WARNING, - "File '%s' included %zu degenerated triangles (removed)\n", tk, c); + "File '%s' included %lu degenerated triangles (removed)\n", + tk, (unsigned long)c); ERR(str_printf(&str, "Degenerated triangles IDs: %u", ids[0])); - FOR_EACH(n, 1, c) { STR_APPEND_PRINTF(&str, ", %u", ids[n]); } + FOR_EACH(n, 1, c) { STR_APPEND_PRINTF(&str, ", %u", ARG1( ids[n] ) ); } logger_print(stardis->logger, LOG_OUTPUT, "%s\n", str_cget(&str)); darray_uint_clear(&degenerated); } diff --git a/src/stardis-parsing.h b/src/stardis-parsing.h @@ -91,7 +91,7 @@ enum dump_path_type { DUMP_NONE = 0, DUMP_SUCCESS = BIT(0), DUMP_ERROR = BIT(1), - DUMP_ALL = DUMP_SUCCESS | DUMP_ERROR, + DUMP_ALL = DUMP_SUCCESS | DUMP_ERROR }; struct args { diff --git a/src/stardis-solid.c b/src/stardis-solid.c @@ -185,17 +185,17 @@ str_print_solid(struct str* str, const struct solid* s) res_T res = RES_OK; ASSERT(str && s); 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); + ARG5( str_cget(&s->name), s->lambda, s->rho, s->cp, s->delta ) ); if(s->vpower != 0) { - STR_APPEND_PRINTF(str, " VPower=%g", s->vpower); + STR_APPEND_PRINTF(str, " VPower=%g", ARG1( s->vpower ) ); } if(s->tinit >= 0) { - STR_APPEND_PRINTF(str, " Tinit=%g", s->tinit); + STR_APPEND_PRINTF(str, " Tinit=%g", ARG1( s->tinit ) ); } if(s->imposed_temperature >= 0) { - STR_APPEND_PRINTF(str, " Temp=%g", s->imposed_temperature); + STR_APPEND_PRINTF(str, " Temp=%g", ARG1( s->imposed_temperature ) ); } - STR_APPEND_PRINTF(str, " (it is medium %u)", s->solid_id); + STR_APPEND_PRINTF(str, " (it is medium %u)", ARG1( s->solid_id ) ); end: return res; error: