stardis

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

commit 9ca7a045b04e5a977788ffeb2088ce4255da9255
parent 715450926c468136a31b7ad2a3bb899c11b65cda
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 14 Sep 2022 18:54:37 +0200

Add HF_BOUNDARY_FOR_SOLID

Diffstat:
Mcmake/CMakeLists.txt | 2++
Msrc/stardis-app.c | 1+
Msrc/stardis-description.c | 12++++++++++++
Msrc/stardis-description.h | 3+++
Msrc/stardis-hbound.h | 2--
Asrc/stardis-hfbound.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/stardis-hfbound.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/stardis-intface.c | 33+++++++++++++++++++++++++++++++++
Msrc/stardis-parsing.c | 135+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
9 files changed, 327 insertions(+), 5 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -159,6 +159,7 @@ set(SDIS_FILES_SRC stardis-fbound-prog.c stardis-hbound.c stardis-hbound-prog.c + stardis-hfbound.c stardis-hfbound-prog.c stardis-intface.c stardis-main.c @@ -187,6 +188,7 @@ set(SDIS_FILES_INC stardis-green-types.h.in stardis-hbound.h stardis-hbound-prog.h + stardis-hfbound.h stardis-hfbound-prog.h stardis-intface.h stardis-output.h diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -604,6 +604,7 @@ validate_properties } break; case DESC_BOUND_H_FOR_SOLID: + case DESC_BOUND_HF_FOR_SOLID: /* FIXME: need specific error codes? */ case DESC_BOUND_H_FOR_SOLID_PROG: case DESC_BOUND_HF_FOR_SOLID_PROG: /* FIXME: need specific error codes? */ if(!(solid_count == 1 && fluid_count == 0)) { diff --git a/src/stardis-description.c b/src/stardis-description.c @@ -21,6 +21,7 @@ #include "stardis-fluid-prog.h" #include "stardis-hbound.h" #include "stardis-hbound-prog.h" +#include "stardis-hfbound.h" #include "stardis-hfbound-prog.h" #include "stardis-tbound.h" #include "stardis-tbound-prog.h" @@ -79,6 +80,9 @@ release_description case DESC_BOUND_H_FOR_FLUID_PROG: release_h_boundary_prog(desc->d.h_boundary_prog, allocator); break; + case DESC_BOUND_HF_FOR_SOLID: + release_hf_boundary(desc->d.hf_boundary, allocator); + break; case DESC_BOUND_HF_FOR_SOLID_PROG: release_hf_boundary_prog(desc->d.hf_boundary_prog, allocator); break; @@ -151,6 +155,9 @@ str_print_description case DESC_BOUND_H_FOR_FLUID_PROG: ERR(str_print_h_boundary_prog(str, desc)); break; + case DESC_BOUND_HF_FOR_SOLID: + ERR(str_print_hf_boundary(str, desc)); + break; case DESC_BOUND_HF_FOR_SOLID_PROG: ERR(str_print_hf_boundary_prog(str, desc)); break; @@ -208,6 +215,8 @@ get_description_name case DESC_BOUND_H_FOR_SOLID_PROG: case DESC_BOUND_H_FOR_FLUID_PROG: return &desc->d.h_boundary_prog->name; + case DESC_BOUND_HF_FOR_SOLID: + return &desc->d.hf_boundary->name; case DESC_BOUND_HF_FOR_SOLID_PROG: return &desc->d.hf_boundary_prog->name; case DESC_BOUND_F_FOR_SOLID: @@ -256,6 +265,9 @@ description_get_medium_id case DESC_BOUND_H_FOR_FLUID_PROG: *id = desc->d.h_boundary_prog->mat_id; return; + case DESC_BOUND_HF_FOR_SOLID: + *id = desc->d.hf_boundary->mat_id; + return; case DESC_BOUND_HF_FOR_SOLID_PROG: *id = desc->d.hf_boundary_prog->mat_id; return; diff --git a/src/stardis-description.h b/src/stardis-description.h @@ -41,6 +41,7 @@ enum description_type { DESC_MAT_FLUID_PROG, DESC_BOUND_H_FOR_FLUID_PROG, DESC_BOUND_H_FOR_SOLID_PROG, + DESC_BOUND_HF_FOR_SOLID, DESC_BOUND_HF_FOR_SOLID_PROG, DESC_BOUND_T_FOR_SOLID_PROG, DESC_BOUND_F_FOR_SOLID_PROG, @@ -101,6 +102,7 @@ struct f_boundary; struct f_boundary_prog; struct h_boundary; struct h_boundary_prog; +struct hf_boundary; struct hf_boundary_prog; struct solid_fluid_connect; struct solid_fluid_connect_prog; @@ -121,6 +123,7 @@ struct description { struct f_boundary_prog* f_boundary_prog; struct h_boundary* h_boundary; struct h_boundary_prog* h_boundary_prog; + struct hf_boundary* hf_boundary; struct hf_boundary_prog* hf_boundary_prog; struct solid_fluid_connect* sf_connect; struct solid_fluid_connect_prog* sf_connect_prog; diff --git a/src/stardis-hbound.h b/src/stardis-hbound.h @@ -19,8 +19,6 @@ #include <rsys/rsys.h> #include <rsys/str.h> -#include "stardis-prog-properties.h" - struct mem_allocator; struct fluid; struct description; diff --git a/src/stardis-hfbound.c b/src/stardis-hfbound.c @@ -0,0 +1,88 @@ +/* Copyright (C) 2018-2022 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "stardis-app.h" +#include "stardis-hfbound.h" +#include "stardis-fluid.h" +#include "stardis-intface.h" + +#include <rsys/rsys.h> +#include <rsys/mem_allocator.h> +#include <rsys/str.h> + +#include <sdis.h> + +#include <limits.h> + +/******************************************************************************* + * Public Functions + ******************************************************************************/ +res_T +init_hf_boundary + (struct mem_allocator* allocator, + struct hf_boundary** dst) +{ + res_T res = RES_OK; + int str_initialized = 0; + ASSERT(allocator && dst && *dst == NULL); + *dst = MEM_CALLOC(allocator, 1, sizeof(**dst)); + if(! *dst) { + res = RES_MEM_ERR; + goto error; + } + str_init(allocator, &(*dst)->name); + str_initialized = 1; + (*dst)->imposed_temperature = -1; + (*dst)->mat_id = UINT_MAX; +end: + return res; +error: + if(str_initialized) str_release(&(*dst)->name); + if(*dst) MEM_RM(allocator, *dst); + goto end; +} + +void +release_hf_boundary + (struct hf_boundary* bound, + struct mem_allocator* allocator) +{ + ASSERT(bound && allocator); + str_release(&bound->name); + if(bound->possible_external_fluid) + release_fluid(bound->possible_external_fluid, allocator); + MEM_RM(allocator, bound); +} + +res_T +str_print_hf_boundary + (struct str* str, + const struct description* desc) +{ + res_T res = RES_OK; + const struct hf_boundary* b; + ASSERT(str && desc && DESC_IS_H(desc)); + b = desc->d.hf_boundary; + ERR(str_append_printf(str, + "H boundary for %s '%s': ref_temperature=%g emissivity=%g specular_fraction=%g " + "hc=%g T=%g (using medium %u as external medium)", + (desc->type == DESC_BOUND_HF_FOR_SOLID ? "solid" : "fluid"), + str_cget(&b->name), b->ref_temperature, b->emissivity, + b->specular_fraction, b->hc, b->imposed_temperature, b->mat_id)); +end: + return res; +error: + goto end; +} diff --git a/src/stardis-hfbound.h b/src/stardis-hfbound.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2018-2022 |Meso|Star> (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifndef SDIS_HFBOUND_H +#define SDIS_HFBOUND_H + +#include <rsys/rsys.h> +#include <rsys/str.h> + +struct mem_allocator; +struct fluid; +struct description; + +/******************************************************************************* + * HF boundary type + ******************************************************************************/ +struct hf_boundary { + struct str name; + double ref_temperature; + double emissivity; + double specular_fraction; + double hc; + double imposed_flux; + double imposed_temperature; + unsigned mat_id; + struct fluid* possible_external_fluid; /* if HF for solid */ +}; + +res_T +init_hf_boundary + (struct mem_allocator* allocator, + struct hf_boundary** dst); + +void +release_hf_boundary + (struct hf_boundary* bound, + struct mem_allocator* allocator); + +res_T +str_print_hf_boundary + (struct str* str, + const struct description* desc); + +#endif diff --git a/src/stardis-intface.c b/src/stardis-intface.c @@ -20,6 +20,7 @@ #include "stardis-solid.h" #include "stardis-hbound.h" #include "stardis-hbound-prog.h" +#include "stardis-hfbound.h" #include "stardis-hfbound-prog.h" #include "stardis-tbound.h" #include "stardis-tbound-prog.h" @@ -403,6 +404,38 @@ create_intface fluid_side_shader->specular_fraction = interface_get_alpha; } break; + case DESC_BOUND_HF_FOR_SOLID: + if(!for_fluid) { + if(sdis_medium_get_type(def_medium) != SDIS_SOLID) { + res = RES_BAD_ARG; + goto error; + } + ASSERT(!fluid_side_shader); + fluid_side_shader = + front_defined ? &interface_shader.back : &interface_shader.front; + } + ext_id = intface->d.hf_boundary->mat_id; /* External material id */ + ASSERT(ext_id < darray_media_ptr_size_get(&stardis->media)); + ASSERT(sdis_medium_get_type(media[ext_id]) == + (for_fluid ? SDIS_SOLID : SDIS_FLUID)); + intface_count++; + boundary_count++; + if(front_defined) back_med = media[ext_id]; + else front_med = media[ext_id]; + interface_shader.convection_coef_upper_bound = intface->d.hf_boundary->hc; + interface_props->hc = intface->d.hf_boundary->hc; + interface_props->ref_temperature = intface->d.hf_boundary->ref_temperature; + interface_props->emissivity = intface->d.hf_boundary->emissivity; + interface_props->alpha = intface->d.hf_boundary->specular_fraction; + if(intface->d.hf_boundary->hc > 0) { + interface_shader.convection_coef = interface_get_convection_coef; + } + fluid_side_shader->reference_temperature = interface_get_ref_temperature; + if(intface->d.hf_boundary->emissivity > 0) { + fluid_side_shader->emissivity = interface_get_emissivity; + fluid_side_shader->specular_fraction = interface_get_alpha; + } + break; case DESC_BOUND_H_FOR_FLUID_PROG: if(sdis_medium_get_type(def_medium) != SDIS_FLUID) { res = RES_BAD_ARG; diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -19,6 +19,7 @@ #include "stardis-description.h" #include "stardis-hbound.h" #include "stardis-hbound-prog.h" +#include "stardis-hfbound.h" #include "stardis-hfbound-prog.h" #include "stardis-tbound.h" #include "stardis-tbound-prog.h" @@ -280,7 +281,7 @@ description_set_name const char* keywords[] = { "AUTO", "BACK", "BOTH", "FLUID", "FLUID_PROG", "FRONT", "F_BOUNDARY_FOR_SOLID", "F_BOUNDARY_FOR_SOLID_PROG", "H_BOUNDARY_FOR_FLUID", "H_BOUNDARY_FOR_FLUID_PROG", - "HF_BOUNDARY_FOR_SOLID_PROG", + "HF_BOUNDARY_FOR_SOLID", "HF_BOUNDARY_FOR_SOLID_PROG", "H_BOUNDARY_FOR_SOLID", "H_BOUNDARY_FOR_SOLID_PROG", "PROGRAM", "PROG_PARAMS", "SCALE", "SOLID", "SOLID_PROG", "SOLID_FLUID_CONNECTION", "SOLID_FLUID_CONNECTION_PROG", "SOLID_SOLID_CONNECTION", @@ -464,6 +465,132 @@ error: goto end; } +/* HF_BOUNDARY_FOR_SOLID Name ref_temperature emissivity specular_fraction hc + * flux T_env STL_filenames */ +static res_T +process_hf + (struct stardis* stardis, + const enum description_type type, + wordexp_t* pwordexp) +{ + char* arg = NULL; + struct description* desc; + size_t sz; + struct hf_boundary* hf_boundary; + size_t idx = 1; + struct fluid* fluid = NULL; + res_T res = RES_OK; + + ASSERT(stardis && pwordexp); + + stardis->counts.hbound_count++; + + sz = darray_descriptions_size_get(&stardis->descriptions); + ERR(darray_descriptions_resize(&stardis->descriptions, sz+1)); + desc = darray_descriptions_data_get(&stardis->descriptions) + sz; + ERR(init_hf_boundary(stardis->allocator, &desc->d.hf_boundary)); + hf_boundary = desc->d.hf_boundary; + desc->type = type; + + CHK_ARG(idx, "hf boundary name"); + ERR(description_set_name(stardis, &hf_boundary->name, arg)); + if(find_description_by_name(stardis, &hf_boundary->name, desc)) { + logger_print(stardis->logger, LOG_ERROR, + "Name already used: %s\n", arg); + if(res == RES_OK) res = RES_BAD_ARG; + goto end; + } + + CHK_ARG(idx, "ref_temperature"); + res = cstr_to_double(arg, &hf_boundary->ref_temperature); + 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; + goto end; + } + stardis->t_range[0] = MMIN(stardis->t_range[0], hf_boundary->ref_temperature); + stardis->t_range[1] = MMAX(stardis->t_range[1], hf_boundary->ref_temperature); + CHK_ARG(idx, "emissivity"); + res = cstr_to_double(arg, &hf_boundary->emissivity); + if(res != RES_OK + || 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; + } + 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) + { + logger_print(stardis->logger, LOG_ERROR, + "Invalid specular fraction: %s\n", arg); + if(res == RES_OK) res = RES_BAD_ARG; + goto end; + } + CHK_ARG(idx, "convection coefficient"); + res = cstr_to_double(arg, &hf_boundary->hc); + 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; + goto end; + } + CHK_ARG(idx, "flux"); + res = cstr_to_double(arg, &hf_boundary->imposed_flux); + if(res != RES_OK + || hf_boundary->imposed_flux == SDIS_FLUX_NONE) { + /* Flux can be < 0 but not undefined */ + logger_print(stardis->logger, LOG_ERROR, + "Invalid flux: %s\n", arg); + if(res == RES_OK) res = RES_BAD_ARG; + goto end; + } + CHK_ARG(idx, "temperature"); + res = cstr_to_double(arg, &hf_boundary->imposed_temperature); + if(res != RES_OK + || hf_boundary->imposed_temperature < 0) + { + logger_print(stardis->logger, LOG_ERROR, "Invalid temperature: %s\n", arg); + if(res == RES_OK) res = RES_BAD_ARG; + goto end; + } + stardis->t_range[0] = MMIN(stardis->t_range[0], hf_boundary->imposed_temperature); + stardis->t_range[1] = MMAX(stardis->t_range[1], hf_boundary->imposed_temperature); + + ASSERT(type == DESC_BOUND_HF_FOR_SOLID); + ERR(init_fluid(stardis->allocator, &fluid)); + fluid->fluid_id = allocate_stardis_medium_id(stardis); + hf_boundary->mat_id = fluid->fluid_id; + hf_boundary->possible_external_fluid = fluid; + ASSERT(sz <= UINT_MAX); + fluid->desc_id = (unsigned)sz; + fluid->imposed_temperature = hf_boundary->imposed_temperature; + fluid->is_outside = 1; + fluid->is_green = stardis->mode & (MODE_BIN_GREEN | MODE_GREEN); + ERR(create_solver_fluid(stardis, fluid)); + logger_print(stardis->logger, LOG_OUTPUT, + "External fluid created: T=%g (it is medium %u)\n", + fluid->imposed_temperature, + fluid->fluid_id); + + ASSERT(sz <= UINT_MAX); + ERR(read_sides_and_files(stardis, 1, (unsigned)sz, pwordexp, &idx)); + +end: + return res; +error: + goto end; +} + static res_T set_argc_argv (struct mem_allocator* allocator, @@ -1201,13 +1328,13 @@ process_sfc if(res == RES_OK) res = RES_BAD_ARG; goto end; } - CHK_ARG(idx, "Convection coefficient"); + CHK_ARG(idx, "convection coefficient"); res = cstr_to_double(arg, &sf_connect->hc); if(res != RES_OK || sf_connect->hc < 0) { logger_print(stardis->logger, LOG_ERROR, - "Invalid Convection coefficient: %s\n", arg); + "Invalid convection coefficient: %s\n", arg); if(res == RES_OK) res = RES_BAD_ARG; goto end; } @@ -1968,6 +2095,8 @@ process_model_line ERR(process_h(stardis, DESC_BOUND_H_FOR_SOLID, pwordexp)); else if(0 == strcasecmp(arg, "H_BOUNDARY_FOR_SOLID_PROG")) ERR(process_h_prog(stardis, DESC_BOUND_H_FOR_SOLID_PROG, pwordexp)); + else if(0 == strcasecmp(arg, "HF_BOUNDARY_FOR_SOLID")) + ERR(process_hf(stardis, DESC_BOUND_HF_FOR_SOLID, pwordexp)); else if(0 == strcasecmp(arg, "HF_BOUNDARY_FOR_SOLID_PROG")) ERR(process_hf_prog(stardis, DESC_BOUND_HF_FOR_SOLID_PROG, pwordexp)); else if(0 == strcasecmp(arg, "H_BOUNDARY_FOR_FLUID"))