rnatm

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

rnatm_voxel.h (3053B)


      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_H
     24 #define RNATM_VOXEL_H
     25 
     26 #include "rnatm.h"
     27 
     28 /*
     29  * Memory layout of a voxel
     30  * ------------------------
     31  *
     32  * The data of a voxel are stored in a list of 4 single-precision floating-point
     33  * numbers ka_min, ka_max, ks_min, ks_max.  For a given voxel, the data
     34  * corresponding to the operation 'O' on the coefficient 'C' are stored at the
     35  * index 'id' between [0, N-1] and calculated as follows:
     36  *
     37  *    id = C * RNATM_SVX_OPS_COUNT__ + O
     38  */
     39 
     40 /* Total number of floating-point numbers per voxel */
     41 #define NFLOATS_PER_VOXEL 4
     42 
     43 /* Calculate the data index of voxel */
     44 static FINLINE size_t
     45 voxel_idata
     46   (const enum rnatm_radcoef radcoef,
     47    const enum rnatm_svx_op op)
     48 {
     49   ASSERT(radcoef == RNATM_RADCOEF_Ka || radcoef == RNATM_RADCOEF_Ks);
     50   ASSERT((unsigned)op < RNATM_SVX_OPS_COUNT__);
     51   return radcoef*RNATM_SVX_OPS_COUNT__ + op;
     52 }
     53 
     54 static FINLINE void
     55 voxel_clear(float* voxel)
     56 {
     57   voxel[voxel_idata(RNATM_RADCOEF_Ka, RNATM_SVX_OP_MIN)] = FLT_MAX;
     58   voxel[voxel_idata(RNATM_RADCOEF_Ka, RNATM_SVX_OP_MAX)] =-FLT_MAX;
     59   voxel[voxel_idata(RNATM_RADCOEF_Ks, RNATM_SVX_OP_MIN)] = FLT_MAX;
     60   voxel[voxel_idata(RNATM_RADCOEF_Ks, RNATM_SVX_OP_MAX)] =-FLT_MAX;
     61 }
     62 
     63 static FINLINE void
     64 voxel_accum(float* dst, const float* src)
     65 {
     66   const size_t ka_min = voxel_idata(RNATM_RADCOEF_Ka, RNATM_SVX_OP_MIN);
     67   const size_t ka_max = voxel_idata(RNATM_RADCOEF_Ka, RNATM_SVX_OP_MAX);
     68   const size_t ks_min = voxel_idata(RNATM_RADCOEF_Ks, RNATM_SVX_OP_MIN);
     69   const size_t ks_max = voxel_idata(RNATM_RADCOEF_Ks, RNATM_SVX_OP_MAX);
     70   ASSERT(dst && src);
     71 
     72   if(src[ka_max] < src[ka_min]) return; /* Discard empty voxel */
     73   ASSERT(src[ks_max] >= src[ks_min]);
     74 
     75   dst[ka_max] += src[ka_max];
     76   dst[ks_max] += src[ks_max];
     77   dst[ka_min] = MMIN(dst[ka_min], src[ka_min]);
     78   dst[ks_min] = MMIN(dst[ks_min], src[ks_min]);
     79 }
     80 
     81 #endif /* RNATM_VOXEL_H */