stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit bc66f16be6163b75a92c3be9f47d2a2ebf907a55
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Sat, 21 Apr 2018 17:25:24 +0200

first commit

Diffstat:
Asrc/Makefile | 16++++++++++++++++
Asrc/args.h | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/b_T_1.stl | 16++++++++++++++++
Asrc/b_T_2.stl | 30++++++++++++++++++++++++++++++
Asrc/b_h_1.stl | 156+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/bc.txt | 4++++
Asrc/m_1.stl | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/m_2.stl | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/m_3.stl | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/main.c | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/material.txt | 4++++
Asrc/stardis-app.c | 364+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/stardis-app.h | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/stardis-compute.c | 352+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 1528 insertions(+), 0 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -0,0 +1,16 @@ +CC=gcc +INC=-I../Stardis-0.1.0-GNU-Linux64/include +LDFLAGS=-lsdis -lsstl -lrsys -L../Stardis-0.1.0-GNU-Linux64/lib -Wl,-rpath=../Stardis-0.1.0-GNU-Linux64/lib +SRC=main.c stardis-app.c stardis-compute.c +DEPS=args.h stardis-app.h + +all: stardis-app + +stardis-app: $(SRC) $(DEPS) + $(CC) -o stardis-app $(SRC) $(INC) $(LDFLAGS) + +debug: main.c + $(CC) -g -o stardis-app-dbg $(SRC) $(INC) $(LDFLAGS) + +clean: + rm -rf stardis-app stardis-app-dbg diff --git a/src/args.h b/src/args.h @@ -0,0 +1,99 @@ +/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)*/ + +#ifndef ARGS_H +#define ARGS_H + +#include <unistd.h> +#include <rsys/rsys.h> +#include <rsys/cstr.h> + +static void +print_help(char* prog) +{ + printf("usage %s -m MEDIUM.txt -b BOUNDARY.txt [-p X:Y:Z:TIME] [-n NUM_OF_REALIZATIONS] [-t NUM_OF_THREADS]\n", prog); +} + +struct args{ + char* medium_filename; + char* bc_filename; + size_t N; + unsigned nthreads; + double probe[4]; +}; +#define ARGS_DEFAULT {NULL, NULL, 10000, SDIS_NTHREADS_DEFAULT, {0,0,0,INF}} + +static res_T +parse_args(const int argc, char** argv, struct args* args) +{ + int opt = 0; + size_t len = 0; + res_T res = RES_OK; + + if (argc == 1) { + print_help(argv[0]); + res = RES_BAD_ARG; + goto error; + } + + while((opt = getopt(argc, argv, "hn:t:b:m:p:")) != -1) { + switch(opt) { + case 'h': + print_help(argv[0]); + res = RES_BAD_ARG; + goto error; + break; + + case 'n': + res = cstr_to_ulong(optarg, &args->N); + if (res != RES_OK){ + fprintf(stderr, "Invalid argument -n %s\n", optarg); + goto error; + } + break; + + case 'b': + args->bc_filename = optarg; + break; + + case 'm': + args->medium_filename = optarg; + break; + + case 't': + res = cstr_to_uint(optarg, &args->nthreads); + if (res != RES_OK){ + fprintf(stderr, "Invalid argument -t %s\n", optarg); + goto error; + } + break; + + case 'p': + cstr_to_list_double(optarg, ':', args->probe, &len, 4); + if(res == RES_OK && len != 4) res = RES_BAD_ARG; + if (res != RES_OK){ + fprintf(stderr, "Invalid argument -p\n", optarg); + goto error; + } + break; + } + } + +if (!args->medium_filename){ + fprintf(stderr, "Argument required -m\n"); + res = RES_BAD_ARG; + goto error; +} + +if (!args->bc_filename){ + fprintf(stderr, "Argument required -b\n"); + res = RES_BAD_ARG; + goto error; +} + +exit: + return res; +error: + goto exit; +} + +#endif /*ARGS_H*/ diff --git a/src/b_T_1.stl b/src/b_T_1.stl @@ -0,0 +1,16 @@ +solid shape, STL ascii file, created with Open CASCADE Technology + facet normal -0.000000e+00 0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet +endsolid shape diff --git a/src/b_T_2.stl b/src/b_T_2.stl @@ -0,0 +1,30 @@ +solid shape, STL ascii file, created with Open CASCADE Technology + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet +endsolid shape diff --git a/src/b_h_1.stl b/src/b_h_1.stl @@ -0,0 +1,156 @@ +solid shape, STL ascii file, created with Open CASCADE Technology + facet normal 1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 -0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 -0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 -0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + endloop + endfacet +endsolid shape diff --git a/src/bc.txt b/src/bc.txt @@ -0,0 +1,4 @@ +#STL_filename h h_coeff T_env | STL_filename T T_value +b_h_1.stl h 0 300 +b_T_1.stl T 300 +b_T_2.stl T 400 diff --git a/src/m_1.stl b/src/m_1.stl @@ -0,0 +1,114 @@ +solid shape, STL ascii file, created with Open CASCADE Technology + facet normal -1.000000e+00 0.000000e+00 -0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal -0.000000e+00 0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + vertex 0.000000e+00 0.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 0.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 -0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 1.000000e+00 0.000000e+00 + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 -0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 0.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet +endsolid shape diff --git a/src/m_2.stl b/src/m_2.stl @@ -0,0 +1,86 @@ +solid shape, STL ascii file, created with Open CASCADE Technology + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal -0.000000e+00 0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + vertex 0.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 0.000000e+00 2.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + vertex 1.000000e+00 0.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 0.000000e+00 2.000000e+00 + endloop + endfacet +endsolid shape diff --git a/src/m_3.stl b/src/m_3.stl @@ -0,0 +1,86 @@ +solid shape, STL ascii file, created with Open CASCADE Technology + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal -1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -1.000000e+00 0.000000e+00 + outer loop + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal -0.000000e+00 0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 -0.000000e+00 -1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + vertex 0.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 0.000000e+00 1.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + vertex 0.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 0.000000e+00 1.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 1.000000e+00 + vertex 0.000000e+00 1.000000e+00 2.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 1.000000e+00 + endloop + endfacet + facet normal 1.000000e+00 0.000000e+00 -0.000000e+00 + outer loop + vertex 1.000000e+00 1.000000e+00 1.000000e+00 + vertex 1.000000e+00 1.000000e+00 2.000000e+00 + vertex 1.000000e+00 5.000000e-01 2.000000e+00 + endloop + endfacet +endsolid shape diff --git a/src/main.c b/src/main.c @@ -0,0 +1,70 @@ +/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)*/ + + +#include "stardis-app.h" + +static void +dump_boundary(FILE* stream, struct boundary* bound) +{ + int i = 0; + fprintf(stream,"# bound_id hc T\n"); + for (i=0; i<sa_size(bound); ++i){ + fprintf(stream,"%i %g %g\n",i , bound[i].hc, bound[i].T); + } +} + +static void +dump_vertex(FILE* stream, struct vertex* vert_list) +{ + int i = 0; + fprintf(stream,"# vertex_id x y z\n"); + for (i=0; i<sa_size(vert_list); ++i){ + fprintf(stream,"%i %g %g %g\n",i ,SPLIT3(vert_list[i].xyz)); + } +} + +static void +dump_triangle(FILE* stream, struct triangle* tri_list) +{ + int i = 0; + fprintf(stream,"# triangle_id vertex_id vertex_id vertex_id"); + fprintf(stream," medium_front medium_back"); + fprintf(stream," bound_id\n"); + for (i=0; i<sa_size(tri_list); ++i){ + fprintf(stream,"%i %i %i %i %i %i %i\n", + i, + SPLIT3(tri_list[i].indices), + tri_list[i].medium_front, + tri_list[i].medium_back, + tri_list[i].bound_id); + } +} + +int main(int argc, char** argv){ + + struct args args = ARGS_DEFAULT; + struct stardis stardis = NULL_STARDIS; + size_t memsz = 0; + int err = 0; + res_T res = RES_OK; + + res = parse_args(argc, argv, &args); + if (res != RES_OK) goto error; + + res = stardis_init(&args, &stardis); + if (res != RES_OK) goto error; + + res = stardis_compute(&stardis); + if (res != RES_OK) goto error; + +exit: + stardis_release(&stardis); + if((memsz = mem_allocated_size()) != 0) { + fprintf(stderr, "Memory leaks: %lu Bytes\n", (unsigned long)memsz); + } + + return err; +error: + err = -1; + goto exit; +} diff --git a/src/material.txt b/src/material.txt @@ -0,0 +1,4 @@ +#STL_filename lambda rho cp delta Tinit +m_1.stl 1.0 1.0 1.0 0.05 300 +m_2.stl 1.0 1.0 1.0 0.05 300 +m_3.stl 1.0 1.0 1.0 0.05 300 diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -0,0 +1,364 @@ +/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)*/ + +#include <string.h> +#include "stardis-app.h" + +#define MEDIUM 0 +#define BOUNDARY 1 + +/******************************************************************************* + * + ******************************************************************************/ + +static inline char* +read_line(char** pb, FILE* stream) +{ + const int chunk = 32; + char* b = *pb; + + if(!b) b = sa_add(b, 128); + + do { + if(!fgets(b, (int)sa_size(b), stream)) return NULL; + + /* Ensure that he whole line is read */ + while(!strrchr(b, '\n') && !feof(stream)) { + fgets(sa_add(b, (size_t)chunk), chunk, stream); + } + + b[strcspn(b, "#\n\r")] = '\0'; /* Rm new line & comments */ + } while(strspn(b, " \t") == strlen(b)); /* Empty line */ + *pb = b; + return b; +} + +static res_T +parse_medium_line(char* line, char** stl_filename, struct material* mat) +{ + char* tk = NULL; + res_T res = RES_OK; + + tk = strtok(line," "); + *stl_filename = malloc(strlen(tk) + 1); + strcpy(*stl_filename,tk); + tk = strtok(NULL," "); + res = cstr_to_double(tk, &mat->lambda); + if (res != RES_OK) { + fprintf(stderr,"invalid lambda\n"); + goto error; + } + tk = strtok(NULL," "); + res = cstr_to_double(tk, &mat->rho); + if (res != RES_OK) { + fprintf(stderr,"invalid rho\n"); + goto error; + } + tk = strtok(NULL," "); + res = cstr_to_double(tk, &mat->cp); + if (res != RES_OK) { + fprintf(stderr,"invalid cp\n"); + goto error; + } + tk = strtok(NULL," "); + res = cstr_to_double(tk, &mat->delta); + if (res != RES_OK) { + fprintf(stderr,"invalid delta\n"); + goto error; + } + tk = strtok(NULL," "); + res = cstr_to_double(tk, &mat->Tinit); + if (res != RES_OK) { + fprintf(stderr,"invalid Tinit\n"); + goto error; + } + +exit: + return res; +error: + goto exit; +} + +static res_T +parse_boundary_line(char* line, char** stl_filename, struct boundary* bound) +{ +#define H_TYPE 0 +#define T_TYPE 1 + char bc_type; + char* tk = NULL; + double value = 0; + res_T res = RES_OK; + + tk = strtok(line," "); + *stl_filename = malloc(strlen(tk) + 1); + strcpy(*stl_filename,tk); + + tk = strtok(NULL," "); + if (strcmp(tk,"h")==0 || strcmp(tk,"H")==0 ){ + bc_type = H_TYPE; + } else if (strcmp(tk,"t")==0 || strcmp(tk,"T")==0 ){ + bc_type = T_TYPE; + } else { + fprintf(stderr,"unknown boundary type: %s\n", tk); + goto error; + } + + tk = strtok(NULL," "); + res = cstr_to_double(tk, &value); + if (res != RES_OK || value < 0) { + fprintf(stderr,"invalid value parameter: %g \n", value); + goto error; + } + + if (bc_type == H_TYPE){ + bound->hc = value; + tk = strtok(NULL," "); + res = cstr_to_double(tk, &value); + if (res != RES_OK || value < 0) { + fprintf(stderr,"invalid value parameter: %g \n", value); + goto error; + } + bound->T = value; + } + + if (bc_type == T_TYPE) bound->T = value; + +#undef H_TYPE +#undef T_TYPE + +exit: + return res; +error: + goto exit; +} +static res_T +read_vertices +(struct sstl_desc* desc, + struct htable_vertex* vertex2id, + unsigned** id2id, + struct vertex** vert_list) +{ + res_T res = RES_OK; + int vtx_index = 0; + + for (vtx_index = 0; vtx_index < desc->vertices_count; ++vtx_index){ + struct vertex vtx = NULL_VERTEX; + unsigned *found_id = NULL; + + vtx.xyz[0] = desc->vertices[3*vtx_index + 0]; + vtx.xyz[1] = desc->vertices[3*vtx_index + 1]; + vtx.xyz[2] = desc->vertices[3*vtx_index + 2]; + + found_id = htable_vertex_find(vertex2id, &vtx); + + if (found_id){ + sa_push(*id2id, *found_id); + } else { + unsigned size = htable_vertex_size_get(vertex2id); + htable_vertex_set(vertex2id, &vtx, &size); + sa_push(*vert_list, vtx); + sa_push(*id2id, size); + } + } + + return res; +} + +static res_T +read_triangles +(int FLAG, + struct sstl_desc* desc, + struct htable_triangle* triangle2id, + unsigned* id2id, char** cl_type, + const unsigned* id, + struct triangle** tri_list) +{ + res_T res = RES_OK; + int tri_index = 0; + for (tri_index = 0; tri_index < desc->triangles_count; ++tri_index){ + struct triangle tri = NULL_TRIANGLE; + unsigned *found_id = NULL; + + tri.sids[0] = tri.indices[0] = id2id[desc->indices[3*tri_index + 0]]; + tri.sids[1] = tri.indices[1] = id2id[desc->indices[3*tri_index + 1]]; + tri.sids[2] = tri.indices[2] = id2id[desc->indices[3*tri_index + 2]]; + + if(tri.sids[0] > tri.sids[1]) SWAP(unsigned, tri.sids[0], tri.sids[1]); + if(tri.sids[1] > tri.sids[2]) SWAP(unsigned, tri.sids[1], tri.sids[2]); + if(tri.sids[0] > tri.sids[1]) SWAP(unsigned, tri.sids[0], tri.sids[1]); + found_id = htable_triangle_find(triangle2id, &tri); + + if (found_id){ + if (FLAG==MEDIUM) (*tri_list)[*found_id].medium_back = *id; + if (FLAG==BOUNDARY) (*tri_list)[*found_id].bound_id = *id; + } else { + unsigned size = htable_triangle_size_get(triangle2id); + if (FLAG==MEDIUM) tri.medium_front = *id; + htable_triangle_set(triangle2id, &tri, &size); + /*printf("triangle %i %i %i\n added at index %i\n", SPLIT3(tri.indices), size);*/ + sa_push(*tri_list, tri); + } + } + return res; +} + + +static res_T +read_stl +(char FLAG, + unsigned id, + char** stl_filename, + struct htable_vertex* vertex2id, + struct htable_triangle* triangle2id, + struct geometry* geometry) +{ + res_T res = RES_OK; + struct sstl* sstl = NULL; + struct sstl_desc desc; + unsigned* id2id = NULL; + + SSTL(create(NULL, NULL, 0, &sstl)); + + + SSTL(load(sstl, *stl_filename)); + SSTL(get_desc(sstl, &desc)); + + read_vertices(&desc, vertex2id, &id2id, &geometry->vertex); + read_triangles(FLAG, &desc, triangle2id, id2id, NULL, &id, &geometry->triangle); + sa_release(id2id); + + +exit: + SSTL(ref_put(sstl)); + return res; +error: + goto exit; +} + + +/******************************************************************************* + * + ******************************************************************************/ + +static res_T +geometry_analyse +(const char* medium_filename, + const char* bc_filename, + struct geometry* geometry, + struct material** material, + struct boundary** boundary) +{ + res_T res = RES_OK; + FILE* input; + char* line = NULL; + struct htable_vertex vertex2id; + struct htable_triangle triangle2id; + + /*init geometry*/ + *geometry = NULL_GEOMETRY; + + /*parse medium file*/ + input = fopen(medium_filename,"r"); + if (!input){ + fprintf(stderr,"Can not open %s\n", medium_filename); + res = RES_IO_ERR; + goto error; + } + + htable_vertex_init(NULL, &vertex2id); + htable_triangle_init(NULL, &triangle2id); + /* loop on media */ + while (read_line(&line, input)){ + char* stl_filename = NULL; + struct material mat = NULL_MATERIAL; + + res = parse_medium_line(line, &stl_filename, &mat); + sa_push(*material,mat); + + /*analyse medium stl*/ + res = read_stl(MEDIUM, geometry->medium_count, &stl_filename, + &vertex2id, &triangle2id, geometry); + + geometry->medium_count += 1; + } + fclose(input); + + /*parse boundary file*/ + input = fopen(bc_filename,"r"); + if (!input){ + fprintf(stderr,"Can not open %s\n", bc_filename); + res = RES_IO_ERR; + goto error; + } + + /* loop on boundaries */ + while (read_line(&line, input)){ + char* stl_filename = NULL; + struct boundary bound = NULL_BOUNDARY; + + res = parse_boundary_line(line, &stl_filename, &bound); + sa_push(*boundary,bound); + + /*analyse medium stl*/ + res = read_stl(BOUNDARY, geometry->boundary_count, &stl_filename, + &vertex2id, &triangle2id, geometry); + + geometry->boundary_count += 1; + } + + fclose(input); + +exit: + htable_vertex_init(NULL, &vertex2id); + htable_triangle_init(NULL, &triangle2id); + sa_release(line); + return res; +error: + goto exit; +} + + +/******************************************************************************* + * + ******************************************************************************/ + +res_T +stardis_init + (const struct args* args, + struct stardis* stardis) +{ + res_T res = RES_OK; + + res = geometry_analyse(args->medium_filename, + args->bc_filename, + &stardis->geometry, + &stardis->material, + &stardis->boundary); + + stardis->N = args->N; + stardis->nthreads = args->nthreads; + stardis->probe[0] = args->probe[0]; + stardis->probe[1] = args->probe[1]; + stardis->probe[2] = args->probe[2]; + stardis->probe[3] = args->probe[3]; + +exit: + return res; +error: + goto exit; +} + + +res_T +stardis_release(struct stardis* stardis) +{ + res_T res = RES_OK; + + res = release_geometry(&stardis->geometry); + sa_release(stardis->material); + sa_release(stardis->boundary); + +exit: + return res; +error: + goto exit; +} diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -0,0 +1,131 @@ +/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)*/ + +#ifndef STARDIS_APP_H +#define STARDIS_APP_H + +#include <star/sstl.h> +#include <rsys/rsys.h> +#include <rsys/float3.h> +#include <rsys/stretchy_array.h> +#include <rsys/hash_table.h> +#include <sdis.h> +#include "args.h" + +struct vertex{ + float xyz[3]; +}; +#define NULL_VERTEX__ {{0.0 ,0.0 ,0.0}} +static const struct vertex NULL_VERTEX = NULL_VERTEX__; + +static inline char +eq_vertex(const struct vertex* a, const struct vertex* b) +{ + return (char)f3_eq(a->xyz, b->xyz); +} + +/* Declare the hash table that map a vertex to its index */ +#define HTABLE_NAME vertex +#define HTABLE_DATA unsigned +#define HTABLE_KEY struct vertex +#define HTABLE_KEY_FUNCTOR_EQ eq_vertex +#include <rsys/hash_table.h> + +struct triangle{ + unsigned indices[3]; + unsigned sids[3]; + int medium_front; + int medium_back; + int bound_id; +}; +#define NULL_TRIANGLE__ {{0, 0, 0}, {0, 0, 0}, 0, 0, -1} +static const struct triangle NULL_TRIANGLE = NULL_TRIANGLE__; + +static char +eq_triangle(const struct triangle* a, const struct triangle* b) +{ + return a->sids[0] == b->sids[0] + && a->sids[1] == b->sids[1] + && a->sids[2] == b->sids[2]; +} + +static size_t +hash_triangle(const struct triangle* tri) +{ + return hash_fnv64(tri->sids, sizeof(unsigned[3])); +} + +/* Declare the hash table that map a triangle to its index */ +#define HTABLE_NAME triangle +#define HTABLE_DATA unsigned +#define HTABLE_KEY struct triangle +#define HTABLE_KEY_FUNCTOR_EQ eq_triangle +#define HTABLE_KEY_FUNCTOR_HASH hash_triangle +#include <rsys/hash_table.h> + +struct geometry{ + struct vertex* vertex; + struct triangle* triangle; + unsigned medium_count; + unsigned boundary_count; + struct sdis_interface** interfaces; +}; +#define NULL_GEOMETRY__ {NULL, NULL, 0, 0, NULL} +static const struct geometry NULL_GEOMETRY = NULL_GEOMETRY__; + +static res_T +release_geometry +(struct geometry* geom) +{ + res_T res = RES_OK; + + sa_release(geom->vertex); + sa_release(geom->triangle); + sa_release(geom->interfaces); + +exit: + return res; +error: + goto exit; +} + +struct material{ + double lambda; + double rho; + double cp; + double delta; + double Tinit; +}; +#define NULL_MATERIAL__ {0.0 ,0.0 ,0.0, 0.0, 0.0} +static const struct material NULL_MATERIAL = NULL_MATERIAL__; + +struct boundary{ + double hc; + double T; +}; +#define NULL_BOUNDARY__ {-1, -1} +static const struct boundary NULL_BOUNDARY = NULL_BOUNDARY__; + +struct stardis{ + struct geometry geometry; + struct material* material; /*array of materials*/ + struct boundary* boundary; /*array of boundaries*/ + + size_t N; /*number of MC realizations*/ + unsigned nthreads; + double probe[4]; /*x,y,z,t of probe*/ +}; +#define NULL_STARDIS__ {NULL_GEOMETRY__, NULL, NULL, 0, 0, {0,0,0,0}} +static const struct stardis NULL_STARDIS = NULL_STARDIS__; + +res_T +stardis_init + (const struct args* args, + struct stardis* stardis); + +res_T +stardis_compute(struct stardis* stardis); + +res_T +stardis_release(struct stardis* stardis); + +#endif /*STARDIS-APP_H*/ diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -0,0 +1,352 @@ +/* Copyright (C) 2018 |Meso|Star> (contact@meso-star.com)*/ + +#include "stardis-app.h" +#include <sdis.h> + +static void +geometry_get_position +(const size_t ivert, + double pos[3], + void* context) +{ + struct geometry* geom = context; + pos[0] = geom->vertex[ivert].xyz[0]; + pos[1] = geom->vertex[ivert].xyz[1]; + pos[2] = geom->vertex[ivert].xyz[2]; +} + +static void +geometry_get_indices +(const size_t itri, + size_t ids[3], + void* context) +{ + struct geometry* geom = context; + ids[0] = geom->triangle[itri].indices[0]; + ids[1] = geom->triangle[itri].indices[1]; + ids[2] = geom->triangle[itri].indices[2]; +} + +static void +geometry_get_interface +(const size_t itri, + struct sdis_interface** interf, + void* context) +{ + struct geometry* geom = context; + *interf = geom->interfaces[itri]; +} + +/******************************************************************************* + * Fluid data + ******************************************************************************/ +struct fluid { + double cp; /* Calorific capacity */ + double rho; /* Volumic mass */ + double temperature; /* < 0 means for unknown temperature */ +}; + +static double +fluid_get_calorific_capacity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct fluid* fluid_props = sdis_data_cget(data); + return fluid_props->cp; +} + +static double +fluid_get_volumic_mass + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct fluid* fluid_props = sdis_data_cget(data); + return fluid_props->rho; +} + +static double +fluid_get_temperature + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct fluid* fluid_props = sdis_data_cget(data); + return fluid_props->temperature; +} + +/******************************************************************************* + * Solid data + ******************************************************************************/ +struct solid { + double cp; /* Calorific capacity */ + double lambda; /* Conductivity */ + double rho; /* Volumic mass */ + double delta; /* Numerical parameter */ + double temperature; /* < 0 means for unknown temperature */ +}; + +static double +solid_get_calorific_capacity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct solid* solid_props = sdis_data_cget(data); + return solid_props->cp; +} + +static double +solid_get_thermal_conductivity + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct solid* solid_props = sdis_data_cget(data); + return solid_props->lambda; +} + +static double +solid_get_volumic_mass + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct solid* solid_props = sdis_data_cget(data); + return solid_props->rho; +} + +static double +solid_get_delta + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct solid* solid_props = sdis_data_cget(data); + return solid_props->delta; +} + +static double +solid_get_delta_boundary + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct solid* solid_props = sdis_data_cget(data); + return solid_props->delta + /* Emperical scale factor that ensures that delta_boundary > delta withouht + * being an exact multiple of delta. */ + * 2.1 ; +} + +static double +solid_get_temperature + (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) +{ + const struct solid* solid_props = sdis_data_cget(data); + if (vtx->time > 0){ + return -1; + }else{ + return solid_props->temperature; + } +} + +/******************************************************************************* + * Interface data + ******************************************************************************/ +struct interface { + double hc; /* Convection coefficient */ + double temperature; /* < 0 means for unknown temperature */ + double epsilon; + double alpha; +}; + +static double +interface_get_convection_coef + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interface* interface_props = sdis_data_cget(data); + return interface_props->hc; +} + +static double +interface_get_temperature + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interface* interface_props = sdis_data_cget(data); + return interface_props->temperature; +} + +static double +interface_get_epsilon + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interface* interface_props = sdis_data_cget(data); + return interface_props->epsilon; +} + + +static double +interface_get_alpha + (const struct sdis_interface_fragment* frag, struct sdis_data* data) +{ + const struct interface* interface_props = sdis_data_cget(data); + return interface_props->alpha; +} + +/******************************************************************************* + * + ******************************************************************************/ + +res_T +stardis_compute(struct stardis* stardis) +{ + res_T res = RES_OK; + struct sdis_device* dev = NULL; + struct sdis_data* data = NULL; + struct solid* solid_props = NULL; + struct fluid* fluid_props = NULL; + struct sdis_solid_shader solid_shader = SDIS_SOLID_SHADER_NULL; + struct sdis_medium** solid_medium = NULL; + struct sdis_fluid_shader fluid_shader = SDIS_FLUID_SHADER_NULL; + struct sdis_medium** fluid_medium = NULL; + + struct sdis_interface_shader interface_shader_boundary = SDIS_INTERFACE_SHADER_NULL; + struct sdis_interface_shader interface_shader_connection = SDIS_INTERFACE_SHADER_NULL; + struct interface* interface_props = NULL; + struct sdis_interface** interfaces = NULL; + + struct sdis_scene* scn; + struct sdis_estimator* estimator; + struct sdis_mc temperature; + + int* bound2fluid = NULL; + double pos[3] = {0,0,0}; + double time = 0; + size_t nfailures; + int i = 0; + + SDIS(device_create(NULL, NULL, SDIS_NTHREADS_DEFAULT, 0, &dev)); + + /* Setup the fluid shader */ + fluid_shader.calorific_capacity = fluid_get_calorific_capacity; + fluid_shader.volumic_mass = fluid_get_volumic_mass; + fluid_shader.temperature = fluid_get_temperature; + + /* create fluid for each hc boundary */ + for (i=0; i<stardis->geometry.boundary_count; ++i){ + if (stardis->boundary[i].hc > -1) { + + SDIS(data_create(dev, sizeof(struct fluid), ALIGNOF(struct fluid), NULL, &data)); + fluid_props = sdis_data_get(data); /* Fetch the allocated memory space */ + fluid_props->cp = 0; + fluid_props->rho = 0; + fluid_props->temperature = stardis->boundary[i].T; + SDIS(fluid_create(dev, &fluid_shader, data, sa_add(fluid_medium, 1))); + SDIS(data_ref_put(data)); + + sa_push(bound2fluid, sa_size(fluid_medium)-1); + } else { + sa_push(bound2fluid, 0); + } + } + + /* Setup the solid shader */ + solid_shader.calorific_capacity = solid_get_calorific_capacity; + solid_shader.thermal_conductivity = solid_get_thermal_conductivity; + solid_shader.volumic_mass = solid_get_volumic_mass; + solid_shader.delta_solid = solid_get_delta; + solid_shader.delta_boundary = solid_get_delta_boundary; + solid_shader.temperature = solid_get_temperature; + + /* Create the solid medium */ + for (i=0; i<stardis->geometry.medium_count; ++i){ + /* Create and setup the solid physical properties */ + SDIS(data_create(dev, sizeof(struct solid), ALIGNOF(struct solid), NULL, &data)); + solid_props = sdis_data_get(data); /* Fetch the allocated memory space */ + solid_props->cp = stardis->material[i].cp; + solid_props->lambda = stardis->material[i].lambda; + solid_props->rho = stardis->material[i].rho; + solid_props->delta = stardis->material[i].delta; + solid_props->temperature = stardis->material[i].Tinit; + SDIS(solid_create(dev, &solid_shader, data, sa_add(solid_medium, 1))); + SDIS(data_ref_put(data)); + } + + /* Setup the interface shader */ + interface_shader_boundary.convection_coef = interface_get_convection_coef; + interface_shader_boundary.temperature = interface_get_temperature; + interface_shader_boundary.emissivity = interface_get_epsilon; + interface_shader_boundary.specular_fraction = interface_get_alpha; + + for (i=0; i<sa_size(stardis->geometry.triangle); ++i){ + int bound_id = stardis->geometry.triangle[i].bound_id; + + if (bound_id > -1){ /* boundary interface */ + double hc = stardis->boundary[bound_id].hc; + double T = stardis->boundary[bound_id].T; + + SDIS(data_create(dev, sizeof(struct interface), ALIGNOF(struct interface), NULL, &data)); + interface_props = sdis_data_get(data); + if (hc > -1) { + interface_props->hc = hc; + interface_props->temperature = -1; + } else { + interface_props->temperature = T; + } + interface_props->epsilon = 0; + interface_props->alpha = 0; + SDIS(interface_create(dev, + solid_medium[stardis->geometry.triangle[i].medium_front], + fluid_medium[bound2fluid[bound_id]], + &interface_shader_boundary, data, sa_add(interfaces,1))); + SDIS(data_ref_put(data)); + + } else { /* solid/solid interface */ + SDIS(interface_create(dev, + solid_medium[stardis->geometry.triangle[i].medium_front], + solid_medium[stardis->geometry.triangle[i].medium_back], + &interface_shader_connection, NULL, sa_add(interfaces,1))); + } + } + stardis->geometry.interfaces = interfaces; + + SDIS(scene_create(dev, + sa_size(stardis->geometry.triangle), + geometry_get_indices, geometry_get_interface, + sa_size(stardis->geometry.vertex), + geometry_get_position, &stardis->geometry, &scn)); + + /* Launch the probe simulation */ + pos[0] = stardis->probe[0]; + pos[1] = stardis->probe[1]; + pos[2] = stardis->probe[2]; + time = stardis->probe[3]; + SDIS(solve_probe(scn, stardis->N, pos, time, 1.0, 300.0, 300.0, &estimator)); + + /* Fetch the estimation data */ + SDIS(estimator_get_temperature(estimator, &temperature)); + SDIS(estimator_get_failure_count(estimator, &nfailures)); + + /* Print the results */ + /*ref = T0 + probe_pos[2]/2.*(T1 - T0);*/ + printf("Temperature at [%g, %g, %g, %g] = %g +/- %g\n", + pos[0], pos[1], pos[2], time, + temperature.E, /* Expected value */ + temperature.SE); /* Standard error */ + printf("#failures: %lu/%lu\n", + (unsigned long)nfailures, + (unsigned long)stardis->N); + + +exit: + for (i=0; i<sa_size(solid_medium); ++i){ + SDIS(medium_ref_put(solid_medium[i])); + } + sa_release(solid_medium); + + for (i=0; i<sa_size(fluid_medium); ++i){ + SDIS(medium_ref_put(fluid_medium[i])); + } + sa_release(fluid_medium); + + for (i=0; i<sa_size(interfaces); ++i){ + SDIS(interface_ref_put(interfaces[i])); + } + sa_release(interfaces); + + sa_release(bound2fluid); + + SDIS(estimator_ref_get(estimator)); + SDIS(scene_ref_put(scn)); + SDIS(device_ref_put(dev)); + return res; +error: + goto exit; +} +