commit a53a834bd4a3be52e04130405f96bbccf381da9e
parent e759a3c0e7a87efdf7afff64d9fab421d0d2dc3a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 17 Nov 2022 12:15:15 +0100
Internally use of the rnatm_fetch_cell_list function
Diffstat:
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/src/rnatm_properties.c b/src/rnatm_properties.c
@@ -964,7 +964,8 @@ static res_T
compute_unnormalized_cumulative_radcoef
(const struct rnatm* atm,
const enum rnatm_radcoef radcoef,
- const double pos[3],
+ const struct rnatm_cell_pos* cells,
+ const size_t ncells,
const size_t iband,
const size_t iquad,
float cumulative[RNATM_MAX_COMPONENTS_COUNT],
@@ -972,7 +973,6 @@ compute_unnormalized_cumulative_radcoef
/* For debug */
const double k_min,
const double k_max)
-
{
struct rnatm_cell_get_radcoef_args cell_args = RNATM_CELL_GET_RADCOEF_ARGS_NULL;
size_t cpnt = RNATM_GAS;
@@ -980,12 +980,13 @@ compute_unnormalized_cumulative_radcoef
size_t icumul = 0;
float k = 0;
res_T res = RES_OK;
- ASSERT(atm && (unsigned)radcoef < RNATM_RADCOEFS_COUNT__);
+ ASSERT(atm && cells && ncells && (unsigned)radcoef < RNATM_RADCOEFS_COUNT__);
ASSERT(cumulative && cumulative_sz);
(void)k_min;
naerosols = darray_aerosol_size_get(&atm->aerosols);
ASSERT(naerosols+1 < RNATM_MAX_COMPONENTS_COUNT);
+ ASSERT(naerosols+1 == ncells);
/* Setup the arguments common to all components */
cell_args.iband = iband;
@@ -996,9 +997,7 @@ compute_unnormalized_cumulative_radcoef
do {
double per_cell_k;
- /* Retrieve the cell of the component */
- res = rnatm_fetch_cell(atm, pos, cpnt, &cell_args.cell);
- if(res != RES_OK) goto error;
+ cell_args.cell = cells[cpnt+1];
/* This component does not exist here */
if(SUVM_PRIMITIVE_NONE(&cell_args.cell.prim)) continue;
@@ -1032,7 +1031,9 @@ rnatm_get_radcoef
const struct rnatm_get_radcoef_args* args,
double* out_k)
{
+ struct rnatm_cell_pos cells[RNATM_MAX_COMPONENTS_COUNT];
float cumul[RNATM_MAX_COMPONENTS_COUNT];
+ size_t ncells;
size_t cumul_sz;
double k = 0;
res_T res = RES_OK;
@@ -1041,11 +1042,16 @@ rnatm_get_radcoef
res = check_rnatm_get_radcoef_args(atm, args);
if(res != RES_OK) goto error;
+ /* Retrieve the cell by component in which pos is located */
+ res = rnatm_fetch_cell_list(atm, args->pos, cells, &ncells);
+ if(res != RES_OK) goto error;
+
/* Calculate the cumulative (unnormalized) of radiative coefficients. Its last
* entry is the sum of the radiative coefficients of each component, which is
* the atmospheric radiative coefficient to be returned. */
- res = compute_unnormalized_cumulative_radcoef(atm, args->radcoef, args->pos,
- args->iband, args->iquad, cumul, &cumul_sz, args->k_min, args->k_max);
+ res = compute_unnormalized_cumulative_radcoef(atm, args->radcoef, cells,
+ ncells, args->iband, args->iquad, cumul, &cumul_sz, args->k_min,
+ args->k_max);
if(res != RES_OK) goto error;
if(cumul_sz == 0) {
@@ -1068,9 +1074,11 @@ rnatm_sample_component
const struct rnatm_sample_component_args* args,
size_t* cpnt)
{
+ struct rnatm_cell_pos cells[RNATM_MAX_COMPONENTS_COUNT];
float cumul[RNATM_MAX_COMPONENTS_COUNT];
float norm;
size_t cumul_sz;
+ size_t ncells;
size_t i;
res_T res = RES_OK;
@@ -1084,8 +1092,12 @@ rnatm_sample_component
goto exit;
}
- res = compute_unnormalized_cumulative_radcoef(atm, args->radcoef, args->pos,
- args->iband, args->iquad, cumul, &cumul_sz, -DBL_MAX, DBL_MAX);
+ /* Retrieve the cell by component in which pos is located */
+ res = rnatm_fetch_cell_list(atm, args->pos, cells, &ncells);
+ if(res != RES_OK) goto error;
+
+ res = compute_unnormalized_cumulative_radcoef(atm, args->radcoef, cells,
+ ncells, args->iband, args->iquad, cumul, &cumul_sz, -DBL_MAX, DBL_MAX);
if(res != RES_OK) goto error;
ASSERT(cumul_sz >= 1);