star-line

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

commit 797b216949b66854a8d1ddfb8483af15c9d7a6ae
parent 57478cd148f7d47a16e3bfbe66fd55715185fa22
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 27 Apr 2022 11:15:24 +0200

Check the identifiers of the molecules and the isotopes

Diffstat:
Msrc/sln_tree.c | 48+++++++++++++++++++++++++++++++++---------------
Msrc/test_sln_tree.c | 14++++++++------
2 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/src/sln_tree.c b/src/sln_tree.c @@ -30,17 +30,35 @@ static res_T check_sln_isotope (struct sln_device* sln, const char* func_name, - const int32_t id, + const int32_t mol_id, + const size_t mol_nisos, const struct sln_isotope* isotope) { - ASSERT(sln && func_name && isotope); + ASSERT(sln && func_name && mol_nisos && isotope); + + if(isotope->id_local >= SLN_MAX_ISOTOPES_COUNT) { + log_err(sln, + "%s: molecule %d: isotope %d: invalid isotope local identifier. " + "It must be less than %d.\n", + func_name, mol_id, isotope->id_local, SLN_MAX_ISOTOPES_COUNT); + return RES_BAD_ARG; + } + + if((size_t)isotope->id_local >= mol_nisos) { + log_warn(sln, + "%s: molecule %d: the isotope local index %d exceeds " + "the overall number of isotopes %lu.\n", + func_name, mol_id, isotope->id_local, mol_nisos); + return RES_OK; /* Do not check the others isotope parameters */ + } if(isotope->abundance < 0) { log_err(sln, "%s: molecule %d: isotope %d: invalid abundance %g.\n", - func_name, id, isotope->id_local, isotope->abundance); + func_name, mol_id, isotope->id_local, isotope->abundance); return RES_BAD_ARG; } + return RES_OK; } @@ -56,12 +74,19 @@ check_sln_molecule size_t i; ASSERT(sln && func_name && metadata && molecule); + if(molecule->id >= SLN_MAX_MOLECULES_COUNT) { + log_err(sln, + "%s: molecule %d: invalid molecule indentifier. It must be less than %d.\n", + func_name, molecule->id, SLN_MAX_MOLECULES_COUNT); + return RES_BAD_ARG; + } + 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", func_name, molecule->id); - return RES_OK; /* Do not check the other parmeters */ + return RES_OK; /* Do not check the others molecule parameters */ } if(molecule->nisotopes >= SLN_MAX_ISOTOPES_COUNT) { @@ -76,17 +101,8 @@ check_sln_molecule abundances_sum = 0; FOR_EACH(i, 0, molecule->nisotopes) { - 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); + const res_T res = check_sln_isotope + (sln, func_name, molecule->id, molecule->nisotopes, molecule->isotopes+i); if(res != RES_OK) return res; abundances_sum += molecule->isotopes[i].abundance; } @@ -104,11 +120,13 @@ check_sln_molecule 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", func_name, molecule->id, molecule->concentration); return RES_BAD_ARG; } + return RES_OK; } diff --git a/src/test_sln_tree.c b/src/test_sln_tree.c @@ -271,18 +271,20 @@ test_tree CHK(sln_tree_ref_put(tree) == RES_OK); tree_args.molecules[0].nisotopes = 2; - tree_args.molecules[0].isotopes[0].abundance = 0.5; + tree_args.molecules[0].isotopes[0].abundance = 0.6; tree_args.molecules[0].isotopes[0].id_local = 0; tree_args.molecules[0].isotopes[1].abundance = 0.5; tree_args.molecules[0].isotopes[1].id_local = 1; + CHK(sln_tree_create(sln, &tree_args, &tree) == RES_BAD_ARG); + tree_args.molecules[0].isotopes[0].abundance = 0.5; + CHK(sln_tree_create(sln, &tree_args, &tree) == RES_OK); CHK(sln_tree_ref_put(tree) == RES_OK); - tree_args.molecules[0].nisotopes = 2; - tree_args.molecules[0].isotopes[0].abundance = 0.6; - tree_args.molecules[0].isotopes[0].id_local = 0; - tree_args.molecules[0].isotopes[1].abundance = 0.5; - tree_args.molecules[0].isotopes[1].id_local = 1; + tree_args.molecules[0].id = SLN_MAX_MOLECULES_COUNT; + CHK(sln_tree_create(sln, &tree_args, &tree) == RES_BAD_ARG); + tree_args.molecules[0].id = 1; + tree_args.molecules[0].isotopes[0].id_local = SLN_MAX_ISOTOPES_COUNT; CHK(sln_tree_create(sln, &tree_args, &tree) == RES_BAD_ARG); }