commit f2fe3360946d58fc845ab009de1accbdd691d764
parent 0ee25b24ca9120dd75b25c6f5bf077f1665e80d6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 28 Oct 2022 10:14:55 +0200
Update sck_band_sample_quad_pt function profile
The function returns the index of the sampled quadrature point, and no
longer the quadrature point itself
Diffstat:
3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/sck.c b/src/sck.c
@@ -650,7 +650,7 @@ res_T
sck_band_sample_quad_pt
(const struct sck_band* sck_band,
const double r, /* Canonical random number in [0, 1[ */
- struct sck_quad_pt* quad_pt)
+ size_t* iquad_pt)
{
const struct band* band = NULL;
const double* cumul = NULL;
@@ -658,7 +658,7 @@ sck_band_sample_quad_pt
double r_next = nextafter(r, DBL_MAX);
size_t i;
- if(!sck_band || !quad_pt) return RES_BAD_ARG;
+ if(!sck_band || !iquad_pt) return RES_BAD_ARG;
if(r < 0 || r >= 1) {
log_err(sck_band->sck__,
@@ -681,8 +681,7 @@ sck_band_sample_quad_pt
ASSERT(cumul[i] > r);
ASSERT(!i || cumul[i-1] <= r);
- /* Fetch the sampled quadrature point */
- sck_band_get_quad_pt(sck_band, i, quad_pt);
+ *iquad_pt = i;
return RES_OK;
}
diff --git a/src/sck.h b/src/sck.h
@@ -139,7 +139,7 @@ SCK_API res_T
sck_band_sample_quad_pt
(const struct sck_band* band,
const double r, /* Canonical random number in [0, 1[ */
- struct sck_quad_pt* quad_pt);
+ size_t* iquad_pt); /* Index of the sampled quadrature point */
SCK_API res_T
sck_quad_pt_compute_hash
diff --git a/src/test_sck_load.c b/src/test_sck_load.c
@@ -43,6 +43,7 @@ check_sck_load
struct sck_band band = SCK_BAND_NULL;
struct sck_quad_pt qpt = SCK_QUAD_PT_NULL;
size_t iband;
+ size_t iqpt;
const size_t nsamps = 1000000;
size_t isamp;
@@ -63,15 +64,14 @@ check_sck_load
CHK(sck_band_get_quad_pt(&band, 1, &qpt) == RES_BAD_ARG);
CHK(sck_band_get_quad_pt(&band, 0, NULL) == RES_BAD_ARG);
- CHK(sck_band_sample_quad_pt(NULL, 0, &qpt) == RES_BAD_ARG);
- CHK(sck_band_sample_quad_pt(&band, 1, &qpt) == RES_BAD_ARG);
+ CHK(sck_band_sample_quad_pt(NULL, 0, &iqpt) == RES_BAD_ARG);
+ CHK(sck_band_sample_quad_pt(&band, 1, &iqpt) == RES_BAD_ARG);
CHK(sck_band_sample_quad_pt(&band, 0, NULL) == RES_BAD_ARG);
FOR_EACH(iband, 0, nbands) {
const double low = (double)(iband+1);
const double upp = (double)(iband+2);
const size_t nqpts = iband + 1;
- size_t iqpt;
double sum[NMOMENTS] = {0};
double sum2[NMOMENTS] = {0};
double E[NMOMENTS] = {0};
@@ -110,7 +110,9 @@ check_sck_load
const double r = rand_canonic();
double w[NMOMENTS];
- CHK(sck_band_sample_quad_pt(&band, r, &qpt) == RES_OK);
+ CHK(sck_band_sample_quad_pt(&band, r, &iqpt) == RES_OK);
+ ASSERT(iqpt < band.quad_pts_count);
+ CHK(sck_band_get_quad_pt(&band, iqpt, &qpt) == RES_OK);
FOR_EACH(imoment, 0, NMOMENTS) {
if(imoment == 0) {
w[imoment] = (double)(qpt.id + 1);