stardis-sfconnect.c (2270B)
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-sfconnect.h" 18 19 #include <rsys/rsys.h> 20 #include <rsys/mem_allocator.h> 21 #include <rsys/str.h> 22 23 #include <sdis.h> 24 25 #include <limits.h> 26 27 /******************************************************************************* 28 * Public Functions 29 ******************************************************************************/ 30 res_T 31 init_sf_connect 32 (struct mem_allocator* allocator, 33 struct solid_fluid_connect** dst) 34 { 35 res_T res = RES_OK; 36 int str_initialized = 0; 37 ASSERT(allocator && dst && *dst == NULL); 38 *dst = MEM_CALLOC(allocator, 1, sizeof(**dst)); 39 if(! *dst) { 40 res = RES_MEM_ERR; 41 goto error; 42 } 43 str_init(allocator, &(*dst)->name); 44 str_initialized = 1; 45 (*dst)->connection_id = UINT_MAX; 46 (*dst)->flux = SDIS_FLUX_NONE; 47 end: 48 return res; 49 error: 50 if(str_initialized) str_release(&(*dst)->name); 51 if(*dst) MEM_RM(allocator, *dst); 52 goto end; 53 } 54 55 void 56 release_sf_connect 57 (struct solid_fluid_connect* connect, 58 struct mem_allocator* allocator) 59 { 60 ASSERT(connect && allocator); 61 str_release(&connect->name); 62 MEM_RM(allocator, connect); 63 } 64 65 res_T 66 str_print_sf_connect 67 (struct str* str, 68 const struct solid_fluid_connect* connect) 69 { 70 res_T res = RES_OK; 71 ASSERT(str && connect); 72 ERR(str_append_printf(str, 73 "Solid-Fluid connection '%s': " 74 "ref_temperature=%g emissivity=%g, specular_fraction=%g hc=%g", 75 str_cget(&connect->name), 76 connect->ref_temperature, connect->emissivity, connect->specular_fraction, 77 connect->hc)); 78 end: 79 return res; 80 error: 81 goto end; 82 } 83