stardis

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

commit cafa938c3245e1348985beec7e94010c8e86d9ca
parent 7c8d95eda05df1e7a4cb7231909a698f59eb6762
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  9 Apr 2024 14:30:55 +0200

Correct the way unknown temperatures are verified

Unknown temperatures are defined by a constant provided by the solver,
and therefore cannot be hard-coded as negative temperatures; in fact,
negative temperatures are now accepted by the solver. This commit
corrects several tests that checked whether a temperature was known or
not by checking the temperature sign. They now use solver-specific
macros. However, it is still not clear whether the reference temperature
can be negative. We therefore continue to check that they are positive
and not simply "known" as defined by the solver.

Diffstat:
Msrc/stardis-fluid.c | 8++++----
Msrc/stardis-intface.c | 4++--
Msrc/stardis-output.c | 10+++++-----
Msrc/stardis-parsing.c | 113+++++++++++++++++++++++++++----------------------------------------------------
Msrc/stardis-solid.c | 8++++----
5 files changed, 53 insertions(+), 90 deletions(-)

diff --git a/src/stardis-fluid.c b/src/stardis-fluid.c @@ -52,12 +52,12 @@ fluid_get_temperature struct sdis_data* data) { const struct fluid* const* fluid_props = sdis_data_cget(data); - if((*fluid_props)->imposed_temperature >= 0) + if(SDIS_TEMPERATURE_IS_KNOWN((*fluid_props)->imposed_temperature)) /* If there is an imposed temp, it is imposed regardless of time */ return (*fluid_props)->imposed_temperature; if(vtx->time <= (*fluid_props)->t0) { /* If time is <= t0: use tinit */ - if((*fluid_props)->tinit < 0) { + if(SDIS_TEMPERATURE_IS_UNKNOWN((*fluid_props)->tinit)) { if(str_is_empty(&(*fluid_props)->name)) { FATAL("fluid_get_temperature: getting undefined Tinit\n"); } else { @@ -154,10 +154,10 @@ str_print_fluid(struct str* str, const struct fluid* f) ASSERT(str && f); ERR(str_append_printf(str, "Fluid '%s': rho=%g cp=%g", str_cget(&f->name), f->rho, f->cp)); - if(f->tinit >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(f->tinit)) { ERR(str_append_printf(str, " Tinit=%g", f->tinit)); } - if(f->imposed_temperature >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(f->imposed_temperature)) { ERR(str_append_printf(str, " Temp=%g", f->imposed_temperature)); } ERR(str_append_printf(str, " (it is medium %u)", f->fluid_id)); diff --git a/src/stardis-intface.c b/src/stardis-intface.c @@ -366,7 +366,7 @@ create_intface goto error; } for_fluid = 1; - ASSERT(intface->d.h_boundary->imposed_temperature >= 0); + ASSERT(SDIS_TEMPERATURE_IS_KNOWN(intface->d.h_boundary->imposed_temperature)); interface_props->imposed_temperature = intface->d.h_boundary->imposed_temperature; ASSERT(fluid_side_shader); @@ -544,7 +544,7 @@ create_intface * a possible external fluid to 'see' the imposed T */ fluid_side_shader->emissivity = interface_get_emissivity; interface_props->emissivity = 1; - ASSERT(intface->d.t_boundary->imposed_temperature >= 0); + ASSERT(SDIS_TEMPERATURE_IS_KNOWN(intface->d.t_boundary->imposed_temperature)); interface_props->imposed_temperature = intface->d.t_boundary->imposed_temperature; break; diff --git a/src/stardis-output.c b/src/stardis-output.c @@ -1128,12 +1128,12 @@ dump_green_ascii sl = desc->d.solid; fprintf(stream, "%u\t%s\t%g\t%g\t%g\t%g", i, str_cget(&sl->name), sl->lambda, sl->rho, sl->cp, sl->vpower); - if(sl->tinit >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(sl->tinit)) { fprintf(stream, "\t%g", sl->tinit); } else { fprintf(stream, "\tNONE"); } - if(sl->imposed_temperature >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(sl->imposed_temperature)) { fprintf(stream, "\t%g\n", sl->imposed_temperature); } else { fprintf(stream, "\tNONE\n"); @@ -1148,19 +1148,19 @@ dump_green_ascii const struct fluid* fl; if(desc->type != DESC_MAT_FLUID) continue; fl = desc->d.fluid; - if(fl->imposed_temperature >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(fl->imposed_temperature)) { fprintf(stream, "%u\t%s\t%g\t%g", i, str_cget(&fl->name), fl->rho, fl->cp); } else { fprintf(stream, "%u\t%s\t%g\t%g", i, str_cget(&fl->name), fl->rho, fl->cp); } - if(fl->tinit >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(fl->tinit)) { fprintf(stream, "\t%g", fl->tinit); } else { fprintf(stream, "\tNONE"); } - if(fl->imposed_temperature >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(fl->imposed_temperature)) { fprintf(stream, "\t%g\n", fl->imposed_temperature); } else { fprintf(stream, "\tNONE\n"); diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -400,9 +400,7 @@ process_h CHK_ARG(idx, "ref_temperature"); res = cstr_to_double(arg, &h_boundary->ref_temperature); - if(res != RES_OK - || h_boundary->ref_temperature < 0) - { + if(res != RES_OK || h_boundary->ref_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid reference temperature: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -413,9 +411,8 @@ process_h CHK_ARG(idx, "emissivity"); res = cstr_to_double(arg, &h_boundary->emissivity); if(res != RES_OK - || h_boundary->emissivity < 0 - || h_boundary->emissivity > 1) - { + || h_boundary->emissivity < 0 + || h_boundary->emissivity > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid emissivity: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -423,9 +420,8 @@ process_h CHK_ARG(idx, "specular fraction"); res = cstr_to_double(arg, &h_boundary->specular_fraction); if(res != RES_OK - || h_boundary->specular_fraction < 0 - || h_boundary->specular_fraction > 1) - { + || h_boundary->specular_fraction < 0 + || h_boundary->specular_fraction > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid specular fraction: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -433,9 +429,7 @@ process_h } CHK_ARG(idx, "Convection coefficient"); res = cstr_to_double(arg, &h_boundary->hc); - if(res != RES_OK - || h_boundary->hc < 0) - { + if(res != RES_OK || h_boundary->hc < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid Convection coefficient: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -444,8 +438,7 @@ process_h CHK_ARG(idx, "temperature"); res = cstr_to_double(arg, &h_boundary->imposed_temperature); if(res != RES_OK - || h_boundary->imposed_temperature < 0) - { + || SDIS_TEMPERATURE_IS_UNKNOWN(h_boundary->imposed_temperature)) { logger_print(stardis->logger, LOG_ERROR, "Invalid temperature: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -521,9 +514,7 @@ process_hf CHK_ARG(idx, "ref_temperature"); res = cstr_to_double(arg, &hf_boundary->ref_temperature); - if(res != RES_OK - || hf_boundary->ref_temperature < 0) - { + if(res != RES_OK || hf_boundary->ref_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid reference temperature: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -534,9 +525,8 @@ process_hf CHK_ARG(idx, "emissivity"); res = cstr_to_double(arg, &hf_boundary->emissivity); if(res != RES_OK - || hf_boundary->emissivity < 0 - || hf_boundary->emissivity > 1) - { + || hf_boundary->emissivity < 0 + || hf_boundary->emissivity > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid emissivity: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -544,9 +534,8 @@ process_hf CHK_ARG(idx, "specular fraction"); res = cstr_to_double(arg, &hf_boundary->specular_fraction); if(res != RES_OK - || hf_boundary->specular_fraction < 0 - || hf_boundary->specular_fraction > 1) - { + || hf_boundary->specular_fraction < 0 + || hf_boundary->specular_fraction > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid specular fraction: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -554,9 +543,7 @@ process_hf } CHK_ARG(idx, "convection coefficient"); res = cstr_to_double(arg, &hf_boundary->hc); - if(res != RES_OK - || hf_boundary->hc < 0) - { + if(res != RES_OK || hf_boundary->hc < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid convection coefficient: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -565,8 +552,7 @@ process_hf CHK_ARG(idx, "temperature"); res = cstr_to_double(arg, &hf_boundary->imposed_temperature); if(res != RES_OK - || hf_boundary->imposed_temperature < 0) - { + || SDIS_TEMPERATURE_IS_UNKNOWN(hf_boundary->imposed_temperature)) { logger_print(stardis->logger, LOG_ERROR, "Invalid temperature: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -1079,7 +1065,7 @@ process_t CHK_ARG(idx, "temperature"); res = cstr_to_double(arg, &t_boundary->imposed_temperature); if(res != RES_OK - || t_boundary->imposed_temperature < 0) + || SDIS_TEMPERATURE_IS_UNKNOWN(t_boundary->imposed_temperature)) { logger_print(stardis->logger, LOG_ERROR, "Invalid temperature: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -1200,7 +1186,7 @@ process_flx CHK_ARG(idx, "flux"); res = cstr_to_double(arg, &f_boundary->imposed_flux); if(res != RES_OK - || f_boundary->imposed_flux == SDIS_FLUX_NONE) { + || f_boundary->imposed_flux == SDIS_FLUX_NONE) { /* Flux can be < 0 but not undefined */ if(res == RES_OK) res = RES_BAD_ARG; logger_print(stardis->logger, LOG_ERROR, "Invalid flux: %s\n", arg); @@ -1327,9 +1313,7 @@ process_sfc CHK_ARG(idx, "ref_temperature"); res = cstr_to_double(arg, &sf_connect->ref_temperature); - if(res != RES_OK - || sf_connect->ref_temperature < 0) - { + if(res != RES_OK || sf_connect->ref_temperature < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid reference temperature: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -1340,9 +1324,8 @@ process_sfc CHK_ARG(idx, "emissivity"); res = cstr_to_double(arg, &sf_connect->emissivity); if(res != RES_OK - || sf_connect->emissivity < 0 - || sf_connect->emissivity > 1) - { + || sf_connect->emissivity < 0 + || sf_connect->emissivity > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid emissivity: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -1350,9 +1333,8 @@ process_sfc CHK_ARG(idx, "specular fraction"); res = cstr_to_double(arg, &sf_connect->specular_fraction); if(res != RES_OK - || sf_connect->specular_fraction < 0 - || sf_connect->specular_fraction > 1) - { + || sf_connect->specular_fraction < 0 + || sf_connect->specular_fraction > 1) { logger_print(stardis->logger, LOG_ERROR, "Invalid specular fraction: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -1360,9 +1342,7 @@ process_sfc } CHK_ARG(idx, "convection coefficient"); res = cstr_to_double(arg, &sf_connect->hc); - if(res != RES_OK - || sf_connect->hc < 0) - { + if(res != RES_OK || sf_connect->hc < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid convection coefficient: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -1485,9 +1465,7 @@ process_ssc CHK_ARG(idx, "contact resistance"); res = cstr_to_double(arg, &ss_connect->tcr); - if(res != RES_OK - || ss_connect->tcr < 0) - { + if(res != RES_OK || ss_connect->tcr < 0) { logger_print(stardis->logger, LOG_ERROR, "Invalid contact resistance: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; @@ -1590,21 +1568,12 @@ read_imposed_temperature str_init(stardis->allocator, &keep); CHK_ARG((*idx), "imposed temperature"); ERR(str_set(&keep, arg)); - if(RES_OK == cstr_to_double(arg, imposed_temperature)) { - /* Was a number */ - if(*imposed_temperature < 0) { - res = RES_BAD_ARG; - goto error; - } - } else { - /* Could be 'unknown' */ - if(0 == strcasecmp(arg, "UNKNOWN")) { - *imposed_temperature = UNKNOWN_MEDIUM_TEMPERATURE; - } else { - res = RES_BAD_ARG; - goto error; - } + if(0 == strcasecmp(arg, "UNKNOWN")) { + *imposed_temperature = UNKNOWN_MEDIUM_TEMPERATURE; + } else if((res = cstr_to_double(arg, imposed_temperature)) != RES_OK) { + goto error; } + end: str_release(&keep); return res; @@ -1717,9 +1686,7 @@ process_solid ERR(read_delta(stardis, &solid->delta, pwordexp, &idx)); CHK_ARG(idx, "Tinit"); res = cstr_to_double(arg, &solid->tinit); - if(res != RES_OK - || solid->tinit < 0) - { + if(res != RES_OK || SDIS_TEMPERATURE_IS_UNKNOWN(solid->tinit)) { logger_print(stardis->logger, LOG_ERROR, "Invalid Tinit: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -1728,8 +1695,8 @@ process_solid stardis->t_range[1] = MMAX(stardis->t_range[1], solid->tinit); ERR(read_imposed_temperature(stardis, &solid->imposed_temperature, pwordexp, &idx)); - if(solid->imposed_temperature >= 0 - && solid->imposed_temperature != solid->tinit) + if(SDIS_TEMPERATURE_IS_KNOWN(solid->imposed_temperature) + && solid->imposed_temperature != solid->tinit) { logger_print(stardis->logger, LOG_ERROR, "Imposed temperature, if defined, must match initial temperature " @@ -1738,8 +1705,9 @@ process_solid res = RES_BAD_ARG; goto end; } - if(solid->imposed_temperature >= 0) + if(SDIS_TEMPERATURE_IS_KNOWN(solid->imposed_temperature)) stardis->t_range[0] = MMIN(stardis->t_range[0], solid->imposed_temperature); + stardis->t_range[1] = MMAX(stardis->t_range[1], solid->imposed_temperature); CHK_ARG(idx, "volumic power"); res = cstr_to_double(arg, &solid->vpower); @@ -1897,9 +1865,7 @@ process_fluid } CHK_ARG(idx, "Tinit"); res = cstr_to_double(arg, &fluid->tinit); - if(res != RES_OK - || fluid->tinit < 0) - { + if(res != RES_OK || SDIS_TEMPERATURE_IS_UNKNOWN(fluid->tinit)) { logger_print(stardis->logger, LOG_ERROR, "Invalid Tinit: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; @@ -1908,9 +1874,8 @@ process_fluid stardis->t_range[1] = MMAX(stardis->t_range[1], fluid->tinit); ERR(read_imposed_temperature(stardis, &fluid->imposed_temperature, pwordexp, &idx)); - if(fluid->imposed_temperature >= 0 - && fluid->imposed_temperature != fluid->tinit) - { + if(SDIS_TEMPERATURE_IS_KNOWN(fluid->imposed_temperature) + && fluid->imposed_temperature != fluid->tinit) { logger_print(stardis->logger, LOG_ERROR, "Imposed temperature, if defined, must match initial temperature " "(initial: %g; imposed: %g)\n", @@ -1918,7 +1883,7 @@ process_fluid res = RES_BAD_ARG; goto end; } - if(fluid->imposed_temperature >= 0) + if(SDIS_TEMPERATURE_IS_KNOWN(fluid->imposed_temperature)) stardis->t_range[0] = MMIN(stardis->t_range[0], fluid->imposed_temperature); stardis->t_range[1] = MMAX(stardis->t_range[1], fluid->imposed_temperature); @@ -2056,9 +2021,7 @@ process_radiative } CHK_ARG(idx, "Trad"); res = cstr_to_double(arg, &stardis->trad); - if(res != RES_OK - || stardis->trad < 0) - { + if(res != RES_OK || SDIS_TEMPERATURE_IS_UNKNOWN(stardis->trad)) { logger_print(stardis->logger, LOG_ERROR, "Invalid Trad: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; diff --git a/src/stardis-solid.c b/src/stardis-solid.c @@ -83,12 +83,12 @@ solid_get_temperature struct sdis_data* data) { const struct solid* const* solid_props = sdis_data_cget(data); - if((*solid_props)->imposed_temperature >= 0) + if(SDIS_TEMPERATURE_IS_KNOWN((*solid_props)->imposed_temperature)) /* If there is an imposed temp, it is imposed regardless of time */ return (*solid_props)->imposed_temperature; if(vtx->time <= (*solid_props)->t0) { /* If time is <= t0: use tinit */ - if((*solid_props)->tinit < 0) { + if(SDIS_TEMPERATURE_IS_UNKNOWN((*solid_props)->tinit)) { if(str_is_empty(&(*solid_props)->name)) { FATAL("solid_get_temperature: getting undefined Tinit\n"); } else { @@ -207,10 +207,10 @@ str_print_solid(struct str* str, const struct solid* s) if(s->vpower != 0) { ERR(str_append_printf(str, " VPower=%g", s->vpower)); } - if(s->tinit >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(s->tinit)) { ERR(str_append_printf(str, " Tinit=%g", s->tinit)); } - if(s->imposed_temperature >= 0) { + if(SDIS_TEMPERATURE_IS_KNOWN(s->imposed_temperature)) { ERR(str_append_printf(str, " Temp=%g", s->imposed_temperature)); } ERR(str_append_printf(str, " (it is medium %u)", s->solid_id));