stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit dc29b53107ce603be7562ded7c873b71a1b20206
parent 48735c862b79e2bdbb0bed222669593a4ba27ed5
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 14 Dec 2023 15:01:31 +0100

Merge branch 'feature_posix_make' into develop

Diffstat:
M.gitignore | 15++++++++-------
AMakefile | 460+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 612+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Dcmake/CMakeLists.txt | 305------------------------------------------------------------------------------
Aconfig.mk | 134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amake.sh | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asdis.pc.in | 16++++++++++++++++
Msrc/sdis.c | 2+-
Msrc/sdis_solve_camera.c | 4++--
Msrc/test_sdis_scene.c | 4++--
Msrc/test_sdis_solve_medium_2d.c | 4++--
Asrc/test_sdis_solve_probe_list.c | 380+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12 files changed, 1411 insertions(+), 612 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,12 +1,13 @@ -compile_commands.json .gitignore -CMakeCache.txt -CMakeFiles -Makefile -tmp [Bb]uild* *.sw[po] -*.[ao] +*.[aod] +*.so *~ +test* +!test*.[ch] +.config +.config_test +.test tags - +*.pc diff --git a/Makefile b/Makefile @@ -0,0 +1,460 @@ +# Copyright (C) 2016-2023 |Méso|Star> (contact@meso-star.com) +# +# 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/>. + +.POSIX: +.SUFFIXES: # Clean up default inference rules + +include config.mk + +LIBNAME_STATIC = libsdis.a +LIBNAME_SHARED = libsdis.so +LIBNAME = $(LIBNAME_$(LIB_TYPE)) + +MPI_DEF = -DSDIS_ENABLE_MPI + +################################################################################ +# Library building +################################################################################ +MPI_SRC = src/sdis_mpi.c +SRC =\ + src/sdis.c\ + src/sdis_camera.c\ + src/sdis_data.c\ + src/sdis_device.c\ + src/sdis_estimator.c\ + src/sdis_estimator_buffer.c\ + src/sdis_green.c\ + src/sdis_heat_path.c\ + src/sdis_heat_path_boundary.c\ + src/sdis_interface.c\ + src/sdis_log.c\ + src/sdis_medium.c\ + src/sdis_misc.c\ + src/sdis_realisation.c\ + src/sdis_scene.c\ + src/sdis_solve.c\ + src/sdis_solve_camera.c\ + src/sdis_tile.c\ + $($(DISTRIB_PARALLELISM)_SRC) +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) + +build_library: .config $(DEP) + @$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \ + $$(if [ -n "$(LIBNAME)" ]; then \ + echo "$(LIBNAME)"; \ + else \ + echo "$(LIBNAME_SHARED)"; \ + fi) + +$(DEP) $(OBJ): config.mk + +$(LIBNAME_SHARED): $(OBJ) + $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS) + +$(LIBNAME_STATIC): libsdis.o + $(AR) -rc $@ $? + $(RANLIB) $@ + +libsdis.o: $(OBJ) + $(LD) -r $(OBJ) -o $@ + $(OBJCOPY) $(OCPFLAGS) $@ + +.config: config.mk + @if [ "$(DISTRIB_PARALLELISM)" = "MPI" ]; then \ + if ! $(PKG_CONFIG) --atleast-version $(MPI_VERSION) $(MPI_PC); then \ + echo "$(MPI_PC) $(MPI_VERSION) not found" >&2; exit 1; fi; fi + @if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \ + echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(S2D_VERSION) s2d; then \ + echo "s2d $(S2D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then \ + echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SENC2D_VERSION) senc2d; then \ + echo "senc2d $(SENC2D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SENC3D_VERSION) senc3d; then \ + echo "senc3d $(SENC3D_VERSION) not found" >&2; exit 1; fi + @if ! $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp; then \ + echo "star-sp $(SSP_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +.SUFFIXES: .c .d .o +.c.d: + @$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) $($(DISTRIB_PARALLELISM)_DEF) -MM -MT "$(@:.d=.o) $@" $< -MF $@ + +.c.o: + $(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DSDIS_SHARED_BUILD $($(DISTRIB_PARALLELISM)_DEF) -c $< -o $@ + +################################################################################ +# Installation +################################################################################ +PKG_MPI =, $(MPI_PC) >= $(MPI_VERSION) + +pkg: + sed -e 's#@PREFIX@#$(PREFIX)#g'\ + -e 's#@VERSION@#$(VERSION)#g'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + -e 's#@S2D_VERSION@#$(S2D_VERSION)#g'\ + -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ + -e 's#@SENC2D_VERSION@#$(SENC2D_VERSION)#g'\ + -e 's#@SENC3D_VERSION@#$(SENC3D_VERSION)#g'\ + -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\ + -e 's#@MPI@#$(PKG_$(DISTRIB_PARALLELISM))#g'\ + sdis.pc.in > sdis.pc + +sdis-local.pc: sdis.pc.in config.mk + sed -e '1d'\ + -e 's#^includedir=.*#includedir=./src/#'\ + -e 's#^libdir=.*#libdir=./#'\ + -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\ + -e 's#@S2D_VERSION@#$(S2D_VERSION)#g'\ + -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\ + -e 's#@SENC2D_VERSION@#$(SENC2D_VERSION)#g'\ + -e 's#@SENC3D_VERSION@#$(SENC3D_VERSION)#g'\ + -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\ + -e 's#@MPI@#$(PKG_$(DISTRIB_PARALLELISM))#g'\ + sdis.pc.in > $@ + +install: build_library pkg + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME) + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" sdis.pc + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/" src/sdis.h + @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/stardis-solver" \ + COPYING README.md + +uninstall: + rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)" + rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sdis.pc" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/stardis-solver/COPYING" + rm -f "$(DESTDIR)$(PREFIX)/share/doc/stardis-solver/README.md" + rm -f "$(DESTDIR)$(PREFIX)/include/sdis.h" + +################################################################################ +# Miscellaneous targets +################################################################################ +all: build_library build_tests + +clean: clean_test + rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) + rm -f .config .config_test .test libsdis.o sdis.pc sdis-local.pc + +distclean: clean + rm -f $(DEP) $(TEST_DEP) + +lint: + shellcheck -o all make.sh + +################################################################################ +# Tests +################################################################################ +TEST_SRC =\ + src/test_sdis_camera.c\ + src/test_sdis_conducto_radiative.c\ + src/test_sdis_conducto_radiative_2d.c\ + src/test_sdis_contact_resistance.c\ + src/test_sdis_contact_resistance_2.c\ + src/test_sdis_convection.c\ + src/test_sdis_convection_non_uniform.c\ + src/test_sdis_data.c\ + src/test_sdis_enclosure_limit_conditions.c\ + src/test_sdis_flux.c\ + src/test_sdis_flux2.c\ + src/test_sdis_flux_with_h.c\ + src/test_sdis_interface.c\ + src/test_sdis_medium.c\ + src/test_sdis_picard.c\ + src/test_sdis_scene.c\ + src/test_sdis_solid_random_walk_robustness.c\ + src/test_sdis_solve_probe.c\ + src/test_sdis_solve_probe3.c\ + src/test_sdis_solve_probe_2d.c\ + src/test_sdis_solve_probe2_2d.c\ + src/test_sdis_solve_probe3_2d.c\ + src/test_sdis_transcient.c\ + src/test_sdis_unstationary_atm.c\ + src/test_sdis_volumic_power.c\ + src/test_sdis_volumic_power4.c +TEST_SRC_LONG =\ + src/test_sdis_volumic_power2.c\ + src/test_sdis_volumic_power2_2d.c\ + src/test_sdis_volumic_power3_2d.c +TEST_SRC_MPI =\ + src/test_sdis.c\ + src/test_sdis_compute_power.c\ + src/test_sdis_device.c\ + src/test_sdis_solve_camera.c\ + src/test_sdis_solve_medium.c\ + src/test_sdis_solve_medium_2d.c\ + src/test_sdis_solve_boundary.c\ + src/test_sdis_solve_boundary_flux.c\ + src/test_sdis_solve_probe2.c\ + src/test_sdis_solve_probe_list.c +TEST_OBJ =\ + $(TEST_SRC:.c=.o)\ + $(TEST_SRC_MPI:.c=.o)\ + $(TEST_SRC_LONG:.c=.o)\ + src/test_sdis_utils.o +TEST_DEP =\ + $(TEST_SRC:.c=.d)\ + $(TEST_SRC_MPI:.c=.d)\ + $(TEST_SRC_LONG:.c=.d)\ + src/test_sdis_utils.d + +PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG) +SDIS_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sdis-local.pc) +SDIS_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs sdis-local.pc) + +# Regular Compiler and linker flags +TEST_CFLAGS = $(CFLAGS_EXE) $(SDIS_CFLAGS) $(RSYS_CFLAGS) +TEST_LIBS = src/test_sdis_utils.o $(LDFLAGS_EXE) $(SDIS_LIBS) $(RSYS_LIBS) -lm + +# Compiler and linker flags for MPI tests +TEST_CFLAGS_MPI =\ + $(TEST_CFLAGS)\ + $($(DISTRIB_PARALLELISM)_CFLAGS)\ + $($(DISTRIB_PARALLELISM)_DEF) +TEST_LIBS_MPI =\ + $(TEST_LIBS)\ + $($(DISTRIB_PARALLELISM)_LIBS) + +build_tests: .config_test build_library $(TEST_DEP) src/test_sdis_utils.d .test + @$(MAKE) -fMakefile -f.test -fsrc/test_sdis_utils.d \ + $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \ + test_bin + +.config_test: config.mk + @if ! $(PKG_CONFIG) --atleast-version $(S3DUT_VERSION) s3dut; then \ + echo "s3dut $(S3DUT_VERSION) not found" >&2; exit 1; fi + @echo "config done" > $@ + +test: build_tests + @$(SHELL) make.sh run_test $(TEST_SRC) + @if [ "$(DISTRIB_PARALLELISM)" != "MPI" ]; then \ + $(SHELL) make.sh run_test $(TEST_SRC_MPI); \ + else \ + $(SHELL) make.sh run_test_mpi $(TEST_SRC_MPI); \ + fi + +test_all: test + @$(SHELL) make_sh run_test $(TEST_SRC_LONG) + +.test: Makefile + @$(SHELL) make.sh config_test $(TEST_SRC) $(TEST_SRC_MPI) $(TEST_SRC_LONG) > $@ + +clean_test: + @$(SHELL) make.sh clean_test $(TEST_SRC) $(TEST_SRC_MPI) $(TEST_SRC_LONG) + +################################################################################ +# Regular tests +################################################################################ +src/test_sdis_camera.d \ +src/test_sdis_conducto_radiative.d \ +src/test_sdis_conducto_radiative_2d.d \ +src/test_sdis_contact_resistance.d \ +src/test_sdis_contact_resistance_2.d \ +src/test_sdis_convection.d \ +src/test_sdis_convection_non_uniform.d \ +src/test_sdis_data.d \ +src/test_sdis_enclosure_limit_conditions.d \ +src/test_sdis_flux.d \ +src/test_sdis_flux2.d \ +src/test_sdis_flux_with_h.d \ +src/test_sdis_interface.d \ +src/test_sdis_medium.d \ +src/test_sdis_picard.d \ +src/test_sdis_solve_probe.d \ +src/test_sdis_solve_probe_2d.d \ +src/test_sdis_solve_probe2_2d.d \ +src/test_sdis_solve_probe3_2d \ +src/test_sdis_transcient.d \ +src/test_sdis_unstationary_atm.d \ +src/test_sdis_utils.d \ +src/test_sdis_volumic_power.d \ +src/test_sdis_volumic_power2.d \ +src/test_sdis_volumic_power2_2d.d \ +src/test_sdis_volumic_power3_2d.d \ +src/test_sdis_volumic_power4.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis_camera.o \ +src/test_sdis_conducto_radiative.o \ +src/test_sdis_conducto_radiative_2d.o \ +src/test_sdis_contact_resistance.o \ +src/test_sdis_contact_resistance_2.o \ +src/test_sdis_convection.o \ +src/test_sdis_convection_non_uniform.o \ +src/test_sdis_data.o \ +src/test_sdis_enclosure_limit_conditions.o \ +src/test_sdis_flux.o \ +src/test_sdis_flux2.o \ +src/test_sdis_flux_with_h.o \ +src/test_sdis_interface.o \ +src/test_sdis_medium.o \ +src/test_sdis_picard.o \ +src/test_sdis_solve_probe.o \ +src/test_sdis_solve_probe_2d.o \ +src/test_sdis_solve_probe2_2d.o \ +src/test_sdis_solve_probe3_2d.o \ +src/test_sdis_transcient.o \ +src/test_sdis_unstationary_atm.o \ +src/test_sdis_utils.o \ +src/test_sdis_volumic_power.o \ +src/test_sdis_volumic_power2.o \ +src/test_sdis_volumic_power2_2d.o \ +src/test_sdis_volumic_power3_2d.o \ +src/test_sdis_volumic_power4.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sdis_camera \ +test_sdis_conducto_radiative \ +test_sdis_conducto_radiative_2d \ +test_sdis_contact_resistance \ +test_sdis_contact_resistance_2 \ +test_sdis_convection \ +test_sdis_convection_non_uniform \ +test_sdis_data \ +test_sdis_enclosure_limit_conditions \ +test_sdis_flux \ +test_sdis_flux2 \ +test_sdis_flux_with_h \ +test_sdis_interface \ +test_sdis_medium \ +test_sdis_picard \ +test_sdis_solve_probe \ +test_sdis_solve_probe_2d \ +test_sdis_solve_probe2_2d \ +test_sdis_solve_probe3_2d \ +test_sdis_transcient \ +test_sdis_unstationary_atm \ +test_sdis_volumic_power \ +test_sdis_volumic_power2 \ +test_sdis_volumic_power2_2d \ +test_sdis_volumic_power3_2d \ +test_sdis_volumic_power4 \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS) -o $@ src/$@.o $(TEST_LIBS) + +################################################################################ +# Tests based on Star-3DUT +################################################################################ +src/test_sdis_solid_random_walk_robustness.d \ +src/test_sdis_solve_probe3.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis_solid_random_walk_robustness.o \ +src/test_sdis_solve_probe3.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sdis_solid_random_walk_robustness \ +test_sdis_solve_probe3 \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -o $@ src/$@.o $(TEST_LIBS) $(S3DUT_LIBS) + +################################################################################ +# Tests based on Star-Enclosures-<2|3>D +################################################################################ +src/test_sdis_scene.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS) $(SENC2D_CFLAGS) $(SENC3D_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis_scene.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS) $(SENC2D_CFLAGS) $(SENC3D_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sdis_scene \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS) $(SENC2D_CFLAGS) $(SENC3D_CFLAGS) -o $@ src/$@.o $(TEST_LIBS) $(SENC2D_LIBS) $(SENC3D_LIBS) + +################################################################################ +# Tests with (optional) MPI support +################################################################################ +src/test_sdis.d \ +src/test_sdis_device.d \ +src/test_sdis_solve_medium_2d.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS_MPI) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis.o \ +src/test_sdis_device.o \ +src/test_sdis_solve_medium_2d.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS_MPI) -c $(@:.o=.c) -o $@ + +test_sdis \ +test_sdis_device \ +test_sdis_solve_medium_2d \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS_MPI) -o $@ src/$@.o $(TEST_LIBS_MPI) + +################################################################################ +# Tests based on Star-3DUT with (optional) MPI support +################################################################################ +src/test_sdis_compute_power.d \ +src/test_sdis_solve_camera.d \ +src/test_sdis_solve_medium.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS_MPI) $(S3DUT_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis_compute_power.o \ +src/test_sdis_solve_camera.o \ +src/test_sdis_solve_medium.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS_MPI) $(S3DUT_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sdis_compute_power \ +test_sdis_solve_camera \ +test_sdis_solve_medium \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS_MPI) $(S3DUT_CFLAGS) -o $@ src/$@.o $(TEST_LIBS_MPI) $(S3DUT_LIBS) + +################################################################################ +# Tests based on Star-3D and Star-3DUT with (optional) MPI support +################################################################################ +src/test_sdis_solve_probe_list.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS_MPI) $(S3D_CFLAGS) $(S3DUT_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis_solve_probe_list.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS_MPI) $(S3D_CFLAGS) $(S3DUT_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sdis_solve_probe_list \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS_MPI) $(S3D_CFLAGS) $(S3DUT_CFLAGS) -o $@ src/$@.o $(TEST_LIBS_MPI) $(S3D_LIBS) $(S3DUT_LIBS) + +################################################################################ +# Tests based on Star-SP with (optional) MPI support +################################################################################ +src/test_sdis_solve_boundary.d \ +src/test_sdis_solve_boundary_flux.d \ +src/test_sdis_solve_probe2.d \ +: config.mk sdis-local.pc + @$(CC) $(TEST_CFLAGS_MPI) $(SSP_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@ + +src/test_sdis_solve_boundary.o \ +src/test_sdis_solve_boundary_flux.o \ +src/test_sdis_solve_probe2.o \ +: config.mk sdis-local.pc + $(CC) $(TEST_CFLAGS_MPI) $(SSP_CFLAGS) -c $(@:.o=.c) -o $@ + +test_sdis_solve_boundary \ +test_sdis_solve_boundary_flux \ +test_sdis_solve_probe2 \ +: config.mk sdis-local.pc $(LIBNAME) src/test_sdis_utils.o + $(CC) $(TEST_CFLAGS_MPI) $(SSP_CFLAGS) -o $@ src/$@.o $(TEST_LIBS_MPI) $(SSP_LIBS) diff --git a/README.md b/README.md @@ -1,119 +1,120 @@ # Stardis-Solver -Stardis-Solver is *free software* that solves *coupled* convecto - conducto - -radiative *thermal problems* in *complex* 2D and 3D *environments*. This C89 -library internally relies on *Monte-Carlo* algorithms based on reformulations -of the main heat transfer phenomena as cross-recursive "thermal paths" that -explore space and time until a boundary condition or an initial condition is -found. The key concept here is that heat transfer phenomena are not considered -separately but naturally coupled via cross-recursive [Monte-Carlo +Stardis-Solver is *free software* that solves *coupled* convecto - +conducto - radiative *thermal problems* in *complex* 2D and 3D +*environments*. This C89 library internally relies on *Monte-Carlo* +algorithms based on reformulations of the main heat transfer phenomena +as cross-recursive "thermal paths" that explore space and time until a +boundary condition or an initial condition is found. The key concept +here is that heat transfer phenomena are not considered separately but +naturally coupled via cross-recursive [Monte-Carlo algorithms](https://hal.archives-ouvertes.fr/hal-02419604/). The hypothesis these algorithms are based upon are the following: -- *conduction*: the discretization of thermal heat transfer in solids introduces - the notion of a conductive path length within the Monte-Carlo algorithm. - Solutions obtained using this algorithm are formally exact at the limit of a - null path length. In practice, this path length has to be adapted for a given - geometric configuration so that its value is small compared to the smallest - typical length of a solid. +- *conduction*: the discretization of thermal heat transfer in solids + introduces the notion of a conductive path length within the + Monte-Carlo algorithm. Solutions obtained using this algorithm are + formally exact at the limit of a null path length. In practice, this + path length has to be adapted for a given geometric configuration so + that its value is small compared to the smallest typical length of a + solid. - *convection*: fluid media are supposed to be isothermal, even if their - temperature may vary with time. This hypothesis relies on the assumption of - perfectly agitated fluids. -- *radiation*: local radiative transfer is solved by an [iterative numerical - method](https://hal.archives-ouvertes.fr/tel-03266863/) (Picard algorithm) - that requires the knowledge of a reference temperature field. At the basic - level (one level of recursion), and using a uniform reference temperature - field, this algorithm translates into the hypothesis of a linearized - radiative transfer. Using a higher order or recursion makes possible to - converge the result closer to the solution of a rigorous - spectrally-integrated radiative transfer (a difference of temperatures to the - power 4 when integrated over the whole spectrum). The higher the recursion - order, the better will be the convergence of the algorithm. - -In Stardis-Solver the system to simulate is represented by a *scene* whose -geometry defines the contour of the object only: in contrast to legacy thermal -solvers *no volumetric mesh* has to be provided. Each geometric primitive as an -associated *interface* that defines its physical properties (e.g. surface -emissivity) and reference the *media* defining the thermal properties on both -side of the primitive. The boundary and initial conditions are defined defined -on the interfaces (convection coefficient, fixed temperature/flux, etc.) and -the media (known temperature). Once fully and consistently described, -computations can be invoked on the resulting scene. + temperature may vary with time. This hypothesis relies on the + assumption of perfectly agitated fluids. +- *radiation*: local radiative transfer is solved by an [iterative + numerical method](https://hal.archives-ouvertes.fr/tel-03266863/) + (Picard algorithm) that requires the knowledge of a reference + temperature field. At the basic level (one level of recursion), and + using a uniform reference temperature field, this algorithm translates + into the hypothesis of a linearized radiative transfer. Using a higher + order or recursion makes possible to converge the result closer to the + solution of a rigorous spectrally-integrated radiative transfer (a + difference of temperatures to the power 4 when integrated over the + whole spectrum). The higher the recursion order, the better will be + the convergence of the algorithm. + +In Stardis-Solver the system to simulate is represented by a *scene* +whose geometry defines the contour of the object only: in contrast to +legacy thermal solvers *no volumetric mesh* has to be provided. Each +geometric primitive as an associated *interface* that defines its +physical properties (e.g. surface emissivity) and reference the *media* +defining the thermal properties on both side of the primitive. The +boundary and initial conditions are defined defined on the interfaces +(convection coefficient, fixed temperature/flux, etc.) and the media +(known temperature). Once fully and consistently described, computations +can be invoked on the resulting scene. The main features of the solver are currently: -- *probe computation*: Stardis-Solver will compute the temperature at any given - position (spatial and temporal). The main idea is that thermal paths start - from this probe position, and scatter in space while going back in time, - until a (spatial) boundary condition or a (temporal) initial condition is - met. In addition to the value of temperature, using a Monte-Carlo method - makes possible to compute a numerical uncertainty (standard deviation of the - weight distribution) over each result. -- *flux computation*: Stardis-Solver can compute the flux over any surface (or - group of surfaces) at any time. Alternatively, it can also compute the total - energy output from a solid element where a internal source of power must be - taken into account. -- *green function*: the value of temperature computed at a probe position is - the average of the Monte-Carlo weight for every thermal path. In practice: - when no internal power sources have to be considered, the weight of any given - thermal path is the temperature of the boundary or initial condition that has - been reached; when internal power sources or imposed fluxes are taken into - account, additional contributions to the weight must be continuously - evaluated by the thermal conduction algorithm, but these contributions are - proportional to the local dissipated power/imposed flux. In any case, the - position and date at the end of each thermal path (and also accumulation - coefficients) can be stored during a first complete Monte-Carlo simulation. - This information, known as the Green function, can then be used in (very - fast) post-processing to compute all required results for different boundary - and initial conditions (and also different internal power sources/imposed - flux). Note that when using the Green function, only boundary and initial - conditions (as well as internal power sources) can be modified: in - particular, the geometry, thermal properties and exchange coefficients have - to remain identical. Furthermore, the green function is only valid under the - assumption of linearized radiative transfer. -- *path visualization*: Stardis-Solver can store the complete spatial and - temporal position along a set of thermal paths, for latter visualization. In - addition of their position and, each thermal path vertex register additional - data as the type of thermal phenomena it simulates, the accumulated - power/flux along the path, etc. +- *probe computation*: Stardis-Solver will compute the temperature at + any given position (spatial and temporal). The main idea is that + thermal paths start from this probe position, and scatter in space + while going back in time, until a (spatial) boundary condition or a + (temporal) initial condition is met. In addition to the value of + temperature, using a Monte-Carlo method makes possible to compute a + numerical uncertainty (standard deviation of the weight distribution) + over each result. +- *flux computation*: Stardis-Solver can compute the flux over any + surface (or group of surfaces) at any time. Alternatively, it can also + compute the total energy output from a solid element where a internal + source of power must be taken into account. +- *green function*: the value of temperature computed at a probe + position is the average of the Monte-Carlo weight for every thermal + path. In practice: when no internal power sources have to be + considered, the weight of any given thermal path is the temperature of + the boundary or initial condition that has been reached; when internal + power sources or imposed fluxes are taken into account, additional + contributions to the weight must be continuously evaluated by the + thermal conduction algorithm, but these contributions are proportional + to the local dissipated power/imposed flux. In any case, the position + and date at the end of each thermal path (and also accumulation + coefficients) can be stored during a first complete Monte-Carlo + simulation. This information, known as the Green function, can then + be used in (very fast) post-processing to compute all required results + for different boundary and initial conditions (and also different + internal power sources/imposed flux). Note that when using the Green + function, only boundary and initial conditions (as well as internal + power sources) can be modified: in particular, the geometry, thermal + properties and exchange coefficients have to remain identical. + Furthermore, the green function is only valid under the assumption of + linearized radiative transfer. +- *path visualization*: Stardis-Solver can store the complete spatial + and temporal position along a set of thermal paths, for latter + visualization. In addition of their position and, each thermal path + vertex register additional data as the type of thermal phenomena it + simulates, the accumulated power/flux along the path, etc. Stardis-Solver is currently used in two frameworks. The -[Stardis](https://gitlab.com/meso-star/stardis.git) CLI and its associated -tools is the reference workflow of Stardis-Solver. It proposes a complete -toolchain from fileformats describing the scene (geometry, thermal properties, -limit and boundary conditions) to computations and post-treatments of the -results ([Stardis-Green](https://gitlab.com/meso-star/stardis-green.git)). +[Stardis](https://gitlab.com/meso-star/stardis.git) CLI and its +associated tools is the reference workflow of Stardis-Solver. It +proposes a complete toolchain from fileformats describing the scene +(geometry, thermal properties, limit and boundary conditions) to +computations and post-treatments of the results +([Stardis-Green](https://gitlab.com/meso-star/stardis-green.git)). Stardis-Solver is also integrated into [SYRTHES](https://www.edf.fr/en/the-edf-group/world-s-largest-power-company/activities/research-and-development/scientific-communities/simulation-softwares?logiciel=10818), -the general thermal free software developed by Electricité De France (EDF). - -## How to build - -Stardis-Solver is compatible GNU/Linux as well as Microsoft Windows 7 and -later, both in 64-bits. It was successfully built with the [GNU Compiler -Collection](https://gcc.gnu.org) (versions 4.9.2 and later) as well as with -Microsoft Visual Studio 2015. - -It relies on the [CMake](http://www.cmake.org) and the -[RCMake](https://gitlab.com/vaplv/rcmake/) package to build. -It also depends on the -[RSys](https://gitlab.com/vaplv/rsys/), -[Star-2D](https://gitlab.com/meso-star/star-2d/), -[Star-3D](https://gitlab.com/meso-star/star-3d/), -[Star-Enclosures-3D](https://gitlab.com/meso-star/star-enclosures-3d/), -[Star-Enclosures-2D](https://gitlab.com/meso-star/star-enclosures-2d/) and -[Star-SP](https://gitlab.com/meso-star/star-sp/) libraries as well as on the -[OpenMP](http://www.openmp.org) 2.0 specification to parallelize its -computations. It may depend on [OpenMPI](https://www.open-mpi.org/) 2.0 if -distributed memory parallelism is enabled via the `ENABLE_MPI` variable of the -CMake file - -First ensure that CMake and a C compiler that implements the OpenMP 2.0 -specification are installed on your system. Then install the RCMake package as -well as all the aforementioned prerequisites. Finally generate the project from -the `cmake/CMakeLists.txt` file by appending to the `CMAKE_PREFIX_PATH` -variable the install directories of its dependencies. +the general thermal free software developed by Electricité De France +(EDF). + +## Requirements + +- C compiler with OpenMP support +- POSIX make +- pkg-config +- Message Passing Interface (optional) +- [RSys](https://gitlab.com/vaplv/rsys) +- [Star 2D](https://gitlab.com/meso-star/star-2d) +- [Star 3D](https://gitlab.com/meso-star/star-3d) +- [Star Enclosures 2D](https://gitlab.com/meso-star/star-enclosures-2D) +- [Star Enclosures 3D](https://gitlab.com/meso-star/star-enclosures-3D) +- [Star SamPling](https://gitlab.com/meso-star/star-sp) + +## Installation + +Edit config.mk as needed, then run: + + make clean install ## Release notes @@ -122,190 +123,205 @@ variable the install directories of its dependencies. - The net flux imposed can be combined with other boundary/connection conditions, i.e. a net flux can be set in addition to convective exchange and radiative transfer. -- Added support for plain text log messages. Until now, log messages were - intended to be read by a VT100-like terminal and could therefore contain - escape sequences that required post-processing to store them in plain text - log files. -- Added support for user-defined signature on the green function. It allows to - check that, when reloaded, a green function is the one expected by the user - according to its own constraints that the green function cannot check itself - such as, for example, that the same deltas are used in conductive random - walks. -- Changes the value of the constant `SDIS_VOLUMIC_POWER_NONE`. Its previous - value of zero caused problems during the evaluation of the propagator: a - media with a power density of zero was not registered in the list of media - with a volumic power. A volumic power that was not zero was therefore not - taken into account during the re-evaluation of the propagator. The constant - is now set to `DBL_MAX`, which means that the medium has no power density, - while a value of 0 is now treated as any valid power density term. +- Added support for plain text log messages. Until now, log messages + were intended to be read by a VT100-like terminal and could therefore + contain escape sequences that required post-processing to store them + in plain text log files. +- Added support for user-defined signature on the green function. It + allows to check that, when reloaded, a green function is the one + expected by the user according to its own constraints that the green + function cannot check itself such as, for example, that the same + deltas are used in conductive random walks. +- Changes the value of the constant `SDIS_VOLUMIC_POWER_NONE`. Its + previous value of zero caused problems during the evaluation of the + propagator: a media with a power density of zero was not registered in + the list of media with a volumic power. A volumic power that was not + zero was therefore not taken into account during the re-evaluation of + the propagator. The constant is now set to `DBL_MAX`, which means that + the medium has no power density, while a value of 0 is now treated as + any valid power density term. ### Version 0.13.1 -Fixed compilation errors and compilation warnings displayed on some versions of -GCC. +Fixed compilation errors and compilation warnings displayed on some +versions of GCC. ### Version 0.13 #### Non linear radiative transfer Uses a new [iterative numerical -method](https://hal.archives-ouvertes.fr/tel-03266863/) to estimate radiative -transfer. With a recursion level of 1, this is equivalent to a linearization of -the radiative transfer but with a reference temperature that can vary in time -and space. By using a higher-order recursion, one can converge towards a -rigorous estimate that takes into account the non-linearity of the radiative -transfer; the higher the recursion order, the better the convergence, but with -the counterpart of an increase in calculation time. +method](https://hal.archives-ouvertes.fr/tel-03266863/) to estimate +radiative transfer. With a recursion level of 1, this is equivalent to a +linearization of the radiative transfer but with a reference temperature +that can vary in time and space. By using a higher-order recursion, one +can converge towards a rigorous estimate that takes into account the +non-linearity of the radiative transfer; the higher the recursion order, +the better the convergence, but with the counterpart of an increase in +calculation time. #### Distributed memory parallelism Uses message passing interface to distribute computation across multiple -computers. Stardis-Solver now, uses a mixed parallelism: on one computer (i.e. -a node), it uses a shared memory parallelism and relies on the message passing -interface to parallelize calculations between several nodes. +computers. Stardis-Solver now, uses a mixed parallelism: on one computer +(i.e. a node), it uses a shared memory parallelism and relies on the +message passing interface to parallelize calculations between several +nodes. #### Type and state of the random number generator -Adds the member input variable `rng_type` to the solve functions. It defines -the type of random number generator to use when no generator is defined. Note -that the `sdis_solve_camera` function does not have a random number generator -as an input variable and has therefore been updated to support it. +Adds the member input variable `rng_type` to the solve functions. It +defines the type of random number generator to use when no generator is +defined. Note that the `sdis_solve_camera` function does not have a +random number generator as an input variable and has therefore been +updated to support it. #### Reading the source code -Refactoring and deep rewriting of the source code to simplify its reading. +Refactoring and deep rewriting of the source code to simplify its +reading. ### Version 0.12.3 -Fix green paths ending in a fluid (transcient computation): The path's end was -not correctly registred and the path was later treated as failed. +Fix green paths ending in a fluid (transcient computation): The path's +end was not correctly registred and the path was later treated as +failed. ### Version 0.12.2 -- Sets the required version of Star-SampPling to 0.12. This version fixes - compilation errors with gcc 11 but introduces API breaks. +- Sets the required version of Star-SampPling to 0.12. This version + fixes compilation errors with gcc 11 but introduces API breaks. - Fix warnings detected by gcc 11. ### Version 0.12.1 -Updates the way numerical issues are handled during a conductive random walk. -Previously, a zealous test would report a numerical error and stop the -calculations when that error could be handled. +Updates the way numerical issues are handled during a conductive random +walk. Previously, a zealous test would report a numerical error and +stop the calculations when that error could be handled. ### Version 0.12 -Add the support of thermal contact resistance between two solids: the new -`thermal_contact_resistance` functor on the data structure `struct -sdis_interface_shader` defines the thermal resistance contact in K.m^2.W^-1 at -a given time and at a specific position onto the interface. +Add the support of thermal contact resistance between two solids: the +new `thermal_contact_resistance` functor on the data structure `struct +sdis_interface_shader` defines the thermal resistance contact in +K.m^2.W^-1 at a given time and at a specific position onto the +interface. ### Version 0.11 -- Add support of unsteady green evaluation. The resulting green function can - then be used to quickly evaluate the system at the same time but with - different limit and initial conditions, volumetric powers and imposed fluxes. -- Add checks on green re-evaluation to ensure that the system remains unchanged - regarding its scale factor and its reference temperature. -- Remove the ambient radiative temperature, the reference temperature and the - geometry scale factor from the list of arguments submitted to the solve - functions. They become scene arguments defined on scene creation. +- Add support of unsteady green evaluation. The resulting green function + can then be used to quickly evaluate the system at the same time but + with different limit and initial conditions, volumetric powers and + imposed fluxes. +- Add checks on green re-evaluation to ensure that the system remains + unchanged regarding its scale factor and its reference temperature. +- Remove the ambient radiative temperature, the reference temperature + and the geometry scale factor from the list of arguments submitted to + the solve functions. They become scene arguments defined on scene + creation. - Update the `sdis_scene_[2d_]create` function profile: its data are now grouped into a variable of type `struct sdis_scene_create_args`. ### Version 0.10.1 -- In green function estimation, the time sent to the user callbacks is no more - the elapsed time from the beginning of the realisation: as in a regular - computation, it is now the observation time. +- In green function estimation, the time sent to the user callbacks is + no more the elapsed time from the beginning of the realisation: as in + a regular computation, it is now the observation time. - Fix the flux computation for boundaries with an imposed flux: it was previously ignored. The new `sdis_estimator_get_imposed_flux` function returns this estimated flux component. -- Return an error if the flux is computed at a boundary whose temperature is - known: this configuration is not currently supported. +- Return an error if the flux is computed at a boundary whose + temperature is known: this configuration is not currently supported. - Fix build with the CL compiler. ### Version 0.10 - Add support of green function [de]serialization. The - `sdis_green_function_write` function serializes the green function into a - stream while the `sdis_green_function_create_from_stream` function - deserialize it. Note that the scene used to deserialize the green function - must be the same of the one used to estimate it: the media and the interfaces - have to be created in the same order, the scene geometry must be the same, - etc. -- Add the `sdis_scene_find_closest_point` function: search the point onto the - scene geometry that is the closest of the submitted position. -- Add the `sdis_compute_power` function that evaluates the power of a medium. + `sdis_green_function_write` function serializes the green function + into a stream while the `sdis_green_function_create_from_stream` + function deserialize it. Note that the scene used to deserialize the + green function must be the same of the one used to estimate it: the + media and the interfaces have to be created in the same order, the + scene geometry must be the same, etc. +- Add the `sdis_scene_find_closest_point` function: search the point + onto the scene geometry that is the closest of the submitted position. +- Add the `sdis_compute_power` function that evaluates the power of a + medium. - Update the solver: the time of the sampled path is now rewind on solid reinjection. ### Version 0.9 -- Update the API of the solve functions: the parameters of the simulation are - now grouped into a unique data structure rather than separately submitted as - function arguments. Thank to this structure and its default value, updating - input parameters should now affect marginally the calling code. -- Improve the logger. Add a prefix to the printed text to indicate the type of - the message (info, error or warning). Add a progress message during - simulation. +- Update the API of the solve functions: the parameters of the + simulation are now grouped into a unique data structure rather than + separately submitted as function arguments. Thank to this structure + and its default value, updating input parameters should now affect + marginally the calling code. +- Improve the logger. Add a prefix to the printed text to indicate the + type of the message (info, error or warning). Add a progress message + during simulation. - Bump the version of the Star-Enclosures <2D|3D> dependencies to 0.5 ### Version 0.8.2 -- Fix an issue when the `sdis_solve_boundary_flux` function was invoked on a - boundary with radiative transfer: several sampled paths were rejected due to - data inconsistencies. +- Fix an issue when the `sdis_solve_boundary_flux` function was invoked + on a boundary with radiative transfer: several sampled paths were + rejected due to data inconsistencies. - Fix a memory leak when the scene creation failed. -- Enable parallelism on Star-Enclosure[2D] to improve the performances of the - enclosure extraction on the setup of the Stardis-Solver scene. +- Enable parallelism on Star-Enclosure[2D] to improve the performances + of the enclosure extraction on the setup of the Stardis-Solver scene. ### Version 0.8.1 - Fix a solver issue that led to reject valid sampled paths. -- Bump the version of the Star-Enclosure[2D] libraries to 0.4.2. These versions - fix a numerical issue that might led to an infinite loop at the scene creation. +- Bump the version of the Star-Enclosure[2D] libraries to 0.4.2. These + versions fix a numerical issue that might led to an infinite loop at + the scene creation. ### Version 0.8 -- Drastically improve the robustness of the solver~: far less realisations are - now rejected. +- Drastically improve the robustness of the solver~: far less + realisations are now rejected. - Add the estimation of the time spent per realisation estimate. Add the - `sdis_estimator_get_realisation_time` function that returns this estimate. -- Add the `sdis_estimator_buffer` API~: it manages a two dimensional array of - regular estimators and provides global estimations over the whole estimators - saved into the buffer. -- Update the signature of the `sdis_solve_camera` function~: it now returns a - `sdis_estimator_buffer`. It now also supports time integration as well as - heat paths registration. + `sdis_estimator_get_realisation_time` function that returns this + estimate. +- Add the `sdis_estimator_buffer` API~: it manages a two dimensional + array of regular estimators and provides global estimations over the + whole estimators saved into the buffer. +- Update the signature of the `sdis_solve_camera` function~: it now + returns a `sdis_estimator_buffer`. It now also supports time + integration as well as heat paths registration. ### Version 0.7 #### Add Green function support -Provide new solve functions that compute and save the Green function, i.e. the -propagator used in regular solvers. The resulting Green function can be then -evaluated to obtain an estimate of the temperature. - -The time spent to compute the Green function is comparable to the computation -time of regular solvers; actually, they rely on the same code. However, its -evaluation is instantaneous while it still handles the limit conditions, the -boundary fluxes and the power term of the media *at the moment* of the -evaluation. This means that one can estimate the Green function of a system -only one time and then evaluate it with different limit conditions, boundary -fluxes or power terms with negligible computation costs. - -Currently, Stardis-Solver assumes that during the Green function estimation, -the properties of the system do not depend on time. In addition, it assumes -that the boundary fluxes and the volumetric powers are constants in time and -space. Anyway, on Green function evaluation, the limit conditions of the -system can still vary in time and space; systems in steady state can be -simulated with Green functions. +Provide new solve functions that compute and save the Green function, +i.e. the propagator used in regular solvers. The resulting Green +function can be then evaluated to obtain an estimate of the temperature. + +The time spent to compute the Green function is comparable to the +computation time of regular solvers; actually, they rely on the same +code. However, its evaluation is instantaneous while it still handles +the limit conditions, the boundary fluxes and the power term of the +media *at the moment* of the evaluation. This means that one can +estimate the Green function of a system only one time and then evaluate +it with different limit conditions, boundary fluxes or power terms with +negligible computation costs. + +Currently, Stardis-Solver assumes that during the Green function +estimation, the properties of the system do not depend on time. In +addition, it assumes that the boundary fluxes and the volumetric powers +are constants in time and space. Anyway, on Green function evaluation, +the limit conditions of the system can still vary in time and space; +systems in steady state can be simulated with Green functions. #### Add heat path registration -Add the `int register_paths` mask to almost all solve functions to enable the -registration against the returned estimator of the failure and/or successful -random paths used by the solvers. For each path, the registered data are: +Add the `int register_paths` mask to almost all solve functions to +enable the registration against the returned estimator of the failure +and/or successful random paths used by the solvers. For each path, the +registered data are: - the vertices of the path; - the type of the path (failed or succeed); @@ -313,119 +329,127 @@ random paths used by the solvers. For each path, the registered data are: - the Monte-Carlo weight of each path vertex; - the current time of each path vertex. -Note that the amount of registered data can be huge if too more paths are -registered. Consequently, this functionality should be used with few -realisations to obtain a subset of representative paths, or to only register -the few paths that failed in order to diagnose what went wrong. +Note that the amount of registered data can be huge if too more paths +are registered. Consequently, this functionality should be used with +few realisations to obtain a subset of representative paths, or to only +register the few paths that failed in order to diagnose what went wrong. #### Miscellaneous -- Add the `sdis_solve_medium` function: it estimates the average temperature - of a medium. -- Fix the setup of the interfaces: the interface associated to a geometric - primitive could not be the right one. +- Add the `sdis_solve_medium` function: it estimates the average + temperature of a medium. +- Fix the setup of the interfaces: the interface associated to a + geometric primitive could not be the right one. ### Version 0.6.1 -- Bump version of the Star-Enclosures[2D] dependencies: the new versions fix - issues in the construction of fluid enclosures. -- Bump version of the Star-<2D|3D> dependencies: the new versions rely on - Embree3 rather than on Embree2 for their ray-tracing back-end. +- Bump version of the Star-Enclosures[2D] dependencies: the new versions + fix issues in the construction of fluid enclosures. +- Bump version of the Star-<2D|3D> dependencies: the new versions rely + on Embree3 rather than on Embree2 for their ray-tracing back-end. ### Version 0.6 -- Add the `sdis_solve_boundary` function: it computes the average temperature - on a subset of geometric primitives. +- Add the `sdis_solve_boundary` function: it computes the average + temperature on a subset of geometric primitives. - Add flux solvers: the new `sdis_solve_probe_boundary_flux` and - `sdis_solve_boundary_flux` functions estimate the convective and radiative - fluxes at a given surface position or for a sub-set of geometric primitives, - respectively. -- Add support of time integration: almost all solvers can estimate the average - temperature on a given time range. Only the `sdis_solve_camera` function does - not support time integration, yet. + `sdis_solve_boundary_flux` functions estimate the convective and + radiative fluxes at a given surface position or for a sub-set of + geometric primitives, respectively. +- Add support of time integration: almost all solvers can estimate the + average temperature on a given time range. Only the + `sdis_solve_camera` function does not support time integration, yet. - Add support of an explicit initial time `t0` for the fluid. -- Fix a bug in the estimation of unknown fluid temperatures: the associativity - between the internal Stardis-Solver data and the user defined data was wrong. +- Fix a bug in the estimation of unknown fluid temperatures: the + associativity between the internal Stardis-Solver data and the user + defined data was wrong. ### Version 0.5 Add support of fluid enclosure with unknown uniform temperature. - The convection coefficient of the surfaces surrounding a fluid whose - temperature is unknown can vary in time and space. Anyway, the caller has to - ensure that for each triangle of the fluid enclosure, the convection - coefficient returned by its `struct sdis_interface_shader` - at a given - position and time - is less than or equal to the `convection_coef_upper_bound` - parameter of the shader. + temperature is unknown can vary in time and space. Anyway, the caller + has to ensure that for each triangle of the fluid enclosure, the + convection coefficient returned by its + `struct sdis_interface_shader` - at a given position and time - is + less than or equal to the `convection_coef_upper_bound` parameter of + the shader. ### Version 0.4 Full rewrite of how the volumetric power is taken into account. - Change the scheme of the random walk "solid re-injection": use a 2D - re-injection scheme in order to handle 2D effects. On one hand, this scheme - drastically improves the accuracy of the temperature estimation in solid with - a volumetric power term. On the other hand it is more sensible to numerical - imprecisions. The previous 1D scheme is thus used in situations where the 2D - scheme exhibits too numerical issues, i.e. on sharp angles. + re-injection scheme in order to handle 2D effects. On one hand, this + scheme drastically improves the accuracy of the temperature estimation + in solid with a volumetric power term. On the other hand it is more + sensible to numerical imprecisions. The previous 1D scheme is thus + used in situations where the 2D scheme exhibits too numerical issues, + i.e. on sharp angles. - Add the missing volumetric power term on solid re-injection. -- Add a corrective term to fix the bias on the volumetric power introduced when - the random walk progresses at a distance of `delta` of a boundary. +- Add a corrective term to fix the bias on the volumetric power + introduced when the random walk progresses at a distance of `delta` of + a boundary. - Add several volumetric power tests. -- Remove the `delta_boundary` parameter of the `struct sdis_solid_shader` data - structure. +- Remove the `delta_boundary` parameter of the `struct + sdis_solid_shader` data structure. ### Version 0.3 -- Some interface properties become double sided: the temperature, emissivity - and specular fraction is defined for each side of the interface. Actually, - only the convection coefficient is shared by the 2 sides of the interface. - The per side interface properties are grouped into the new `struct - sdis_interface_side_shader` data structure. -- Add the support of fixed fluxes: the flux is a per side interface property. - Currently, the flux is handled only for the interface sides facing a solid - medium. +- Some interface properties become double sided: the temperature, + emissivity and specular fraction is defined for each side of the + interface. Actually, only the convection coefficient is shared by the + 2 sides of the interface. The per side interface properties are + grouped into the new `struct sdis_interface_side_shader` data + structure. +- Add the support of fixed fluxes: the flux is a per side interface + property. Currently, the flux is handled only for the interface sides + facing a solid medium. - Add the `sdis_scene_boundary_project_pos` function that computes the - parametric coordinates of a world space position projected onto a given - primitive with respect to its normal. If the projection lies outside the - primitive, its parametric coordinates are wrapped against its boundaries in - order to ensure that they are valid coordinates into the primitive. Actually, - this function was mainly added to help in the definition of the probe - position onto a boundary as expected by the + parametric coordinates of a world space position projected onto a + given primitive with respect to its normal. If the projection lies + outside the primitive, its parametric coordinates are wrapped against + its boundaries in order to ensure that they are valid coordinates into + the primitive. Actually, this function was mainly added to help in the + definition of the probe position onto a boundary as expected by the `sdis_solve_probe_boundary` function. -- Update the default comportment of the interface shader when a function is not - set. -- Rename the `SDIS_MEDIUM_<FLUID|SOLID>` constants in `SDIS_<FLUID|SOLID>`. -- Rename the `enum sdis_side_flag` enumerate in `enum sdis_side` and update its - values. +- Update the default comportment of the interface shader when a function + is not set. +- Rename the `SDIS_MEDIUM_<FLUID|SOLID>` constants in + `SDIS_<FLUID|SOLID>`. +- Rename the `enum sdis_side_flag` enumerate in `enum sdis_side` and + update its values. ### Version 0.2 -- Add the support of volumic power to solid media: add the `volumic_power` - functor to the `sdis_solid_shader` data structure that, once defined, should - return the volumic power of the solid at a specific position and time. On - solve invocation, the conductive random walks take into account this - spatio-temporal volumic power in the computation of the solid temperature. -- Add the `sdis_solve_probe_boundary` function: it computes the temperature at - a given position and time onto a geometric primitive. The probe position is - defined by the index of the primitive and a parametric coordinates onto it. -- Add the `sdis_scene_get_boundary_position` function: it computes a world - space position from the index of a geometric primitive and a parametric - coordinate onto it. -- Fix how the `sdis_solve_probe` was parallelised. The submitted `threads_hint` - parameter was not correctly handled. +- Add the support of volumic power to solid media: add the + `volumic_power` functor to the `sdis_solid_shader` data structure + that, once defined, should return the volumic power of the solid at a + specific position and time. On solve invocation, the conductive random + walks take into account this spatio-temporal volumic power in the + computation of the solid temperature. +- Add the `sdis_solve_probe_boundary` function: it computes the + temperature at a given position and time onto a geometric primitive. + The probe position is defined by the index of the primitive and a + parametric coordinates onto it. +- Add the `sdis_scene_get_boundary_position` function: it computes a + world space position from the index of a geometric primitive and a + parametric coordinate onto it. +- Fix how the `sdis_solve_probe` was parallelised. The submitted + `threads_hint` parameter was not correctly handled. ### Version 0.1 - Add the support of radiative temperature. - Add the `sdis_camera` API: it defines a pinhole camera into the scene. -- Add the `sdis_accum_buffer` API: it is a pool of MC accumulators, i.e. a sum - of MC weights and square weights. -- Add the `sdis_solve_camera` function: it relies on a `sdis_camera` and a - `sdis_accum_buffer` to compute the radiative temperature that reaches each - pixel of an image whose definition is defined by the caller. Note that - actually this function uses the same underlying MC algorithm behind the - `sdis_solve_probe` function. +- Add the `sdis_accum_buffer` API: it is a pool of MC accumulators, i.e. + a sum of MC weights and square weights. +- Add the `sdis_solve_camera` function: it relies on a `sdis_camera` and + a `sdis_accum_buffer` to compute the radiative temperature that + reaches each pixel of an image whose definition is defined by the + caller. Note that actually this function uses the same underlying MC + algorithm behind the `sdis_solve_probe` function. ### Version 0.0 @@ -433,13 +457,15 @@ First version and implementation of the Stardis-Solver API. - Support fluid/solid and solid/solid interfaces. - Only conduction is currently fully supported: convection and radiative - temperature are not computed yet. Fluid media can be added to the system but - currently, Stardis-Solver assumes that their temperature are known. + temperature are not computed yet. Fluid media can be added to the + system but currently, Stardis-Solver assumes that their temperature + are known. ## License -Copyright (C) 2016-2023 |Méso|Star> (<contact@meso-star.com>). Stardis-Solver -is free software released under the GPLv3+ license: GNU GPL version 3 or later. -You are welcome to redistribute it under certain conditions; refer to the -COPYING files for details. +Copyright (C) 2016-2023 |Méso|Star> (contact@meso-star.com) + +Stardis-Solver is free software released under the GPLv3+ license: GNU +GPL version 3 or later. You are welcome to redistribute it under +certain conditions; refer to the COPYING files for details. diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -1,305 +0,0 @@ -# Copyright (C) 2016-2023 |Méso|Star> (contact@meso-star.com) -# -# 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/>. - -cmake_minimum_required(VERSION 3.1) -project(stardis C) -enable_testing() - -include(CMakeDependentOption) - -set(SDIS_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src) -option(NO_TEST "Do not build tests" OFF) -option(ENABLE_MPI - "Enable the support of distributed parallelism \ -using the Message Passing Interface specification." ON) - -CMAKE_DEPENDENT_OPTION(ALL_TESTS - "Perform basic and advanced tests" OFF "NOT NO_TEST" OFF) - -############################################################################### -# Check dependencies -############################################################################### -find_package(RCMake 0.4 REQUIRED) -find_package(Star2D 0.5 REQUIRED) -find_package(Star3D 0.8 REQUIRED) -find_package(StarSP 0.13 REQUIRED) -find_package(StarEnc2D 0.5 REQUIRED) -find_package(StarEnc3D 0.5 REQUIRED) -find_package(RSys 0.13 REQUIRED) -find_package(OpenMP 2.0 REQUIRED) - -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR}) -include(rcmake) -include(rcmake_runtime) - -include_directories( - ${Star2D_INCLUDE_DIR} - ${Star3D_INCLUDE_DIR} - ${StarSP_INCLUDE_DIR} - ${StarEnc2D_INCLUDE_DIR} - ${StarEnc3D_INCLUDE_DIR} - ${RSys_INCLUDE_DIR}) - -if(ENABLE_MPI) - find_package(MPI 2 REQUIRED) - set(CMAKE_C_COMPILER ${MPI_C_COMPILER}) - include_directories(${MPI_INCLUDE_PATH}) -endif() - -rcmake_append_runtime_dirs(_runtime_dirs - RSys Star2D Star3D StarSP StarEnc2D StarEnc3D) - -############################################################################### -# Configure and define targets -############################################################################### -set(VERSION_MAJOR 0) -set(VERSION_MINOR 14) -set(VERSION_PATCH 0) -set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - -set(SDIS_FILES_SRC - sdis.c - sdis_camera.c - sdis_data.c - sdis_device.c - sdis_estimator.c - sdis_estimator_buffer.c - sdis_green.c - sdis_heat_path.c - sdis_heat_path_boundary.c - sdis_interface.c - sdis_log.c - sdis_medium.c - sdis_misc.c - sdis_realisation.c - sdis_scene.c - sdis_solve.c - sdis_solve_camera.c - sdis_tile.c) - -set(SDIS_FILES_INC_API - sdis.h) - -set(SDIS_FILES_INC - sdis_c.h - sdis_camera.h - sdis_device_c.h - sdis_estimator_c.h - sdis_green.h - sdis_heat_path.h - sdis_heat_path_boundary_c.h - sdis_heat_path_boundary_Xd.h - sdis_heat_path_boundary_Xd_fixed_flux.h - sdis_heat_path_boundary_Xd_solid_fluid_picard1.h - sdis_heat_path_boundary_Xd_solid_solid.h - sdis_heat_path_conductive_Xd.h - sdis_heat_path_convective_Xd.h - sdis_heat_path_radiative_Xd.h - sdis_interface_c.h - sdis_log.h - sdis_misc.h - sdis_misc_Xd.h - sdis_medium_c.h - sdis_realisation.h - sdis_realisation_Xd.h - sdis_scene_c.h - sdis_scene_Xd.h - sdis_solve_boundary_Xd.h - sdis_solve_medium_Xd.h - sdis_solve_probe_Xd.h - sdis_solve_probe_boundary_Xd.h - sdis_tile.h - sdis_Xd_begin.h - sdis_Xd_end.h) - -if(ENABLE_MPI) - set(SDIS_FILES_SRC ${SDIS_FILES_SRC} sdis_mpi.c) - set(SDIS_FILES_INC ${SDIS_FILES_INC} sdis_mpi.h) -endif() - -set(SDIS_FILES_DOC COPYING README.md) - -# Prepend each file by `SDIS_SOURCE_DIR' -rcmake_prepend_path(SDIS_FILES_SRC ${SDIS_SOURCE_DIR}) -rcmake_prepend_path(SDIS_FILES_INC ${SDIS_SOURCE_DIR}) -rcmake_prepend_path(SDIS_FILES_INC_API ${SDIS_SOURCE_DIR}) -rcmake_prepend_path(SDIS_FILES_DOC ${PROJECT_SOURCE_DIR}/../) - -if(CMAKE_COMPILER_IS_GNUCC) - set(MATH_LIB m) -endif() - -if(MSVC) - ### disable verbose warnings: - # warning C4127: conditional expression is constant - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4127") - # warning C4204: - # nonstandard extension used : non-constant aggregate initializer - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4204") - # warning C4938: Floating point reduction variable may cause inconsistent - # results under /fp:strict or #pragma fenv_access - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4938") -endif() - -add_library(sdis SHARED - ${SDIS_FILES_SRC} - ${SDIS_FILES_INC} - ${SDIS_FILES_INC_API}) -target_link_libraries(sdis - RSys Star2D Star3D StarSP StarEnc2D StarEnc3D ${MATH_LIB}) - -set_target_properties(sdis PROPERTIES - DEFINE_SYMBOL SDIS_SHARED_BUILD - COMPILE_FLAGS ${OpenMP_C_FLAGS} - VERSION ${VERSION} - SOVERSION ${VERSION_MAJOR}) -rcmake_copy_runtime_libraries(sdis) - -if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(sdis PROPERTIES LINK_FLAGS "${OpenMP_C_FLAGS}") -endif() - -if(ENABLE_MPI) - set_target_properties(sdis PROPERTIES COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") -endif() - -rcmake_setup_devel(sdis Stardis ${VERSION} sdis_version.h) - -############################################################################### -# Add tests -############################################################################### -if(NOT NO_TEST) - find_package(Star3DUT REQUIRED 0.2.0) - - add_library(sdis-test-utils STATIC - ${SDIS_SOURCE_DIR}/test_sdis_utils.h - ${SDIS_SOURCE_DIR}/test_sdis_utils.c) - - function(build_test _name) - add_executable(${_name} ${SDIS_SOURCE_DIR}/${_name}.c) - target_link_libraries(${_name} sdis-test-utils RSys sdis) - endfunction() - - function(register_test _name) - add_test(${_name} ${ARGN}) - rcmake_set_test_runtime_dirs(${_name} _runtime_dirs) - endfunction() - - function(new_test _name) - build_test(${_name}) - register_test(${_name} ${_name}) - endfunction() - - new_test(test_sdis_camera) - new_test(test_sdis_conducto_radiative) - new_test(test_sdis_conducto_radiative_2d) - new_test(test_sdis_contact_resistance) - new_test(test_sdis_contact_resistance_2) - new_test(test_sdis_convection) - new_test(test_sdis_convection_non_uniform) - new_test(test_sdis_data) - new_test(test_sdis_device) - new_test(test_sdis_enclosure_limit_conditions) - new_test(test_sdis_flux) - new_test(test_sdis_flux2) - new_test(test_sdis_flux_with_h) - new_test(test_sdis_interface) - new_test(test_sdis_medium) - new_test(test_sdis_picard) - new_test(test_sdis_scene) - new_test(test_sdis_solid_random_walk_robustness) - new_test(test_sdis_solve_probe) - new_test(test_sdis_solve_probe3) - new_test(test_sdis_solve_probe_2d) - new_test(test_sdis_solve_probe2_2d) - new_test(test_sdis_solve_probe3_2d) - new_test(test_sdis_transcient) - new_test(test_sdis_unstationary_atm) - new_test(test_sdis_volumic_power) - new_test(test_sdis_volumic_power4) - - build_test(test_sdis) - build_test(test_sdis_compute_power) - build_test(test_sdis_solve_camera) - build_test(test_sdis_solve_medium) - build_test(test_sdis_solve_medium_2d) - build_test(test_sdis_solve_boundary) - build_test(test_sdis_solve_boundary_flux) - build_test(test_sdis_solve_probe2) - - # Additionnal tests - build_test(test_sdis_volumic_power2) - build_test(test_sdis_volumic_power2_2d) - build_test(test_sdis_volumic_power3_2d) - - if(ALL_TESTS) - add_test(test_sdis_volumic_power2 test_sdis_volumic_power2) - add_test(test_sdis_volumic_power2_2d test_sdis_volumic_power2_2d) - add_test(test_sdis_volumic_power3_2d test_sdis_volumic_power3_2d) - endif() - - target_link_libraries(test_sdis_compute_power Star3DUT) - target_link_libraries(test_sdis_solid_random_walk_robustness Star3DUT) - target_link_libraries(test_sdis_solve_medium Star3DUT) - target_link_libraries(test_sdis_solve_probe3 Star3DUT) - target_link_libraries(test_sdis_solve_probe3_2d ${MATH_LIB}) - target_link_libraries(test_sdis_solve_camera Star3DUT) - - target_link_libraries(test_sdis_solve_boundary StarSP) - target_link_libraries(test_sdis_solve_boundary_flux StarSP) - target_link_libraries(test_sdis_solve_probe2 StarSP) - target_link_libraries(test_sdis_solve_medium StarSP) - - set(_mpi_tests - test_sdis - test_sdis_compute_power - test_sdis_solve_camera - test_sdis_solve_medium - test_sdis_solve_medium_2d - test_sdis_solve_boundary - test_sdis_solve_boundary_flux - test_sdis_solve_probe2) - - if(NOT ENABLE_MPI) - foreach(_test ${_mpi_tests}) - add_test(${_test} ${_test}) - endforeach() - else() - set_target_properties(test_sdis PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - set_target_properties(test_sdis_device PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - - foreach(_test ${_mpi_tests}) - set_target_properties(${_test} PROPERTIES - COMPILE_DEFINITIONS "SDIS_ENABLE_MPI") - add_test(${_test}_mpi_on mpirun -n 2 ${_test} mpi) - add_test(${_test}_no_mpi ${_test}) - endforeach() - endif() - - rcmake_copy_runtime_libraries(test_sdis_solid_random_walk_robustness) - -endif() - -############################################################################### -# Define output & install directories -############################################################################### -install(TARGETS sdis - ARCHIVE DESTINATION bin - LIBRARY DESTINATION lib - RUNTIME DESTINATION bin) -install(FILES ${SDIS_FILES_INC_API} DESTINATION include/) -install(FILES ${SDIS_FILES_DOC} DESTINATION share/doc/stardis-solver) diff --git a/config.mk b/config.mk @@ -0,0 +1,134 @@ +VERSION = 0.14.0 +PREFIX = /usr/local + +LIB_TYPE = SHARED +#LIB_TYPE = STATIC + +BUILD_TYPE = RELEASE +#BUILD_TYPE = DEBUG + +# Defines whether distributed parallelism is supported. Any value other +# than MPI disables its supports. So, simply comment the macro to +# deactivate it. +DISTRIB_PARALLELISM = MPI + +# MPI pkg-config file +MPI_PC = ompi + +################################################################################ +# Tools +################################################################################ +AR = ar +CC = cc +LD = ld +OBJCOPY = objcopy +PKG_CONFIG = pkg-config +RANLIB = ranlib + +################################################################################ +# Dependencies +################################################################################ +PCFLAGS_SHARED = +PCFLAGS_STATIC = --static +PCFLAGS = $(PCFLAGS_$(LIB_TYPE)) + +MPI_VERSION = 2 +MPI_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags $(MPI_PC)) +MPI_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs $(MPI_PC)) + +RSYS_VERSION = 0.14 +RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys) +RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys) + +S2D_VERSION = 0.7 +S2D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s2d) +S2D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s2d) + +S3D_VERSION = 0.10 +S3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3d) +S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d) + +SENC2D_VERSION = 0.5 +SENC2D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags senc2d) +SENC2D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs senc2d) + +SENC3D_VERSION = 0.5 +SENC3D_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags senc3d) +SENC3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs senc3d) + +SSP_VERSION = 0.14 +SSP_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags star-sp) +SSP_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs star-sp) + +# For tests only +S3DUT_VERSION = 0.4 +S3DUT_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags s3dut) +S3DUT_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3dut) + +DPDC_CFLAGS =\ + $(RSYS_CFLAGS)\ + $(S2D_CFLAGS)\ + $(S3D_CFLAGS)\ + $(SENC2D_CFLAGS)\ + $(SENC3D_CFLAGS)\ + $(SSP_CFLAGS)\ + $($(DISTRIB_PARALLELISM)_CFLAGS)\ + -fopenmp +DPDC_LIBS =\ + $(RSYS_LIBS)\ + $(S2D_LIBS)\ + $(S3D_LIBS)\ + $(SENC2D_LIBS)\ + $(SENC3D_LIBS)\ + $(SSP_LIBS)\ + $($(DISTRIB_PARALLELISM)_LIBS)\ + -lm\ + -fopenmp + +################################################################################ +# Compilation options +################################################################################ +WFLAGS =\ + -Wall\ + -Wcast-align\ + -Wconversion\ + -Wextra\ + -Wmissing-declarations\ + -Wmissing-prototypes\ + -Wshadow + +CFLAGS_HARDENED =\ + -D_FORTIFY_SOURCES=2\ + -fcf-protection=full\ + -fstack-clash-protection\ + -fstack-protector-strong + +CFLAGS_COMMON =\ + -std=c89\ + -pedantic\ + -fvisibility=hidden\ + -fstrict-aliasing\ + $(CFLAGS_HARDENED)\ + $(WFLAGS) + +CFLAGS_RELEASE = -O3 -DNDEBUG $(CFLAGS_COMMON) +CFLAGS_DEBUG = -g $(CFLAGS_COMMON) +CFLAGS = $(CFLAGS_$(BUILD_TYPE)) + +CFLAGS_SO = $(CFLAGS) -fPIC +CFLAGS_EXE = $(CFLAGS) -fPIE + +################################################################################ +# Linker options +################################################################################ +LDFLAGS_HARDENED = -Wl,-z,relro,-z,now +LDFLAGS_DEBUG = $(LDFLAGS_HARDENED) +LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED) +LDFLAGS = $(LDFLAGS_$(BUILD_TYPE)) + +LDFLAGS_SO = $(LDFLAGS) -shared -Wl,--no-undefined +LDFLAGS_EXE = $(LDFLAGS) -pie + +OCPFLAGS_DEBUG = --localize-hidden +OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded +OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE)) diff --git a/make.sh b/make.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# Copyright (C) 2016-2023 |Méso|Star> (contact@meso-star.com) +# +# 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/>. + +set -e + +config_test() +{ + for i in "$@"; do + test=$(basename "${i}" ".c") + test_list="${test_list} ${test}" + printf "%s: %s\n" "${test}" "src/${test}.o" + done + printf "test_bin: %s\n" "${test_list}" +} + +check() +{ + name="$1" + prog="$2" + shift 2 + + printf "%s " "${name}" + if PATH=./:"${PATH}" "${prog}" "$@" > /dev/null 2>&1; then + printf "\033[1;32mOK\033[m\n" + else + printf "\033[1;31mError\033[m\n" + fi 2> /dev/null +} + +run_test() +{ + for i in "$@"; do + prog="$(basename "${i}" ".c")" + check "${prog}" "${prog}" + done +} + +run_test_mpi() +{ + for i in "$@"; do + test="$(basename "${i}" ".c")" + check "${test}_mpi_on" mpirun -n 2 "${test}" mpi + check "${test}_no_mpi" "${test}" + done +} + +clean_test() +{ + for i in "$@"; do + rm -f "$(basename "${i}" ".c")" + done +} + +install() +{ + prefix=$1 + shift 1 + + mkdir -p "${prefix}" + + for i in "$@"; do + dst="${prefix}/${i##*/}" + + if cmp -s "${i}" "${dst}"; then + printf "Up to date %s\n" "${dst}" + else + printf "Installing %s\n" "${dst}" + cp "${i}" "${prefix}" + fi + done +} + +"$@" diff --git a/sdis.pc.in b/sdis.pc.in @@ -0,0 +1,16 @@ +prefix=@PREFIX@ +includedir=${prefix}/include +libdir=${prefix}/lib + +Requires: rsys >= @RSYS_VERSION@, star-sp >= @SSP_VERSION@ +Requires.private:\ + s2d >= @S2D_VERSION@,\ + s3d >= @S3D_VERSION@,\ + senc2d >= @SENC3D_VERSION@,\ + senc3d >= @SENC3D_VERSION@ @MPI@ +Name: sdis +Description: Stardis Solver +Version: @VERSION@ +Libs: -L${libdir} -lsdis +Libs.private: -fopenmp -lm +CFlags: -I${includedir} diff --git a/src/sdis.c b/src/sdis.c @@ -105,7 +105,7 @@ rewind_progress_printing(struct sdis_device* dev) || dev->mpi_nprocs == 1) return; - FOR_EACH(i, 0, dev->mpi_nprocs-1) { + FOR_EACH(i, 0, (size_t)(dev->mpi_nprocs-1)) { log_info(dev, "\033[1A\r"); /* Move up */ } } diff --git a/src/sdis_solve_camera.c b/src/sdis_solve_camera.c @@ -603,7 +603,7 @@ sdis_solve_camera /* Here we go! Launch the Monte Carlo estimation */ omp_set_num_threads((int)scn->dev->nthreads); - register_paths = is_master_process + register_paths = is_master_process ? args->register_paths : SDIS_HEAT_PATH_NONE; #pragma omp parallel for schedule(static, 1/*chunk size*/) for(mcode = mcode_1st; mcode < (int64_t)ntiles_adjusted; mcode+=mcode_incr) { @@ -621,7 +621,7 @@ sdis_solve_camera tile_org[0] = morton2D_decode_u16((uint32_t)(mcode>>0)); if(tile_org[0] >= ntiles_x) continue; /* Discard tile */ tile_org[1] = morton2D_decode_u16((uint32_t)(mcode>>1)); - if(tile_org[1] >= ntiles_y) continue; /* Disaard tile */ + if(tile_org[1] >= ntiles_y) continue; /* Discard tile */ res_local = tile_create(scn->dev->allocator, &tile); if(tile == NULL) { diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c @@ -19,8 +19,8 @@ #include <rsys/double2.h> #include <rsys/double3.h> #include <rsys/math.h> -#include<star/senc2d.h> -#include<star/senc3d.h> +#include <star/senc2d.h> +#include <star/senc3d.h> struct context { const double* positions; diff --git a/src/test_sdis_solve_medium_2d.c b/src/test_sdis_solve_medium_2d.c @@ -293,8 +293,8 @@ main(int argc, char** argv) OK(sdis_data_ref_put(data)); /* Setup the square geometry */ - sa_add(positions, square_nvertices*2); - sa_add(indices, square_nsegments*2); + (void)sa_add(positions, square_nvertices*2); + (void)sa_add(indices, square_nsegments*2); memcpy(positions, square_vertices, square_nvertices*sizeof(double[2])); memcpy(indices, square_indices, square_nsegments*sizeof(size_t[2])); diff --git a/src/test_sdis_solve_probe_list.c b/src/test_sdis_solve_probe_list.c @@ -0,0 +1,380 @@ +/* Copyright (C) 2016-2023 |Méso|Star> (contact@meso-star.com) + * + * 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 "sdis.h" +#include "test_sdis_utils.h" + +#include <star/s3d.h> +#include <star/s3dut.h> + +/* + * The system is a trilinear profile of steady state temperature, i.e. at each + * point of the system we can analytically calculate the temperature. We immerse + * a super shape in this temperature field which represents a solid in which we + * want to evaluate by Monte Carlo the temperature at several positions. On the + * Monte Carlo side, the temperature of the super shape is unknown. Only the + * boundary temperature is set to the temperature of the aforementioned + * trilinear profile. Thus, we should find by Monte Carlo the temperature + * defined by the trilinear profile. + * + * /\ <-- T(x,y,z) + * T(z) ___/ \___ + * | \ . T=? / + * o-- T(x) /_ __ _\ + * / \/ \/ + * T(y) + */ + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static double +trilinear_profile(const double pos[3]) +{ + /* Range in X, Y and Z in which the trilinear profile is defined */ + const double lower = -10; + const double upper = +10; + + /* Upper temperature limit in X, Y and Z [K]. Lower temperature limit is + * implicitly 0 */ + const double a = 333; /* Upper temperature limit in X [K] */ + const double b = 432; /* Upper temperature limit in Y [K] */ + const double c = 579; /* Upper temperature limit in Z [K] */ + + double x, y, z; + + /* Check pre-conditions */ + CHK(pos); + CHK(lower <= pos[0] && pos[0] <= upper); + CHK(lower <= pos[1] && pos[1] <= upper); + CHK(lower <= pos[2] && pos[2] <= upper); + + x = (pos[0] - lower) / (upper - lower); + y = (pos[1] - lower) / (upper - lower); + z = (pos[2] - lower) / (upper - lower); + return a*x + b*y + c*z; +} + +static double +compute_delta(struct s3d_scene_view* view) +{ + float S = 0; /* Surface */ + float V = 0; /* Volume */ + + OK(s3d_scene_view_compute_area(view, &S)); + OK(s3d_scene_view_compute_volume(view, &V)); + CHK(S > 0 && V > 0); + + return (4.0*V/S)/20.0; +} + +/******************************************************************************* + * Super shape + ******************************************************************************/ +static struct s3dut_mesh* +create_super_shape(void) +{ + struct s3dut_mesh* mesh = NULL; + struct s3dut_super_formula f0 = S3DUT_SUPER_FORMULA_NULL; + struct s3dut_super_formula f1 = S3DUT_SUPER_FORMULA_NULL; + const double radius = 1; + const unsigned nslices = 256; + + f0.A = 1.5; f0.B = 1; f0.M = 11.0; f0.N0 = 1; f0.N1 = 1; f0.N2 = 2.0; + f1.A = 1.0; f1.B = 2; f1.M = 3.6; f1.N0 = 1; f1.N1 = 2; f1.N2 = 0.7; + OK(s3dut_create_super_shape(NULL, &f0, &f1, radius, nslices, nslices/2, &mesh)); + + return mesh; +} + +/******************************************************************************* + * View, i.e. acceleration structure used to query geometry. In this test it is + * used to calculate the delta parameter and to sample the probe positions in + * the supershape. + ******************************************************************************/ +static void +view_get_indices(const unsigned itri, unsigned ids[3], void* ctx) +{ + struct s3dut_mesh_data* mesh_data = ctx; + CHK(ids && mesh_data && itri < mesh_data->nprimitives); + /* Flip the indices to ensure that the normal points into the super shape */ + ids[0] = (unsigned)mesh_data->indices[itri*3+0]; + ids[1] = (unsigned)mesh_data->indices[itri*3+2]; + ids[2] = (unsigned)mesh_data->indices[itri*3+1]; +} + +static void +view_get_position(const unsigned ivert, float pos[3], void* ctx) +{ + struct s3dut_mesh_data* mesh_data = ctx; + CHK(pos && mesh_data && ivert < mesh_data->nvertices); + pos[0] = (float)mesh_data->positions[ivert*3+0]; + pos[1] = (float)mesh_data->positions[ivert*3+1]; + pos[2] = (float)mesh_data->positions[ivert*3+2]; +} + +static struct s3d_scene_view* +create_view(struct s3dut_mesh* mesh) +{ + struct s3d_vertex_data vdata = S3D_VERTEX_DATA_NULL; + struct s3d_device* s3d = NULL; + struct s3d_scene* scn = NULL; + struct s3d_shape* shape = NULL; + struct s3d_scene_view* view = NULL; + + struct s3dut_mesh_data mesh_data; + + OK(s3dut_mesh_get_data(mesh, &mesh_data)); + + vdata.usage = S3D_POSITION; + vdata.type = S3D_FLOAT3; + vdata.get = view_get_position; + OK(s3d_device_create(NULL, NULL, 0, &s3d)); + OK(s3d_shape_create_mesh(s3d, &shape)); + OK(s3d_mesh_setup_indexed_vertices(shape, (unsigned)mesh_data.nprimitives, + view_get_indices, (unsigned)mesh_data.nvertices, &vdata, 1, &mesh_data)); + OK(s3d_scene_create(s3d, &scn)); + OK(s3d_scene_attach_shape(scn, shape)); + OK(s3d_scene_view_create(scn, S3D_TRACE, &view)); + + OK(s3d_device_ref_put(s3d)); + OK(s3d_shape_ref_put(shape)); + OK(s3d_scene_ref_put(scn)); + + return view; +} + +/******************************************************************************* + * Scene, i.e. the system to simulate + ******************************************************************************/ +struct scene_context { + struct s3dut_mesh_data mesh_data; + struct sdis_interface* interf; +}; +static const struct scene_context SCENE_CONTEXT_NULL = {{0}, NULL}; + +static void +scene_get_indices(const size_t itri, size_t ids[3], void* ctx) +{ + struct scene_context* context = ctx; + CHK(ids && context && itri < context->mesh_data.nprimitives); + /* Flip the indices to ensure that the normal points into the super shape */ + ids[0] = (unsigned)context->mesh_data.indices[itri*3+0]; + ids[1] = (unsigned)context->mesh_data.indices[itri*3+2]; + ids[2] = (unsigned)context->mesh_data.indices[itri*3+1]; +} + +static void +scene_get_interface(const size_t itri, struct sdis_interface** interf, void* ctx) +{ + struct scene_context* context = ctx; + CHK(interf && context && itri < context->mesh_data.nprimitives); + *interf = context->interf; +} + +static void +scene_get_position(const size_t ivert, double pos[3], void* ctx) +{ + struct scene_context* context = ctx; + CHK(pos && context && ivert < context->mesh_data.nvertices); + pos[0] = context->mesh_data.positions[ivert*3+0]; + pos[1] = context->mesh_data.positions[ivert*3+1]; + pos[2] = context->mesh_data.positions[ivert*3+2]; +} + +static struct sdis_scene* +create_scene + (struct sdis_device* sdis, + const struct s3dut_mesh* mesh, + struct sdis_interface* interf) +{ + struct sdis_scene* scn = NULL; + struct sdis_scene_create_args scn_args = SDIS_SCENE_CREATE_ARGS_DEFAULT; + struct scene_context context = SCENE_CONTEXT_NULL; + + OK(s3dut_mesh_get_data(mesh, &context.mesh_data)); + context.interf = interf; + + scn_args.get_indices = scene_get_indices; + scn_args.get_interface = scene_get_interface; + scn_args.get_position = scene_get_position; + scn_args.nprimitives = context.mesh_data.nprimitives; + scn_args.nvertices = context.mesh_data.nvertices; + scn_args.context = &context; + OK(sdis_scene_create(sdis, &scn_args, &scn)); + return scn; +} + +/******************************************************************************* + * Solid, i.e. medium of the super shape + ******************************************************************************/ +#define SOLID_PROP(Prop, Val) \ + static double \ + solid_get_##Prop \ + (const struct sdis_rwalk_vertex* vtx, \ + struct sdis_data* data) \ + { \ + (void)vtx, (void)data; /* Avoid the "unused variable" warning */ \ + return Val; \ + } +SOLID_PROP(calorific_capacity, 500.0) /* [J/K/Kg] */ +SOLID_PROP(thermal_conductivity, 25.0) /* [W/m/K] */ +SOLID_PROP(volumic_mass, 7500.0) /* [kg/m^3] */ +SOLID_PROP(temperature, -1/*<=> unknown*/) /* [K] */ +#undef SOLID_PROP + +static double +solid_get_delta + (const struct sdis_rwalk_vertex* vtx, + struct sdis_data* data) +{ + const double* delta = sdis_data_get(data); + (void)vtx; /* Avoid the "unused variable" warning */ + return *delta; +} + +static struct sdis_medium* +create_solid(struct sdis_device* sdis, struct s3d_scene_view* view) +{ + struct sdis_solid_shader shader = SDIS_SOLID_SHADER_NULL; + struct sdis_medium* solid = NULL; + struct sdis_data* data = NULL; + double* delta = NULL; + + OK(sdis_data_create(sdis, sizeof(double), ALIGNOF(double), NULL, &data)); + delta = sdis_data_get(data); + *delta = compute_delta(view); + + shader.calorific_capacity = solid_get_calorific_capacity; + shader.thermal_conductivity = solid_get_thermal_conductivity; + shader.volumic_mass = solid_get_volumic_mass; + shader.delta = solid_get_delta; + shader.temperature = solid_get_temperature; + OK(sdis_solid_create(sdis, &shader, data, &solid)); + return solid; +} + +/******************************************************************************* + * Dummy environment, i.e. environment surrounding the super shape. It is + * defined only for Stardis compliance: in Stardis, an interface must divide 2 + * media. + ******************************************************************************/ +static struct sdis_medium* +create_dummy(struct sdis_device* sdis) +{ + struct sdis_fluid_shader shader = SDIS_FLUID_SHADER_NULL; + struct sdis_medium* dummy = NULL; + + shader.calorific_capacity = dummy_medium_getter; + shader.volumic_mass = dummy_medium_getter; + shader.temperature = dummy_medium_getter; + OK(sdis_fluid_create(sdis, &shader, NULL, &dummy)); + return dummy; +} + +/******************************************************************************* + * Interface: its temperature is fixed to the trilinear profile + ******************************************************************************/ +static double +interface_get_temperature + (const struct sdis_interface_fragment* frag, + struct sdis_data* data) +{ + (void)data; /* Avoid the "unused variable" warning */ + return trilinear_profile(frag->P); +} + +static struct sdis_interface* +create_interface + (struct sdis_device* sdis, + struct sdis_medium* front, + struct sdis_medium* back) +{ + struct sdis_interface* interf = NULL; + struct sdis_interface_shader shader = SDIS_INTERFACE_SHADER_NULL; + + shader.front.temperature = interface_get_temperature; + shader.back.temperature = interface_get_temperature; + OK(sdis_interface_create(sdis, front, back, &shader, NULL, &interf)); + return interf; +} + +/******************************************************************************* + * Validations + ******************************************************************************/ +static void +check_probe(struct sdis_scene* scn) +{ + struct sdis_solve_probe_args args = SDIS_SOLVE_PROBE_ARGS_DEFAULT; + struct sdis_mc T = SDIS_MC_NULL; + struct sdis_estimator* estimator = NULL; + double ref = 0; /* Analytical reference */ + + args.nrealisations = 100000; + args.position[0] = 0; + args.position[1] = 0; + args.position[2] = 0; + OK(sdis_solve_probe(scn, &args, &estimator)); + OK(sdis_estimator_get_temperature(estimator, &T)); + + ref = trilinear_profile(args.position); + printf("T(%g, %g, %g) = %g ~ %g +/- %g\n", + SPLIT3(args.position), ref, T.E, T.SE); + CHK(eq_eps(ref, T.E, 3*T.SE)); + + OK(sdis_estimator_ref_put(estimator)); +} + +/******************************************************************************* + * The test + ******************************************************************************/ +int +main(int argc, char** argv) +{ + /* Stardis */ + struct sdis_device* sdis = NULL; + struct sdis_interface* interf = NULL; + struct sdis_medium* solid = NULL; + struct sdis_medium* dummy = NULL; /* Medium surrounding the solid */ + struct sdis_scene* scn = NULL; + + /* Miscellaneous */ + struct s3d_scene_view* view = NULL; + struct s3dut_mesh* super_shape = NULL; + int is_master_process = 0; + + (void)argc, (void)argv; /* Avoid the "unused variable" warning */ + + create_default_device(&argc, &argv, &is_master_process, &sdis); + + super_shape = create_super_shape(); + view = create_view(super_shape); + + solid = create_solid(sdis, view); + dummy = create_dummy(sdis); + interf = create_interface(sdis, solid, dummy); + scn = create_scene(sdis, super_shape, interf); + + check_probe(scn); + + OK(s3dut_mesh_ref_put(super_shape)); + OK(sdis_medium_ref_put(solid)); + OK(sdis_medium_ref_put(dummy)); + OK(sdis_interface_ref_put(interf)); + OK(sdis_scene_ref_put(scn)); + + free_default_device(sdis); + return 0; +}