htgop

Optical properties of a gas mixture
git clone git://git.meso-star.fr/htgop.git
Log | Files | Refs | README | LICENSE

commit 782c5a211aaf4a79c94bd5dee2935d328670daa3
parent 5ef0e34476fba5b4ce137351c1eb0305fb8e29d1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  3 Aug 2018 17:12:02 +0200

Test the get_radiative_properties_bounds functions

Diffstat:
Mcmake/CMakeLists.txt | 10++++++++--
Msrc/htgop_fetch_radiative_properties.h | 5-----
Msrc/htgop_get_radiative_properties_bounds.h | 5-----
Asrc/test_htgop_get_radiative_properties_bounds.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/test_htgop_get_radiative_properties_bounds.h | 202+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 270 insertions(+), 12 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -108,15 +108,21 @@ if(NOT NO_TEST) new_test(test_htgop) build_test(test_htgop_fetch_radiative_properties) + build_test(test_htgop_get_radiative_properties_bounds) build_test(test_htgop_load) build_test(test_htgop_sample) + add_test(test_htgop_fetch_radiative_properties + test_htgop_fetch_radiative_properties + ${HTGOP_ETC_DIRECTORY}/ecrad_opt_prop.txt) + add_test(test_htgop_get_radiative_properties_bounds + test_htgop_get_radiative_properties_bounds + ${HTGOP_ETC_DIRECTORY}/ecrad_opt_prop.txt) add_test(test_htgop_load test_htgop_load ${HTGOP_ETC_DIRECTORY}/ecrad_opt_prop.txt) add_test(test_htgop_sample test_htgop_sample ${HTGOP_ETC_DIRECTORY}/ecrad_opt_prop.txt) - add_test(test_htgop_fetch_radiative_properties - test_htgop_fetch_radiative_properties ${HTGOP_ETC_DIRECTORY}/ecrad_opt_prop.txt) + endif() ################################################################################ diff --git a/src/htgop_fetch_radiative_properties.h b/src/htgop_fetch_radiative_properties.h @@ -13,16 +13,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef HTGOP_FETCH_RADIATIVE_PROPERTIES_H -#define HTGOP_FETCH_RADIATIVE_PROPERTIES_H - #include "htgop.h" #include "htgop_c.h" #include <rsys/algorithm.h> -#endif /* HTGOP_FETCH_RADIATIVE_PROPERTIES_H */ - #if !defined(DATA) || !defined(DOMAIN) #error "Missing the <DATA|DOMAIN> macro." #endif diff --git a/src/htgop_get_radiative_properties_bounds.h b/src/htgop_get_radiative_properties_bounds.h @@ -13,14 +13,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef HTGOP_GET_RADIATIVE_PROPERTIES_BOUNDS_H -#define HTGOP_GET_RADIATIVE_PROPERTIES_BOUNDS_H - #include "htgop.h" #include "htgop_c.h" -#endif /* HTGOP_GET_RADIATIVE_PROPERTIES_BOUNDS_H */ - #if !defined(DATA) || !defined(DOMAIN) #error "Missing the <DATA|DOMAIN> macro." #endif diff --git a/src/test_htgop_get_radiative_properties_bounds.c b/src/test_htgop_get_radiative_properties_bounds.c @@ -0,0 +1,60 @@ +/* Copyright (C) |Meso|Star> 2018 (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "htgop.h" +#include "test_htgop_utils.h" + +#include <rsys/math.h> +#include <float.h> + +/* Generate the check_layer_lw_ka_bounds */ +#define DOMAIN lw +#define DATA ka +#include "test_htgop_get_radiative_properties_bounds.h" +/* Generate the check_layer_sw_ka_bounds */ +#define DOMAIN sw +#define DATA ka +#include "test_htgop_get_radiative_properties_bounds.h" +/* Generate the check_layer_sw_ks_bounds */ +#define DOMAIN sw +#define DATA ks +#include "test_htgop_get_radiative_properties_bounds.h" + +int +main(int argc, char** argv) +{ + struct mem_allocator allocator; + struct htgop* htgop; + + if(argc < 2) { + fprintf(stderr, "Usage: %s FILENAME\n", argv[0]); + return 1; + } + + CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); + CHK(htgop_create(NULL, &allocator, 1, &htgop) == RES_OK); + CHK(htgop_load(htgop, argv[1]) == RES_OK); + + check_layer_lw_ka_bounds(htgop); + check_layer_sw_ka_bounds(htgop); + check_layer_sw_ks_bounds(htgop); + + CHK(htgop_ref_put(htgop) == RES_OK); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHK(mem_allocated_size() == 0); + return 0; +} diff --git a/src/test_htgop_get_radiative_properties_bounds.h b/src/test_htgop_get_radiative_properties_bounds.h @@ -0,0 +1,202 @@ +/* Copyright (C) |Meso|Star> 2018 (contact@meso-star.com) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "htgop.h" +#include "htgop_c.h" + +#if !defined(DATA) || !defined(DOMAIN) + #error "Missing the <DATA|DOMAIN> macro." +#endif + +/* Helper macros */ +#define GET_NSPECINTS \ + CONCAT(CONCAT(htgop_get_, DOMAIN), _spectral_intervals_count) +#define GET_SPECINT \ + CONCAT(CONCAT(htgop_get_, DOMAIN), _spectral_interval) +#define LAY_GET_BOUNDS \ + CONCAT(CONCAT(CONCAT(CONCAT(htgop_layers_get_,DOMAIN),_),DATA),_bounds) +#define LAY_SPECINT_QUADS_GET_BOUNDS \ + CONCAT(CONCAT(CONCAT(CONCAT( \ + htgop_layer_,DOMAIN),_spectral_interval_quadpoints_get_),DATA),_bounds) +#define LAY_SPECINT_TAB_GET_BOUNDS \ + CONCAT(CONCAT(CONCAT(CONCAT( \ + htgop_layer_,DOMAIN),_spectral_interval_tab_get_),DATA),_bounds) +#define LAY_SPECINT \ + CONCAT(CONCAT(htgop_layer_, DOMAIN),_spectral_interval) +#define LAY_SPECINT_TAB \ + CONCAT(CONCAT(htgop_layer_, DOMAIN),_spectral_interval_tab) +#define GET_LAY_SPECINT \ + CONCAT(CONCAT(htgop_layer_get_, DOMAIN), _spectral_interval) +#define GET_LAY_SPECINT_TAB \ + CONCAT(CONCAT(htgop_layer_, DOMAIN), _spectral_interval_get_tab) +#define K_TAB CONCAT(DATA, _tab) + +static void CONCAT(CONCAT(CONCAT(CONCAT( +check_layer_,DOMAIN),_),DATA),_bounds)(struct htgop* htgop) +{ + struct htgop_layer lay; + struct LAY_SPECINT band; + size_t nlays, nbands; + size_t ilay, iband; + size_t band_range[2]; + size_t lay_range[2]; + size_t quad_range[2]; + double bounds[2]; + + CHK(GET_NSPECINTS(htgop, &nbands) == RES_OK); + CHK(htgop_get_layers_count(htgop, &nlays) == RES_OK); + + CHK(nlays && nbands); + + lay_range[0] = lay_range[1] = 0; + band_range[0] = band_range[1] = 0; + CHK(LAY_GET_BOUNDS(NULL, lay_range, band_range, bounds) == RES_BAD_ARG); + CHK(LAY_GET_BOUNDS(htgop, NULL, band_range, bounds) == RES_BAD_ARG); + CHK(LAY_GET_BOUNDS(htgop, lay_range, NULL, bounds) == RES_BAD_ARG); + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, NULL) == RES_BAD_ARG); + + lay_range[1] = nlays; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, bounds) == RES_BAD_ARG); + lay_range[1] = 0; + band_range[1] = nlays; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, bounds) == RES_BAD_ARG); + band_range[1] = 0; + + if(nlays > 1) { + lay_range[0] = 1; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, bounds) == RES_BAD_ARG); + lay_range[0] = 0; + } + if(nbands > 1) { + band_range[0] = 1; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, bounds) == RES_BAD_ARG); + band_range[0] = 0; + } + + CHK(htgop_get_layer(htgop, 0, &lay) == RES_OK); + CHK(GET_LAY_SPECINT(&lay, 0, &band) == RES_OK); + + CHK(band.quadrature_length); + quad_range[0] = quad_range[1] = 0; + CHK(LAY_SPECINT_QUADS_GET_BOUNDS(NULL, quad_range, bounds) == RES_BAD_ARG); + CHK(LAY_SPECINT_QUADS_GET_BOUNDS(&band, NULL, bounds) == RES_BAD_ARG); + CHK(LAY_SPECINT_QUADS_GET_BOUNDS(&band, quad_range, NULL) == RES_BAD_ARG); + + quad_range[1] = band.quadrature_length; + CHK(LAY_SPECINT_QUADS_GET_BOUNDS(&band, quad_range, bounds) == RES_BAD_ARG); + quad_range[1] = 0; + if(band.quadrature_length) { + quad_range[0] = 1; + CHK(LAY_SPECINT_QUADS_GET_BOUNDS(&band, quad_range, bounds) == RES_BAD_ARG); + quad_range[0] = 0; + } + + FOR_EACH(iband, 0, nbands) { + double band_bounds[2] = {DBL_MAX, -DBL_MAX}; + + FOR_EACH(ilay, 0, nlays) { + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + + band_range[0] = iband; + band_range[1] = iband; + lay_range[0] = ilay; + lay_range[1] = ilay; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, bounds) == RES_OK); + + band_bounds[0] = MMIN(band_bounds[0], bounds[0]); + band_bounds[1] = MMAX(band_bounds[1], bounds[1]); + + lay_range[0] = 0; + lay_range[1] = ilay; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, bounds) == RES_OK); + + CHK(bounds[0] == band_bounds[0]); + CHK(bounds[1] == band_bounds[1]); + } + } + + FOR_EACH(ilay, 0, nlays) { + double lay_bounds[2] = {DBL_MAX, -DBL_MAX}; + + CHK(htgop_get_layer(htgop, ilay, &lay) == RES_OK); + + FOR_EACH(iband, 0, nbands) { + double band_bounds[2] = {DBL_MAX, -DBL_MAX}; + double band_bounds_tmp[2] = {DBL_MAX, -DBL_MAX}; + size_t iquad; + + CHK(GET_LAY_SPECINT(&lay, iband, &band) == RES_OK); + + FOR_EACH(iquad, 0, band.quadrature_length) { + struct LAY_SPECINT_TAB tab; + double quad_bounds[2] = {DBL_MAX, -DBL_MAX}; + double quad_bounds_tmp[2] = {DBL_MAX, -DBL_MAX}; + size_t itab; + + CHK(GET_LAY_SPECINT_TAB(&band, iquad, &tab) == RES_OK); + + CHK(LAY_SPECINT_TAB_GET_BOUNDS(&tab, quad_bounds) == RES_OK); + + FOR_EACH(itab, 0, tab.tab_length) { + quad_bounds_tmp[0] = MMIN(quad_bounds_tmp[0], tab.K_TAB[itab]); + quad_bounds_tmp[1] = MMAX(quad_bounds_tmp[1], tab.K_TAB[itab]); + } + CHK(quad_bounds[0] == quad_bounds_tmp[0]); + CHK(quad_bounds[1] == quad_bounds_tmp[1]); + band_bounds_tmp[0] = MMIN(band_bounds_tmp[0], quad_bounds[0]); + band_bounds_tmp[1] = MMAX(band_bounds_tmp[1], quad_bounds[1]); + + quad_range[0] = 0; + quad_range[1] = iquad; + CHK(LAY_SPECINT_QUADS_GET_BOUNDS + (&band, quad_range, quad_bounds_tmp) == RES_OK); + + CHK(quad_bounds_tmp[0] == band_bounds_tmp[0]); + CHK(quad_bounds_tmp[1] == band_bounds_tmp[1]); + } + + band_range[0] = iband; + band_range[1] = iband; + lay_range[0] = ilay; + lay_range[1] = ilay; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, band_bounds) == RES_OK); + CHK(band_bounds[0] == band_bounds_tmp[0]); + CHK(band_bounds[1] == band_bounds_tmp[1]); + + lay_bounds[0] = MMIN(lay_bounds[0], band_bounds[0]); + lay_bounds[1] = MMAX(lay_bounds[1], band_bounds[1]); + + band_range[0] = 0; + band_range[1] = iband; + CHK(LAY_GET_BOUNDS(htgop, lay_range, band_range, band_bounds) == RES_OK); + CHK(lay_bounds[0] == band_bounds[0]); + CHK(lay_bounds[1] == band_bounds[1]); + } + } +} + +#undef GET_NSPECINTS +#undef GET_SPECINT +#undef LAY_GET_BOUNDS +#undef LAY_SPECINT_QUADS_GET_BOUNDS +#undef LAY_SPECINT_TAB_GET_BOUNDS +#undef LAY_SPECINT +#undef LAY_SPECINT_TAB +#undef GET_LAY_SPECINT +#undef GET_LAY_SPECINT_TAB +#undef K_TAB +#undef DOMAIN +#undef DATA