rnatm_c.h (9265B)
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_C_H 24 #define RNATM_C_H 25 26 #include "rnatm.h" 27 28 #include <rsys/dynamic_array_size_t.h> 29 #include <rsys/logger.h> 30 #include <rsys/ref_count.h> 31 #include <rsys/str.h> 32 33 struct rnsf; 34 struct ssf_phase; 35 36 /* Generate the dynamic array of dynamic array of size_t */ 37 #define DARRAY_NAME size_t_list 38 #define DARRAY_DATA struct darray_size_t 39 #define DARRAY_FUNCTOR_INIT darray_size_t_init 40 #define DARRAY_FUNCTOR_RELEASE darray_size_t_release 41 #define DARRAY_FUNCTOR_COPY darray_size_t_copy 42 #define DARRAY_FUNCTOR_COPY_AND_RELEASE darray_size_t_copy_and_release 43 #include <rsys/dynamic_array.h> 44 45 /******************************************************************************* 46 * Phase function (SSF) 47 ******************************************************************************/ 48 extern LOCAL_SYM res_T 49 phase_init 50 (struct mem_allocator* allocator, 51 struct ssf_phase** phase); 52 53 extern LOCAL_SYM void 54 phase_release 55 (struct ssf_phase** phase); 56 57 extern LOCAL_SYM res_T 58 phase_copy 59 (struct ssf_phase** dst, 60 struct ssf_phase* const* src); 61 62 extern LOCAL_SYM res_T 63 phase_copy_and_release 64 (struct ssf_phase** dst, 65 struct ssf_phase** src); 66 67 /* Generate the dynamic array of SSF phase function */ 68 #define DARRAY_NAME phase 69 #define DARRAY_DATA struct ssf_phase* 70 #define DARRAY_FUNCTOR_INIT phase_init 71 #define DARRAY_FUNCTOR_RELEASE phase_release 72 #define DARRAY_FUNCTOR_COPY phase_copy 73 #define DARRAY_FUNCTOR_COPY_AND_RELEASE phase_copy_and_release 74 #include <rsys/dynamic_array.h> 75 76 /******************************************************************************* 77 * Phase function 78 ******************************************************************************/ 79 struct phase_fn { 80 struct rnsf* rnsf; 81 struct darray_phase phase_lst; 82 }; 83 84 extern LOCAL_SYM res_T 85 phase_fn_init 86 (struct mem_allocator* allocator, 87 struct phase_fn* phase_fn); 88 89 extern LOCAL_SYM void 90 phase_fn_release 91 (struct phase_fn* phase_fn); 92 93 extern LOCAL_SYM res_T 94 phase_fn_copy 95 (struct phase_fn* dst, 96 const struct phase_fn* src); 97 98 extern LOCAL_SYM res_T 99 phase_fn_copy_and_release 100 (struct phase_fn* dst, 101 struct phase_fn* src); 102 103 /* Generate the dynamic array of RNSF phase functions */ 104 #define DARRAY_NAME phase_fn 105 #define DARRAY_DATA struct phase_fn 106 #define DARRAY_FUNCTOR_INIT phase_fn_init 107 #define DARRAY_FUNCTOR_RELEASE phase_fn_release 108 #define DARRAY_FUNCTOR_COPY phase_fn_copy 109 #define DARRAY_FUNCTOR_COPY_AND_RELEASE phase_fn_copy_and_release 110 #include <rsys/dynamic_array.h> 111 112 /******************************************************************************* 113 * Gas 114 ******************************************************************************/ 115 struct gas { 116 struct suvm_volume* volume; 117 struct ssf_phase* rayleigh; 118 struct sbuf* temperatures; 119 struct sck* ck; 120 size_t ntetrahedra; 121 size_t nvertices; 122 }; 123 124 extern LOCAL_SYM res_T 125 gas_init 126 (struct mem_allocator* allocator, 127 struct gas* gas); 128 129 extern LOCAL_SYM void 130 gas_release 131 (struct gas* gas); 132 133 extern LOCAL_SYM res_T 134 gas_copy 135 (struct gas* dst, 136 const struct gas* src); 137 138 extern LOCAL_SYM res_T 139 gas_copy_and_release 140 (struct gas* dst, 141 struct gas* src); 142 143 /******************************************************************************* 144 * Aerosol 145 ******************************************************************************/ 146 struct aerosol { 147 struct darray_phase_fn phase_fn_lst; 148 struct str name; 149 struct suvm_volume* volume; 150 struct sbuf* phase_fn_ids; 151 struct sars* sars; 152 size_t ntetrahedra; 153 size_t nvertices; 154 }; 155 156 extern LOCAL_SYM res_T 157 aerosol_init 158 (struct mem_allocator* allocator, 159 struct aerosol* aerosol); 160 161 extern LOCAL_SYM void 162 aerosol_release 163 (struct aerosol* aerosol); 164 165 extern LOCAL_SYM res_T 166 aerosol_copy 167 (struct aerosol* dst, 168 const struct aerosol* src); 169 170 extern LOCAL_SYM res_T 171 aerosol_copy_and_release 172 (struct aerosol* dst, 173 struct aerosol* src); 174 175 /* Define the dynamic array of aerosols */ 176 #define DARRAY_NAME aerosol 177 #define DARRAY_DATA struct aerosol 178 #define DARRAY_FUNCTOR_INIT aerosol_init 179 #define DARRAY_FUNCTOR_RELEASE aerosol_release 180 #define DARRAY_FUNCTOR_COPY aerosol_copy 181 #define DARRAY_FUNCTOR_COPY_AND_RELEASE aerosol_copy_and_release 182 #include <rsys/dynamic_array.h> 183 184 /******************************************************************************* 185 * Acceleration structure 186 ******************************************************************************/ 187 struct accel_struct { 188 struct svx_tree* octree; 189 fpos_t fpos; /* Position of the serialized octree data in the storage file */ 190 size_t iband; /* Index of the spectral band */ 191 size_t iquad_pt; /* Index of the quadrature point */ 192 }; 193 194 extern LOCAL_SYM res_T 195 accel_struct_init 196 (struct mem_allocator* allocator, 197 struct accel_struct* accel_struct); 198 199 extern LOCAL_SYM void 200 accel_struct_release 201 (struct accel_struct* accel_struct); 202 203 extern LOCAL_SYM res_T 204 accel_struct_copy 205 (struct accel_struct* dst, 206 const struct accel_struct* src); 207 208 extern LOCAL_SYM res_T 209 accel_struct_copy_and_release 210 (struct accel_struct* dst, 211 struct accel_struct* src); 212 213 /* Define the dynamic array of acceleration structures */ 214 #define DARRAY_NAME accel_struct 215 #define DARRAY_DATA struct accel_struct 216 #define DARRAY_FUNCTOR_INIT accel_struct_init 217 #define DARRAY_FUNCTOR_RELEASE accel_struct_release 218 #define DARRAY_FUNCTOR_COPY accel_struct_copy 219 #define DARRAY_FUNCTOR_COPY_AND_RELEASE accel_struct_copy_and_release 220 #include <rsys/dynamic_array.h> 221 222 /******************************************************************************* 223 * Spectral band 224 ******************************************************************************/ 225 struct band { 226 size_t index; /* Index of the spectral band */ 227 size_t nquad_pts; /* Number of quadrature points in the band */ 228 229 /* Offset toward the first acceleration structure of the band */ 230 size_t offset_accel_struct; 231 }; 232 233 /* Define the dynamic array of spectral bands */ 234 #define DARRAY_NAME band 235 #define DARRAY_DATA struct band 236 #include <rsys/dynamic_array.h> 237 238 /******************************************************************************* 239 * Atmosphere 240 ******************************************************************************/ 241 struct rnatm { 242 struct gas gas; 243 struct darray_aerosol aerosols; 244 struct darray_accel_struct accel_structs; 245 struct darray_band bands; /* Spectral bands to be taken into account */ 246 struct str name; 247 248 FILE* octrees_storage; 249 250 unsigned grid_definition[3]; 251 252 /* Spectral range to consider (in nanometers). Limits are inclusive */ 253 double spectral_range[2]; 254 /* Ids of the bands covered by the spectral range. Limits are inclusive */ 255 size_t ibands[2]; 256 double optical_thickness; /* Threshold used during octree building */ 257 258 unsigned nthreads; 259 int verbose; 260 261 struct logger* logger; 262 struct logger logger__; 263 struct mem_allocator* allocator; 264 struct mem_allocator svx_allocator; 265 266 struct mutex* mutex; 267 268 struct svx_device* svx; 269 int svx_allocator_is_init; 270 ref_T ref; 271 }; 272 273 extern LOCAL_SYM res_T 274 setup_meshes 275 (struct rnatm* atm, 276 const struct rnatm_create_args* args); 277 278 extern LOCAL_SYM res_T 279 setup_properties 280 (struct rnatm* atm, 281 const struct rnatm_create_args* args); 282 283 extern LOCAL_SYM res_T 284 check_properties 285 (const struct rnatm* atm); 286 287 extern LOCAL_SYM res_T 288 setup_octrees 289 (struct rnatm* atm, 290 const struct rnatm_create_args* args); 291 292 extern LOCAL_SYM res_T 293 make_sure_octree_is_loaded 294 (struct rnatm* atm, 295 const size_t iaccel_struct); 296 297 extern LOCAL_SYM void 298 unload_octree 299 (struct rnatm* atm, 300 const size_t iaccel_struct); 301 302 /* Get the radiative coefficient of the input tetrahedron. The output radiative 303 * coefficients per vertex are defined even if the tetrahedron is invalid or if 304 * no spectral data is defined for this component for the considered band. In 305 * such cases, the k returned are zero and the function returns 0 instead of 1*/ 306 extern LOCAL_SYM int 307 tetra_get_radcoef 308 (const struct rnatm* atm, 309 const struct suvm_primitive* tetra, 310 const size_t component, 311 const size_t iband, 312 const size_t iquad_pt, 313 const enum rnatm_radcoef radcoef, 314 float k[4]); 315 316 #endif /* RNATM_C_H */