star-line

Structure for accelerating line importance sampling
git clone git://git.meso-star.fr/star-line.git
Log | Files | Refs | README | LICENSE

commit ed53868fa7436745e98c0f75c49a712ae33b91fd
parent fd538198f530fa3222ab56ede755d826ef931dd7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  4 May 2022 12:44:06 +0200

Handle errors returned by partition function calculation

Diffstat:
Msrc/sln_line.c | 37+++++++++++++++++++++++++++++++------
Msrc/sln_line.h | 2+-
Msrc/sln_tree.c | 3++-
3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/sln_line.c b/src/sln_line.c @@ -62,10 +62,11 @@ line_intensity return intensity_ref * partition_function * tmp * fol ; } -static double +static res_T line_profile_factor (const struct sln_tree* tree, - const struct shtr_line* shtr_line) + const struct shtr_line* shtr_line, + double* out_profile_factor) { /* Star-HITRAN data */ struct shtr_molecule molecule = SHTR_MOLECULE_NULL; @@ -85,7 +86,9 @@ line_profile_factor double T; /* Temperature */ int molid; /* Molecule id */ int isoid; /* Isotope id local to its molecule */ - ASSERT(tree); + + res_T res = RES_OK; + ASSERT(tree && shtr_line && out_profile_factor); /* Fetch the molecule data */ mol_params = tree_get_molecule_params(tree, shtr_line->molecule_id); @@ -109,6 +112,14 @@ line_profile_factor isoid = shtr_line->isotope_id_local; T = tree->temperature; BD_TIPS_2017(&molid, &T, &isoid, &gj, &Q_T); + if(Q_T <= 0) { + log_err(tree->sln, + "molecule %d: isotope %d: invalid partition function at T=%g\n", + molid, isoid, T); + res = RES_BAD_ARG; + goto error; + } + Q = Q_Tref/Q_T; /* Compute the intensity */ @@ -119,7 +130,13 @@ line_profile_factor tree->temperature, T_REF, nu_c); profile_factor = 1.e2 * density * intensity; /* In m^-1.cm^-1 */ - return profile_factor; + +exit: + *out_profile_factor = profile_factor; + return res; +error: + profile_factor = NaN; + goto exit; } /* Regularly mesh the interval [wavenumber, wavenumber+spectral_length[. Note @@ -242,7 +259,7 @@ error: /******************************************************************************* * Local function ******************************************************************************/ -void +res_T line_setup(struct sln_tree* tree, const size_t iline) { struct shtr_molecule molecule = SHTR_MOLECULE_NULL; @@ -250,6 +267,7 @@ line_setup(struct sln_tree* tree, const size_t iline) struct line* line = NULL; double molar_mass = 0; /* In kg.mol^-1 */ const struct molecule_params* mol_params = NULL; + res_T res = RES_OK; ASSERT(tree && iline < darray_line_size_get(&tree->lines)); line = darray_line_data_get(&tree->lines) + iline; @@ -265,12 +283,19 @@ line_setup(struct sln_tree* tree, const size_t iline) molar_mass = molecule.isotopes[shtr_line->isotope_id_local].molar_mass*1e-3; /* Setup the line */ + res = line_profile_factor(tree, shtr_line, &line->profile_factor); + if(res != RES_OK) goto error; + line->wavenumber = line_center(shtr_line, tree->pressure); - line->profile_factor = line_profile_factor(tree, shtr_line); line->gamma_d = sln_compute_line_half_width_doppler (line->wavenumber, molar_mass, tree->temperature); line->gamma_l = sln_compute_line_half_width_lorentz(shtr_line->gamma_air, shtr_line->gamma_self, tree->pressure, mol_params->concentration); + +exit: + return res; +error: + goto exit; } double diff --git a/src/sln_line.h b/src/sln_line.h @@ -42,7 +42,7 @@ line_center return line->wavenumber + line->delta_air * pressure; } -extern LOCAL_SYM void +extern LOCAL_SYM res_T line_setup (struct sln_tree* tree, const size_t iline); diff --git a/src/sln_tree.c b/src/sln_tree.c @@ -327,7 +327,8 @@ setup_lines(struct sln_tree* tree, const char* caller) } FOR_EACH(iline, 0, nlines) { - line_setup(tree, iline); + res = line_setup(tree, iline); + if(res != RES_OK) goto error; } exit: