shtr_line_list_c.h (4458B)
1 /* Copyright (C) 2022, 2025, 2026 |Méso|Star> (contact@meso-star.com) 2 * Copyright (C) 2025, 2026 Université de Lorraine 3 * Copyright (C) 2022 Centre National de la Recherche Scientifique 4 * Copyright (C) 2022 Université Paul Sabatier 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 18 19 #ifndef SHTR_LINE_LIST_C_H 20 #define SHTR_LINE_LIST_C_H 21 22 #include "shtr.h" 23 24 #include <rsys/dynamic_array.h> 25 #include <rsys/ref_count.h> 26 27 /* 28 * Brief summary of the design 29 * 30 * Since the number of lines can be very large, one of the challenges is to 31 * reduce the memory footprint. Several line parameters are therefore encoded 32 * with reduced precision (see “struct line”). 33 * 34 * Lines are saved in memory blocks of BLOCK_SIZE, stored in a dynamic arrayf. 35 * Using a dynamic array of memory blocks rather than a simple dynamic array of 36 * contiguous bytes is motivated by the issue of additional memory overhead 37 * associated with the use of dynamic arrays for which the overall number of 38 * entries is unknown. On the worst case, the memory overhead here is equal to 39 * twice the number of blocks multiplied by the size of a pointer, compared to 40 * twice the size required to store all the lines. 41 */ 42 43 /* Size in bytes of a memory block in which compressed data is stored */ 44 #define BLOCK_SIZE (1024*1024) 45 46 struct line { 47 double wavenumber; /* Central wavenumber in vacuum [cm^-1] */ 48 double intensity; /* Reference intensity [cm^-1/(molec.cm^2)] */ 49 float lower_state_energy; /* [cm^-1] */ 50 float delta_air; /* Air-pressure wavenumber shift [cm^-1.atm^-1] */ 51 52 /* Packed data on 4 bytes: 53 * - gamma_air in fixed precision (integer: 0; fractional: 14) 54 * - gamma_self in fixed precision (integer: 0; fractional: 14) 55 * - isotope_id_local on 4 bits. 56 * 57 * Note that the The value of the isotopic index is _not_ the value of the 58 * isotopic index read from the HITRAN file. The original value is in [0, 9] 59 * with 0 actually meaning 10. Thus, once decoded, the index is located in [1, 60 * 10]. The next member variable simply stores this index but decremented by 61 * one in order to make it compatible with C indexing. As a result, it can be 62 * used directly to index the 'isotopes' array of a 'shtr_molecule' data 63 * structure loaded from an isotope metadata file */ 64 int32_t gair14_gself14_isoid4; 65 66 /* Temperature-dependent exponent. This is actually a floating-point number 67 * with the last 7 bits of the mantissa disabled. They store the molecule 68 * identifier. */ 69 int32_t nair25_molid7; 70 }; 71 #define LINE_NULL__ {0} 72 static const struct line LINE_NULL = LINE_NULL__; 73 74 STATIC_ASSERT(sizeof(struct line)==32, Unexpected_sizeof_struct_line); 75 76 /* Ensure that a block is filled with lines data, i.e., it does not contain any 77 * padding bytes, so that once a list of blocks is serialized, the resulting 78 * data forms a continuous list of lines. This ensures that lines can be loaded 79 * into memory blocks from anywhere in the list, without worrying about the 80 * layout of the original blocks */ 81 STATIC_ASSERT((BLOCK_SIZE % sizeof(struct line)) == 0, Unexpected_sizeof_block); 82 83 /* Generate the dynamic array of char*, the dynamic array of memory blocks */ 84 #define DARRAY_NAME charp 85 #define DARRAY_DATA char* 86 #include <rsys/dynamic_array.h> 87 88 /* Version of the line list. One should increment it and perform a version 89 * management onto serialized data when the line list structure is updated. */ 90 static const int SHTR_LINE_LIST_VERSION = 2; 91 92 /* Forward declaration */ 93 struct cache; 94 95 struct shtr_line_list { 96 /* Lines sorted in ascending order wrt their wavenumber */ 97 struct darray_charp blocks; /* Memory where compressed lines are stored */ 98 size_t nlines; /* Overall number of lines */ 99 100 /* Informations on line parameters */ 101 struct shtr_line_list_info info; 102 103 struct shtr* shtr; 104 ref_T ref; 105 }; 106 107 #endif /* SHTR_LINE_LIST_C_H */