rnatm

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

commit 3e8b20486a297f30a9e4c017afe061c02ea94e82
parent 6665e77837092e655c3422e51b28e2d794f14cd3
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri, 28 Oct 2022 10:30:52 +0200

Add functions rnatm_find_bands and rnatm_band_sample_quad_pt

Diffstat:
Msrc/rnatm.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/rnatm.h | 16++++++++++++++++
2 files changed, 70 insertions(+), 0 deletions(-)

diff --git a/src/rnatm.c b/src/rnatm.c @@ -381,6 +381,60 @@ rnatm_get_spectral_items_count(const struct rnatm* atm) return darray_accel_struct_size_get(&atm->accel_structs); } +res_T +rnatm_find_bands + (const struct rnatm* rnatm, + const double range[2], /* In nm. Limits are inclusive */ + size_t ibands[2]) /* Range of overlaped bands. Limits are inclusive */ +{ + double range_adjusted[2]; + + if(!rnatm + || !range + || range[0] > rnatm->spectral_range[1] + || range[1] < rnatm->spectral_range[0]) + return RES_BAD_ARG; + + /* Clamp the submitted range to the spectral domain of the atmosphere */ + range_adjusted[0] = MMAX(range[0], rnatm->spectral_range[0]); + range_adjusted[1] = MMIN(range[1], rnatm->spectral_range[1]); + + return sck_find_bands(rnatm->gas.ck, range_adjusted, ibands); +} + +res_T +rnatm_band_sample_quad_pt + (const struct rnatm* rnatm, + const double r, /* Canonical random number in [0, 1[ */ + const size_t iband, + size_t* iquad) +{ + struct sck_band band; + res_T res = RES_OK; + + if(!rnatm || !iquad) { + res = RES_BAD_ARG; + goto error; + } + + res = sck_get_band(rnatm->gas.ck, iband, &band); + if(res != RES_OK) goto error; + + /* Reject the band if it does not overlap the atmosphere spectral domain */ + if(band.lower/*Inclusive*/ > rnatm->spectral_range[1] + || band.upper/*Exclusive*/ <= rnatm->spectral_range[0]) { + return RES_BAD_ARG; + } + + res = sck_band_sample_quad_pt(&band, r, iquad); + if(res != RES_OK) goto error; + +exit: + return res; +error: + goto exit; +} + /******************************************************************************* * Local functions ******************************************************************************/ diff --git a/src/rnatm.h b/src/rnatm.h @@ -275,6 +275,22 @@ RNATM_API size_t rnatm_get_spectral_items_count (const struct rnatm* atm); +/* Returns the range of band indices covered by a given spectral range. The + * returned index range is degenerated (i.e. ibands[0] > ibands[1]) if no band + * is found */ +RNATM_API res_T +rnatm_find_bands + (const struct rnatm* rnatm, + const double range[2], /* In nm. Limits are inclusive */ + size_t ibands[2]); /* Range of overlaped bands. Limits are inclusive */ + +RNATM_API res_T +rnatm_band_sample_quad_pt + (const struct rnatm* rnatm, + const double r, /* Canonical random number in [0, 1[ */ + const size_t iband, /* Index of the band to sample */ + size_t* iquad); + /* Writes a set of octrees following the VTK file format */ RNATM_API res_T rnatm_write_vtk_octrees