commit fdf9b0bf88de3ff4b22b7de72599f829878cb490
parent b96c5b0698f6d9bb82d51290dd7d81d4653dda46
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 6 Nov 2025 11:42:54 +0100
stardis: make the position of the sun constant per time interval
This ensures that energy is conserved given the input data, i.e., the
average incident solar flux over the time interval for a horizontal
surface. Using a continuous sun position over the interval leads to
invalid results, up to a limit of infinite solar flux in the case of a
solar source with zero elevation.
Diffstat:
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/src/stardis_smeteo.c b/src/stardis_smeteo.c
@@ -207,28 +207,25 @@ compute_sun_position
struct scem_location pos = SCEM_LOCATION_NULL;
/* Time and date */
- struct tm date_utc0 = {0};
- time_t time_since_jan_1_1850_utc0 = 0; /* [s] */
+ const struct tm* date_utc0 = NULL;
+ size_t i = 0;
res_T res = RES_OK;
ASSERT(bcond && sun);
- /* The limit condition stores the number of seconds elapsed since the epoch
- * until January 1, 1850, UTC +00:00 time. Thus, add this offset to the number
- * of seconds elapsed since January 1, 1850, UTC +00:00 to convert this number
- * of seconds to UTC+00:00 */
- time_since_jan_1_1850_utc0 = /* [s] */
- (time_t)((double)bcond->lib_desc.jan_1_1850 + time);
-
- /* Convert time in number of seconds into a broken-down time as expected by
- * the Star-CElestial-Mechanics library */
- CHK(localtime_r(&time_since_jan_1_1850_utc0, &date_utc0) != 0);
+ /* Get the time associated with the interval. Thus, the position of the sun is
+ * assumed to be constant during the interval. This is necessary to ensure
+ * energy conservation given how solar flux is defined, namely as an average
+ * over the time interval of the solar flux incident perpendicular to a
+ * horizontal surface. */
+ i = get_meteo_entry_id(bcond, time);
+ date_utc0 = &bcond->lib_desc.smeteo_desc.entries[i].time;
/* Compute the solar position at the specified location and date */
pos.latitude = bcond->lib_desc.smeteo_desc.latitude;
pos.longitude = bcond->lib_desc.smeteo_desc.longitude;
res = scem_sun_position_from_earth
- (&date_utc0, &pos, bcond->lib_desc.algo, sun);
+ (date_utc0, &pos, bcond->lib_desc.algo, sun);
CHK(res == RES_OK);
}