commit fb1b04ce1d3b2927b69344594f579e79d610b06f parent d96338f5abb146f9bb2109508c81aa9317cf3ff5 Author: Christophe Coustet <christophe.coustet@meso-star.com> Date: Mon, 7 Sep 2026 16:04:42 +0200 Merge branch 'release_0.11' Diffstat:
76 files changed, 277 insertions(+), 99 deletions(-)
diff --git a/Makefile b/Makefile @@ -89,6 +89,7 @@ src/.config: config.mk $(PKG_CONFIG) --atleast-version $(SCPR_VERSION) scpr $(PKG_CONFIG) --atleast-version $(SSF_VERSION) ssf $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp + $(PKG_CONFIG) --atleast-version $(SCEM_VERSION) scem @echo "config done" > $@ $(DEP) : $(HDR) @@ -111,6 +112,7 @@ src/ssol.pc: ssol.pc.in -e 's#@SCPR_VERSION@#$(SCPR_VERSION)#g'\ -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\ -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\ + -e 's#@SCEM_VERSION@#$(SCEM_VERSION)#g'\ ssol.pc.in > $@ src/ssol-local.pc: ssol.pc.in @@ -123,6 +125,7 @@ src/ssol-local.pc: ssol.pc.in -e 's#@SCPR_VERSION@#$(SCPR_VERSION)#g'\ -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\ -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\ + -e 's#@SCEM_VERSION@#$(SCEM_VERSION)#g'\ ssol.pc.in > $@ src/ssol_version.h: src/ssol_version.h.in diff --git a/README.md b/README.md @@ -10,11 +10,11 @@ development effort funded by [Ademe](https://www.ademe.fr/) is ongoing. ## How to build -This library, as part of the Solstice app, can be built on any POSIX system. +This library, as part of the Solstice app, can be built on any x86-64 POSIX system. Note that you will most likely want to build the entire Solstice app rather than -this library alone. If so, a good starting point is the -[start-build](https://gitlab.com/meso-star/star-build) build system. +this library alone. If so, a good starting point is the dedicated +[Solstice web page](https://www.meso-star.com/solstice/install.html). The Solstice-Solver library depends on the [RSys](https://gitlab.com/vaplv/rsys/), @@ -35,6 +35,12 @@ the project by running: ## Release notes +### Version 0.11 + +- Add location + date as a way to define sun direction. + +- Add 2 algorithm to compute sun direction from locatio + date (Meeus and PSA). + ### Version 0.10 Replace CMake with a POSIX Makefile @@ -160,7 +166,7 @@ Fix the creation of a glossy BSDF that uses a pillbox microfacet distribution. ## License -Copyright (C) 2018-2026 |Meso|Star> (<contact@meso-star.com>). +Copyright (C) 2018-2026 |Méso|Star> (<contact@meso-star.com>). Copyright (C) 2016, 2018 CNRS. Solstice-Solver is free software released under the GPL v3+ license: GNU GPL diff --git a/config.mk b/config.mk @@ -1,5 +1,5 @@ VERSION_MAJOR = 0 -VERSION_MINOR = 10 +VERSION_MINOR = 11 VERSION_PATCH = 0 VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH) @@ -36,10 +36,11 @@ S3DUT_VERSION = 0.4 SCPR_VERSION = 0.5 SSF_VERSION = 0.10 SSP_VERSION = 0.15 +SCEM_VERSION = 0.1 -INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys s3d s3dut scpr ssf star-sp)\ +INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys s3d s3dut scpr ssf star-sp scem)\ -fopenmp -LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys s3d s3dut scpr ssf star-sp)\ +LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys s3d s3dut scpr ssf star-sp scem)\ -fopenmp -lm ################################################################################ diff --git a/src/ssol.h b/src/ssol.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -45,6 +45,7 @@ struct logger; struct mem_allocator; struct ssp_rng; +struct tm; /* Opaque Solstice solver types */ struct ssol_atmosphere; @@ -132,6 +133,18 @@ enum ssol_data_type { SSOL_DATA_SPECTRUM }; +/* The algorithm used to produce sun direction from location and date */ +enum ssol_sun_direction_algorithm { + SSOL_SUN_DIRECTION_ALGORITHM_MEEUS, + SSOL_SUN_DIRECTION_ALGORITHM_PSA +}; + +/* The longitude must be in [-180, 180] degrees relative to Greenwich. + * The angle is positive towards the east. + * The latitude must be in [-90, 90] degrees relative to the equator. + * It is positive towards the north. */ +struct ssol_location { double latitude; double longitude; }; + /* Describe a vertex data */ struct ssol_vertex_data { enum ssol_attrib_usage usage; /* Semantic of the data */ @@ -1032,6 +1045,28 @@ ssol_sun_set_direction (struct ssol_sun* sun, const double direction[3]); +/* Main sun direction defined by location and date using the currently defined + * algorithm. */ +SSOL_API res_T +ssol_sun_set_location_and_date + (struct ssol_sun* sun, + const struct ssol_location* location, + const struct tm* date); + +/* Set the algorithm used to produce sun direction from location and date. + * Suns are created with algorithm == SSOL_SUN_DIRECTION_ALGORITHM_MEEUS, + * regardless of their type. */ +SSOL_API res_T +ssol_sun_set_algorithm + (struct ssol_sun* sun, + const enum ssol_sun_direction_algorithm algorithm); + +SSOL_API res_T +ssol_sun_get_algorithm + (const struct ssol_sun* sun, + enum ssol_sun_direction_algorithm* algorithm); + +/* Get direction from sun */ SSOL_API res_T ssol_sun_get_direction (const struct ssol_sun* sun, diff --git a/src/ssol_atmosphere.c b/src/ssol_atmosphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_atmosphere_c.h b/src/ssol_atmosphere_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_c.h b/src/ssol_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_camera.c b/src/ssol_camera.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_camera.h b/src/ssol_camera.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_data.c b/src/ssol_data.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_device.c b/src/ssol_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_device_c.h b/src/ssol_device_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_draw.c b/src/ssol_draw.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_draw.h b/src/ssol_draw.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_draw_draft.c b/src/ssol_draw_draft.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_draw_pt.c b/src/ssol_draw_pt.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_estimator.c b/src/ssol_estimator.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_estimator_c.h b/src/ssol_estimator_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_image.c b/src/ssol_image.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_image_c.h b/src/ssol_image_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_instance.c b/src/ssol_instance.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_instance_c.h b/src/ssol_instance_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_material.c b/src/ssol_material.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_material_c.h b/src/ssol_material_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_mc_receiver.c b/src/ssol_mc_receiver.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -21,11 +21,6 @@ #include <rsys/double3.h> #include <star/s3d.h> -#ifdef COMPILER_CL - #pragma warning(push) - #pragma warning(disable:4706) /* Assignment within a condition */ -#endif - /******************************************************************************* * Exported functions ******************************************************************************/ @@ -171,8 +166,3 @@ ssol_mc_shape_get_mc_primitive return RES_OK; } - -#ifdef COMPILER_CL - #pragma warning(pop) -#endif - diff --git a/src/ssol_object.c b/src/ssol_object.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_object_c.h b/src/ssol_object_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_param_buffer.c b/src/ssol_param_buffer.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_ranst_sun_dir.c b/src/ssol_ranst_sun_dir.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -109,21 +109,21 @@ chi_value(const double csr) static FINLINE double phi_solar_disk(const double theta) { - /* The parameter theta is the zenith angle in radians */ + /* The parameter theta is the elevation in radians */ return cos(326 * theta) / cos(308 * theta); } static FINLINE double phi_circum_solor_region(const double theta, const struct ran_buie_state* state) { - /* The parameter theta is the zenith angle in radians */ + /* The parameter theta is the elevation in radians */ return state->etokTimes1000toGamma * pow(theta, state->gamma); } static FINLINE double phi(const double theta, const struct ran_buie_state* state) { - /* The parameter theta is the zenith angle in radians */ + /* The parameter theta is the elevation in radians */ if (theta < state->thetaSD) return phi_solar_disk(theta); else return phi_circum_solor_region(theta, state); } @@ -131,7 +131,7 @@ phi(const double theta, const struct ran_buie_state* state) static FINLINE double pdf_theta(const double theta, const struct ran_buie_state* state) { - /* The parameter theta is the zenith angle in radians */ + /* The parameter theta is the elevation in radians */ return state->alpha * phi(theta, state) * sin(theta); } @@ -174,7 +174,7 @@ proba_rect1 } static FINLINE double -zenith_angle(struct ssp_rng* rng, const struct ran_buie_state* state) +elevation_angle(struct ssp_rng* rng, const struct ran_buie_state* state) { double theta; double value; @@ -228,7 +228,7 @@ ran_buie_get double phi, theta, sinTheta, cosTheta, cosPhi, sinPhi; ASSERT(ran->state.buie.thetaSD > 0); phi = ssp_rng_uniform_double(rng, 0, 2 * PI); - theta = zenith_angle(rng, &ran->state.buie); + theta = elevation_angle(rng, &ran->state.buie); sinTheta = sin(theta); cosTheta = cos(theta); cosPhi = cos(phi); diff --git a/src/ssol_ranst_sun_dir.h b/src/ssol_ranst_sun_dir.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_ranst_sun_wl.c b/src/ssol_ranst_sun_wl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_ranst_sun_wl.h b/src/ssol_ranst_sun_wl.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_scene.c b/src/ssol_scene.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_scene_c.h b/src/ssol_scene_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_shape.c b/src/ssol_shape.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_shape_c.h b/src/ssol_shape_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -881,7 +881,7 @@ trace_radiative_path struct ranst_sun_wl* ran_sun_wl, const struct ssol_path_tracker* tracker) /* May be NULL */ { - struct path path; + struct path path = {0}; struct ssol_medium in_medium = SSOL_MEDIUM_VACUUM; struct ssol_medium out_medium = SSOL_MEDIUM_VACUUM; struct s3d_hit hit = S3D_HIT_NULL; diff --git a/src/ssol_spectrum.c b/src/ssol_spectrum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_spectrum_c.h b/src/ssol_spectrum_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/ssol_sun.c b/src/ssol_sun.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -21,6 +21,8 @@ #include "ssol_ranst_sun_wl.h" #include "ssol_spectrum_c.h" +#include <star/scem.h> + #include <rsys/rsys.h> #include <rsys/mem_allocator.h> #include <rsys/ref_count.h> @@ -65,6 +67,7 @@ sun_create SSOL(device_ref_get(dev)); sun->dev = dev; sun->type = type; + sun->algorithm = SSOL_SUN_DIRECTION_ALGORITHM_MEEUS; ref_init(&sun->ref); exit: @@ -136,6 +139,76 @@ ssol_sun_set_direction(struct ssol_sun* sun, const double direction[3]) } res_T +ssol_sun_set_location_and_date + (struct ssol_sun* sun, + const struct ssol_location* loc, + const struct tm* date) +{ + res_T res = RES_OK; + struct scem_sun_pos sun_pos; + struct scem_location scem_loc; + enum scem_sun_algo algorithm; + + if(!sun || !loc|| !date) { + res = RES_BAD_ARG; + goto error; + } + + if(loc->latitude < -90 || loc->latitude > 90 + || loc->longitude < -180 || loc->longitude > 180) + { + res = RES_BAD_ARG; + goto error; + } + + scem_loc.latitude = loc->latitude; + scem_loc.longitude = loc->longitude; + + switch(sun->algorithm ) { + case SSOL_SUN_DIRECTION_ALGORITHM_PSA : + algorithm = SCEM_SUN_PSA ; + break; + case SSOL_SUN_DIRECTION_ALGORITHM_MEEUS : + algorithm = SCEM_SUN_MEEUS ; + break; + default: FATAL("Unknown sun positioning algorithm."); + } + res = scem_sun_position_from_earth(date, &scem_loc, algorithm, &sun_pos); + if(res != RES_OK) goto error; + res = scem_sun_position_to_sun_vector(&sun_pos, sun->direction); + if(res != RES_OK) goto error; + +exit: + return res; +error: + goto exit; +} + +res_T +ssol_sun_set_algorithm + (struct ssol_sun* sun, + const enum ssol_sun_direction_algorithm algorithm) +{ + if(!sun || + (algorithm != SSOL_SUN_DIRECTION_ALGORITHM_MEEUS + && algorithm != SSOL_SUN_DIRECTION_ALGORITHM_PSA)) + return RES_BAD_ARG; + sun->algorithm = algorithm; + return RES_OK; +} + +res_T +ssol_sun_get_algorithm + (const struct ssol_sun* sun, + enum ssol_sun_direction_algorithm* algorithm) +{ + if(!sun || !algorithm) + return RES_BAD_ARG; + *algorithm = sun->algorithm; + return RES_OK; +} + +res_T ssol_sun_get_direction(const struct ssol_sun* sun, double direction[3]) { if(!sun || !direction) diff --git a/src/ssol_sun_c.h b/src/ssol_sun_c.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -17,6 +17,8 @@ #ifndef SSOL_SUN_C_H #define SSOL_SUN_C_H +#include "ssol.h" + #include <rsys/ref_count.h> #include <rsys/list.h> @@ -55,6 +57,7 @@ struct ssol_sun { struct gaussian gaussian; struct buie csr; } data; + enum ssol_sun_direction_algorithm algorithm; struct ssol_device* dev; ref_T ref; diff --git a/src/test_ssol_atmosphere.c b/src/test_ssol_atmosphere.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_by_receiver_integration.c b/src/test_ssol_by_receiver_integration.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_camera.c b/src/test_ssol_camera.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_circ2D_geometry.h b/src/test_ssol_circ2D_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_cube_geometry.h b/src/test_ssol_cube_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_data.c b/src/test_ssol_data.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_device.c b/src/test_ssol_device.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_draw.c b/src/test_ssol_draw.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_geometries.h b/src/test_ssol_geometries.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_image.c b/src/test_ssol_image.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_instance.c b/src/test_ssol_instance.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_material.c b/src/test_ssol_material.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_materials.h b/src/test_ssol_materials.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_object.c b/src/test_ssol_object.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_param_buffer.c b/src/test_ssol_param_buffer.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_rect2D_geometry.h b/src/test_ssol_rect2D_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_rect_geometry.h b/src/test_ssol_rect_geometry.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_scene.c b/src/test_ssol_scene.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_shape.c b/src/test_ssol_shape.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver1.c b/src/test_ssol_solver1.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver10.c b/src/test_ssol_solver10.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver11.c b/src/test_ssol_solver11.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver12.c b/src/test_ssol_solver12.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver2.c b/src/test_ssol_solver2.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver2b.c b/src/test_ssol_solver2b.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver3.c b/src/test_ssol_solver3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver4.c b/src/test_ssol_solver4.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver5.c b/src/test_ssol_solver5.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver6.c b/src/test_ssol_solver6.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver7.c b/src/test_ssol_solver7.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver8.c b/src/test_ssol_solver8.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_solver9.c b/src/test_ssol_solver9.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_spectrum.c b/src/test_ssol_spectrum.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify diff --git a/src/test_ssol_sun.c b/src/test_ssol_sun.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify @@ -14,11 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#define _XOPEN_SOURCE /* strptime support */ + #include "ssol.h" #include "test_ssol_utils.h" #include <rsys/double3.h> +#include <time.h> + int main(int argc, char** argv) { @@ -29,8 +33,11 @@ main(int argc, char** argv) struct ssol_sun* sun; const double dir0[3] = { 0, 0, 0 }; double dir[3] = { 1, 0, 0 }; - double tmp[3]; + double tmp[3], res[3]; double dni; + struct tm date; + enum ssol_sun_direction_algorithm algo; + struct ssol_location loc; (void) argc, (void) argv; mem_init_proxy_allocator(&allocator, &mem_default_allocator); @@ -60,13 +67,73 @@ main(int argc, char** argv) CHK(ssol_sun_set_direction(sun, NULL) == RES_BAD_ARG); CHK(ssol_sun_set_direction(sun, dir0) == RES_BAD_ARG); CHK(ssol_sun_set_direction(sun, dir) == RES_OK); - CHK(ssol_sun_set_direction(sun, dir) == RES_OK); CHK(ssol_sun_get_direction(NULL, tmp) == RES_BAD_ARG); CHK(ssol_sun_get_direction(sun, NULL) == RES_BAD_ARG); CHK(ssol_sun_get_direction(sun, tmp) == RES_OK); CHK(d3_eq(dir, tmp) == 1); + CHK(ssol_sun_set_algorithm(NULL, 999) == RES_BAD_ARG); + CHK(ssol_sun_set_algorithm(NULL, SSOL_SUN_DIRECTION_ALGORITHM_MEEUS) == RES_BAD_ARG); + CHK(ssol_sun_set_algorithm(sun, 999) == RES_BAD_ARG); + CHK(ssol_sun_set_algorithm(sun, SSOL_SUN_DIRECTION_ALGORITHM_PSA) == RES_OK); + + CHK(ssol_sun_get_algorithm(NULL, NULL) == RES_BAD_ARG); + CHK(ssol_sun_get_algorithm(NULL, &algo) == RES_BAD_ARG); + CHK(ssol_sun_get_algorithm(sun, NULL) == RES_BAD_ARG); + CHK(ssol_sun_get_algorithm(sun, &algo) == RES_OK); + CHK(algo == SSOL_SUN_DIRECTION_ALGORITHM_PSA); + + CHK(ssol_sun_set_algorithm(sun, SSOL_SUN_DIRECTION_ALGORITHM_MEEUS) == RES_OK); + strptime("2026-6-21T12:4:0", "%Y-%m-%dT%H:%M:%S", &date); + loc.latitude = 0; loc.longitude = 0; + CHK(ssol_sun_set_location_and_date(NULL, NULL, NULL) == RES_BAD_ARG); + CHK(ssol_sun_set_location_and_date(NULL, NULL, &date) == RES_BAD_ARG); + CHK(ssol_sun_set_location_and_date(NULL, &loc, NULL) == RES_BAD_ARG); + CHK(ssol_sun_set_location_and_date(sun, NULL, NULL) == RES_BAD_ARG); + CHK(ssol_sun_set_location_and_date(NULL, &loc, &date) == RES_BAD_ARG); + CHK(ssol_sun_set_location_and_date(sun, &loc, NULL) == RES_BAD_ARG); + CHK(ssol_sun_set_location_and_date(sun, NULL, &date) == RES_BAD_ARG); + loc.latitude = 100; loc.longitude = 0; + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_BAD_ARG); + loc.latitude = 0; loc.longitude = 200; + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_BAD_ARG); + loc.latitude = 100; loc.longitude = 200; + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_BAD_ARG); + loc.latitude = 23.436; loc.longitude = 0; + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_OK); + + CHK(ssol_sun_get_direction(sun, tmp) == RES_OK); + d3(res, 0,0,-1); + CHK(d3_eq_eps(res, tmp, 1e-4) == 1); + + CHK(ssol_sun_set_algorithm(sun, SSOL_SUN_DIRECTION_ALGORITHM_PSA) == RES_OK); + loc.latitude = 23.436; loc.longitude = 0; + strptime("2026-6-21T12:1:49", "%Y-%m-%dT%H:%M:%S", &date); + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_OK); + + CHK(ssol_sun_get_direction(sun, tmp) == RES_OK); + d3(res, 0,0,-1); + CHK(d3_eq_eps(res, tmp, 1e-4) == 1); + + CHK(ssol_sun_set_algorithm(sun, SSOL_SUN_DIRECTION_ALGORITHM_MEEUS) == RES_OK); + loc.latitude = 0; loc.longitude = 0; + strptime("2026-6-21T10:0:0", "%Y-%m-%dT%H:%M:%S", &date); + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_OK); + + CHK(ssol_sun_get_direction(sun, tmp) == RES_OK); + d3(res, -0.47252,-0.397792,-0.78643); + CHK(d3_eq_eps(res, tmp, 1e-4) == 1); + + CHK(ssol_sun_set_algorithm(sun, SSOL_SUN_DIRECTION_ALGORITHM_PSA) == RES_OK); + loc.latitude = 0; loc.longitude = 0; + strptime("2026-6-21T10:0:0", "%Y-%m-%dT%H:%M:%S", &date); + CHK(ssol_sun_set_location_and_date(sun, &loc, &date) == RES_OK); + + CHK(ssol_sun_get_direction(sun, tmp) == RES_OK); + d3(res, -0.465014,-0.397733,-0.79093); + CHK(d3_eq_eps(res, tmp, 1e-4) == 1); + CHK(ssol_sun_set_dni(NULL, 1000) == RES_BAD_ARG); CHK(ssol_sun_set_dni(sun, 0) == RES_BAD_ARG); CHK(ssol_sun_set_dni(sun, 1000) == RES_OK); diff --git a/src/test_ssol_utils.h b/src/test_ssol_utils.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) +/* Copyright (C) 2018-2026 |Méso|Star> (contact@meso-star.com) * Copyright (C) 2016, 2018 CNRS * * This program is free software: you can redistribute it and/or modify