star-line

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

commit f844c376ab4951c7b5e27ac0f57ae9b54df5f1c8
parent 1c0ac0cce49ddb62c08888af958782db8987f5d8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 26 Apr 2022 09:39:36 +0200

Check the isotope abundances of the sln_tree_build function

Diffstat:
Msrc/sln_tree.c | 44++++++++++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/sln_tree.c b/src/sln_tree.c @@ -37,7 +37,7 @@ check_sln_isotope if(isotope->abundance < 0) { log_err(sln, - "%s: molecule `%d': isotope `%d': invalid abundance `%g'.\n", + "%s: molecule %d: isotope %d: invalid abundance %g.\n", func_name, id, isotope->id_local, isotope->abundance); return RES_BAD_ARG; } @@ -51,6 +51,7 @@ check_sln_molecule struct shtr_isotope_metadata* metadata, const struct sln_molecule* molecule) { + double abundances_sum = 0; struct shtr_molecule mol = SHTR_MOLECULE_NULL; size_t i; ASSERT(sln && func_name && metadata && molecule); @@ -58,8 +59,9 @@ check_sln_molecule SHTR(isotope_metadata_find_molecule(metadata, molecule->id, &mol)); if(SHTR_MOLECULE_IS_NULL(&mol)) { log_warn(sln, - "%s: the molecule `%d' is not found in the isotope metadata.\n", + "%s: the molecule %d is not found in the isotope metadata.\n", func_name, molecule->id); + return RES_OK; /* Do not check the other parmeters */ } if(molecule->nisotopes >= SLN_MAX_ISOTOPES_COUNT) { @@ -72,19 +74,38 @@ check_sln_molecule return RES_BAD_ARG; } + abundances_sum = 0; FOR_EACH(i, 0, molecule->nisotopes) { - const res_T res = check_sln_isotope - (sln, func_name, molecule->id, molecule->isotopes+i); + res_T res = RES_OK; + + if((size_t)molecule->isotopes[i].id_local >= mol.nisotopes) { + log_warn(sln, + "%s: molecule %d: the isotope local index %d exceeds " + "the overall number of isotopes %lu.\n", + func_name, molecule->id, molecule->isotopes[i].id_local, + molecule->nisotopes); + continue; /* Skip the isotope */ + } + res = check_sln_isotope(sln, func_name, molecule->id, molecule->isotopes+i); if(res != RES_OK) return res; + abundances_sum += molecule->isotopes[i].abundance; + } + + if(abundances_sum > 1) { + log_err(sln, + "%s: molecule %d: the sum of the isotope abundances %g is invalid. " + "It must be less than or equal to 1.\n", + func_name, molecule->id, abundances_sum); + return RES_BAD_ARG; } if(molecule->concentration < 0) { - log_err(sln, "%s: molecule `%d': invalid concentration `%g'.\n", + log_err(sln, "%s: molecule %d: invalid concentration %g.\n", func_name, molecule->id, molecule->concentration); return RES_BAD_ARG; } if(molecule->cutoff <= 0) { - log_err(sln, "%s: molecule `%d': invalid line cutoff `%g'.\n", + log_err(sln, "%s: molecule %d: invalid line cutoff %g.\n", func_name, molecule->id, molecule->concentration); return RES_BAD_ARG; } @@ -107,12 +128,6 @@ check_sln_tree_create_args return RES_BAD_ARG; } - if(args->max_nlines_per_leaf == 0) { - log_err(sln, "%s: invalid maximum number of lines per leaf `%lu'.\n", - func_name, (unsigned long)args->max_nlines_per_leaf); - return RES_BAD_ARG; - } - /* Check the list of molecules to be taken into account */ if(args->nmolecules >= SLN_MAX_MOLECULES_COUNT) { log_err(sln, @@ -141,11 +156,12 @@ check_sln_tree_create_args } if(args->pressure < 0) { - log_err(sln, "%s: invalid pressure `%g'.\n", func_name, args->pressure); + log_err(sln, "%s: invalid pressure %g.\n", func_name, args->pressure); return RES_BAD_ARG; } + if(args->temperature < 0) { - log_err(sln, "%s: invalid temperature `%g'.\n", func_name, args->temperature); + log_err(sln, "%s: invalid temperature %g.\n", func_name, args->temperature); return RES_BAD_ARG; } return RES_OK;