commit 3c773e852fbc213e00b3c2309f3e1192d7006352
parent 282051b3137371ee09c4cf4228822ca03500992f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 22 Apr 2022 15:50:44 +0200
Update the sl_tree_create input arguments
Add the list of isotopes per molecule with their abundance
Diffstat:
| M | src/sln.h | | | 21 | +++++++++++++-------- |
| M | src/sln_tree.c | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ |
2 files changed, 72 insertions(+), 14 deletions(-)
diff --git a/src/sln.h b/src/sln.h
@@ -58,29 +58,34 @@ struct sln_device_create_args {
static const struct sln_device_create_args SLN_DEVICE_CREATE_ARGS_DEFAULT =
SLN_DEVICE_CREATE_ARGS_DEFAULT__;
+struct sln_isotope {
+ double abundance;
+ int32_t id_local; /* Isotopes identifier _local_ to the molecule */
+};
+#define SLN_ISOTOPE_NULL__ {0, 0}
+static const struct sln_isotope SLN_ISOTOPE_NULL = SLN_ISOTOPE_NULL__;
+
struct sln_molecule {
- /* List of isotopes identifier to consider for this molecule. The listed
- * idenfiers are _local_ to the molecule */
- int32_t isotope_ids_local[SLN_MAX_ISOTOPES_COUNT];
- size_t nisotopes; /* 0 <=> select all the isotopes */
+ /* List of isotopes to be taken into account */
+ struct sln_isotope isotopes[SLN_MAX_ISOTOPES_COUNT];
+ size_t nisotopes; /* 0 <=> select all the isotopes of the molecules */
- /* TODO check with Yaniss if these parameters are per molecule or per isotope */
double concentration;
double cutoff; /* in cm^1 */
int32_t id; /* Identifier of the molecule into the isotope metadata */
};
-#define SLN_MOLECULE_NULL__ {{0}, 0, 0, 0, 0}
+#define SLN_MOLECULE_NULL__ {{SLN_ISOTOPE_NULL__}, 0, 0, 0, 0}
static const struct sln_molecule SLN_MOLECULE_NULL = SLN_MOLECULE_NULL__;
struct sln_tree_create_args {
/* Isotope metadata and overall list of spectral lines */
- const struct shtr_isotope_metadata* metadata;
+ struct shtr_isotope_metadata* metadata;
struct shtr_lines_list* lines;
/* List of molecules to be taken into account with its associated
* concentration and cutoff */
- const struct sln_molecule molecules[SLN_MAX_MOLECULES_COUNT];
+ struct sln_molecule molecules[SLN_MAX_MOLECULES_COUNT];
size_t nmolecules;
double wavenumber_range[2]; /* Spectral range */
diff --git a/src/sln_tree.c b/src/sln_tree.c
@@ -27,12 +27,40 @@
* Helper functions
******************************************************************************/
static res_T
+check_sln_isotope
+ (struct sln_device* sln,
+ const char* func_name,
+ const int32_t id,
+ const struct sln_isotope* isotope)
+{
+ ASSERT(sln && func_name && isotope);
+
+ if(isotope->abundance < 0) {
+ log_err(sln,
+ "%s: molecule `%d': isotope `%d': invalid abundance `%g'.\n",
+ func_name, id, isotope->id_local, isotope->abundance);
+ return RES_BAD_ARG;
+ }
+ return RES_OK;
+}
+
+static res_T
check_sln_molecule
(struct sln_device* sln,
const char* func_name,
+ struct shtr_isotope_metadata* metadata,
const struct sln_molecule* molecule)
{
- ASSERT(sln && func_name && molecule);
+ struct shtr_molecule mol = SHTR_MOLECULE_NULL;
+ size_t i;
+ ASSERT(sln && func_name && metadata && 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",
+ func_name, molecule->id);
+ }
if(molecule->nisotopes >= SLN_MAX_ISOTOPES_COUNT) {
log_err(sln,
@@ -44,13 +72,18 @@ check_sln_molecule
return RES_BAD_ARG;
}
- /* TODO check with Yaniss */
+ FOR_EACH(i, 0, molecule->nisotopes) {
+ const res_T res = check_sln_isotope
+ (sln, func_name, molecule->id, molecule->isotopes+i);
+ if(res != RES_OK) return res;
+ }
+
if(molecule->concentration < 0) {
log_err(sln, "%s: molecule `%d': invalid concentration `%g'.\n",
func_name, molecule->id, molecule->concentration);
return RES_BAD_ARG;
}
- if(molecule->cutoff < 0) {
+ 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;
@@ -64,6 +97,7 @@ check_sln_tree_create_args
const char* func_name,
const struct sln_tree_create_args* args)
{
+ double concentrations_sum = 0;
size_t i;
ASSERT(sln && func_name);
if(!args) return RES_BAD_ARG;
@@ -72,6 +106,13 @@ check_sln_tree_create_args
if(!args->metadata || !args->lines) {
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,
@@ -82,12 +123,23 @@ check_sln_tree_create_args
(unsigned long)SLN_MAX_MOLECULES_COUNT);
return RES_BAD_ARG;
}
+
+ concentrations_sum = 0;
FOR_EACH(i, 0, args->nmolecules) {
- const res_T res = check_sln_molecule(sln, func_name, args->molecules+i);
+ const res_T res = check_sln_molecule
+ (sln, func_name, args->metadata, args->molecules+i);
if(res != RES_OK) return res;
+ concentrations_sum += args->molecules[i].concentration;
+ }
+
+ if(concentrations_sum > 1) {
+ log_err(sln,
+ "%s: the sum of the molecule concentrations %g is invalid. "
+ "It must be less than or equal to 1.\n",
+ func_name, concentrations_sum);
+ return RES_BAD_ARG;
}
- /* Check the thermodynamic properties. TODO check with Yaniss */
if(args->pressure < 0) {
log_err(sln, "%s: invalid pressure `%g'.\n", func_name, args->pressure);
return RES_BAD_ARG;
@@ -109,6 +161,7 @@ create_lines_view
Invalid_SLN_MAX_MOLECULES_COUNT);
STATIC_ASSERT(SLN_MAX_ISOTOPES_COUNT <= SHTR_MAX_ISOTOPES_COUNT,
Invalid_SLN_MAX_ISOTOPES_COUNT);
+
struct shtr_lines_view_create_args view_args = SHTR_LINES_VIEW_CREATE_ARGS_NULL;
struct shtr_lines_view* view = NULL;
size_t imol, iiso;
@@ -128,7 +181,7 @@ create_lines_view
view_mol->id = tree_mol->id;
view_mol->nisotopes = tree_mol->nisotopes;
FOR_EACH(iiso, 0, tree_mol->nisotopes) {
- view_mol->isotope_ids_local[iiso] = tree_mol->isotope_ids_local[iiso];
+ view_mol->isotope_ids_local[iiso] = tree_mol->isotopes[iiso].id_local;
}
}