star-ck

Describe the radiative properties of gas mixtures
git clone git://git.meso-star.fr/star-ck.git
Log | Files | Refs | README | LICENSE

sck_c.h (3992B)


      1 /* Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2020, 2021 CNRS
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SCK_C_H
     18 #define SCK_C_H
     19 
     20 #include <rsys/dynamic_array_double.h>
     21 #include <rsys/logger.h>
     22 #include <rsys/ref_count.h>
     23 #include <rsys/str.h>
     24 
     25 struct mem_allocator;
     26 
     27 struct quad_pt {
     28   struct band* band; /* Band to which the quadrature point belongs */
     29   float* ka_list; /* Per node ka */
     30   size_t map_len;
     31   double weight;
     32 };
     33 
     34 static INLINE void
     35 quad_pt_init(struct mem_allocator* allocator, struct quad_pt* quad)
     36 {
     37   ASSERT(quad);
     38   (void)allocator;
     39   quad->band = NULL;
     40   quad->ka_list = NULL;
     41   quad->map_len = 0;
     42   quad->weight = 0;
     43 }
     44 
     45 extern LOCAL_SYM void
     46 quad_pt_release
     47   (struct quad_pt* quad);
     48 
     49 extern LOCAL_SYM res_T
     50 quad_pt_copy
     51   (struct quad_pt* dst,
     52    const struct quad_pt* src);
     53 
     54 static INLINE res_T
     55 quad_pt_copy_and_release(struct quad_pt* dst, struct quad_pt* src)
     56 {
     57   ASSERT(dst && src);
     58   dst->band = src->band;
     59   dst->ka_list = src->ka_list;
     60   dst->map_len = src->map_len;
     61   dst->weight = src->weight;
     62   return RES_OK;
     63 }
     64 
     65 /* Define the dynamic array of quadrature points */
     66 #define DARRAY_NAME quad_pt
     67 #define DARRAY_DATA struct quad_pt
     68 #define DARRAY_FUNCTOR_INIT quad_pt_init
     69 #define DARRAY_FUNCTOR_RELEASE quad_pt_release
     70 #define DARRAY_FUNCTOR_COPY quad_pt_copy
     71 #define DARRAY_FUNCTOR_COPY_AND_RELEASE quad_pt_copy_and_release
     72 #include <rsys/dynamic_array.h>
     73 
     74 struct band {
     75   struct sck* sck;
     76   double low; /* Lower bound in nm (inclusive) */
     77   double upp; /* Upper bound in nm (exclusive) */
     78   size_t map_len; /* 0 <=> band's data are not mapped, i.e. they are loaded */
     79   float* ks_list; /* Per node ks */
     80   struct darray_quad_pt quad_pts;
     81   struct darray_double quad_pts_cumul;
     82 };
     83 
     84 static INLINE void
     85 band_init(struct mem_allocator* allocator, struct band* band)
     86 {
     87   ASSERT(band);
     88   band->sck = NULL;
     89   band->low = DBL_MAX;
     90   band->upp =-DBL_MAX;
     91   band->map_len = 0;
     92   band->ks_list = NULL;
     93   darray_quad_pt_init(allocator, &band->quad_pts);
     94   darray_double_init(allocator, &band->quad_pts_cumul);
     95 }
     96 
     97 extern LOCAL_SYM void
     98 band_release
     99   (struct band* band);
    100 
    101 extern LOCAL_SYM res_T
    102 band_copy
    103   (struct band* dst,
    104    const struct band* src);
    105 
    106 static INLINE res_T
    107 band_copy_and_release(struct band* dst, struct band* src)
    108 {
    109   res_T res = RES_OK;
    110   ASSERT(dst && src);
    111 
    112   dst->sck = src->sck;
    113   dst->low = src->low;
    114   dst->upp = src->upp;
    115   dst->map_len = src->map_len;
    116   dst->ks_list = src->ks_list;
    117   res = darray_quad_pt_copy_and_release(&dst->quad_pts, &src->quad_pts);
    118   if(res != RES_OK) return res;
    119   res = darray_double_copy_and_release
    120     (&dst->quad_pts_cumul, &src->quad_pts_cumul);
    121   if(res != RES_OK) return res;
    122   return RES_OK;
    123 }
    124 
    125 /* Define the dynamic array of bands */
    126 #define DARRAY_NAME band
    127 #define DARRAY_DATA struct band
    128 #define DARRAY_FUNCTOR_INIT band_init
    129 #define DARRAY_FUNCTOR_RELEASE band_release
    130 #define DARRAY_FUNCTOR_COPY band_copy
    131 #define DARRAY_FUNCTOR_COPY_AND_RELEASE band_copy_and_release
    132 #include <rsys/dynamic_array.h>
    133 
    134 struct mem_allocator;
    135 
    136 struct sck {
    137   /* Loaded data */
    138   uint64_t pagesize;
    139   uint64_t nnodes;
    140   struct darray_band bands;
    141 
    142   size_t pagesize_os;
    143   struct str name; /* path/stream name */
    144 
    145   struct mem_allocator* allocator;
    146   struct logger* logger;
    147   struct logger logger__; /* Default logger */
    148   int verbose;
    149   ref_T ref;
    150 };
    151 
    152 #endif /* SCK_C_H */