commit 2b504c33b6316bfd7d1e9740928cbf84d2d0e2dc
parent e3d1e1e772016c136c879464a37c4337e7c741a5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 16 Nov 2022 19:01:40 +0100
Replace structure of rnatm_cell with that of rnatm_cell_pos
It has the same member variables as rnatm_cell but adds barycentric
coordinates in the cell
Diffstat:
3 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/src/rnatm.h b/src/rnatm.h
@@ -88,14 +88,16 @@ struct rnatm_aerosol_args {
static const struct rnatm_aerosol_args RNATM_AEROSOL_ARGS_NULL =
RNATM_AEROSOL_ARGS_NULL__;
-struct rnatm_cell {
+struct rnatm_cell_pos {
struct suvm_primitive prim; /* Volumetric primitive */
+ double barycentric_coords[4]; /* position relative to `prim' */
+
/* Component to which the cell belongs. This is either an aerosol index or
* the RNATM_GAS constant */
size_t component;
};
-#define RNATM_CELL_NULL__ {SUVM_PRIMITIVE_NULL__, RNATM_GAS}
-static const struct rnatm_cell RNATM_CELL_NULL = RNATM_CELL_NULL__;
+#define RNATM_CELL_POS_NULL__ {SUVM_PRIMITIVE_NULL__, {0,0,0,0}, RNATM_GAS}
+static const struct rnatm_cell_pos RNATM_CELL_POS_NULL = RNATM_CELL_POS_NULL__;
struct rnatm_band_desc {
double lower; /* Lower band wavelength in nm (inclusive) */
@@ -139,8 +141,7 @@ static const struct rnatm_sample_component_args
RNATM_SAMPLE_COMPONENT_ARGS_NULL = RNATM_SAMPLE_COMPONENT_ARGS_NULL__;
struct rnatm_cell_get_radcoef_args {
- struct rnatm_cell cell; /* Cell to query */
- double barycentric_coords[4]; /* Position into and relative to the cell */
+ struct rnatm_cell_pos cell; /* Cell to query */
size_t iband; /* Index of the spectral band to query */
size_t iquad; /* Index of the quadrature point to query in the band */
@@ -152,8 +153,7 @@ struct rnatm_cell_get_radcoef_args {
double k_max;
};
#define RNATM_CELL_GET_RADCOEF_ARGS_NULL__ { \
- RNATM_CELL_NULL__, \
- {0, 0, 0, 0}, /* Barycentric coordinates */ \
+ RNATM_CELL_POS_NULL__, \
0, 0, /* Spectral data (band, quadrature pointh) */ \
RNATM_RADCOEFS_COUNT__, \
DBL_MAX /* For debug: Radcoef range */ \
@@ -162,13 +162,12 @@ static const struct rnatm_cell_get_radcoef_args
RNATM_CELL_GET_RADCOEF_ARGS_NULL = RNATM_CELL_GET_RADCOEF_ARGS_NULL__;
struct rnatm_cell_create_phase_fn_args {
- struct rnatm_cell cell; /* Cell to query */
- double barycentric_coords[4]; /* Position into and relative to the cell */
+ struct rnatm_cell_pos cell; /* Cell to query */
double wavelength; /* In nm */
double r[2]; /* Random numbers uniformaly distributed in [0, 1[ */
};
#define RNATM_CELL_CREATE_PHASE_FN_ARGS_NULL__ { \
- RNATM_CELL_NULL__, {0,0,0,0}, 0, {0,0} \
+ RNATM_CELL_POS_NULL__, 0, {0,0} \
}
static const struct rnatm_cell_create_phase_fn_args
RNATM_CELL_CREATE_PHASE_FN_ARGS_NULL = RNATM_CELL_CREATE_PHASE_FN_ARGS_NULL__;
@@ -306,8 +305,7 @@ rnatm_fetch_cell
const double pos[3],
/* Component. This is either an aerosol index or the RNATM_GAS constant */
const size_t cpnt,
- struct rnatm_cell* cell,
- double barycentric_coords[4]); /* `pos' relative to the returned `cell' */
+ struct rnatm_cell_pos* cell);
RNATM_API res_T
rnatm_cell_get_radcoef
diff --git a/src/rnatm_mesh.c b/src/rnatm_mesh.c
@@ -131,12 +131,11 @@ rnatm_fetch_cell
(const struct rnatm* atm,
const double pos[3],
const size_t cpnt,
- struct rnatm_cell* cell,
- double barycentric_coords[4])
+ struct rnatm_cell_pos* cell)
{
res_T res = RES_OK;
- if(!atm || !pos || !cell || !barycentric_coords) {
+ if(!atm || !pos || !cell) {
res = RES_BAD_ARG;
goto error;
}
@@ -145,7 +144,8 @@ rnatm_fetch_cell
/* Gas */
if(cpnt == RNATM_GAS) {
- res = suvm_volume_at(atm->gas.volume, pos, &cell->prim, barycentric_coords);
+ res = suvm_volume_at
+ (atm->gas.volume, pos, &cell->prim, cell->barycentric_coords);
if(res != RES_OK) {
log_err(atm, "Error retrieving gas cell at %g, %g, %g\n",
SPLIT3(pos));
@@ -155,7 +155,8 @@ rnatm_fetch_cell
/* Aerosol */
} else if(cpnt < rnatm_get_aerosols_count(atm)) {
const struct aerosol* aerosol = darray_aerosol_cdata_get(&atm->aerosols) + cpnt;
- res = suvm_volume_at(aerosol->volume, pos, &cell->prim, barycentric_coords);
+ res = suvm_volume_at
+ (aerosol->volume, pos, &cell->prim, cell->barycentric_coords);
if(res != RES_OK) {
log_err(atm, "Error retrieving %s cell at %g, %g, %g\n",
str_cget(&aerosol->name), SPLIT3(pos));
diff --git a/src/rnatm_properties.c b/src/rnatm_properties.c
@@ -124,10 +124,10 @@ check_rnatm_cell_get_radcoef_args
/* Invalid barycentric coordinates */
sum_bcoords =
- args->barycentric_coords[0]
- + args->barycentric_coords[1]
- + args->barycentric_coords[2]
- + args->barycentric_coords[3];
+ args->cell.barycentric_coords[0]
+ + args->cell.barycentric_coords[1]
+ + args->cell.barycentric_coords[2]
+ + args->cell.barycentric_coords[3];
if(!eq_eps(sum_bcoords, 1, 1.e-6))
return RES_BAD_ARG;
@@ -178,10 +178,10 @@ check_rnatm_cell_create_phase_fn_args
/* Invalid barycentric coordinates */
sum_bcoords =
- args->barycentric_coords[0]
- + args->barycentric_coords[1]
- + args->barycentric_coords[2]
- + args->barycentric_coords[3];
+ args->cell.barycentric_coords[0]
+ + args->cell.barycentric_coords[1]
+ + args->cell.barycentric_coords[2]
+ + args->cell.barycentric_coords[3];
if(!eq_eps(sum_bcoords, 1, 1.e-6))
return RES_BAD_ARG;
@@ -921,7 +921,7 @@ cell_create_phase_fn_aerosol
aerosol = darray_aerosol_data_get(&atm->aerosols) + args->cell.component;
/* Sample the cell node to consider */
- bcoords = args->barycentric_coords;
+ bcoords = args->cell.barycentric_coords;
if(args->r[0] < bcoords[0]) {
icell_node = 0;
} else if(args->r[0] < bcoords[0] + bcoords[1]) {
@@ -997,8 +997,7 @@ compute_unnormalized_cumulative_radcoef
double per_cell_k;
/* Retrieve the cell of the component */
- res = rnatm_fetch_cell
- (atm, pos, cpnt, &cell_args.cell, cell_args.barycentric_coords);
+ res = rnatm_fetch_cell(atm, pos, cpnt, &cell_args.cell);
if(res != RES_OK) goto error;
/* This component does not exist here */
@@ -1137,10 +1136,10 @@ rnatm_cell_get_radcoef
/* Calculate the radiative coefficient by linearly interpolating the
* coefficients defined by tetrahedron vertex */
- k = vtx_k[0] * args->barycentric_coords[0]
- + vtx_k[1] * args->barycentric_coords[1]
- + vtx_k[2] * args->barycentric_coords[2]
- + vtx_k[3] * args->barycentric_coords[3];
+ k = vtx_k[0] * args->cell.barycentric_coords[0]
+ + vtx_k[1] * args->cell.barycentric_coords[1]
+ + vtx_k[2] * args->cell.barycentric_coords[2]
+ + vtx_k[3] * args->cell.barycentric_coords[3];
/* Fix interpolation accuracy issues */
min_vtx_k = MMIN(MMIN(vtx_k[0], vtx_k[1]), MMIN(vtx_k[2], vtx_k[3]));