htgop

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

commit 03d054f2f1fc87c5e6469731dfa9952f1b4c9817
parent ad6902011ff7d23bf4d4a14eacffe8790c5313cb
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  3 Aug 2018 11:24:36 +0200

Upd the get radiative properties bounds API + clean-up & refactoring

Diffstat:
Mcmake/CMakeLists.txt | 2+-
Msrc/htgop.c | 153++++++++++++++++++++++++++++++++++---------------------------------------------
Msrc/htgop.h | 42++++++++++++++++++++++++++++--------------
Dsrc/htgop_fetch_radiative_properties.c | 38--------------------------------------
Msrc/htgop_fetch_radiative_properties.h | 34++++++++++++++++++++--------------
Asrc/htgop_get_radiative_properties_bounds.h | 189+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/htgop_parse_layers_spectral_intervals_data.h | 22++++++++++++++--------
7 files changed, 318 insertions(+), 162 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -42,11 +42,11 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set(HTGOP_FILES_SRC htgop.c - htgop_fetch_radiative_properties.c htgop_sample_sw_spectral_interval_CIE_1931_XYZ.c) set(HTGOP_FILES_INC htgop_c.h htgop_fetch_radiative_properties.h + htgop_get_radiative_properties_bounds.h htgop_layer.h htgop_parse_layers_spectral_intervals_data.h htgop_reader.h diff --git a/src/htgop.c b/src/htgop.c @@ -136,16 +136,16 @@ error: } /* Generate the parse_layers_spectral_intervals_ka_lw function */ -#define LAYER_SPECINT_DATA ka -#define LAYER_SPECINT_DOMAIN lw +#define DOMAIN lw +#define DATA ka #include "htgop_parse_layers_spectral_intervals_data.h" /* Generate the parse_layers_spectral_intervals_ka_sw function */ -#define LAYER_SPECINT_DATA ka -#define LAYER_SPECINT_DOMAIN sw +#define DOMAIN sw +#define DATA ka #include "htgop_parse_layers_spectral_intervals_data.h" /* Generate the parse_layers_spectral_intervals_ks_sw function */ -#define LAYER_SPECINT_DATA ks -#define LAYER_SPECINT_DOMAIN sw +#define DOMAIN sw +#define DATA ks #include "htgop_parse_layers_spectral_intervals_data.h" static res_T @@ -500,7 +500,8 @@ htgop_get_layer if(!htgop || !layer) return RES_BAD_ARG; HTGOP(get_layers_count(htgop, &n)); if(ilayer >= n) { - log_err(htgop, "%s: invalid layer `%lu'.\n", FUNC_NAME, ilayer); + log_err(htgop, "%s: invalid layer `%lu'.\n", + FUNC_NAME, (unsigned long)ilayer); return RES_BAD_ARG; } l = darray_layer_cdata_get(&htgop->layers) + ilayer; @@ -512,6 +513,7 @@ htgop_get_layer layer->sw_spectral_intervals_count = darray_lay_sw_specint_size_get(&l->sw_specints); layer->data__ = l; + layer->htgop = htgop; return RES_OK; } @@ -524,11 +526,16 @@ htgop_layer_get_lw_spectral_interval const struct layer* l; const struct layer_lw_spectral_interval* lspecint; if(!layer || !specint) return RES_BAD_ARG; - if(ispecint >= layer->lw_spectral_intervals_count) return RES_BAD_ARG; + if(ispecint >= layer->lw_spectral_intervals_count) { + log_err(layer->htgop, "%s: invalid spectral interval `%lu'.\n", + FUNC_NAME, (unsigned long)ispecint); + return RES_BAD_ARG; + } l = layer->data__; lspecint = darray_lay_lw_specint_cdata_get(&l->lw_specints) + ispecint; specint->ka_nominal = darray_double_cdata_get(&lspecint->ka_nominal); specint->quadrature_length = darray_double_size_get(&lspecint->ka_nominal); + specint->htgop = layer->htgop; specint->data__ = lspecint; return RES_OK; } @@ -542,12 +549,17 @@ htgop_layer_get_sw_spectral_interval const struct layer* l; const struct layer_sw_spectral_interval* lspecint; if(!layer || !specint) return RES_BAD_ARG; - if(ispecint >= layer->sw_spectral_intervals_count) return RES_BAD_ARG; + if(ispecint >= layer->sw_spectral_intervals_count) { + log_err(layer->htgop, "%s: invalid spectral interval `%lu'.\n", + FUNC_NAME, (unsigned long)ispecint); + return RES_BAD_ARG; + } l = layer->data__; lspecint = darray_lay_sw_specint_cdata_get(&l->sw_specints) + ispecint; specint->ka_nominal = darray_double_cdata_get(&lspecint->ka_nominal); specint->ks_nominal = darray_double_cdata_get(&lspecint->ks_nominal); specint->quadrature_length = darray_double_size_get(&lspecint->ka_nominal); + specint->htgop = layer->htgop; specint->data__ = lspecint; return RES_OK; } @@ -561,11 +573,16 @@ htgop_layer_lw_spectral_interval_get_tab const struct layer_lw_spectral_interval* lspecint; const struct darray_double* t; if(!specint || !tab) return RES_BAD_ARG; - if(iquad >= specint->quadrature_length) return RES_BAD_ARG; + if(iquad >= specint->quadrature_length) { + log_err(specint->htgop, "%s: invalid quadrature point `%lu'.\n", + FUNC_NAME, (unsigned long)iquad); + return RES_BAD_ARG; + } lspecint = specint->data__; t = darray_dbllst_cdata_get(&lspecint->ka_tab) + iquad; tab->ka_tab = darray_double_cdata_get(t); tab->tab_length = darray_double_size_get(t); + tab->htgop = specint->htgop; return RES_OK; } @@ -579,13 +596,18 @@ htgop_layer_sw_spectral_interval_get_tab const struct darray_double* ka_tab; const struct darray_double* ks_tab; if(!specint || !tab) return RES_BAD_ARG; - if(iquad >= specint->quadrature_length) return RES_BAD_ARG; + if(iquad >= specint->quadrature_length) { + log_err(specint->htgop, "%s: invalid quadrature point `%lu'.\n", + FUNC_NAME, (unsigned long)iquad); + return RES_BAD_ARG; + } lspecint = specint->data__; ka_tab = darray_dbllst_cdata_get(&lspecint->ka_tab) + iquad; ks_tab = darray_dbllst_cdata_get(&lspecint->ks_tab) + iquad; tab->ka_tab = darray_double_cdata_get(ka_tab); tab->ks_tab = darray_double_cdata_get(ks_tab); tab->tab_length = darray_double_size_get(ka_tab); + tab->htgop = specint->htgop; return RES_OK; } @@ -648,7 +670,7 @@ htgop_get_lw_spectral_interval interval->quadrature_pdf = darray_double_cdata_get(&quad_pdfs[ispecint]); interval->quadrature_cdf = darray_double_cdata_get(&quad_cdfs[ispecint]); interval->quadrature_length = darray_double_size_get(&quad_pdfs[ispecint]); - interval->data__ = htgop; + interval->htgop = htgop; return RES_OK; } @@ -677,7 +699,7 @@ htgop_get_sw_spectral_interval interval->quadrature_pdf = darray_double_cdata_get(&quad_pdfs[ispecint]); interval->quadrature_cdf = darray_double_cdata_get(&quad_cdfs[ispecint]); interval->quadrature_length = darray_double_size_get(&quad_pdfs[ispecint]); - interval->data__ = htgop; + interval->htgop = htgop; return RES_OK; } @@ -687,16 +709,15 @@ htgop_spectral_interval_sample_quadrature const double r, /* Canonical number in [0, 1[ */ size_t* iquad_point) /* Id of the sample quadrature point */ { - const struct htgop* htgop; double r_next = nextafter(r, DBL_MAX); double* find; size_t i; if(!specint || !iquad_point) return RES_BAD_ARG; - htgop = specint->data__; if(r < 0 || r >= 1) { - log_err(htgop, "%s: invalid canonical random number `%g'.\n", FUNC_NAME, r); + log_err(specint->htgop, + "%s: invalid canonical random number `%g'.\n", FUNC_NAME, r); return RES_BAD_ARG; } @@ -749,77 +770,35 @@ htgop_position_to_layer_id return RES_OK; } -#define DEFINE_LAYER_GET_K_BOUNDS(Domain, Data) \ - res_T \ - htgop_layer_get_##Domain##_##Data##_bounds \ - (const struct htgop_layer* layer, double bounds[2]) \ - { \ - size_t i; \ - if(!layer || !bounds) return RES_BAD_ARG; \ - bounds[0] = DBL_MAX; \ - bounds[1] =-DBL_MAX; \ - FOR_EACH(i, 0, layer->Domain##_spectral_intervals_count) { \ - struct htgop_layer_##Domain##_spectral_interval band; \ - double tmp[2]; \ - HTGOP(layer_get_##Domain##_spectral_interval(layer, i, &band)); \ - HTGOP(layer_##Domain##_spectral_interval_get_##Data##_bounds \ - (&band, tmp)); \ - bounds[0] = MMIN(bounds[0], tmp[0]); \ - bounds[1] = MMAX(bounds[1], tmp[1]); \ - } \ - return RES_OK; \ - } -DEFINE_LAYER_GET_K_BOUNDS(lw, ka) -DEFINE_LAYER_GET_K_BOUNDS(sw, ka) -DEFINE_LAYER_GET_K_BOUNDS(sw, ks) -#undef DEFINE_LAYER_GET_K_BOUNDS - -#define DEFINE_LAYER_SPECTRAL_INTERVAL_GET_K_BOUNDS(Domain, Data) \ - res_T \ - htgop_layer_##Domain##_spectral_interval_get_##Data##_bounds \ - (const struct htgop_layer_##Domain##_spectral_interval* band, \ - double bounds[2]) \ - { \ - size_t i; \ - if(!band || !bounds) return RES_BAD_ARG; \ - bounds[0] = DBL_MAX; \ - bounds[1] =-DBL_MAX; \ - FOR_EACH(i, 0, band->quadrature_length) { \ - struct htgop_layer_##Domain##_spectral_interval_tab tab; \ - double tmp[2]; \ - HTGOP(layer_##Domain##_spectral_interval_get_tab(band, i, &tab)); \ - HTGOP(layer_##Domain##_spectral_interval_tab_get_##Data##_bounds \ - (&tab, tmp)); \ - bounds[0] = MMIN(bounds[0], tmp[0]); \ - bounds[1] = MMAX(bounds[1], tmp[1]); \ - } \ - return RES_OK; \ - } -DEFINE_LAYER_SPECTRAL_INTERVAL_GET_K_BOUNDS(lw, ka) -DEFINE_LAYER_SPECTRAL_INTERVAL_GET_K_BOUNDS(sw, ka) -DEFINE_LAYER_SPECTRAL_INTERVAL_GET_K_BOUNDS(sw, ks) -#undef DEFINE_LAYER_SPECTRAL_INTERVAL_GET_K_BOUNDS - -#define DEFINE_LAYER_SPECTRAL_INTERVAL_TAB_GET_K_BOUNDS(Domain, Data) \ - res_T \ - htgop_layer_##Domain##_spectral_interval_tab_get_##Data##_bounds \ - (const struct htgop_layer_##Domain##_spectral_interval_tab* tab, \ - double bounds[2]) \ - { \ - size_t i; \ - if(!tab || !bounds) return RES_BAD_ARG; \ - bounds[0] = DBL_MAX; \ - bounds[1] =-DBL_MAX; \ - FOR_EACH(i, 0, tab->tab_length) { \ - bounds[0] = MMIN(bounds[0], tab->ka_tab[i]); \ - bounds[1] = MMAX(bounds[1], tab->ka_tab[i]); \ - } \ - return RES_OK; \ - } -DEFINE_LAYER_SPECTRAL_INTERVAL_TAB_GET_K_BOUNDS(lw, ka) -DEFINE_LAYER_SPECTRAL_INTERVAL_TAB_GET_K_BOUNDS(sw, ka) -DEFINE_LAYER_SPECTRAL_INTERVAL_TAB_GET_K_BOUNDS(sw, ks) -#undef DEFINE_LAYER_SPECTRAL_INTERVAL_TAB_GET_K_BOUNDS +/* Generate the htgop_layer_fetch_lw_ka function */ +#define DOMAIN lw +#define DATA ka +#include "htgop_fetch_radiative_properties.h" + +/* Generate the htgop_layer_fetch_sw_ka function */ +#define DOMAIN sw +#define DATA ka +#include "htgop_fetch_radiative_properties.h" + +/* Generate the htgop_layer_fetch_sw_ks function */ +#define DOMAIN sw +#define DATA ks +#include "htgop_fetch_radiative_properties.h" + +/* Generate the functions that get the boundaries of ka in LW */ +#define DOMAIN lw +#define DATA ka +#include "htgop_get_radiative_properties_bounds.h" + +/* Generate the functions that get the boundaries of ka in SW */ +#define DOMAIN sw +#define DATA ka +#include "htgop_get_radiative_properties_bounds.h" + +/* Generate the functions that get the boundaries of ks in SW */ +#define DOMAIN sw +#define DATA ks +#include "htgop_get_radiative_properties_bounds.h" /******************************************************************************* * Local functions diff --git a/src/htgop.h b/src/htgop.h @@ -31,9 +31,9 @@ * returns an error. One should use this macro on htgop function calls for * which no explicit error checking is performed */ #ifndef NDEBUG - #define HTGOP(Func) ASSERT(htgop_ ## Func == RES_OK) + #define HTGOP(Func) ASSERT(CONCAT(htgop_, Func) == RES_OK) #else - #define HTGOP(Func) htgop_ ## Func + #define HTGOP(Func) CONCAT(htgop_, Func) #endif /* Forward declaration of external data types */ @@ -54,7 +54,7 @@ struct htgop_spectral_interval { const double* quadrature_pdf; /* Normalized PDF of the quadrature */ const double* quadrature_cdf; /* CDF of the quadrature */ size_t quadrature_length; /* #quadrature points of the interval */ - const void* data__; /* Internal data */ + const struct htgop* htgop; }; struct htgop_level { @@ -69,24 +69,28 @@ struct htgop_layer { size_t tab_length; /* Length of the tabulated xH2O */ size_t lw_spectral_intervals_count; size_t sw_spectral_intervals_count; + const struct htgop* htgop; const void* data__; /* Internal data */ }; struct htgop_layer_lw_spectral_interval { const double* ka_nominal; /* Per quadrature point absorption coef */ size_t quadrature_length; + const struct htgop* htgop; const void* data__; /* Internal data */ }; struct htgop_layer_lw_spectral_interval_tab { const double* ka_tab; /* Tabulated absorption coef */ size_t tab_length; /* == lengh of the tabulated xH2O */ + const struct htgop* htgop; }; struct htgop_layer_sw_spectral_interval { const double* ka_nominal; /* Per quadrature point absorption coef */ const double* ks_nominal; /* Per quadrature point scattering coef */ size_t quadrature_length; + const struct htgop* htgop; const void* data__; /* Internal data */ }; @@ -94,6 +98,7 @@ struct htgop_layer_sw_spectral_interval_tab { const double* ka_tab; /* Tabulated absorption coef */ const double* ks_tab; /* Tabulated scattering coef */ size_t tab_length; /* == lengh of the tabulated xH2O */ + const struct htgop* htgop; }; BEGIN_DECLS /* HTGOP API */ @@ -289,33 +294,42 @@ htgop_sample_sw_spectral_interval_CIE_1931_Z * Retrieve the boundaries of the radiative properties ******************************************************************************/ HTGOP_API res_T -htgop_layer_get_lw_ka_bounds - (const struct htgop_layer* layer, +htgop_layers_get_lw_ka_bounds + (const struct htgop* htgop, + const size_t ilayer_range[2], /* Range of layers to handle */ + const size_t ispecint_range[2], /* Range of spectral intervals to handle */ double bounds[2]); HTGOP_API res_T -htgop_layer_get_sw_ka_bounds - (const struct htgop_layer* layer, +htgop_layers_get_sw_ka_bounds + (const struct htgop* htgop, + const size_t ilayer_range[2], /* Range of layers to handle */ + const size_t ispecint_range[2], /* Range of spectral intervals to handle */ double bounds[2]); HTGOP_API res_T -htgop_layer_get_sw_ks_bounds - (const struct htgop_layer* layer, +htgop_layers_get_sw_ks_bounds + (const struct htgop* htgop, + const size_t ilayer_range[2], /* Range of layers to handle */ + const size_t ispecint_range[2], /* Range of spectral intervals to handle */ double bounds[2]); HTGOP_API res_T -htgop_layer_lw_spectral_interval_get_ka_bounds +htgop_layer_lw_spectral_interval_quadpoints_get_ka_bounds (const struct htgop_layer_lw_spectral_interval* specint, - double bounds[2]); + const size_t iquad_range[2], /* Range of quadrature points to handle */ + double bounds[2]); HTGOP_API res_T -htgop_layer_sw_spectral_interval_get_ka_bounds +htgop_layer_sw_spectral_interval_quadpoints_get_ka_bounds (const struct htgop_layer_sw_spectral_interval* specint, - double bounds[2]); + const size_t iquad_range[2], /* Range of quadrature points to handle */ + double bounds[2]); HTGOP_API res_T -htgop_layer_sw_spectral_interval_get_ks_bounds +htgop_layer_sw_spectral_interval_quadpoints_get_ks_bounds (const struct htgop_layer_sw_spectral_interval* specint, + const size_t iquad_range[2], /* Range of quadrature points to handle */ double bounds[2]); HTGOP_API res_T diff --git a/src/htgop_fetch_radiative_properties.c b/src/htgop_fetch_radiative_properties.c @@ -1,38 +0,0 @@ -/* 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" - -#include <rsys/algorithm.h> - -/******************************************************************************* - * Exported functions - ******************************************************************************/ -/* Generate the htgop_layer_fetch_lw_ka function */ -#define LAYER_SPECINT_DOMAIN lw -#define LAYER_SPECINT_DATA ka -#include "htgop_fetch_radiative_properties.h" - -/* Generate the htgop_layer_fetch_sw_ka function */ -#define LAYER_SPECINT_DOMAIN sw -#define LAYER_SPECINT_DATA ka -#include "htgop_fetch_radiative_properties.h" - -/* Generate the htgop_layer_fetch_sw_ks function */ -#define LAYER_SPECINT_DOMAIN sw -#define LAYER_SPECINT_DATA ks -#include "htgop_fetch_radiative_properties.h" - diff --git a/src/htgop_fetch_radiative_properties.h b/src/htgop_fetch_radiative_properties.h @@ -13,8 +13,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#if !defined(LAYER_SPECINT_DATA) || !defined(LAYER_SPECINT_DOMAIN) - #error "Missing the LAYER_SPECINT_<DATA|DOMAIN> macro." +#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 /* @@ -23,18 +33,14 @@ */ /* Helper macros */ -#define SPECINT \ - CONCAT(CONCAT(htgop_layer_, LAYER_SPECINT_DOMAIN),_spectral_interval) -#define SPECINT_TAB \ - CONCAT(CONCAT(htgop_layer_, LAYER_SPECINT_DOMAIN),_spectral_interval_tab) -#define GET_SPECINT \ - CONCAT(CONCAT(htgop_layer_get_, LAYER_SPECINT_DOMAIN), _spectral_interval) -#define GET_SPECINT_TAB \ - CONCAT(CONCAT(htgop_layer_, LAYER_SPECINT_DOMAIN), _spectral_interval_get_tab) -#define K_tab CONCAT(LAYER_SPECINT_DATA, _tab) +#define SPECINT CONCAT(CONCAT(htgop_layer_, DOMAIN),_spectral_interval) +#define SPECINT_TAB CONCAT(CONCAT(htgop_layer_, DOMAIN),_spectral_interval_tab) +#define GET_SPECINT CONCAT(CONCAT(htgop_layer_get_, DOMAIN), _spectral_interval) +#define GET_SPECINT_TAB CONCAT(CONCAT(htgop_layer_, DOMAIN), _spectral_interval_get_tab) +#define K_tab CONCAT(DATA, _tab) res_T -CONCAT(CONCAT(CONCAT(htgop_layer_fetch_,LAYER_SPECINT_DOMAIN),_),LAYER_SPECINT_DATA) +CONCAT(CONCAT(CONCAT(htgop_layer_fetch_,DOMAIN),_),DATA) (const struct htgop_layer* layer, const size_t ispecint, const size_t iquad_point, @@ -97,5 +103,5 @@ CONCAT(CONCAT(CONCAT(htgop_layer_fetch_,LAYER_SPECINT_DOMAIN),_),LAYER_SPECINT_D #undef GET_SPECINT #undef GET_SPECINT_TAB #undef K_tab -#undef LAYER_SPECINT_DATA -#undef LAYER_SPECINT_DOMAIN +#undef DATA +#undef DOMAIN diff --git a/src/htgop_get_radiative_properties_bounds.h b/src/htgop_get_radiative_properties_bounds.h @@ -0,0 +1,189 @@ +/* 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/>. */ + +#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 + +/* + * Generate functions that retrieve the boundaries of the radiative properties + */ + +res_T +CONCAT(CONCAT(CONCAT(CONCAT(htgop_layers_get_,DOMAIN),_),DATA),_bounds) + (const struct htgop* htgop, + const size_t ilayer_range[2], + const size_t ispecint_range[2], + double bounds[2]) +{ + size_t ilayer; + size_t nlayers; + size_t nspecints; + res_T res = RES_OK; + + if(!htgop || !bounds || !ilayer_range || !ispecint_range || !bounds) { + res = RES_BAD_ARG; + goto error; + } + + HTGOP(get_layers_count(htgop, &nlayers)); + if(ilayer_range[0] > ilayer_range[1] + || ilayer_range[0] >= nlayers + || ilayer_range[1] <= nlayers) { + log_err(htgop, "%s: invalid range of layers [%lu, %lu].\n", FUNC_NAME, + (unsigned long)ilayer_range[0], (unsigned long)ilayer_range[1]); + res = RES_BAD_ARG; + goto error; + } + + HTGOP(CONCAT(CONCAT(get_,DOMAIN),_spectral_intervals_count)(htgop, &nspecints)); + if(ispecint_range[0] > ispecint_range[1] + || ispecint_range[0] >= nspecints + || ispecint_range[1] >= nspecints) { + log_err(htgop, "%s: invalid range of spectral intervals [%lu, %lu].\n", + FUNC_NAME, + (unsigned long)ispecint_range[0], + (unsigned long)ispecint_range[1]); + res = RES_BAD_ARG; + goto error; + } + + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + FOR_EACH(ilayer, ilayer_range[0], ilayer_range[1]+1) { + struct htgop_layer layer; + size_t ispecint; + HTGOP(get_layer(htgop, ilayer, &layer)); + + FOR_EACH(ispecint, ispecint_range[0], ispecint_range[1]+1) { + struct CONCAT(CONCAT(htgop_layer_,DOMAIN),_spectral_interval) specint; + size_t iquad_range[2]; + double quad_bounds[2]; + + HTGOP(CONCAT(CONCAT(layer_get_,DOMAIN),_spectral_interval) + (&layer, ispecint, &specint)); + + iquad_range[0] = 0; + iquad_range[1] = specint.quadrature_length - 1; + HTGOP(CONCAT(CONCAT(CONCAT(CONCAT( + layer_,DOMAIN),_spectral_interval_quadpoints_get_),DATA),_bounds) + (&specint, iquad_range, quad_bounds)); + + bounds[0] = MMIN(bounds[0], quad_bounds[0]); + bounds[1] = MMAX(bounds[1], quad_bounds[1]); + } + } +exit: + return res; +error: + if(bounds) { + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + } + goto exit; +} + +res_T CONCAT(CONCAT(CONCAT(CONCAT( +htgop_layer_,DOMAIN),_spectral_interval_quadpoints_get_),DATA),_bounds) + (const struct CONCAT(CONCAT(htgop_layer_,DOMAIN),_spectral_interval)* specint, + const size_t quad_range[2], + double bounds[2]) +{ + size_t iquad; + res_T res = RES_OK; + + if(!specint || !bounds) { + res = RES_BAD_ARG; + goto error; + } + + if(quad_range[0] > quad_range[1] + || quad_range[0] >= specint->quadrature_length + || quad_range[1] >= specint->quadrature_length) { + log_err(specint->htgop, + "%s: invalid range of quadrature points [%lu, %lu].\n", FUNC_NAME, + (unsigned long)quad_range[0], (unsigned long)quad_range[1]); + res = RES_BAD_ARG; + goto error; + } + + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + + FOR_EACH(iquad, quad_range[0], quad_range[1]+1) { + struct CONCAT(CONCAT(htgop_layer_,DOMAIN),_spectral_interval_tab) tab; + double tab_bounds[2]; + + HTGOP(CONCAT(CONCAT(layer_,DOMAIN),_spectral_interval_get_tab) + (specint, iquad, &tab)); + HTGOP(CONCAT(CONCAT(CONCAT(CONCAT( + layer_,DOMAIN),_spectral_interval_tab_get_),DATA),_bounds) + (&tab, tab_bounds)); + + bounds[0] = MMIN(bounds[0], tab_bounds[0]); + bounds[1] = MMAX(bounds[1], tab_bounds[1]); + } + +exit: + return res; +error: + if(bounds) { + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + } + goto exit; +} + +res_T CONCAT(CONCAT(CONCAT(CONCAT( +htgop_layer_,DOMAIN),_spectral_interval_tab_get_),DATA),_bounds) + (const struct CONCAT(CONCAT(htgop_layer_,DOMAIN),_spectral_interval_tab)* tab, + double bounds[2]) +{ + size_t i; + res_T res = RES_OK; + + if(!tab || !bounds) { + res = RES_BAD_ARG; + goto error; + } + + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + FOR_EACH(i, 0, tab->tab_length) { + bounds[0] = MMIN(bounds[0], tab->CONCAT(DATA,_tab[i])); + bounds[1] = MMAX(bounds[1], tab->CONCAT(DATA,_tab[i])); + } + + return RES_OK; +exit: + return res; +error: + if(bounds) { + bounds[0] = DBL_MAX; + bounds[1] =-DBL_MAX; + } + goto exit; +} + +#undef DATA +#undef DOMAIN diff --git a/src/htgop_parse_layers_spectral_intervals_data.h b/src/htgop_parse_layers_spectral_intervals_data.h @@ -13,21 +13,28 @@ * 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_PARSE_LAYERS_SPECTRAL_INTERVALS_DATA_H +#define HTGOP_PARSE_LAYERS_SPECTRAL_INTERVALS_DATA_H + +#include "htgop_c.h" +#include "htgop_reader.h" + +#endif /* HTGOP_PARSE_LAYERS_SPECTRAL_INTERVALS_DATA_H */ + /* * Generate the function that parses a per layer and per spectral interval data * for a given domain. */ -#if !defined(LAYER_SPECINT_DATA) || !defined(LAYER_SPECINT_DOMAIN) - #error "Missing the LAYER_SPECINT_<DATA|DOMAIN> macro." +#if !defined(DATA) || !defined(DOMAIN) + #error "Missing the <DATA|DOMAIN> macro." #endif -#define DATA CONCAT(CONCAT(LAYER_SPECINT_DATA, _), LAYER_SPECINT_DOMAIN) -#define XDOMAIN(Name) CONCAT(CONCAT(LAYER_SPECINT_DOMAIN, _), Name) -#define XDATA(Name) CONCAT(CONCAT(LAYER_SPECINT_DATA, _), Name) +#define XDOMAIN(Name) CONCAT(CONCAT(DOMAIN, _), Name) +#define XDATA(Name) CONCAT(CONCAT(DATA, _), Name) static res_T -CONCAT(parse_layers_spectral_intervals_, DATA) +CONCAT(CONCAT(CONCAT(parse_layers_spectral_intervals_, DATA), _), DOMAIN) (struct htgop* htgop, struct reader* rdr) { struct layer* layers = NULL; @@ -103,7 +110,6 @@ error: } #undef DATA +#undef DOMAIN #undef XDOMAIN #undef XDATA -#undef LAYER_SPECINT_DATA -#undef LAYER_SPECINT_DOMAIN