rnatm

Load and structure data describing an atmosphere
git clone git://git.meso-star.fr/rnatm.git
Log | Files | Refs | README | LICENSE

rnatm_voxel_partition.h (5019B)


      1 /* Copyright (C) 2022, 2023, 2025 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2022, 2023, 2025 Institut Pierre-Simon Laplace
      3  * Copyright (C) 2022, 2023, 2025 Institut de Physique du Globe de Paris
      4  * Copyright (C) 2022, 2023, 2025 |Méso|Star> (contact@meso-star.com)
      5  * Copyright (C) 2022, 2023, 2025 Observatoire de Paris
      6  * Copyright (C) 2022, 2023, 2025 Université de Reims Champagne-Ardenne
      7  * Copyright (C) 2022, 2023, 2025 Université de Versaille Saint-Quentin
      8  * Copyright (C) 2022, 2023, 2025 Université Paul Sabatier
      9  *
     10  * This program is free software: you can redistribute it and/or modify
     11  * it under the terms of the GNU General Public License as published by
     12  * the Free Software Foundation, either version 3 of the License, or
     13  * (at your option) any later version.
     14  *
     15  * This program is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     18  * GNU General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU General Public License
     21  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     22 
     23 #ifndef RNATM_VOXEL_PARTITION_H
     24 #define RNATM_VOXEL_PARTITION_H
     25 
     26 #include "rnatm_voxel.h"
     27 
     28 #include <rsys/list.h>
     29 #include <rsys/rsys.h>
     30 
     31 struct pool_create_args {
     32   size_t partition_definition; /* #voxels along XYZ. Must be a power of 2 */
     33 
     34   size_t npartitions; /* Overall number of partitions managed by the pool */
     35   size_t voxel_width; /* Number of items for each voxel data */
     36 
     37   /* Number of pre-allocated partitions must be <= npartitions */
     38   size_t npreallocated_partitions;
     39 
     40   struct mem_allocator* allocator; /* NULL <=> default allocator */
     41 };
     42 #define POOL_CREATE_ARGS_DEFAULT__ {0, 32, 1, 32, NULL}
     43 static const struct pool_create_args POOL_CREATE_ARGS_DEFAULT =
     44   POOL_CREATE_ARGS_DEFAULT__;
     45 
     46 /******************************************************************************
     47  * Partition of voxels, i.e. subset of voxels
     48  ******************************************************************************/
     49 struct partition;
     50 
     51 extern LOCAL_SYM void
     52 partition_free
     53   (struct partition* partition);
     54 
     55 /* Commit the partitition, i.e. it can be fetched from the pool up to N times
     56  * where N is defined by ref_count */
     57 extern LOCAL_SYM void
     58 partition_commit
     59   (struct partition* partition,
     60    const size_t ref_count);
     61 
     62 extern LOCAL_SYM size_t
     63 partition_get_id
     64   (const struct partition* partition);
     65 
     66 extern LOCAL_SYM size_t
     67 partition_get_definition
     68   (const struct partition* partition);
     69 
     70 /* Empty the partition, that is, its voxels are freed. Therefore, the
     71  * partition_get_voxel function can no longer be called; you have to use the
     72  * partition_cget_voxel function instead */
     73 extern LOCAL_SYM void
     74 partition_empty
     75   (struct partition* partition);
     76 
     77 extern LOCAL_SYM float*
     78 partition_get_voxel
     79   (struct partition* partition,
     80    const size_t ivoxel,
     81    const size_t iitem);
     82 
     83 /* Returns a voxel even if the partition is empty. In the latter case, it
     84  * always returns an empty voxel */
     85 extern LOCAL_SYM const float*
     86 partition_cget_voxel
     87   (struct partition* partition,
     88    const size_t ivoxel,
     89    const size_t iitem);
     90 
     91 extern LOCAL_SYM void
     92 partition_clear_voxels
     93   (struct partition* partition);
     94 
     95 extern LOCAL_SYM void
     96 partition_accum
     97   (struct partition* dst,
     98    struct partition* src);
     99 
    100 /******************************************************************************
    101  * Partition pool, i.e. collection of partitions of voxels that are accessible
    102  * concurrently by several threads
    103  ******************************************************************************/
    104 struct pool;
    105 
    106 extern LOCAL_SYM res_T
    107 pool_create
    108   (const struct pool_create_args* args,
    109    struct pool** pool);
    110 
    111 extern LOCAL_SYM void
    112 pool_ref_get
    113   (struct pool* pool);
    114 
    115 extern LOCAL_SYM void
    116 pool_ref_put
    117   (struct pool* pool);
    118 
    119 extern LOCAL_SYM size_t
    120 pool_get_partition_definition
    121   (const struct pool* pool);
    122 
    123 extern LOCAL_SYM size_t
    124 pool_get_voxel_width
    125   (const struct pool* pool);
    126 
    127 /* Returns a free partition. Waits for a free partition to be available.
    128  * Returns NULL if an error occurs */
    129 extern LOCAL_SYM struct partition*
    130 pool_next_partition
    131   (struct pool* pool);
    132 
    133 /* Same as pool_next_partition but the returned partition has no ID (it
    134  * cannot be commited). Such a partition is used as a temporary variable */
    135 extern LOCAL_SYM struct partition*
    136 pool_dummy_partition
    137   (struct pool* pool);
    138 
    139 /* Returns the partition with the identifier 'ipartition'. Waits for the
    140  * partition to be available. Returns NULL if an error occurs */
    141 extern LOCAL_SYM struct partition*
    142 pool_fetch_partition
    143   (struct pool* pool,
    144    const size_t ipartition);
    145 
    146 /* Makes the pool invalid. Once invalidated, the 'next' and 'fetch'
    147  * functions return NULL */
    148 extern LOCAL_SYM void
    149 pool_invalidate
    150   (struct pool* pool);
    151 
    152 /* Reset the next partition to fetch to 0 */
    153 extern LOCAL_SYM void
    154 pool_reset
    155   (struct pool* pool);
    156 
    157 #endif /* RNATM_VOXEL_PARTITION_H */