solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 34c1f431e3ef0c4ff983a68fba1600f9c39b5eaa
parent ae496eb2b7cccfac69d6a0f2ceadb00cef0227e8
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 29 Jun 2016 17:58:07 +0200

First try at spectra.

Diffstat:
Mcmake/CMakeLists.txt | 7+++++--
Msrc/ssol.h | 4++--
Asrc/ssol_spectrum.c | 118+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ssol_spectrum_c.h | 28++++++++++++++++++++++++++++
Asrc/test_ssol_spectrum.c | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 217 insertions(+), 4 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -53,7 +53,8 @@ set(SSOL_FILES_SRC ssol_object.c ssol_object_instance.c ssol_scene.c - ssol_shape.c) + ssol_shape.c + ssol_spectrum.c) set(SSOL_FILES_INC_API ssol.h) @@ -65,7 +66,8 @@ set(SSOL_FILES_INC ssol_object_c.h ssol_object_instance_c.h ssol_scene_c.h - ssol_shape_c.h) + ssol_shape_c.h + ssol_spectrum_c.h) set(SSOL_FILES_DOC COPYING README.md) @@ -121,6 +123,7 @@ if(NOT NO_TEST) new_test(test_ssol_object_instance) new_test(test_ssol_scene) new_test(test_ssol_shape) + new_test(test_ssol_spectrum) endif(NOT NO_TEST) ################################################################################ diff --git a/src/ssol.h b/src/ssol.h @@ -428,7 +428,7 @@ ssol_object_instance_is_attached SSOL_API res_T ssol_spectrum_create (struct ssol_device* dev, - struct ssol_spectrum* spectrum); + struct ssol_spectrum** spectrum); SSOL_API res_T ssol_spectrum_ref_get @@ -486,7 +486,7 @@ ssol_sun_set_direction SSOL_API res_T ssol_sun_set_spectrum (struct ssol_sun* sun, - const struct ssol_spectrum* spectrum); + struct ssol_spectrum* spectrum); SSOL_API res_T ssol_sun_set_pillbox_aperture diff --git a/src/ssol_spectrum.c b/src/ssol_spectrum.c @@ -0,0 +1,117 @@ +/* Copyright (C) CNRS 2016 +* +* 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 "ssol.h" +#include "ssol_spectrum_c.h" +#include "ssol_device_c.h" + +#include <rsys/rsys.h> +#include <rsys/mem_allocator.h> +#include <rsys/ref_count.h> +#include <rsys/math.h> + +/******************************************************************************* +* Helper functions +******************************************************************************/ + +static void +spectrum_release(ref_T* ref) +{ + struct ssol_spectrum* spectrum; + struct ssol_device* dev; + ASSERT(ref); + spectrum = CONTAINER_OF(ref, struct ssol_spectrum, ref); + dev = spectrum->dev; + ASSERT(dev && dev->allocator); + MEM_RM(dev->allocator, spectrum); + SSOL(device_ref_put(dev)); +} + +/******************************************************************************* +* Local functions +******************************************************************************/ + +/******************************************************************************* +* Exported ssol_image functions +******************************************************************************/ + +res_T +ssol_spectrum_create + (struct ssol_device* dev, + struct ssol_spectrum** out_spectrum) +{ + struct ssol_spectrum* spectrum = NULL; + res_T res = RES_OK; + if (!dev || !out_spectrum) { + return RES_BAD_ARG; + } + + spectrum = (struct ssol_spectrum*)MEM_CALLOC + (dev->allocator, 1, sizeof(struct ssol_spectrum)); + if (!spectrum) { + res = RES_MEM_ERR; + goto error; + } + + SSOL(device_ref_get(dev)); + spectrum->dev = dev; + ref_init(&spectrum->ref); + +exit: + if (out_spectrum) *out_spectrum = spectrum; + return res; +error: + if (spectrum) { + SSOL(spectrum_ref_put(spectrum)); + spectrum = NULL; + } + goto exit; +} + +res_T +ssol_spectrum_ref_get + (struct ssol_spectrum* spectrum) +{ + if (!spectrum) + return RES_BAD_ARG; + ref_get(&spectrum->ref); + return RES_OK; +} + +res_T +ssol_spectrum_ref_put + (struct ssol_spectrum* spectrum) +{ + if (!spectrum) + return RES_BAD_ARG; + ref_put(&spectrum->ref, spectrum_release); + return RES_OK; +} + +SSOL_API res_T +ssol_spectrum_setup + (struct ssol_spectrum* spectrum, + const double* wavelenghts, + const double* data, + const size_t nwavelength) +{ + if (!spectrum + || nwavelength <= 0 + || !wavelenghts + || !data) + return RES_BAD_ARG; + /* TODO */ + return RES_OK; +} +\ No newline at end of file diff --git a/src/ssol_spectrum_c.h b/src/ssol_spectrum_c.h @@ -0,0 +1,28 @@ +/* Copyright (C) CNRS 2016 +* +* 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 SSOL_SPECTRUM_C_H +#define SSOL_SPECTRUM_C_H + +#include <rsys/ref_count.h> +#include <rsys/list.h> + +struct ssol_spectrum { + + struct ssol_device* dev; + ref_T ref; +}; + +#endif /* SSOL_SPECTRUM_C_H */ diff --git a/src/test_ssol_spectrum.c b/src/test_ssol_spectrum.c @@ -0,0 +1,63 @@ +/* Copyright (C) CNRS 2016 +* +* 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 "ssol.h" +#include "test_ssol_utils.h" + +#include <rsys/logger.h> + +/******************************************************************************* +* test main program +******************************************************************************/ +int +main(int argc, char** argv) +{ + struct logger logger; + struct mem_allocator allocator; + struct ssol_device* dev; + struct ssol_spectrum* spectrum; + (void) argc, (void) argv; + + mem_init_proxy_allocator(&allocator, &mem_default_allocator); + + CHECK(logger_init(&allocator, &logger), RES_OK); + logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); + logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); + logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); + + CHECK(ssol_device_create(&logger, &allocator, SSOL_NTHREADS_DEFAULT, 0, &dev), RES_OK); + + CHECK(ssol_spectrum_create(NULL, &spectrum), RES_BAD_ARG); + CHECK(ssol_spectrum_create(dev, NULL), RES_BAD_ARG); + CHECK(ssol_spectrum_create(dev, &spectrum), RES_OK); + + CHECK(ssol_spectrum_ref_get(NULL), RES_BAD_ARG); + CHECK(ssol_spectrum_ref_get(spectrum), RES_OK); + + CHECK(ssol_spectrum_ref_put(NULL), RES_BAD_ARG); + CHECK(ssol_spectrum_ref_put(spectrum), RES_OK); + + CHECK(ssol_spectrum_ref_put(spectrum), RES_OK); + + CHECK(ssol_device_ref_put(dev), RES_OK); + + logger_release(&logger); + + check_memory_allocator(&allocator); + mem_shutdown_proxy_allocator(&allocator); + CHECK(mem_allocated_size(), 0); + + return 0; +} +\ No newline at end of file