stardis-test

Test Stardis behaviors
git clone git://git.meso-star.fr/stardis-test.git
Log | Files | Refs | README | LICENSE

commit 7398cdef0cbe462e2596a0c4024b1904177137d3
parent ffbd6d3bef13319ff6755a842f7f77ddb6c355a4
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  1 Mar 2024 19:01:48 +0100

Testing external flux with a programmable external source

Programmable here means that the constant parameters of the spherical
source are defined in a library. In other words, we've enhanced the
current test with a new validation using the same spherical source, but
whose position and power are returned by a dynamically loaded library.
To spice up the test, we have nevertheless modified the BRDF of the
scene in order to validate the calculation of external fluxes in the
presence of a specular BRDF.

Diffstat:
MMakefile | 33+++++++++++++++++++++++++--------
Msrc/sadist_external_flux.c | 56+++++++++++++++++++++++++++++++++++++++++++++++++-------
Asrc/sadist_lib_spherical_source.c | 180+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 254 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile @@ -33,8 +33,16 @@ default: .config $(TESTS) clean: rm -f .config src/*.o src/*.d rm -f ground.stl sphere.stl sshape.stl wall.stl probes.txt scene.txt - rm -f libsadist-triprof.so $(TESTS) + rm -f libsadist-triprof.so libsadist-spherical-source.so $(TESTS) +test: $(TESTS) + @#$(SHELL) make.sh check sadist_probe_boundary ./sadist_probe_boundary + @#$(SHELL) make.sh check sadist_probe_boundary_list ./sadist_probe_boundary -p4 + @$(SHELL) make.sh check sadist_external_flux ./sadist_external_flux + +################################################################################ +# Libraries +################################################################################ src/sadist_lib_trilinear_profile.o:\ config.mk\ src/sadist.h\ @@ -45,13 +53,23 @@ libsadist-triprof.so: src/sadist_lib_trilinear_profile.o $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_trilinear_profile.o \ $(LDFLAGS_SO) $(RSYS_LIBS) +src/sadist_lib_spherical_source.o: config.mk src/sadist_lib_spherical_source.c + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ + +libsadist-spherical-source.so: config.mk src/sadist_lib_spherical_source.o + $(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ src/sadist_lib_spherical_source.o \ + $(LDFLAGS_SO) $(RSYS_LIBS) + +################################################################################ +# Tests +################################################################################ src/sadist_probe_boundary.o:\ config.mk\ src/sadist.h\ src/sadist_probe_boundary.c $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@ -sadist_probe_boundary: src/sadist_probe_boundary.o libsadist-triprof.so +sadist_probe_boundary: config.mk src/sadist_probe_boundary.o libsadist-triprof.so $(CC) $(CFLAGS_EXE) $(S3DUT_CFLAGS) $(RSYS_CFLAGS) -o $@ src/$@.o \ $(LDFLAGS_EXE) $(S3DUT_LIBS) $(RSYS_LIBS) -lm @@ -61,9 +79,8 @@ src/sadist_external_flux.o:\ src/sadist_external_flux.c $(CC) $(CFLAGS_EXE) -c $(@:.o=.c) -o $@ -sadist_external_flux: src/sadist_external_flux.o - $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) - -test: $(TESTS) - @$(SHELL) make.sh check sadis_probe_boundary ./sadist_probe_boundary - @$(SHELL) make.sh check sadis_probe_boundary_list ./sadist_probe_boundary -p 4 +sadist_external_flux:\ + config.mk\ + src/sadist_external_flux.o\ + libsadist-spherical-source.so + $(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(RSYS_LIBS) -lm diff --git a/src/sadist_external_flux.c b/src/sadist_external_flux.c @@ -51,17 +51,24 @@ #define FILENAME_GROUND "ground.stl" #define FILENAME_WALL "wall.stl" #define FILENAME_SCENE "scene.txt" +#define FILENAME_SCENE_PROG "scene2.txt" #define SOURCE_ELEVATION 30.0 /* [degree] */ #define SOURCE_DISTANCE 1.5e11 /* [m] */ +#define SOURCE_RADIUS 6.5991756e8 +#define SOURCE_POWER 3.845e26 /* [W] */ /* Probe position */ #define PX -0.05 #define PY 1000.0 #define PZ 0.0 -/* Command */ -#define COMMAND "stardis -V3 -p "STR(PX)","STR(PY)","STR(PZ)" -M "FILENAME_SCENE +/* The Commands and the expected temperatures */ +#define COMMAND1 "stardis -i -V3 -p "STR(PX)","STR(PY)","STR(PZ)" -M "FILENAME_SCENE +#define COMMAND2 "stardis -i -V3 -p "STR(PX)","STR(PY)","STR(PZ)\ + " -M "FILENAME_SCENE_PROG" -n 100000" +#define T_REF1 375.88 /* [K] */ +#define T_REF2 417.77 /* [K] */ static const double ground_vertices[] = { 0.0, -1.0, -1.0e6, @@ -125,12 +132,39 @@ setup_scene(FILE* fp) pos[0], pos[1], pos[2]); } +static void +setup_scene_prog(FILE* fp) +{ + const double elevation = MDEG2RAD(SOURCE_ELEVATION); + double pos[3]; + ASSERT(fp); + + fprintf(fp, "PROGRAM source libsadist-spherical-source.so\n"); + fprintf(fp, "SOLID ground 1.15 1700 800 5.0e-3 0 UNKNOWN 0 FRONT " + FILENAME_GROUND "\n"); + fprintf(fp, "SOLID wall 1.15 1700 800 5.0e-3 0 UNKNOWN 0 FRONT " + FILENAME_WALL "\n"); + fprintf(fp, "FLUID dummy 1 1 300 300 BACK "FILENAME_GROUND" BACK "FILENAME_WALL "\n"); + fprintf(fp, "SOLID_FLUID_CONNECTION fluid_ground 0 0 1 0 "FILENAME_GROUND "\n"); + fprintf(fp, "SOLID_FLUID_CONNECTION fluid_wall 0 1 0 10 "FILENAME_WALL "\n"); + fprintf(fp, "TRAD 0 0\n"); + + pos[0] = cos(elevation) * SOURCE_DISTANCE; + pos[1] = sin(elevation) * SOURCE_DISTANCE; + pos[2] = 0; + + fprintf(fp, "SPHERICAL_SOURCE_PROG "STR(SOURCE_RADIUS)" source " + "PROG_PARAMS dummy -p %f,%f,%f -w "STR(SOURCE_POWER)"\n", + pos[0], pos[1], pos[2]); +} + static int init(void) { FILE* fp_ground = NULL; FILE* fp_wall = NULL; FILE* fp_scene = NULL; + FILE* fp_scene_prog = NULL; int err = 0; if((fp_ground = fopen(FILENAME_GROUND, "w")) == NULL) { @@ -151,34 +185,41 @@ init(void) err = errno; goto error; } + if((fp_scene_prog = fopen(FILENAME_SCENE_PROG, "w")) == NULL) { + fprintf(stderr, "Error opening the `"FILENAME_SCENE_PROG"' file -- %s\n", + strerror(errno)); + err = errno; + goto error; + } sadist_write_stl(fp_ground, ground_vertices, ground_nvertices, indices, ntriangles); sadist_write_stl(fp_wall, wall_vertices, wall_nvertices, indices, ntriangles); setup_scene(fp_scene); + setup_scene_prog(fp_scene_prog); exit: if(fp_ground && fclose(fp_ground)) { perror("fclose"); if(!err) err = errno; } if(fp_wall && fclose(fp_wall)) { perror("fclose"); if(!err) err = errno; } if(fp_scene && fclose(fp_scene)) { perror("fclose"); if(!err) err = errno; } + if(fp_scene_prog && fclose(fp_scene_prog)) { perror("fclose"); if(!err) err = errno; } return err; error: goto exit; } static int -run(void) +run(const char* command, const double ref) { FILE* output = NULL; double E = 0; double SE = 0; - const double ref = 375.88; int n = 0; int err = 0; int status = 0; - printf(COMMAND"\n"); + printf("%s\n", command); - if(!(output = popen(COMMAND, "r"))) { + if(!(output = popen(command, "r"))) { fprintf(stderr, "Error executing stardis -- %s\n", strerror(errno)); err = errno; goto error; @@ -219,7 +260,8 @@ main(int argc, char** argv) (void)argc, (void)argv; if((err = init())) goto error; - if((err = run())) goto error; + if((err = run(COMMAND1, T_REF1))) goto error; + if((err = run(COMMAND2, T_REF2))) goto error; exit: return err; diff --git a/src/sadist_lib_spherical_source.c b/src/sadist_lib_spherical_source.c @@ -0,0 +1,180 @@ +/* Copyright (C) 2024 |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 <stardis/stardis-prog-properties.h> + +#include <stdarg.h> /* va_list */ +#include <getopt.h> + +#include <rsys/cstr.h> +#include <rsys/mem_allocator.h> + +#include <getopt.h> + +struct source { + double position[3]; + double power; /* [W] */ +}; +#define SOURCE_NULL__ {{0,0,0}, 0} +static const struct source SOURCE_NULL = SOURCE_NULL__; + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +print_usage(FILE* stream, const char* name) +{ + ASSERT(name); + fprintf(stream, "usage: %s [-h] [-p x,y,z] [-w power]\n", name); +} + +static res_T +parse_args + (const struct stardis_description_create_context *ctx, + struct source* source, + int argc, + char* argv[]) +{ + size_t len = 0; + int opt = 0; + res_T res = RES_OK; + ASSERT(ctx && source); + + optind = 1; + while((opt = getopt(argc, argv, "hp:w:")) != -1) { + switch(opt) { + case 'h': + print_usage(stdout, ctx->name); + break; + case 'p': + res = cstr_to_list_double(optarg, ',', source->position, &len, 3); + if(res == RES_OK && len < 3) res = RES_BAD_ARG; + break; + case 'w': + res = cstr_to_double(optarg, &source->power); + if(res == RES_OK && source->power < 0) res = RES_BAD_ARG; + break; + default: res = RES_BAD_ARG; + } + if(res != RES_OK) { + if(optarg) { + fprintf(stderr, "%s: invalid option argument '%s' -- '%c'\n", + ctx->name, optarg, opt); + } + goto error; + } + } + +exit: + return res; +error: + goto exit; +} + +/******************************************************************************* + * Create data + ******************************************************************************/ +void* +stardis_create_data + (const struct stardis_description_create_context *ctx, + void* libdata, + size_t argc, + char* argv[]) +{ + struct source* source = NULL; + res_T res = RES_OK; + (void)libdata; + + source = mem_alloc(sizeof(*source)); + if(!source) { + fprintf(stderr, "%s:%d: error allocating the external spherical source.\n", + __FILE__, __LINE__); + goto error; + } + *source = SOURCE_NULL; + + res = parse_args(ctx, source, (int)argc, argv); + if(res != RES_OK) goto error; + +exit: + return source; +error: + if(source) { + mem_rm(source); + source = NULL; + } + goto exit; +} + +void +stardis_release_data(void* data) +{ + ASSERT(data); + mem_rm(data); +} + +/******************************************************************************* + * External source + ******************************************************************************/ +double* +stardis_spherical_source_position + (const double time, /* [s] */ + double position[3], + void* data) +{ + struct source* source = data; + (void)time; /* Avoid "unused variable" warning */ + ASSERT(source); + position[0] = source->position[0]; + position[1] = source->position[1]; + position[2] = source->position[2]; + return position; +} + +double /* [W] */ +stardis_spherical_source_power(const double time /* [s] */, void* data) +{ + struct source* source = data; + (void)time; /* Avoid "unused variable" warning */ + ASSERT(source); + return source->power; /* [W] */ +} + +/******************************************************************************* + * Legal notices + ******************************************************************************/ +const char* +get_copyright_notice(void* data) +{ + (void)data; /* Avoid "unused variable" warnings */ + return "Copyright (C) 2024 |Méso|Star> (contact@meso-star.com)"; +} + +const char* +get_license_short(void* data) +{ + (void)data; /* Avoid "unused variable" warnings */ + return "GNU GPL version 3 or later <http://www.gnu.org/licenses/>"; +} + +const char* +get_license_text(void* data) +{ + (void)data; /* Avoid "unused variable" warnings */ + return + "This is free software released under the GPL v3+ license: GNU GPL\n" + "version 3 or later. You are welcome to redistribute it under certain\n" + "conditions; refer to <http://www.gnu.org/licenses/> for details."; +}