commit 76dc0a6221a0c538a878d47025d1cb7ca6719d7f
parent 2786fe4d3b9f1a86838d1af3f5d8f11d68cd06d0
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 7 Dec 2020 11:39:04 +0100
Change library name/prefix and begin its implementation
Diffstat:
| M | README.md | | | 5 | +++-- |
| M | cmake/CMakeLists.txt | | | 60 | +++++++++++++++++++++++++++++++----------------------------- |
| D | src/atrgm.c | | | 115 | ------------------------------------------------------------------------------- |
| D | src/atrgm.h | | | 84 | ------------------------------------------------------------------------------- |
| D | src/atrgm_c.h | | | 37 | ------------------------------------- |
| D | src/atrgm_log.c | | | 124 | ------------------------------------------------------------------------------- |
| D | src/atrgm_log.h | | | 68 | -------------------------------------------------------------------- |
| A | src/atrstm.c | | | 162 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/atrstm.h | | | 106 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/atrstm_c.h | | | 43 | +++++++++++++++++++++++++++++++++++++++++++ |
| A | src/atrstm_log.c | | | 124 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | src/atrstm_log.h | | | 68 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
12 files changed, 537 insertions(+), 459 deletions(-)
diff --git a/README.md b/README.md
@@ -1,4 +1,4 @@
-# AsToRia: Gas Mixture
+# AsToRia: Semi-Transparent Medium
This C library loads and manages the spectral data of a gas mixture whose
geometric support are tetrahedra.
@@ -9,8 +9,9 @@ This library is compatible GNU/Linux 64-bits. It relies the
[CMake](http://www.cmake.org) and the
[RCMake](https://gitlab.com/vaplv/rcmake/) packages to build.
It also depends on the
+[Astoria: Thermodynamic Properties](https://gitlab.com/meso-star/atrtp/),
[RSys](https://gitlab.com/vaplv/rsys/),
-[Star-UVM](https://gitlab.com/meso-star/star-uvm/),
+[Star-UnstructuredVolumetricMesh](https://gitlab.com/meso-star/star-uvm/),
[Star-TetraHedra](https://gitlab.com/meso-star/star-tetrahedra/) libraries,
and on [OpenMP](https://www.openmp.org) 1.2 the parallelize its computations.
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -14,15 +14,16 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 2.8)
-project(atrgm C)
+project(atrstm C)
enable_testing()
-set(ATRGM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
+set(ATRSTM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
option(NO_TEST "Do not build tests" OFF)
################################################################################
# Check dependencies
################################################################################
+find_package(AtrTP 0.0 REQUIRED)
find_package(OpenMP 1.2 REQUIRED)
find_package(RCMake 0.4 REQUIRED)
find_package(RSys 0.10 REQUIRED)
@@ -34,6 +35,7 @@ include(rcmake)
include(rcmake_runtime)
include_directories(
+ ${AtrTP_INCLUDE_DIR}
${RSys_INCLUDE_DIR}
${StarTetraHedra_INCLUDE_DIR}
${StarUVM_INCLUDE_DIR})
@@ -46,37 +48,37 @@ set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
-set(ATRGM_FILES_SRC
- atrgm.c
- atrgm_log.c)
-set(ATRGM_FILES_INC
- atrgm_c.h
- atrgm_log.h)
-set(ATRGM_FILES_INC_API
- atrgm.h)
+set(ATRSTM_FILES_SRC
+ atrstm.c
+ atrstm_log.c)
+set(ATRSTM_FILES_INC
+ atrstm_c.h
+ atrstm_log.h)
+set(ATRSTM_FILES_INC_API
+ atrstm.h)
-set(ATRGM_FILES_DOC COPYING README.md)
+set(ATRSTM_FILES_DOC COPYING README.md)
-# Prepend each file in the `ATRGM_FILES_<SRC|INC>' list by `ATRGM_SOURCE_DIR'
-rcmake_prepend_path(ATRGM_FILES_SRC ${ATRGM_SOURCE_DIR})
-rcmake_prepend_path(ATRGM_FILES_INC ${ATRGM_SOURCE_DIR})
-rcmake_prepend_path(ATRGM_FILES_INC_API ${ATRGM_SOURCE_DIR})
-rcmake_prepend_path(ATRGM_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
+# Prepend each file in the `ATRSTM_FILES_<SRC|INC>' list by `ATRSTM_SOURCE_DIR'
+rcmake_prepend_path(ATRSTM_FILES_SRC ${ATRSTM_SOURCE_DIR})
+rcmake_prepend_path(ATRSTM_FILES_INC ${ATRSTM_SOURCE_DIR})
+rcmake_prepend_path(ATRSTM_FILES_INC_API ${ATRSTM_SOURCE_DIR})
+rcmake_prepend_path(ATRSTM_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
-add_library(atrgm SHARED ${ATRGM_FILES_SRC} ${ATRGM_FILES_INC} ${ATRGM_FILES_INC_API})
-target_link_libraries(atrgm RSys StarTetraHedra StarUVM)
+add_library(atrstm SHARED ${ATRSTM_FILES_SRC} ${ATRSTM_FILES_INC} ${ATRSTM_FILES_INC_API})
+target_link_libraries(atrstm AtrTP RSys StarTetraHedra StarUVM)
if(CMAKE_COMPILER_IS_GNUCC)
- set_target_properties(atrgm PROPERTIES LINK_FLAGS "${OpenMP_C_FLAGS}")
+ set_target_properties(atrstm PROPERTIES LINK_FLAGS "${OpenMP_C_FLAGS}")
endif()
-set_target_properties(atrgm PROPERTIES
+set_target_properties(atrstm PROPERTIES
COMPILE_FLAGS ${OpenMP_C_FLAGS}
- DEFINE_SYMBOL ATRGM_SHARED_BUILD
+ DEFINE_SYMBOL ATRSTM_SHARED_BUILD
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR})
-rcmake_setup_devel(atrgm AtrGM ${VERSION} astoria/atrgm.h)
+rcmake_setup_devel(atrstm AtrGM ${VERSION} astoria/atrstm_version.h)
################################################################################
# Add tests
@@ -84,9 +86,9 @@ rcmake_setup_devel(atrgm AtrGM ${VERSION} astoria/atrgm.h)
if(NOT NO_TEST)
# function(build_test _name)
# add_executable(${_name}
- # ${ATRGM_SOURCE_DIR}/${_name}.c
- # ${ATRGM_SOURCE_DIR}/test_atrgm_utils.h)
- # target_link_libraries(${_name} atrgm RSys ${ARGN})
+ # ${ATRSTM_SOURCE_DIR}/${_name}.c
+ # ${ATRSTM_SOURCE_DIR}/test_atrstm_utils.h)
+ # target_link_libraries(${_name} atrstm RSys ${ARGN})
# endfunction()
#
# function(new_test _name)
@@ -94,16 +96,16 @@ if(NOT NO_TEST)
# add_test(${_name} ${_name})
# endfunction()
#
- # new_test(test_atrgm)
+ # new_test(test_atrstm)
endif()
################################################################################
# Define output & install directories
################################################################################
-install(TARGETS atrgm
+install(TARGETS atrstm
ARCHIVE DESTINATION bin
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
-install(FILES ${ATRGM_FILES_INC_API} DESTINATION include/astoria)
-install(FILES ${ATRGM_FILES_DOC} DESTINATION share/doc/atrgm)
+install(FILES ${ATRSTM_FILES_INC_API} DESTINATION include/astoria)
+install(FILES ${ATRSTM_FILES_DOC} DESTINATION share/doc/atrstm)
diff --git a/src/atrgm.c b/src/atrgm.c
@@ -1,115 +0,0 @@
-/* Copyright (C) 2020 CNRS
- *
- * 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 "atrgm.h"
-#include "atrgm_c.h"
-#include "atrgm_log.h"
-
-#include <rsys/mem_allocator.h>
-
-#include <omp.h>
-
-/*******************************************************************************
- * Helper functions
- ******************************************************************************/
-static void
-release_atrgm(ref_T* ref)
-{
- struct atrgm* atrgm;
- ASSERT(ref);
- atrgm = CONTAINER_OF(ref, struct atrgm, ref);
- if(atrgm->logger == &atrgm->logger__) logger_release(&atrgm->logger__);
- str_release(&atrgm->name);
- MEM_RM(atrgm->allocator, atrgm);
-}
-
-/*******************************************************************************
- * Exported functions
- ******************************************************************************/
-res_T
-atrgm_create
- (struct logger* logger, /* NULL <=> use default logger */
- struct mem_allocator* mem_allocator, /* NULL <=> use default allocator */
- const struct atrgm_args* args,
- struct atrgm** out_atrgm)
-{
- struct atrgm* atrgm = NULL;
- struct mem_allocator* allocator = NULL;
- int nthreads_max;
- res_T res = RES_OK;
-
- if(!out_atrgm) {
- res = RES_BAD_ARG;
- goto error;
- }
-
- allocator = mem_allocator ? mem_allocator : &mem_default_allocator;
- atrgm = MEM_CALLOC(allocator, 1, sizeof(*atrgm));
- if(!atrgm) {
- if(args->verbose) {
- #define ERR_STR "Could not allocate the AtrGM data structure.\n"
- if(logger) {
- logger_print(logger, LOG_ERROR, ERR_STR);
- } else {
- fprintf(stderr, MSG_ERROR_PREFIX ERR_STR);
- }
- #undef ERR_STR
- }
- res = RES_MEM_ERR;
- goto error;
- }
- nthreads_max = MMAX(omp_get_max_threads(), omp_get_num_procs());
- ref_init(&atrgm->ref);
- atrgm->allocator = allocator;
- atrgm->verbose = args->verbose;
- atrgm->nthreads = MMIN(args->nthreads, (unsigned)nthreads_max);
-
- if(logger) {
- atrgm->logger = logger;
- } else {
- setup_log_default(atrgm);
- }
-
- res = str_set(&atrgm->name, args->name);
- if(res != RES_OK) {
- log_err(atrgm, "Cannot setup the gas mixture name to `%s'.\n", args->name);
- goto error;
- }
-
- /* TODO load data */
-
-exit:
- if(out_atrgm) *out_atrgm = atrgm;
- return res;
-error:
- if(atrgm) { ATRGM(ref_put(atrgm)); atrgm = NULL; }
- goto exit;
-}
-
-res_T
-atrgm_ref_get(struct atrgm* atrgm)
-{
- if(!atrgm) return RES_BAD_ARG;
- ref_get(&atrgm->ref);
- return RES_OK;
-}
-
-res_T
-atrgm_ref_put(struct atrgm* atrgm)
-{
- if(!atrgm) return RES_BAD_ARG;
- ref_put(&atrgm->ref, release_atrgm);
- return RES_OK;
-}
diff --git a/src/atrgm.h b/src/atrgm.h
@@ -1,84 +0,0 @@
-/* Copyright (C) 2020 CNRS
- *
- * 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/>. */
-
-#ifndef ATRGM_H
-#define ATRGM_H
-
-#include <rsys/rsys.h>
-
-/* Library symbol management */
-#if defined(ATRGM_SHARED_BUILD) /* Build shared library */
- #define ATRGM_API extern EXPORT_SYM
-#elif defined(ATRGM_STATIC) /* Use/build static library */
- #define ATRGM_API extern LOCAL_SYM
-#else /* Use shared library */
- #define ATRGM_API extern IMPORT_SYM
-#endif
-
-/* Helper macro that asserts if the invocation of the atrgm function `Func'
- * returns an error. One should use this macro on suvm function calls for
- * which no explicit error checking is performed */
-#ifndef NDEBUG
- #define ATRGM(Func) ASSERT(atrgm_ ## Func == RES_OK)
-#else
- #define ATRGM(Func) atrgm_ ## Func
-#endif
-
-struct atrgm_args {
- const char* sth_filename; /* Filename of the Star-TetraHedra mesh */
- const char* name; /* Name of the gas mixture */
- unsigned nthreads; /* Hint on the number of threads to use */
- int verbose; /* Verbosity level */
-};
-
-#define ATRGM_ARGS_DEFAULT__ { \
- NULL, /* sth_filename */ \
- "gas mixture", /* Name */ \
- (unsigned)~0, /* #threads */ \
- 0 /* Verbosity level */ \
-}
-static const struct atrgm_args ATRGM_ARGS_DEFAULT = ATRGM_ARGS_DEFAULT__;
-
-/* Forward declaration of extern data types */
-struct logger;
-struct mem_allocator;
-
-/* Forward declaration of opaque data type */
-struct atrgm;
-
-BEGIN_DECLS
-
-/*******************************************************************************
- * AtgGM API
- ******************************************************************************/
-ATRGM_API res_T
-atrgm_create
- (struct logger* logger, /* NULL <=> use default logger */
- struct mem_allocator* allocator, /* NULL <=> use default allocator */
- const struct atrgm_args* args,
- struct atrgm** atrgm);
-
-ATRGM_API res_T
-atrgm_ref_get
- (struct atrgm* atrgm);
-
-
-ATRGM_API res_T
-atrgm_ref_put
- (struct atrgm* atrgm);
-
-END_DECLS
-
-#endif /* ATRGM_H */
diff --git a/src/atrgm_c.h b/src/atrgm_c.h
@@ -1,37 +0,0 @@
-/* Copyright (C) 2020 CNRS
- *
- * 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/>. */
-
-#ifndef ATRGM_C_H
-#define ATRGM_C_H
-
-#include <rsys/logger.h>
-#include <rsys/ref_count.h>
-#include <rsys/str.h>
-
-struct mem_allocator;
-
-struct atrgm {
- unsigned nthreads; /* #nthreads */
-
- struct str name; /* Name of the gas mixture */
-
- struct mem_allocator* allocator;
- struct logger* logger;
- struct logger logger__; /* Default logger */
- int verbose;
- ref_T ref;
-};
-
-#endif /* ATRGM_C_H */
diff --git a/src/atrgm_log.c b/src/atrgm_log.c
@@ -1,124 +0,0 @@
-/* Copyright (C) 2020 CNRS
- *
- * 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 "atrgm_c.h"
-#include "atrgm_log.h"
-
-#include <rsys/cstr.h>
-#include <rsys/logger.h>
-
-#include <stdarg.h>
-
-/*******************************************************************************
- * Helper functions
- ******************************************************************************/
-static INLINE void
-log_msg
- (const struct atrgm* atrgm,
- const enum log_type stream,
- const char* msg,
- va_list vargs)
-{
- ASSERT(atrgm && msg);
- if(atrgm->verbose) {
- res_T res; (void)res;
- res = logger_vprint(atrgm->logger, stream, msg, vargs);
- ASSERT(res == RES_OK);
- }
-}
-
-static void
-print_info(const char* msg, void* ctx)
-{
- (void)ctx;
- fprintf(stderr, MSG_INFO_PREFIX"%s", msg);
-}
-
-static void
-print_err(const char* msg, void* ctx)
-{
- (void)ctx;
- fprintf(stderr, MSG_ERROR_PREFIX"%s", msg);
-}
-
-static void
-print_warn(const char* msg, void* ctx)
-{
- (void)ctx;
- fprintf(stderr, MSG_WARNING_PREFIX"%s", msg);
-}
-
-/*******************************************************************************
- * Local functions
- ******************************************************************************/
-res_T
-setup_log_default(struct atrgm* atrgm)
-{
- res_T res = RES_OK;
- ASSERT(atrgm);
-
- res = logger_init(atrgm->allocator, &atrgm->logger__);
- if(res != RES_OK) {
- if(atrgm->verbose) {
- fprintf(stderr,
- MSG_ERROR_PREFIX
- "Could not setup the AtrGM default logger -- %s.\n",
- res_to_cstr(res));
- }
- goto error;
- }
- logger_set_stream(&atrgm->logger__, LOG_OUTPUT, print_info, NULL);
- logger_set_stream(&atrgm->logger__, LOG_ERROR, print_err, NULL);
- logger_set_stream(&atrgm->logger__, LOG_WARNING, print_warn, NULL);
- atrgm->logger = &atrgm->logger__;
-
-exit:
- return res;
-error:
- goto exit;
-}
-
-void
-log_info(const struct atrgm* atrgm, const char* msg, ...)
-{
- va_list vargs_list;
- ASSERT(atrgm && msg);
-
- va_start(vargs_list, msg);
- log_msg(atrgm, LOG_OUTPUT, msg, vargs_list);
- va_end(vargs_list);
-}
-
-void
-log_err(const struct atrgm* atrgm, const char* msg, ...)
-{
- va_list vargs_list;
- ASSERT(atrgm && msg);
-
- va_start(vargs_list, msg);
- log_msg(atrgm, LOG_ERROR, msg, vargs_list);
- va_end(vargs_list);
-}
-
-void
-log_warn(const struct atrgm* atrgm, const char* msg, ...)
-{
- va_list vargs_list;
- ASSERT(atrgm && msg);
-
- va_start(vargs_list, msg);
- log_msg(atrgm, LOG_WARNING, msg, vargs_list);
- va_end(vargs_list);
-}
diff --git a/src/atrgm_log.h b/src/atrgm_log.h
@@ -1,68 +0,0 @@
-/* Copyright (C) 2020 CNRS
- *
- * 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/>. */
-
-#ifndef ATRGM_LOG_H
-#define ATRGM_LOG_H
-
-#include <rsys/rsys.h>
-
-#define MSG_INFO_PREFIX "AtrGM:\x1b[1m\x1b[32minfo\x1b[0m: "
-#define MSG_ERROR_PREFIX "AtrGM:\x1b[1m\x1b[31merror\x1b[0m: "
-#define MSG_WARNING_PREFIX "AtrGM:\x1b[1m\x1b[33mwarning\x1b[0m: "
-
-struct atrgm;
-struct logger;
-
-extern LOCAL_SYM res_T
-setup_log_default
- (struct atrgm* atrgm);
-
-/* Conditionally log a message on the LOG_OUTPUT stream of the atrgm logger,
- * with respect to its verbose flag */
-extern LOCAL_SYM void
-log_info
- (const struct atrgm* atrgm,
- const char* msg,
- ...)
-#ifdef COMPILER_GCC
- __attribute((format(printf, 2, 3)))
-#endif
-;
-
-/* Conditionally log a message on the LOG_ERROR stream of the atrgm logger,
- * with respect to its verbose flag */
-extern LOCAL_SYM void
-log_err
- (const struct atrgm* atrgm,
- const char* msg,
- ...)
-#ifdef COMPILER_GCC
- __attribute((format(printf, 2, 3)))
-#endif
-;
-
-/* Conditionally log a message on the LOG_WARNING stream of the atrgm logger,
- * with respect to its verbose flag */
-extern LOCAL_SYM void
-log_warn
- (const struct atrgm* atrgm,
- const char* msg,
- ...)
-#ifdef COMPILER_GCC
- __attribute((format(printf, 2, 3)))
-#endif
-;
-
-#endif /* ATRGM_LOG_H */
diff --git a/src/atrstm.c b/src/atrstm.c
@@ -0,0 +1,162 @@
+/* Copyright (C) 2020 CNRS
+ *
+ * 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 "atrstm.h"
+#include "atrstm_c.h"
+#include "atrstm_log.h"
+
+#include <astoria/atrtp.h>
+
+#include <rsys/mem_allocator.h>
+#include <star/sth.h>
+#include <star/suvm.h>
+
+#include <omp.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static int
+check_args(const struct atrstm_args* args)
+{
+ return args
+ && args->sth_filename
+ && (args->spectral_type != ATRSTM_SPECTRAL_LW || args->atrck_filename)
+ && args->atrtp_filename
+ && args->atrri_filename
+ && args->name
+ && (unsigned)args->spectral_type < ATRSTM_SPECTRAL_TYPES_COUNT__
+ && args->wlen_range[0] <= args->wlen_range[1]
+ && args->grid_max_definition[0]
+ && args->grid_max_definition[1]
+ && args->grid_max_definition[2]
+ && args->optical_thickness >= 0
+ && args->nthreads;
+}
+
+static void
+release_atrstm(ref_T* ref)
+{
+ struct atrstm* atrstm;
+ ASSERT(ref);
+ atrstm = CONTAINER_OF(ref, struct atrstm, ref);
+ if(atrstm->sth) STH(ref_put(atrstm->sth));
+ if(atrstm->atrtp) ATRTP(ref_put(atrstm->atrtp));
+ if(atrstm->logger == &atrstm->logger__) logger_release(&atrstm->logger__);
+ str_release(&atrstm->name);
+ MEM_RM(atrstm->allocator, atrstm);
+}
+
+/*******************************************************************************
+ * Exported functions
+ ******************************************************************************/
+res_T
+atrstm_create
+ (struct logger* logger, /* NULL <=> use default logger */
+ struct mem_allocator* mem_allocator, /* NULL <=> use default allocator */
+ const struct atrstm_args* args,
+ struct atrstm** out_atrstm)
+{
+ struct atrstm* atrstm = NULL;
+ struct mem_allocator* allocator = NULL;
+ int nthreads_max;
+ res_T res = RES_OK;
+
+ if(!out_atrstm || check_args(args)) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ allocator = mem_allocator ? mem_allocator : &mem_default_allocator;
+ atrstm = MEM_CALLOC(allocator, 1, sizeof(*atrstm));
+ if(!atrstm && check_args(args)) {
+ if(args->verbose) {
+ #define ERR_STR "Could not allocate the AtrGM data structure.\n"
+ if(logger) {
+ logger_print(logger, LOG_ERROR, ERR_STR);
+ } else {
+ fprintf(stderr, MSG_ERROR_PREFIX ERR_STR);
+ }
+ #undef ERR_STR
+ }
+ res = RES_MEM_ERR;
+ goto error;
+ }
+ nthreads_max = MMAX(omp_get_max_threads(), omp_get_num_procs());
+ ref_init(&atrstm->ref);
+ atrstm->allocator = allocator;
+ atrstm->verbose = args->verbose;
+ atrstm->nthreads = MMIN(args->nthreads, (unsigned)nthreads_max);
+
+ if(logger) {
+ atrstm->logger = logger;
+ } else {
+ setup_log_default(atrstm);
+ }
+
+ if(args->spectral_type == ATRSTM_SPECTRAL_SW
+ && args->wlen_range[0] != args->wlen_range[1]) {
+ log_err(atrstm,
+ "Invalid spectral range [%g, %g], Only monochromatic computations are "
+ "supported in shortwave.\n",
+ args->wlen_range[0],
+ args->wlen_range[1]);
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ res = str_set(&atrstm->name, args->name);
+ if(res != RES_OK) {
+ log_err(atrstm, "Cannot setup the gas mixture name to `%s'.\n", args->name);
+ goto error;
+ }
+
+ /* Load the volumetric mesh */
+ res = sth_create
+ (atrstm->logger, atrstm->allocator, atrstm->verbose, &atrstm->sth);
+ if(res != RES_OK) goto error;
+ res = sth_load(atrstm->sth, args->sth_filename);
+ if(res != RES_OK) goto error;
+
+ /* Load the thermodynamic properties of the volumetric mesh */
+ res = atrtp_create
+ (atrstm->logger, atrstm->allocator, atrstm->verbose, &atrstm->atrtp);
+ if(res != RES_OK) goto error;
+ res = atrtp_load(atrstm->atrtp, args->atrtp_filename);
+ if(res != RES_OK) goto error;
+
+exit:
+ if(out_atrstm) *out_atrstm = atrstm;
+ return res;
+error:
+ if(atrstm) { ATRSTM(ref_put(atrstm)); atrstm = NULL; }
+ goto exit;
+}
+
+res_T
+atrstm_ref_get(struct atrstm* atrstm)
+{
+ if(!atrstm) return RES_BAD_ARG;
+ ref_get(&atrstm->ref);
+ return RES_OK;
+}
+
+res_T
+atrstm_ref_put(struct atrstm* atrstm)
+{
+ if(!atrstm) return RES_BAD_ARG;
+ ref_put(&atrstm->ref, release_atrstm);
+ return RES_OK;
+}
diff --git a/src/atrstm.h b/src/atrstm.h
@@ -0,0 +1,106 @@
+/* Copyright (C) 2020 CNRS
+ *
+ * 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/>. */
+
+#ifndef ATRSTM_H
+#define ATRSTM_H
+
+#include <rsys/rsys.h>
+#include <float.h>
+#include <limits.h>
+
+/* Library symbol management */
+#if defined(ATRSTM_SHARED_BUILD) /* Build shared library */
+ #define ATRSTM_API extern EXPORT_SYM
+#elif defined(ATRSTM_STATIC) /* Use/build static library */
+ #define ATRSTM_API extern LOCAL_SYM
+#else /* Use shared library */
+ #define ATRSTM_API extern IMPORT_SYM
+#endif
+
+/* Helper macro that asserts if the invocation of the atrstm function `Func'
+ * returns an error. One should use this macro on suvm function calls for
+ * which no explicit error checking is performed */
+#ifndef NDEBUG
+ #define ATRSTM(Func) ASSERT(atrstm_ ## Func == RES_OK)
+#else
+ #define ATRSTM(Func) atrstm_ ## Func
+#endif
+
+enum atrstm_spectral_type {
+ ATRSTM_SPECTRAL_LW, /* Longwave */
+ ATRSTM_SPECTRAL_SW, /* Shortwave */
+ ATRSTM_SPECTRAL_TYPES_COUNT__
+};
+
+struct atrstm_args {
+ const char* sth_filename; /* Filename of the Star-TetraHedra mesh */
+ const char* atrck_filename; /* Filename of the Correlated K */
+ const char* atrtp_filename; /* Filename of the Thermodynamic properties */
+ const char* atrri_filename; /* Filename of the refraction index LUT */
+ const char* name; /* Name of the gas mixture */
+ enum atrstm_spectral_type spectral_type; /* Longwave/shortwave */
+ double wlen_range[2]; /* Spectral range to handle In nm */
+ unsigned grid_max_definition[3]; /* Maximum definition of the grid */
+ double optical_thickness; /* Threshold used during octree building */
+ unsigned nthreads; /* Hint on the number of threads to use */
+ int verbose; /* Verbosity level */
+};
+
+#define ATRSTM_ARGS_DEFAULT__ { \
+ NULL, /* STh filename */ \
+ NULL, /* AtrCK filename */ \
+ NULL, /* AtrTP filename */ \
+ NULL, /* AtrRI filename */ \
+ "gas mixture", /* Name */ \
+ ATRSTM_SPECTRAL_TYPES_COUNT__, /* Spectral type */ \
+ {DBL_MAX,-DBL_MAX}, /* Spectral integration range */ \
+ {UINT_MAX, UINT_MAX, UINT_MAX}, /* Acceleration grid max definition */ \
+ 1, /* Optical thickness */ \
+ (unsigned)~0, /* #threads */ \
+ 0 /* Verbosity level */ \
+}
+static const struct atrstm_args ATRSTM_ARGS_DEFAULT = ATRSTM_ARGS_DEFAULT__;
+
+/* Forward declaration of extern data types */
+struct logger;
+struct mem_allocator;
+
+/* Forward declaration of opaque data type */
+struct atrstm;
+
+BEGIN_DECLS
+
+/*******************************************************************************
+ * AtgGM API
+ ******************************************************************************/
+ATRSTM_API res_T
+atrstm_create
+ (struct logger* logger, /* NULL <=> use default logger */
+ struct mem_allocator* allocator, /* NULL <=> use default allocator */
+ const struct atrstm_args* args,
+ struct atrstm** atrstm);
+
+ATRSTM_API res_T
+atrstm_ref_get
+ (struct atrstm* atrstm);
+
+
+ATRSTM_API res_T
+atrstm_ref_put
+ (struct atrstm* atrstm);
+
+END_DECLS
+
+#endif /* ATRSTM_H */
diff --git a/src/atrstm_c.h b/src/atrstm_c.h
@@ -0,0 +1,43 @@
+/* Copyright (C) 2020 CNRS
+ *
+ * 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/>. */
+
+#ifndef ATRSTM_C_H
+#define ATRSTM_C_H
+
+#include <rsys/logger.h>
+#include <rsys/ref_count.h>
+#include <rsys/str.h>
+
+/* Forward declaration of external data types */
+struct atrtp;
+struct mem_allocator;
+struct sth;
+
+struct atrstm {
+ struct atrtp* atrtp; /* Handle toward the Astoria Thermodynamic properties */
+ struct sth* sth; /* Handle toward Star-TetraHedra */
+
+ unsigned nthreads; /* #nthreads */
+
+ struct str name; /* Name of the gas mixture */
+
+ struct mem_allocator* allocator;
+ struct logger* logger;
+ struct logger logger__; /* Default logger */
+ int verbose;
+ ref_T ref;
+};
+
+#endif /* ATRSTM_C_H */
diff --git a/src/atrstm_log.c b/src/atrstm_log.c
@@ -0,0 +1,124 @@
+/* Copyright (C) 2020 CNRS
+ *
+ * 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 "atrstm_c.h"
+#include "atrstm_log.h"
+
+#include <rsys/cstr.h>
+#include <rsys/logger.h>
+
+#include <stdarg.h>
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static INLINE void
+log_msg
+ (const struct atrstm* atrstm,
+ const enum log_type stream,
+ const char* msg,
+ va_list vargs)
+{
+ ASSERT(atrstm && msg);
+ if(atrstm->verbose) {
+ res_T res; (void)res;
+ res = logger_vprint(atrstm->logger, stream, msg, vargs);
+ ASSERT(res == RES_OK);
+ }
+}
+
+static void
+print_info(const char* msg, void* ctx)
+{
+ (void)ctx;
+ fprintf(stderr, MSG_INFO_PREFIX"%s", msg);
+}
+
+static void
+print_err(const char* msg, void* ctx)
+{
+ (void)ctx;
+ fprintf(stderr, MSG_ERROR_PREFIX"%s", msg);
+}
+
+static void
+print_warn(const char* msg, void* ctx)
+{
+ (void)ctx;
+ fprintf(stderr, MSG_WARNING_PREFIX"%s", msg);
+}
+
+/*******************************************************************************
+ * Local functions
+ ******************************************************************************/
+res_T
+setup_log_default(struct atrstm* atrstm)
+{
+ res_T res = RES_OK;
+ ASSERT(atrstm);
+
+ res = logger_init(atrstm->allocator, &atrstm->logger__);
+ if(res != RES_OK) {
+ if(atrstm->verbose) {
+ fprintf(stderr,
+ MSG_ERROR_PREFIX
+ "Could not setup the AtrGM default logger -- %s.\n",
+ res_to_cstr(res));
+ }
+ goto error;
+ }
+ logger_set_stream(&atrstm->logger__, LOG_OUTPUT, print_info, NULL);
+ logger_set_stream(&atrstm->logger__, LOG_ERROR, print_err, NULL);
+ logger_set_stream(&atrstm->logger__, LOG_WARNING, print_warn, NULL);
+ atrstm->logger = &atrstm->logger__;
+
+exit:
+ return res;
+error:
+ goto exit;
+}
+
+void
+log_info(const struct atrstm* atrstm, const char* msg, ...)
+{
+ va_list vargs_list;
+ ASSERT(atrstm && msg);
+
+ va_start(vargs_list, msg);
+ log_msg(atrstm, LOG_OUTPUT, msg, vargs_list);
+ va_end(vargs_list);
+}
+
+void
+log_err(const struct atrstm* atrstm, const char* msg, ...)
+{
+ va_list vargs_list;
+ ASSERT(atrstm && msg);
+
+ va_start(vargs_list, msg);
+ log_msg(atrstm, LOG_ERROR, msg, vargs_list);
+ va_end(vargs_list);
+}
+
+void
+log_warn(const struct atrstm* atrstm, const char* msg, ...)
+{
+ va_list vargs_list;
+ ASSERT(atrstm && msg);
+
+ va_start(vargs_list, msg);
+ log_msg(atrstm, LOG_WARNING, msg, vargs_list);
+ va_end(vargs_list);
+}
diff --git a/src/atrstm_log.h b/src/atrstm_log.h
@@ -0,0 +1,68 @@
+/* Copyright (C) 2020 CNRS
+ *
+ * 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/>. */
+
+#ifndef ATRSTM_LOG_H
+#define ATRSTM_LOG_H
+
+#include <rsys/rsys.h>
+
+#define MSG_INFO_PREFIX "AtrGM:\x1b[1m\x1b[32minfo\x1b[0m: "
+#define MSG_ERROR_PREFIX "AtrGM:\x1b[1m\x1b[31merror\x1b[0m: "
+#define MSG_WARNING_PREFIX "AtrGM:\x1b[1m\x1b[33mwarning\x1b[0m: "
+
+struct atrstm;
+struct logger;
+
+extern LOCAL_SYM res_T
+setup_log_default
+ (struct atrstm* atrstm);
+
+/* Conditionally log a message on the LOG_OUTPUT stream of the atrstm logger,
+ * with respect to its verbose flag */
+extern LOCAL_SYM void
+log_info
+ (const struct atrstm* atrstm,
+ const char* msg,
+ ...)
+#ifdef COMPILER_GCC
+ __attribute((format(printf, 2, 3)))
+#endif
+;
+
+/* Conditionally log a message on the LOG_ERROR stream of the atrstm logger,
+ * with respect to its verbose flag */
+extern LOCAL_SYM void
+log_err
+ (const struct atrstm* atrstm,
+ const char* msg,
+ ...)
+#ifdef COMPILER_GCC
+ __attribute((format(printf, 2, 3)))
+#endif
+;
+
+/* Conditionally log a message on the LOG_WARNING stream of the atrstm logger,
+ * with respect to its verbose flag */
+extern LOCAL_SYM void
+log_warn
+ (const struct atrstm* atrstm,
+ const char* msg,
+ ...)
+#ifdef COMPILER_GCC
+ __attribute((format(printf, 2, 3)))
+#endif
+;
+
+#endif /* ATRSTM_LOG_H */