stardis

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

stardis-description.c (8767B)


      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-description.h"
     18 #include "stardis-solid.h"
     19 #include "stardis-solid-prog.h"
     20 #include "stardis-fluid.h"
     21 #include "stardis-fluid-prog.h"
     22 #include "stardis-hbound.h"
     23 #include "stardis-hbound-prog.h"
     24 #include "stardis-hfbound.h"
     25 #include "stardis-hfbound-prog.h"
     26 #include "stardis-tbound.h"
     27 #include "stardis-tbound-prog.h"
     28 #include "stardis-fbound.h"
     29 #include "stardis-fbound-prog.h"
     30 #include "stardis-sfconnect.h"
     31 #include "stardis-sfconnect-prog.h"
     32 #include "stardis-ssconnect.h"
     33 #include "stardis-ssconnect-prog.h"
     34 #include "stardis-program.h"
     35 
     36 #include <rsys/rsys.h>
     37 #include <rsys/mem_allocator.h>
     38 #include <rsys/str.h>
     39 
     40 #include <sdis.h>
     41 
     42 #include <limits.h>
     43 
     44 res_T
     45 init_description
     46   (struct mem_allocator* alloc,
     47    struct description* desc)
     48 {
     49   ASSERT(desc);
     50   (void)alloc;
     51   desc->type = DESCRIPTION_TYPE_COUNT__;
     52   desc->d.fluid = NULL;
     53   return RES_OK;
     54 }
     55 
     56 void
     57 release_description
     58   (struct description* desc,
     59    struct mem_allocator* allocator)
     60 {
     61   ASSERT(desc && allocator);
     62   switch (desc->type) {
     63   case DESC_MAT_SOLID:
     64     release_solid(desc->d.solid, allocator);
     65     break;
     66   case DESC_MAT_SOLID_PROG:
     67     release_solid_prog(desc->d.solid_prog, allocator);
     68     break;
     69   case DESC_MAT_FLUID:
     70     release_fluid(desc->d.fluid, allocator);
     71     break;
     72   case DESC_MAT_FLUID_PROG:
     73     release_fluid_prog(desc->d.fluid_prog, allocator);
     74     break;
     75   case DESC_BOUND_H_FOR_SOLID:
     76   case DESC_BOUND_H_FOR_FLUID:
     77     release_h_boundary(desc->d.h_boundary, allocator);
     78     break;
     79   case DESC_BOUND_H_FOR_SOLID_PROG:
     80   case DESC_BOUND_H_FOR_FLUID_PROG:
     81     release_h_boundary_prog(desc->d.h_boundary_prog, allocator);
     82     break;
     83   case DESC_BOUND_HF_FOR_SOLID:
     84     release_hf_boundary(desc->d.hf_boundary, allocator);
     85     break;
     86   case DESC_BOUND_HF_FOR_SOLID_PROG:
     87     release_hf_boundary_prog(desc->d.hf_boundary_prog, allocator);
     88     break;
     89   case DESC_BOUND_T_FOR_SOLID:
     90     release_t_boundary(desc->d.t_boundary, allocator);
     91     break;
     92   case DESC_BOUND_T_FOR_SOLID_PROG:
     93     release_t_boundary_prog(desc->d.t_boundary_prog, allocator);
     94     break;
     95   case DESC_BOUND_F_FOR_SOLID:
     96     release_f_boundary(desc->d.f_boundary, allocator);
     97     break;
     98   case DESC_BOUND_F_FOR_SOLID_PROG:
     99     release_f_boundary_prog(desc->d.f_boundary_prog, allocator);
    100     break;
    101   case DESC_SOLID_FLUID_CONNECT:
    102     release_sf_connect(desc->d.sf_connect, allocator);
    103     break;
    104   case DESC_SOLID_FLUID_CONNECT_PROG:
    105     release_sf_connect_prog(desc->d.sf_connect_prog, allocator);
    106     break;
    107   case DESC_SOLID_SOLID_CONNECT:
    108     release_ss_connect(desc->d.ss_connect, allocator);
    109     break;
    110   case DESC_SOLID_SOLID_CONNECT_PROG:
    111     release_ss_connect_prog(desc->d.ss_connect_prog, allocator);
    112     break;
    113   case DESC_PROGRAM:
    114    release_program(desc->d.program, allocator);
    115    break;
    116   default:
    117     FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n");
    118   }
    119 }
    120 
    121 res_T
    122 str_print_description
    123   (struct str* str,
    124    const unsigned rank,
    125    const struct description* desc)
    126 {
    127   res_T res = RES_OK;
    128   ASSERT(str && desc);
    129   str_clear(str);
    130   ERR(str_printf(str, "Description %u: ", rank));
    131   switch (desc->type) {
    132   case DESC_MAT_SOLID:
    133     ERR(str_print_solid(str, desc->d.solid));
    134     break;
    135   case DESC_MAT_SOLID_PROG:
    136     ERR(str_print_solid_prog(str, desc->d.solid_prog));
    137     break;
    138   case DESC_MAT_FLUID:
    139     ERR(str_print_fluid(str, desc->d.fluid));
    140     break;
    141   case DESC_MAT_FLUID_PROG:
    142     ERR(str_print_fluid_prog(str, desc->d.fluid_prog));
    143     break;
    144   case DESC_BOUND_T_FOR_SOLID:
    145     ERR(str_print_t_boundary(str, desc->d.t_boundary));
    146     break;
    147   case DESC_BOUND_T_FOR_SOLID_PROG:
    148     ERR(str_print_t_boundary_prog(str, desc->d.t_boundary_prog));
    149     break;
    150   case DESC_BOUND_H_FOR_SOLID:
    151   case DESC_BOUND_H_FOR_FLUID:
    152     ERR(str_print_h_boundary(str, desc));
    153     break;
    154   case DESC_BOUND_H_FOR_SOLID_PROG:
    155   case DESC_BOUND_H_FOR_FLUID_PROG:
    156     ERR(str_print_h_boundary_prog(str, desc));
    157     break;
    158   case DESC_BOUND_HF_FOR_SOLID:
    159     ERR(str_print_hf_boundary(str, desc));
    160     break;
    161   case DESC_BOUND_HF_FOR_SOLID_PROG:
    162     ERR(str_print_hf_boundary_prog(str, desc));
    163     break;
    164   case DESC_BOUND_F_FOR_SOLID:
    165     ERR(str_print_f_boundary(str, desc->d.f_boundary));
    166     break;
    167   case DESC_BOUND_F_FOR_SOLID_PROG:
    168     ERR(str_print_f_boundary_prog(str, desc->d.f_boundary_prog));
    169     break;
    170   case DESC_SOLID_FLUID_CONNECT:
    171     ERR(str_print_sf_connect(str, desc->d.sf_connect));
    172     break;
    173   case DESC_SOLID_FLUID_CONNECT_PROG:
    174     ERR(str_print_sf_connect_prog(str, desc->d.sf_connect_prog));
    175     break;
    176   case DESC_SOLID_SOLID_CONNECT:
    177     ERR(str_print_ss_connect(str, desc->d.ss_connect));
    178     break;
    179   case DESC_SOLID_SOLID_CONNECT_PROG:
    180     ERR(str_print_ss_connect_prog(str, desc->d.ss_connect_prog));
    181     break;
    182   case DESC_PROGRAM:
    183     ERR(str_print_program(str, desc->d.program));
    184     break;
    185   default:
    186     FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n");
    187   }
    188 end:
    189   return res;
    190 error:
    191   goto end;
    192 }
    193 
    194 const struct str*
    195 get_description_name
    196   (const struct description* desc)
    197 {
    198   ASSERT(desc);
    199   switch (desc->type) {
    200   case DESC_MAT_SOLID:
    201     return &desc->d.solid->name;
    202   case DESC_MAT_SOLID_PROG:
    203     return &desc->d.solid_prog->name;
    204   case DESC_MAT_FLUID:
    205     return &desc->d.fluid->name;
    206   case DESC_MAT_FLUID_PROG:
    207     return &desc->d.fluid_prog->name;
    208   case DESC_BOUND_T_FOR_SOLID:
    209     return &desc->d.t_boundary->name;
    210   case DESC_BOUND_T_FOR_SOLID_PROG:
    211     return &desc->d.t_boundary_prog->name;
    212   case DESC_BOUND_H_FOR_SOLID:
    213   case DESC_BOUND_H_FOR_FLUID:
    214     return &desc->d.h_boundary->name;
    215   case DESC_BOUND_H_FOR_SOLID_PROG:
    216   case DESC_BOUND_H_FOR_FLUID_PROG:
    217     return &desc->d.h_boundary_prog->name;
    218   case DESC_BOUND_HF_FOR_SOLID:
    219     return &desc->d.hf_boundary->name;
    220   case DESC_BOUND_HF_FOR_SOLID_PROG:
    221     return &desc->d.hf_boundary_prog->name;
    222   case DESC_BOUND_F_FOR_SOLID:
    223     return &desc->d.f_boundary->name;
    224   case DESC_BOUND_F_FOR_SOLID_PROG:
    225     return &desc->d.f_boundary_prog->name;
    226   case DESC_SOLID_FLUID_CONNECT:
    227     return &desc->d.sf_connect->name;
    228   case DESC_SOLID_FLUID_CONNECT_PROG:
    229     return &desc->d.sf_connect_prog->name;
    230   case DESC_SOLID_SOLID_CONNECT:
    231     return &desc->d.ss_connect->name;
    232   case DESC_SOLID_SOLID_CONNECT_PROG:
    233     return &desc->d.ss_connect_prog->name;
    234   case DESC_PROGRAM:
    235     return &desc->d.program->name;
    236   default:
    237     FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n");
    238   }
    239 }
    240 
    241 void
    242 description_get_medium_id
    243   (const struct description* desc,
    244    unsigned* id)
    245 {
    246   ASSERT(desc && id);
    247   switch (desc->type) {
    248   case DESC_MAT_SOLID:
    249     *id = desc->d.solid->solid_id;
    250     return;
    251   case DESC_MAT_SOLID_PROG:
    252     *id = desc->d.solid_prog->solid_id;
    253     return;
    254   case DESC_MAT_FLUID:
    255     *id = desc->d.fluid->fluid_id;
    256     return;
    257   case DESC_MAT_FLUID_PROG:
    258     *id = desc->d.fluid_prog->fluid_id;
    259     return;
    260   case DESC_BOUND_H_FOR_SOLID:
    261   case DESC_BOUND_H_FOR_FLUID:
    262     *id = desc->d.h_boundary->mat_id;
    263     return;
    264   case DESC_BOUND_H_FOR_SOLID_PROG:
    265   case DESC_BOUND_H_FOR_FLUID_PROG:
    266     *id = desc->d.h_boundary_prog->mat_id;
    267     return;
    268   case DESC_BOUND_HF_FOR_SOLID:
    269     *id = desc->d.hf_boundary->mat_id;
    270     return;
    271   case DESC_BOUND_HF_FOR_SOLID_PROG:
    272     *id = desc->d.hf_boundary_prog->mat_id;
    273     return;
    274   case DESC_BOUND_T_FOR_SOLID:
    275     *id = desc->d.t_boundary->mat_id;
    276     return;
    277   case DESC_BOUND_T_FOR_SOLID_PROG:
    278     *id = desc->d.t_boundary_prog->mat_id;
    279     return;
    280   case DESC_BOUND_F_FOR_SOLID:
    281     *id = desc->d.f_boundary->mat_id;
    282     return;
    283   case DESC_BOUND_F_FOR_SOLID_PROG:
    284     *id = desc->d.f_boundary_prog->mat_id;
    285     return;
    286   case DESC_SOLID_FLUID_CONNECT: /* No medium linked to SF */
    287   case DESC_SOLID_SOLID_CONNECT: /* No medium linked to SS */
    288   case DESC_SOLID_FLUID_CONNECT_PROG: /* No medium linked to SF */
    289   case DESC_SOLID_SOLID_CONNECT_PROG: /* No medium linked to SS */
    290   case DESC_PROGRAM: /* No medium linked to PRORGRAM */
    291   default:
    292     FATAL("error:" STR(__FILE__) ":" STR(__LINE__)": Invalid type.\n");
    293   }
    294 }