stardis

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

commit 64634982242a4612cd62a6789e1dc7faeab7b63a
parent c4e8be0ddeeab61435840eb29f640bcda4221bf4
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Thu,  4 Feb 2021 16:30:17 +0100

Add parsing solid solid connection to support thermal contact resistance

Diffstat:
Mdoc/stardis-input.5.txt | 5+++++
Mdoc/stardis.1.txt.in | 6+++---
Msrc/stardis-app.h | 76+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Msrc/stardis-intface.c | 31+++++++++++++++++++++++++++++--
Msrc/stardis-intface.h | 3+++
Msrc/stardis-parsing.c | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 171 insertions(+), 8 deletions(-)

diff --git a/doc/stardis-input.5.txt b/doc/stardis-input.5.txt @@ -99,6 +99,7 @@ _______ | <f-bound-for-solid> <media-connection> ::= <solid-fluid-connect> + | <solid-solid-connect> <comment> ::= "#" Any text introduced by the # character @@ -132,6 +133,8 @@ _______ <solid-fluid-connect> ::= "SOLID_FLUID_CONNECTION" <bound-name> <emissivity> \ <specular-fraction> <hc> <triangles> +<solid-solid-connect> ::= "SOLID_SOLID_CONNECTION" <bound-name> \ + <contact-resistance> <triangles> ------------------------------------- <medium-name> ::= STRING # no space allowed @@ -167,6 +170,8 @@ _______ <hc> ::= REAL # in W/(m2.K); in [0, INF) +<contact-resistance> ::= REAL # in m2.K/W in [0, INF) + <flux> ::= REAL # in W/m2; in (-INF , INF) <triangles> ::= <file-name> [ <triangles> ] diff --git a/doc/stardis.1.txt.in b/doc/stardis.1.txt.in @@ -95,7 +95,7 @@ EXCLUSIVE OPTIONS be in a medium. The probe coordinates must be in the same system as the geometry. -*-P* _x,y,z[,time-range]_:: +*-P* _x,y,z[,time-range][,medium_name]_:: Compute the temperature at the given probe on an interface at a given time. By default the compute time range is @STARDIS_ARGS_DEFAULT_COMPUTE_TIME@. The probe is supposed to be on an interface and is moved to the closest point of @@ -108,14 +108,14 @@ EXCLUSIVE OPTIONS range is @STARDIS_ARGS_DEFAULT_COMPUTE_TIME@. The medium does not need to be connex. -*-s* _file[,time-range]_:: +*-s* _file[,time-range][,FRONT|BACK]_:: Compute the mean temperature on a given 2D region at a given time, the region being defined as the front sides of the triangles in the provided *STL* file. By default the compute time range is @STARDIS_ARGS_DEFAULT_COMPUTE_TIME@. These triangles are not added to the geometry, but must be part of it. The region does not need to be connex. -*-S* _file[,time-range]_:: +*-S* _file[,time-range][,FRONT|BACK]_:: Compute the by-triangle mean temperature on a given 2D region at a given time, the region being defined as the front sides of the triangles in the provided *STL* file. These triangles are not added to the geometry, but must diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -106,6 +106,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 }; @@ -415,6 +416,58 @@ cp_release_sf_connect return cp_sf_connect(dst, src); } +struct solid_solid_connect { + struct str name; + double tcr; + unsigned connection_id; +}; + +static FINLINE void +release_ss_connect(struct solid_solid_connect* connect) +{ + str_release(&connect->name); +} + +static FINLINE void +init_ss(struct mem_allocator* allocator, struct solid_solid_connect* dst) +{ + str_init(allocator, &dst->name); + dst->tcr = 0; + dst->connection_id = UINT_MAX; +} + +static res_T +str_print_ss_connect + (struct str* str, + const struct solid_solid_connect* c) +{ + res_T res = RES_OK; + ASSERT(str && c); + STR_APPEND_PRINTF(str, "Solid-Solid connection '%s':", ARG1( str_cget(&c->name) ) ); + STR_APPEND_PRINTF(str, " contact resistance=%g", ARG1( c->tcr ) ); +end: + return res; +error: + goto end; +} + +static FINLINE res_T +cp_ss_connect + (struct solid_solid_connect* dst, const struct solid_solid_connect* src) +{ + dst->connection_id = src->connection_id; + dst->tcr = src->tcr; + return str_copy(&dst->name, &src->name); +} + +static FINLINE res_T +cp_release_ss_connect + (struct solid_solid_connect* dst, struct solid_solid_connect* src) +{ + return cp_ss_connect(dst, src); +} + + struct description { enum description_type type; union { @@ -424,6 +477,7 @@ 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; }; @@ -460,6 +514,9 @@ release_description(struct description* desc) case DESC_SOLID_FLUID_CONNECT: release_sf_connect(&desc->d.sf_connect); break; + case DESC_SOLID_SOLID_CONNECT: + release_ss_connect(&desc->d.ss_connect); + break; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } @@ -496,6 +553,9 @@ str_print_description case DESC_SOLID_FLUID_CONNECT: ERR(str_print_sf_connect(str, &desc->d.sf_connect)); break; + case DESC_SOLID_SOLID_CONNECT: + ERR(str_print_ss_connect(str, &desc->d.ss_connect)); + break; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } @@ -525,6 +585,8 @@ get_description_name return &desc->d.f_boundary.name; case DESC_SOLID_FLUID_CONNECT: return &desc->d.sf_connect.name; + case DESC_SOLID_SOLID_CONNECT: + return &desc->d.ss_connect.name; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } @@ -582,7 +644,14 @@ cp_description } ERR(cp_sf_connect(&dst->d.sf_connect, &src->d.sf_connect)); break; - default: + case DESC_SOLID_SOLID_CONNECT: + if(dst->type == DESCRIPTION_TYPE_COUNT__) { + dst->type = src->type; + init_ss(src->d.ss_connect.name.allocator, &dst->d.ss_connect); + } + ERR(cp_ss_connect(&dst->d.ss_connect, &src->d.ss_connect)); + break; + default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } end: @@ -616,6 +685,7 @@ description_get_medium_id *id = desc->d.f_boundary.mat_id; return; case DESC_SOLID_FLUID_CONNECT: /* No medium linked to SF */ + case DESC_SOLID_SOLID_CONNECT: /* No medium linked to SS */ default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } @@ -699,10 +769,10 @@ log_prt_fn(const char* msg, void* ctx) struct counts { unsigned smed_count, fmed_count, tbound_count, hbound_count, - fbound_count, sfconnect_count; + fbound_count, sfconnect_count, ssconnect_count; }; #define COUNTS_NULL__ {\ - 0, 0, 0, 0, 0, 0\ + 0, 0, 0, 0, 0, 0, 0\ } /* Type to store the primitives of a compute region */ diff --git a/src/stardis-intface.c b/src/stardis-intface.c @@ -75,6 +75,17 @@ interface_get_alpha return interface_props->alpha; } +static double +interface_get_tcr + (const struct sdis_interface_fragment* frag, + struct sdis_data* data) +{ + const struct intface* interface_props = sdis_data_cget(data); + (void)frag; + return interface_props->tcr; +} + + /******************************************************************************* * Public Functions ******************************************************************************/ @@ -94,7 +105,8 @@ create_intface struct sdis_data* data = NULL; unsigned fd, bd, cd, descr[SG3D_PROP_TYPES_COUNT__]; int fluid_count = 0, solid_count = 0; - int solid_fluid_connection_count = 0, connection_count = 0, boundary_count = 0; + int solid_fluid_connection_count = 0, solid_solid_connection_count = 0; + int connection_count = 0, boundary_count = 0; const struct description* descriptions; struct sdis_medium** media; res_T res = RES_OK; @@ -185,7 +197,8 @@ create_intface struct sdis_medium* def_medium = NULL; unsigned ext_id; if(connect->type != DESC_SOLID_FLUID_CONNECT - && front_defined == back_defined) + && connect->type != DESC_SOLID_SOLID_CONNECT + && front_defined == back_defined) { /* 1 and only 1 defined */ res = RES_BAD_ARG; @@ -335,6 +348,20 @@ create_intface fluid_side_shader->specular_fraction = interface_get_alpha; } break; + case DESC_SOLID_SOLID_CONNECT: + /* Both front and back should be defined */ + if(solid_count != 2 || fluid_count != 0) { + res = RES_BAD_ARG; + goto error; + } + ASSERT(front_defined && back_defined); + connection_count++; + solid_solid_connection_count++; + interface_props->tcr = connect->d.ss_connect.tcr; + if(connect->d.ss_connect.tcr > 0) { + interface_shader.thermal_contact_resistance = interface_get_tcr; + } + break; default: FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n"); } diff --git a/src/stardis-intface.h b/src/stardis-intface.h @@ -27,9 +27,12 @@ struct dummies; * Interface data ******************************************************************************/ struct intface { + /* fluid - solid */ double hc; double emissivity; double alpha; + /* solid - solid */ + double tcr; /* Imposed compute temperature & flux */ double imposed_temperature; double imposed_flux; diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -1428,6 +1428,62 @@ error: goto end; } +/* SOLID_SOLID_CONNECTION Name contact-resitance STL_filenames */ +static res_T +process_ssc + (struct stardis* stardis, + char** tok_ctx) +{ + char* tk = NULL; + struct description* desc; + size_t sz; + res_T res = RES_OK; + + ASSERT(stardis && tok_ctx); + + stardis->counts.ssconnect_count++; + + sz = darray_descriptions_size_get(&stardis->descriptions); + ERR(darray_descriptions_resize(&stardis->descriptions, sz + 1)); + desc = darray_descriptions_data_get(&stardis->descriptions) + sz; + init_ss(stardis->allocator, &desc->d.ss_connect); + + /* Use a medium ID even if there is no medium here + * As other cases use media IDs as unique IDs for read_sides_and_files calls + * we continue the trend to ensure connection ID is OK */ + desc->type = DESC_SOLID_SOLID_CONNECT; + desc->d.ss_connect.connection_id = allocate_stardis_medium_id(stardis); + + CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "solid solid connection name"); + ERR(description_set_name(stardis, &desc->d.ss_connect.name, tk)); + if(find_description_by_name(stardis, &desc->d.ss_connect.name, NULL) + != desc) + { + logger_print(stardis->logger, LOG_ERROR, + "Name already used: %s\n", tk); + if(res == RES_OK) res = RES_BAD_ARG; + goto end; + } + + CHK_TOK(strtok_r(NULL, " \t", tok_ctx), "contact resistance"); + res = cstr_to_double(tk, &desc->d.ss_connect.tcr); + if(res != RES_OK + || desc->d.ss_connect.tcr < 0) + { + logger_print(stardis->logger, LOG_ERROR, "Invalid contact resistance: %s\n", tk); + if(res == RES_OK) res = RES_BAD_ARG; + goto end; + } + + ASSERT(sz <= UINT_MAX); + ERR(read_sides_and_files(stardis, 1, (unsigned)sz, tok_ctx)); + +end: + return res; +error: + goto end; +} + static res_T read_imposed_temperature (struct stardis* stardis, @@ -1779,6 +1835,8 @@ process_model_line ERR(process_flx(stardis, dummies, &tok_ctx)); else if(0 == strcmp(tk, "SOLID_FLUID_CONNECTION")) ERR(process_sfc(stardis, &tok_ctx)); + else if(0 == strcmp(tk, "SOLID_SOLID_CONNECTION")) + ERR(process_ssc(stardis, &tok_ctx)); else if(0 == strcmp(tk, "SOLID")) ERR(process_solid(stardis, &tok_ctx)); else if(0 == strcmp(tk, "FLUID"))