star-line

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

commit 1aca00cb6f5382d232b463cf99589e878c0bc000
parent 8ea0c65551aa3c9c1b004d5318ba0b336cbccf69
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  9 Mar 2022 18:22:59 +0100

Begin the implementation of the sln_tree

Diffstat:
Mcmake/CMakeLists.txt | 3++-
Msrc/sln.h | 8+++++++-
Asrc/sln_tree.c | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 159 insertions(+), 2 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -45,7 +45,8 @@ set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) set(SLN_FILES_SRC sln_device.c - sln_log.c) + sln_log.c + sln_tree.c) set(SLN_FILES_INC sln_device_c.h sln_log.h) diff --git a/src/sln.h b/src/sln.h @@ -57,7 +57,7 @@ static const struct sln_device_create_args SLN_DEVICE_CREATE_ARGS_DEFAULT = struct sln_molecule { double concentration; double cutoff; /* in cm^1 */ - int32_t molecule_id; + int32_t id; /* Identifier of the molecule into the isotopo metadata */ }; struct sln_tree_create_args { @@ -73,7 +73,12 @@ struct sln_tree_create_args { /* Thermodynamic properties */ double pressure; /* In atm */ double temperature; /* In K */ + + size_t max_nlines_per_leaf; }; +#define SLN_TREE_CREATE_ARGS_DEFAULT__ {NULL, NULL, NULL, 0, 0, 0, 64} +static const struct sln_tree_create_args SLN_TREE_CREATE_ARGS_DEFAULT = + SLN_TREE_CREATE_ARGS_DEFAULT__; /* Forward declarations of opaque data structures */ struct sln_device; @@ -101,6 +106,7 @@ sln_device_ref_put SLN_API res_T sln_tree_create (struct sln_device* sln, + const struct sln_tree_create_args* args, struct sln_tree** tree); SLN_API res_T diff --git a/src/sln_tree.c b/src/sln_tree.c @@ -0,0 +1,150 @@ +/* Copyright (C) 2022 CNRS - LMD + * Copyright (C) 2022 |Meso|Star> (contact@meso-star.com) + * Copyright (C) 2022 Université Paul Sabatier - IRIT + * Copyright (C) 2022 Université Paul Sabatier - Laplace + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "sln.h" +#include "sln_device_c.h" +#include "sln_log.h" + +#include <rsys/ref_count.h> + +struct sln_tree { + struct sln_device* sln; + ref_T ref; +}; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static res_T +check_sln_molecule + (struct sln_device* sln, + const char* func_name, + const struct sln_molecule* molecule) +{ + ASSERT(sln && molecule); + /* TODO check with Yaniss */ + 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) { + log_err(sln, "%s: molecule `%d': invalid line cutoff `%g'.\n", + func_name, molecule->id, molecule->concentration); + return RES_BAD_ARG; + } + return RES_OK; +} + +static res_T +check_sln_tree_create_args + (struct sln_device* sln, + const char* func_name, + const struct sln_tree_create_args* args) +{ + size_t i; + ASSERT(sln); + if(!args) return RES_BAD_ARG; + + /* Check lines data base */ + if(!args->metadata || !args->lines) { + return RES_BAD_ARG; + } + + /* Check the list of molecules to be taken into account */ + if(args->nmolecules && args->molecules) { + return RES_BAD_ARG; + } + FOR_EACH(i, 0, args->nmolecules) { + const res_T res = check_sln_molecule(sln, func_name, args->molecules+i); + if(res != RES_OK) return res; + } + + /* 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; + } + if(args->temperature < 0) { + log_err(sln, "%s: invalid temperature `%g'.\n", func_name, args->temperature); + return RES_BAD_ARG; + } + return RES_OK; +} + +static void +release_tree(ref_T* ref) +{ + struct sln_tree* tree = CONTAINER_OF(ref, struct sln_tree, ref); + struct sln_device* sln = NULL; + ASSERT(ref); + sln = tree->sln; + MEM_RM(sln->allocator, tree); + SLN(device_ref_put(sln)); +} + +/******************************************************************************* + * Exported symbols + ******************************************************************************/ +res_T +sln_tree_create + (struct sln_device* sln, + const struct sln_tree_create_args* args, + struct sln_tree** out_tree) +{ + struct sln_tree* tree = NULL; + res_T res = RES_OK; + + if(!sln || !out_tree) { res = RES_BAD_ARG; goto error; } + res = check_sln_tree_create_args(sln, FUNC_NAME, args); + if(res != RES_OK) goto error; + + tree = MEM_CALLOC(sln->allocator, 1, sizeof(struct sln_tree)); + if(!tree) { + log_err(sln, "%s: could not allocate the tree data structure.\n", + FUNC_NAME); + res = RES_MEM_ERR; + goto error; + } + ref_init(&tree->ref); + SLN(device_ref_get(sln)); + tree->sln = sln; + +exit: + if(out_tree) *out_tree = tree; + return res; +error: + if(tree) { SLN(tree_ref_put(tree)); tree = NULL; } + goto exit; +} + +res_T +sln_tree_ref_get(struct sln_tree* tree) +{ + if(!tree) return RES_BAD_ARG; + ref_get(&tree->ref); + return RES_OK; +} + +res_T +sln_tree_ref_put(struct sln_tree* tree) +{ + if(!tree) return RES_BAD_ARG; + ref_put(&tree->ref, release_tree); + return RES_OK; +}