commit 45786c9616be1e265340d326d869a7869efc7a15
parent 5b612d5a716d8b1b404666e7ecb256b4dca46bba
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 13 Aug 2025 12:41:33 +0200
Star implementing a Stardis plugin
It will be used to couple the meteorological data loaded by the smeteo
library with the Stardis program, which uses the Monte Carlo method to
solve coupled heat transfers.
Currently, only the loading of meteorological data is implemented. The
compilation system has also been updated to compile it automatically
based on the value of the PLUGIN macro, so that it can simply be ignored
to allow the library and utility to be compiled without requiring the
Stardis dependency.
No accessors to the meteorological data required by Stardis have been
implemented. The plugin documentation is also missing.
Diffstat:
4 files changed, 308 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
@@ -22,7 +22,7 @@ LIBNAME_SHARED = libsmeteo.so
LIBNAME = $(LIBNAME_$(LIB_TYPE))
default: library
-all: default tests util
+all: default tests util $(PLUGIN)
################################################################################
# Library
@@ -93,6 +93,40 @@ $(UTIL_OBJ): config.mk smeteo-local.pc
$(CC) $(CFLAGS_UTIL) -c $(@:.o=.c) -o $@
################################################################################
+# Plugin
+################################################################################
+PLUGIN_SRC =\
+ src/stardis_smeteo_library.c
+PLUGIN_OBJ = $(PLUGIN_SRC:.c=.o)
+PLUGIN_DEP = $(PLUGIN_SRC:.c=.d)
+
+INCS_PLUGIN = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys smeteo-local stardis)
+LIBS_PLUGIN = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys smeteo-local)
+
+CFLAGS_PLUGIN = -std=c89 $(CFLAGS_SO) $(INCS_PLUGIN)
+LDFLAGS_PLUGIN = $(LDFLAGS_SO) $(LIBS_PLUGIN)
+
+stardis: library $(PLUGIN_DEP)
+ @$(MAKE) -fMakefile $$(for i in $(PLUGIN_DEP); do echo -f $${i}; done) \
+ libstardis_smeteo.so
+
+libstardis_smeteo.so $(PLUGIN_DEP) $(PLUGIN_OBJ): \
+ config.mk smeteo-local.pc .config_plugin
+
+.config_plugin:
+ $(PKG_CONFIG) --atleast-version $(STARDIS_VERSION) stardis
+ @echo 'config done' > $@
+
+libstardis_smeteo.so: $(PLUGIN_OBJ)
+ $(CC) $(CFLAGS_PLUGIN) -o $@ $(PLUGIN_OBJ) $(LDFLAGS_PLUGIN)
+
+$(PLUGIN_DEP): $(@:.d=.c)
+ @$(CC) $(CFLAGS_PLUGIN) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
+
+$(PLUGIN_OBJ): $(@:.o=.c)
+ $(CC) $(CFLAGS_PLUGIN) -c $(@:.o=.c) -o $@
+
+################################################################################
# Miscellaneous
################################################################################
pkg:
@@ -109,7 +143,7 @@ smeteo-local.pc: smeteo.pc.in
-e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
smeteo.pc.in > $@
-install: library util pkg
+install: library util pkg $(PLUGIN)
install() { mode="$$1"; prefix="$$2"; shift 2; \
mkdir -p "$${prefix}"; \
cp "$$@" "$${prefix}"; \
@@ -121,10 +155,14 @@ install: library util pkg
install 755 "$(DESTDIR)$(BINPREFIX)/" smeteo; \
install 644 "$(DESTDIR)$(MANPREFIX)/man1" doc/smeteo.1; \
install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/smeteo.5; \
- install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-meteo" COPYING README.md
+ install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-meteo" COPYING README.md; \
+ if [ $(PLUGIN) = "stardis" ]; then \
+ install 755 "$(DESTDIR)$(LIBPREFIX)" libstardis_smeteo.so; \
+ fi
uninstall:
rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
+ rm -f "$(DESTDIR)$(LIBPREFIX)/libstardis_smeteo.so"
rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/smeteo.pc"
rm -f "$(DESTDIR)$(INCPREFIX)/star/smeteo.h"
rm -f "$(DESTDIR)$(BINPREFIX)/smeteo"
@@ -140,7 +178,8 @@ lint:
clean: clean_test
rm -f $(DEP) $(OBJ) $(LIBNAME)
rm -f $(UTIL_DEP) $(UTIL_OBJ) smeteo
- rm -f .config libsmeteo.o smeteo.pc smeteo-local.pc
+ rm -f $(PLUGIN_DEP) $(PLUGIN_OBJ) libstardis_smeteo.so
+ rm -f .config .config_plugin libsmeteo.o smeteo.pc smeteo-local.pc
################################################################################
# Tests
diff --git a/config.mk b/config.mk
@@ -1,6 +1,9 @@
VERSION = 0.0.0
PREFIX = /usr/local
+# Comment out the macro to disable the compilation of the Stardis plugin
+PLUGIN = stardis
+
LIB_TYPE = SHARED
#LIB_TYPE = STATIC
@@ -33,6 +36,9 @@ RSYS_VERSION = 0.14
INCS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
+# For Stardis plugin
+STARDIS_VERSION = 0.11
+
################################################################################
# Compilation options
################################################################################
diff --git a/src/stardis_smeteo.h b/src/stardis_smeteo.h
@@ -0,0 +1,163 @@
+/* Copyright (C) 2025 |Méso|Star> (contact@meso-star.com)
+ *
+ * This program is free software: you can redismshbute 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 dismshbuted 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 STARDIS_SMETEO_H
+#define STARDIS_SMETEO_H
+
+#include <stardis/stardis-prog-properties.h>
+#include <rsys/rsys.h>
+
+BEGIN_DECLS
+
+/*******************************************************************************
+ * Library data, i.e., constant data for all physical properties created from
+ * this instance of the plugin, i.e., those used to define media, connections,
+ * or boundary conditions. In this case, it is data read from meteorological
+ * data
+ ******************************************************************************/
+STARDIS_API void*
+stardis_create_library_data
+ (const struct stardis_program_context* ctx,
+ size_t argc,
+ char* argv[]);
+
+STARDIS_API void
+stardis_release_library_data
+ (void* lib_data);
+
+STARDIS_API enum stardis_return_status
+stardis_finalize_library_data
+ (void* lib_data);
+
+/*******************************************************************************
+ * Create a boundary condition
+ ******************************************************************************/
+STARDIS_API void*
+stardis_create_data
+ (const struct stardis_description_create_context* ctx,
+ void* lib_data,
+ size_t argc,
+ char* argv[]);
+
+/*******************************************************************************
+ * Functions for a Neumann + Robin boundary condition.
+ * This condition is used to couple Stardis with meteorological data via a net
+ * flux imposed at the ground interface.
+ ******************************************************************************/
+/* Returns the convection coefficient retrieved from meteorological data */
+STARDIS_API double /* > 0 [W/K/m^2] */
+stardis_convection_coefficient
+ (const struct stardis_interface_fragment* frag,
+ void* data);
+
+/* Maximum H value calculated from the meteorological data set.
+ *
+ * This function is mandatory for Stardis, as it cannot assume that the
+ * atmospheric temperature is known, since it queries it through a plugin
+ * function on which it cannot make any assumptions, even if the caller knows
+ * that it always returns a known temperature. Stardis must therefore ensure
+ * that it is able to sample a convective path, a procedure that requires this
+ * upper limit. But in reality, this data should never be used. In any case, it
+ * must provide Stardis with this expected value as long as this (questionable)
+ * constraint is an expected value of its API.*/
+STARDIS_API double /* >0 [W/K/m^2] */
+stardis_max_convection_coefficient
+ (void* data);
+
+/* Net ground flux calculated from meteorological data */
+STARDIS_API double /* [W/m^2] */
+stardis_boundary_flux
+ (const struct stardis_interface_fragment* frag,
+ void* data);
+
+/* Atmospheric temperature retrieve from meteorological data */
+STARDIS_API double /* >0 [K] */
+stardis_medium_temperature
+ (const struct stardis_vertex* vtx,
+ void* data);
+
+/* Ground emissivity, which should depend on the type of source. For short
+ * waves, it should be retrieved from the constant albedo of the ground, while
+ * for long waves, it should be defined by the user when creating the data.
+ * However, the way in which solar flux is currently handled does not allow for
+ * a distinction between sources: it is simply a net flux imposed on the ground.
+ * Until the sun is explicitly handled by an external source, emissivity will
+ * therefore always be retrieved from the albedo of the ground. */
+STARDIS_API double
+stardis_emissivity
+ (const struct stardis_interface_fragment* frag,
+ const unsigned source_id,
+ void* data);
+
+/* Control the specularity of the ground BRDF */
+STARDIS_API double
+stardis_specular_fraction
+ (const struct stardis_interface_fragment* frag,
+ const unsigned source_id,
+ void* data);
+
+/* Reference ground temperature used by Stardis to calculate exchanges by
+ * radiative transfer. It returns the surface temperature provided by
+ * meteorological data, as this should be a good estimate of the ground
+ * temperature, at least as long as the geometry of the ground corresponds to
+ * the model used to estimate it (a priori an infinite slab). */
+STARDIS_API double /* >0 [K] */
+stardis_reference_temperature
+ (const struct stardis_interface_fragment* frag,
+ void* data);
+
+/* Range of reference ground temperatures calculated from the entire set of
+ * surface temperatures provided by meteorological data */
+STARDIS_API double* /* <=> range */
+stardis_t_range
+ (void* data,
+ double range[2]); /* >0 [K] */
+
+/*******************************************************************************
+ * Functions for a Dirichlet boundary condition.
+ * This condition is used as a very basic coupling between Stardis and the
+ * meteorological data, of which only its ground temperature is used.
+ ******************************************************************************/
+/* Ground temperature */
+STARDIS_API double /* >0 [K] */
+stardis_boundary_temperature
+ (const struct stardis_interface_fragment* frag,
+ void* data);
+
+/* Range of ground temperatures calculated from the entire set of surface
+ * temperatures provided by meteorological data */
+STARDIS_API double* /* <=> range */
+stardis_t_range
+ (void* data,
+ double range[2]); /* >0 [K] */
+
+/*******************************************************************************
+ * Various mandatory legal functions
+ ******************************************************************************/
+STARDIS_API const char*
+get_copyright_notice
+ (void* data);
+
+STARDIS_API const char*
+get_license_short
+ (void* data);
+
+STARDIS_API const char*
+get_license_text
+ (void* data);
+
+END_DECLS
+
+#endif /* STARDIS_SMETEO_H */
diff --git a/src/stardis_smeteo_library.c b/src/stardis_smeteo_library.c
@@ -0,0 +1,96 @@
+/* Copyright (C) 2025 |Méso|Star> (contact@meso-star.com)
+ *
+ * This program is free software: you can redismshbute 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 dismshbuted 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 "smeteo.h"
+#include "stardis_smeteo.h"
+
+struct args {
+ char* filename;
+};
+#define ARGS_DEFAULT__ {0}
+static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
+
+/*******************************************************************************
+ * Helper functions
+ ******************************************************************************/
+static void
+usage(FILE* stream, const char* name)
+{
+ fprintf(stream, "usage: %s file\n", name);
+}
+
+static res_T
+args_init(struct args* args, int argc, char* argv[])
+{
+ res_T res = RES_OK;
+ ASSERT(args && argc >= 1 && argv);
+
+ *args = ARGS_DEFAULT;
+ if(argc == 1) { res = RES_BAD_ARG; goto error; }
+
+ args->filename = argv[1];
+
+exit:
+ return res;
+error:
+ usage(stderr, argv[0]);
+ goto exit;
+}
+
+/*******************************************************************************
+ * Exported symbols
+ ******************************************************************************/
+void*
+stardis_create_library_data
+ (const struct stardis_program_context* ctx,
+ size_t argc,
+ char* argv[])
+{
+ struct args args = ARGS_DEFAULT;
+
+ struct smeteo_create_args smeteo_args = SMETEO_CREATE_ARGS_DEFAULT;
+ struct smeteo* smeteo = NULL;
+
+ res_T res = RES_OK;
+
+ /* Parse library arguments */
+ if((res = args_init(&args, (int)argc, argv)) != RES_OK) goto error;
+
+ /* Create a smeteo instance */
+ smeteo_args.verbose = ctx->verbosity_level;
+ if((res = smeteo_create(&smeteo_args, &smeteo)) != RES_OK) goto error;
+
+ /* Load meteorological data */
+ if((res = smeteo_load(smeteo, args.filename)) != RES_OK) goto error;
+
+exit:
+ return smeteo;
+error:
+ if(smeteo) { SMETEO(ref_put(smeteo)); smeteo = NULL; }
+ goto exit;
+}
+
+void
+stardis_release_library_data(void* lib_data)
+{
+ SMETEO(ref_put(lib_data));
+}
+
+enum stardis_return_status
+stardis_finalize_library_data(void* lib_data)
+{
+ (void)lib_data;
+ return STARDIS_SUCCESS; /* Nothing to be done */
+}