stardis-hbound.c (2572B)
1 /* Copyright (C) 2018-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "stardis-app.h" 17 #include "stardis-hbound.h" 18 #include "stardis-fluid.h" 19 #include "stardis-intface.h" 20 21 #include <rsys/rsys.h> 22 #include <rsys/mem_allocator.h> 23 #include <rsys/str.h> 24 25 #include <sdis.h> 26 27 #include <limits.h> 28 29 /******************************************************************************* 30 * Public Functions 31 ******************************************************************************/ 32 res_T 33 init_h_boundary 34 (struct mem_allocator* allocator, 35 struct h_boundary** dst) 36 { 37 res_T res = RES_OK; 38 int str_initialized = 0; 39 ASSERT(allocator && dst && *dst == NULL); 40 *dst = MEM_CALLOC(allocator, 1, sizeof(**dst)); 41 if(! *dst) { 42 res = RES_MEM_ERR; 43 goto error; 44 } 45 str_init(allocator, &(*dst)->name); 46 str_initialized = 1; 47 (*dst)->imposed_temperature = SDIS_TEMPERATURE_NONE; 48 (*dst)->mat_id = UINT_MAX; 49 end: 50 return res; 51 error: 52 if(str_initialized) str_release(&(*dst)->name); 53 if(*dst) MEM_RM(allocator, *dst); 54 goto end; 55 } 56 57 void 58 release_h_boundary 59 (struct h_boundary* bound, 60 struct mem_allocator* allocator) 61 { 62 ASSERT(bound && allocator); 63 str_release(&bound->name); 64 if(bound->possible_external_fluid) 65 release_fluid(bound->possible_external_fluid, allocator); 66 MEM_RM(allocator, bound); 67 } 68 69 res_T 70 str_print_h_boundary 71 (struct str* str, 72 const struct description* desc) 73 { 74 res_T res = RES_OK; 75 const struct h_boundary* b; 76 ASSERT(str && desc && DESC_IS_H(desc)); 77 b = desc->d.h_boundary; 78 ERR(str_append_printf(str, 79 "H boundary for %s '%s': ref_temperature=%g emissivity=%g specular_fraction=%g " 80 "hc=%g T=%g (using medium %u as external medium)", 81 (desc->type == DESC_BOUND_H_FOR_SOLID ? "solid" : "fluid"), 82 str_cget(&b->name), b->ref_temperature, b->emissivity, 83 b->specular_fraction, b->hc, b->imposed_temperature, b->mat_id)); 84 end: 85 return res; 86 error: 87 goto end; 88 }