stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

sdis_radiative_env.c (2955B)


      1 /* Copyright (C) 2016-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 "sdis_device_c.h"
     17 #include "sdis_log.h"
     18 #include "sdis_radiative_env_c.h"
     19 
     20 #include <rsys/mem_allocator.h>
     21 
     22 /*******************************************************************************
     23  * Helper functions
     24  ******************************************************************************/
     25 static void
     26 radiative_env_release(ref_T* ref)
     27 {
     28   struct sdis_radiative_env* radenv = NULL;
     29   struct sdis_device* dev = NULL;
     30   ASSERT(ref);
     31   radenv = CONTAINER_OF(ref, struct sdis_radiative_env, ref);
     32   dev = radenv->dev;
     33   if(radenv->data) SDIS(data_ref_put(radenv->data));
     34   MEM_RM(dev->allocator, radenv);
     35   SDIS(device_ref_put(dev));
     36 }
     37 
     38 /*******************************************************************************
     39  * Exported functions
     40  ******************************************************************************/
     41 res_T
     42 sdis_radiative_env_create
     43   (struct sdis_device* dev,
     44    const struct sdis_radiative_env_shader* shader,
     45    struct sdis_data* data, /* Data sent to the shader. May be NULL */
     46    struct sdis_radiative_env** out_radenv)
     47 {
     48   struct sdis_radiative_env* radenv = NULL;
     49   res_T res = RES_OK;
     50 
     51   if(!dev || !shader || !out_radenv) {
     52     res = RES_BAD_ARG;
     53     goto error;
     54   }
     55 
     56   radenv = MEM_CALLOC(dev->allocator, 1, sizeof(*radenv));
     57   if(!radenv) {
     58     res = RES_MEM_ERR;
     59     goto error;
     60   }
     61   ref_init(&radenv->ref);
     62   SDIS(device_ref_get(dev));
     63   radenv->dev = dev;
     64   radenv->shader = *shader;
     65   if(data) {
     66     SDIS(data_ref_get(data));
     67     radenv->data = data;
     68   }
     69 
     70 exit:
     71   if(out_radenv) *out_radenv = radenv;
     72   return res;
     73 error:
     74   goto exit;
     75 }
     76 
     77 res_T
     78 sdis_radiative_env_ref_get(struct sdis_radiative_env* radenv)
     79 {
     80   if(!radenv) return RES_BAD_ARG;
     81   ref_get(&radenv->ref);
     82   return RES_OK;
     83 }
     84 
     85 res_T
     86 sdis_radiative_env_ref_put(struct sdis_radiative_env* radenv)
     87 {
     88   if(!radenv) return RES_BAD_ARG;
     89   ref_put(&radenv->ref, radiative_env_release);
     90   return RES_OK;
     91 }
     92 
     93 res_T
     94 sdis_radiative_env_get_shader
     95   (struct sdis_radiative_env* radenv,
     96    struct sdis_radiative_env_shader* shader)
     97 {
     98   if(!radenv || !shader) return RES_BAD_ARG;
     99   *shader = radenv->shader;
    100   return RES_OK;
    101 }
    102 
    103 struct sdis_data*
    104 sdis_radiative_env_get_data(struct sdis_radiative_env* radenv)
    105 {
    106   ASSERT(radenv);
    107   return radenv->data;
    108 }