stardis

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

stardis-sfconnect-prog.c (3006B)


      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-prog.h"
     18 #include "stardis-prog-properties.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_sf_connect_prog
     34   (struct mem_allocator* allocator,
     35    struct solid_fluid_connect_prog** 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_init(allocator, &(*dst)->prog_name);
     47   str_initialized = 1;
     48   (*dst)->connection_id = UINT_MAX;
     49 end:
     50   return res;
     51 error:
     52   if(str_initialized) {
     53     str_release(&(*dst)->name);
     54     str_release(&(*dst)->prog_name);
     55   }
     56   if(*dst) MEM_RM(allocator, *dst);
     57   goto end;
     58 }
     59 
     60 void
     61 release_sf_connect_prog
     62   (struct solid_fluid_connect_prog* connect,
     63    struct mem_allocator* allocator)
     64 {
     65   size_t i;
     66   ASSERT(connect && allocator);
     67   str_release(&connect->name);
     68   str_release(&connect->prog_name);
     69   if(connect->prog_data)
     70     connect->release(connect->prog_data);
     71   for(i = 0; i < connect->argc; i++) MEM_RM(allocator, connect->argv[i]);
     72   MEM_RM(allocator, connect->argv);
     73   /* library_close call is managed at lib_data level */
     74   MEM_RM(allocator, connect);
     75 }
     76 
     77 res_T
     78 str_print_sf_connect_prog
     79   (struct str* str,
     80    const struct solid_fluid_connect_prog* c)
     81 {
     82   res_T res = RES_OK;
     83   ASSERT(str && c);
     84   ASSERT(c->argc >= 1); /* At least one argument which is the program name */
     85 
     86   ERR(str_append_printf(str,
     87     "programmed Solid-Fluid connection '%s': lib='%s'",
     88     str_cget(&c->name), str_cget(&c->prog_name)));
     89   if(c->argc > 1) {
     90     size_t i;
     91     ERR(str_append_printf(str, ", provided arguments:\n"));
     92     for(i = 1; i < c->argc; i++) {
     93       ERR(str_append_printf(str, (i+1 == c->argc ? "\t%s" : "\t%s\n"), c->argv[i]));
     94     }
     95   }
     96 end:
     97   return res;
     98 error:
     99   goto end;
    100 }
    101 
    102 double
    103 sf_connect_prog_get_hmax
    104   (const struct solid_fluid_connect_prog* connect)
    105 {
    106   return connect->hmax(connect->prog_data);
    107 }