star-ck

Describe the radiative properties of gas mixtures
git clone git://git.meso-star.fr/star-ck.git
Log | Files | Refs | README | LICENSE

commit 8e156b814352b65e4fe5d99814dac05dcaa7a736
parent 9c3e340f4be8cf2a87b1e9728b5f8e858a3052a1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  4 Nov 2020 10:18:42 +0100

Upd the band API hand handle unormalized quad-pt weights

Diffstat:
Msrc/atrck.c | 26+++++++++++++++++++++-----
Msrc/atrck.h | 4++--
Msrc/test_atrck_load.c | 16+++++++---------
3 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/src/atrck.c b/src/atrck.c @@ -150,6 +150,21 @@ read_band darray_double_data_get(&band->quad_pts_cumul)[iquad_pt] = cumul; } + /* The weights are not normalized */ + if(!eq_eps(cumul, 1.0, 1.e-6)) { + log_warn(atrck, + "%s: band %lu: the weights of the quadrature points are not normalised.\n", + stream_name, (unsigned long)band->id); + + /* Renormalize the cumulative */ + FOR_EACH(iquad_pt, 0, nquad_pts) { + darray_double_data_get(&band->quad_pts_cumul)[iquad_pt] /= cumul; + } + } + + /* Handle imprecision issue */ + darray_double_data_get(&band->quad_pts_cumul)[nquad_pts-1] = 1.0; + exit: return res; error: @@ -186,7 +201,7 @@ load_stream(struct atrck* atrck, FILE* stream, const char* stream_name) log_err(atrck, "%s: invalid page size %lu. The page size attribute must be aligned on " "the page size of the operating system (%lu).\n", - stream_name, + stream_name, (unsigned long)atrck->pagesize, (unsigned long)atrck->pagesize_os); res = RES_BAD_ARG; @@ -421,6 +436,7 @@ atrck_get_band atrck_band->upper = band->upp; atrck_band->quad_pts_count = darray_quad_pt_size_get(&band->quad_pts); atrck_band->id = (size_t)band->id; + atrck_band->atrck__ = atrck; atrck_band->band__ = band; exit: @@ -431,8 +447,7 @@ error: res_T atrck_band_get_quad_pt - (const struct atrck* atrck, - const struct atrck_band* atrck_band, + (const struct atrck_band* atrck_band, const size_t iquad_pt, struct atrck_quad_pt* atrck_quad_pt) { @@ -440,14 +455,15 @@ atrck_band_get_quad_pt const struct quad_pt* quad_pt = NULL; res_T res = RES_OK; - if(!atrck || !atrck_band || !atrck_quad_pt) { + if(!atrck_band || !atrck_quad_pt) { res = RES_BAD_ARG; goto error; } band = atrck_band->band__; if(iquad_pt >= atrck_band->quad_pts_count) { - log_err(atrck, "%s: band %lu: invalid quadrature point index %lu.\n", + log_err(atrck_band->atrck__, + "%s: band %lu: invalid quadrature point index %lu.\n", FUNC_NAME, (unsigned long)atrck_band->id, (unsigned long)iquad_pt); res = RES_BAD_ARG; goto error; diff --git a/src/atrck.h b/src/atrck.h @@ -43,6 +43,7 @@ struct atrck_band { size_t id; /* Internal data */ + const struct atrck* atrck__; const void* band__; }; static const struct atrck_band ATRCK_BAND_NULL; @@ -108,8 +109,7 @@ atrck_get_band ATRCK_API res_T atrck_band_get_quad_pt - (const struct atrck* atrck, - const struct atrck_band* band, + (const struct atrck_band* band, const size_t iquad_pt, struct atrck_quad_pt* quad_pt); diff --git a/src/test_atrck_load.c b/src/test_atrck_load.c @@ -43,10 +43,9 @@ check_atrck_load CHK(atrck_get_band(atrck, 0, &band) == RES_OK); CHK(band.quad_pts_count == 1); - CHK(atrck_band_get_quad_pt(NULL, &band, 0, &qpt) == RES_BAD_ARG); - CHK(atrck_band_get_quad_pt(atrck, NULL, 0, &qpt) == RES_BAD_ARG); - CHK(atrck_band_get_quad_pt(atrck, &band, 1, &qpt) == RES_BAD_ARG); - CHK(atrck_band_get_quad_pt(atrck, &band, 0, NULL) == RES_BAD_ARG); + CHK(atrck_band_get_quad_pt( NULL, 0, &qpt) == RES_BAD_ARG); + CHK(atrck_band_get_quad_pt( &band, 1, &qpt) == RES_BAD_ARG); + CHK(atrck_band_get_quad_pt( &band, 0, NULL) == RES_BAD_ARG); FOR_EACH(iband, 0, nbands) { const double low = (double)iband; @@ -62,10 +61,10 @@ check_atrck_load FOR_EACH(iqpt, 0, nqpts) { const double abscissa = (double)iqpt*10.0; - const double weight = (double)(iqpt+1)*0.1; + const double weight = 1.0/(double)nqpts; size_t inode; - CHK(atrck_band_get_quad_pt(atrck, &band, iqpt, &qpt) == RES_OK); + CHK(atrck_band_get_quad_pt(&band, iqpt, &qpt) == RES_OK); CHK(qpt.abscissa == abscissa); CHK(qpt.weight == weight); @@ -96,7 +95,6 @@ test_load(struct atrck* atrck) CHK(fwrite(&nbands, sizeof(nbands), 1, fp) == 1); CHK(fwrite(&nnodes, sizeof(nnodes), 1, fp) == 1); - FOR_EACH(iband, 0, nbands) { const double low = (double)iband; const double upp = (double)(iband+1); @@ -112,7 +110,7 @@ test_load(struct atrck* atrck) /* Write per band quadrature points */ FOR_EACH(iqpt, 0, nqpts) { const double abscissa = (double)iqpt*10.0; - const double weight = (double)(iqpt+1)*0.1; + const double weight = 1.0/(double)nqpts; CHK(fwrite(&abscissa, sizeof(abscissa), 1, fp) == 1); CHK(fwrite(&weight, sizeof(weight), 1, fp) == 1); } @@ -312,7 +310,7 @@ test_load_files(struct atrck* atrck, int argc, char** argv) struct atrck_quad_pt qpt; size_t inode; - CHK(atrck_band_get_quad_pt(atrck, &band, iqpt, &qpt) == RES_OK); + CHK(atrck_band_get_quad_pt(&band, iqpt, &qpt) == RES_OK); CHK(qpt.abscissa == qpt.abscissa); /* !NaN */ CHK(qpt.weight == qpt.weight); /* !NaN */ CHK(qpt.weight > 0);