stardis-test

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

commit ffbd6d3bef13319ff6755a842f7f77ddb6c355a4
parent 129c9029861ee47c090c14de35b827f44c6b8884
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 29 Feb 2024 14:40:58 +0100

Test external flux

This new test validates Stardis in handling an external source described
by constant parameters.

Diffstat:
MMakefile | 13+++++++++++--
Asrc/sadist_external_flux.c | 228+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 239 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -18,7 +18,7 @@ include config.mk -TESTS = sadist_probe_boundary +TESTS = sadist_probe_boundary sadist_external_flux # Default target default: .config $(TESTS) @@ -32,7 +32,7 @@ default: .config $(TESTS) clean: rm -f .config src/*.o src/*.d - rm -f sphere.stl sshape.stl scene.txt probes.txt + rm -f ground.stl sphere.stl sshape.stl wall.stl probes.txt scene.txt rm -f libsadist-triprof.so $(TESTS) src/sadist_lib_trilinear_profile.o:\ @@ -55,6 +55,15 @@ sadist_probe_boundary: 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 +src/sadist_external_flux.o:\ + config.mk\ + src/sadist.h\ + 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 diff --git a/src/sadist_external_flux.c b/src/sadist_external_flux.c @@ -0,0 +1,228 @@ +/* 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/>. */ + +#define _POSIX_C_SOURCE 200112L /* popen */ + +#include "sadist.h" + +#include <rsys/math.h> + +#include <math.h> +#include <string.h> /* strerror */ +#include <wait.h> /* WIFEXITED, WEXITSTATUS */ + +/* + * The system consists of 2 parallelepipeds: a vertical one called the wall, and + * a horizontal one representing the floor. The wall is a black body, while the + * floor is a perfectly reflective surface. The surrounding fluid has a fixed + * temperature and, finally, an external spherical source represents the sun. + * This test calculates the steady temperature at a position in the wall and + * compares it with the analytical solution given for a perfectly diffuse or + * specular ground. + * + * (-0.1,1500) + * +---+ External source + * | E=1 T_FLUID ## + * Probe x | _\ #### + * | | / / ## + * +---+ \__/ + * (0,500) + * + * (0,0) + * Y *--------E=0------------- - - - + * | | + * o--X *------------------------ - - - + * / (0,-1) + * Z + * + */ +#define FILENAME_GROUND "ground.stl" +#define FILENAME_WALL "wall.stl" +#define FILENAME_SCENE "scene.txt" + +#define SOURCE_ELEVATION 30.0 /* [degree] */ +#define SOURCE_DISTANCE 1.5e11 /* [m] */ + +/* 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 + +static const double ground_vertices[] = { + 0.0, -1.0, -1.0e6, + 1.0e12, -1.0, -1.0e6, + 0.0, 1.0, -1.0e6, + 1.0e12, 1.0, -1.0e6, + 0.0, -1.0, 1.0e6, + 1.0e12, -1.0, 1.0e6, + 0.0, 1.0, 1.0e6, + 1.0e12, 1.0, 1.0e6 +}; +static const size_t ground_nvertices = sizeof(ground_vertices)/(sizeof(double)*3); + +static const double wall_vertices[] = { + -0.1, 500.0, -500.0, + 0.0, 500.0, -500.0, + -0.1, 1500.0, -500.0, + 0.0, 1500.0, -500.0, + -0.1, 500.0, 500.0, + 0.0, 500.0, 500.0, + -0.1, 1500.0, 500.0, + 0.0, 1500.0, 500.0 +}; +static const size_t wall_nvertices = sizeof(wall_vertices)/(sizeof(double)*3); + +/* Ground and the wall indices */ +static const size_t indices[] = { + 0, 2, 1, 1, 2, 3, /* -z */ + 0, 4, 2, 2, 4, 6, /* -x */ + 4, 5, 6, 6, 5, 7, /* +z */ + 3, 7, 5, 5, 1, 3, /* +x */ + 2, 6, 7, 7, 3, 2, /* +y */ + 0, 1, 5, 5, 4, 0, /* -y */ +}; + +static const size_t ntriangles = sizeof(indices) / (sizeof(size_t)*3); + +/******************************************************************************* + * Helper functions + ******************************************************************************/ +static void +setup_scene(FILE* fp) +{ + const double elevation = MDEG2RAD(SOURCE_ELEVATION); + double pos[3]; + ASSERT(fp); + + 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 0 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 6.5991756e8 %f %f %f 3.845e26\n", + pos[0], pos[1], pos[2]); +} + +static int +init(void) +{ + FILE* fp_ground = NULL; + FILE* fp_wall = NULL; + FILE* fp_scene = NULL; + int err = 0; + + if((fp_ground = fopen(FILENAME_GROUND, "w")) == NULL) { + fprintf(stderr, "Error opening the `"FILENAME_GROUND"' file -- %s\n", + strerror(errno)); + err = errno; + goto error; + } + if((fp_wall = fopen(FILENAME_WALL, "w")) == NULL) { + fprintf(stderr, "Error opening the `"FILENAME_WALL "' file -- %s\n", + strerror(errno)); + err = errno; + goto error; + } + if((fp_scene = fopen(FILENAME_SCENE, "w")) == NULL) { + fprintf(stderr, "Error opening the `"FILENAME_SCENE"' 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); + +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; } + return err; +error: + goto exit; +} + +static int +run(void) +{ + 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"); + + if(!(output = popen(COMMAND, "r"))) { + fprintf(stderr, "Error executing stardis -- %s\n", strerror(errno)); + err = errno; + goto error; + } + + if((n = fscanf(output, "%lf %lf %*d %*d", &E, &SE)), n != 2 && n != EOF) { + fprintf(stderr, "Error reading the output stream -- %s\n", strerror(errno)); + err = errno; + goto error; + } + + /* Check command exit status */ + if((status=pclose(output)), output=NULL, status) { + if(WIFEXITED(status)) err = WEXITSTATUS(status); + goto error; + } + + printf("T = %g ~ %g +/- %g\n", ref, E, SE); + if(!eq_eps(ref, E, SE*3)) { + err = 1; + goto error; + } + +exit: + if(output) pclose(output); + return err; +error: + goto exit; +} + +/******************************************************************************* + * The test + ******************************************************************************/ +int +main(int argc, char** argv) +{ + int err = 0; + (void)argc, (void)argv; + + if((err = init())) goto error; + if((err = run())) goto error; + +exit: + return err; +error: + goto exit; +}