stardis

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

commit fa71d0c640e9a96196309f3ac415dea570c61e28
parent bb6c91fb28583a939f5eb873a7b7edd3dbbdd578
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date:   Sun, 22 Apr 2018 22:55:03 +0200

ajout de la lib tinyexpr pour le support des expressions formelles

Diffstat:
Msrc/Makefile | 2+-
Msrc/bc.txt | 8++++----
Msrc/material.txt | 8++++----
Msrc/stardis-app.c | 59++++++++++++++++++++++++-----------------------------------
Msrc/stardis-app.h | 8++++----
Msrc/stardis-compute.c | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
6 files changed, 96 insertions(+), 56 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -11,7 +11,7 @@ all: stardis-app stardis-app: $(SRC) $(DEPS) $(CC) -o stardis-app $(SRC) $(INC) $(LDFLAGS) -debug: main.c +debug: $(SRC) $(DEPS) $(CC) -g -o stardis-app-dbg $(SRC) $(INC) $(LDFLAGS) clean: diff --git a/src/bc.txt b/src/bc.txt @@ -1,4 +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 +#STL_filename h h_coeff T_env(x,y,z,t) | STL_filename T T_value(x,y,z,t) +b_h_1.stl h 0 "300" +b_T_1.stl T "300 + sin(2*pi*t)" +b_T_2.stl T "300 + sin(2*pi*t)" diff --git a/src/material.txt b/src/material.txt @@ -1,4 +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 +#STL_filename lambda rho cp delta Tinit(x,y,z) +m_1.stl 1.0 1.0 1.0 0.05 "300 + x" +m_2.stl 1.0 1.0 1.0 0.05 "300 - 2*y + z " +m_3.stl 1.0 1.0 1.0 0.05 "300 + 10*x" diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -2,6 +2,8 @@ #include <string.h> #include "stardis-app.h" +#include <tinyexpr.h> + #define MEDIUM 0 #define BOUNDARY 1 @@ -65,12 +67,10 @@ parse_medium_line(char* line, char** stl_filename, struct material* mat) 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; - } + tk = strtok(NULL,"\""); + tk = strtok(NULL,"\""); + mat->Tinit = malloc(strlen(tk) + 1); + strcpy(mat->Tinit,tk); exit: return res; @@ -81,11 +81,7 @@ error: 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," "); @@ -94,37 +90,30 @@ parse_boundary_line(char* line, char** stl_filename, struct boundary* bound) tk = strtok(NULL," "); if (strcmp(tk,"h")==0 || strcmp(tk,"H")==0 ){ - bc_type = H_TYPE; + tk = strtok(NULL," "); + res = cstr_to_double(tk, &bound->hc); + if (res != RES_OK ) { + fprintf(stderr,"invalid value parameter: %g \n", bound->hc); + goto error; + } + + tk = strtok(NULL,"\""); + tk = strtok(NULL,"\""); + bound->T = malloc(strlen(tk) + 1); + strcpy(bound->T,tk); + } else if (strcmp(tk,"t")==0 || strcmp(tk,"T")==0 ){ - bc_type = T_TYPE; + + tk = strtok(NULL,"\""); + tk = strtok(NULL,"\""); + bound->T = malloc(strlen(tk) + 1); + strcpy(bound->T,tk); + } 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: diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -93,16 +93,16 @@ struct material{ double rho; double cp; double delta; - double Tinit; + char* Tinit; }; -#define NULL_MATERIAL__ {0.0 ,0.0 ,0.0, 0.0, 0.0} +#define NULL_MATERIAL__ {0.0 ,0.0 ,0.0, 0.0, NULL} static const struct material NULL_MATERIAL = NULL_MATERIAL__; struct boundary{ double hc; - double T; + char* T; }; -#define NULL_BOUNDARY__ {-1, -1} +#define NULL_BOUNDARY__ {-1, NULL} static const struct boundary NULL_BOUNDARY = NULL_BOUNDARY__; struct stardis{ diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -2,6 +2,7 @@ #include "stardis-app.h" #include <sdis.h> +#include <tinyexpr.h> static void geometry_get_position @@ -43,7 +44,7 @@ geometry_get_interface struct fluid { double cp; /* Calorific capacity */ double rho; /* Volumic mass */ - double temperature; /* < 0 means for unknown temperature */ + char* temperature; }; static double @@ -67,7 +68,22 @@ 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; + double temperature = 0; + char* math_expr = fluid_props->temperature; + double x, y, z, t; + /* Store variable names and pointers. */ + te_variable vars[] = {{"x", &x}, {"y", &y}, {"z", &z}, {"t", &t}}; + int err; + + /* Compile the expression with variables. */ + te_expr *expr = te_compile(math_expr, vars, 4, &err); + x = vtx->P[0]; + y = vtx->P[1]; + z = vtx->P[2]; + t = vtx->time; + temperature = te_eval(expr); + te_free(expr); + return temperature; } /******************************************************************************* @@ -78,7 +94,7 @@ struct solid { double lambda; /* Conductivity */ double rho; /* Volumic mass */ double delta; /* Numerical parameter */ - double temperature; /* < 0 means for unknown temperature */ + char* temperature; }; static double @@ -128,11 +144,25 @@ static double solid_get_temperature (const struct sdis_rwalk_vertex* vtx, struct sdis_data* data) { + double temperature = 0; const struct solid* solid_props = sdis_data_cget(data); if (vtx->time > 0){ return -1; }else{ - return solid_props->temperature; + char* math_expr = solid_props->temperature; + double x, y, z; + /* Store variable names and pointers. */ + te_variable vars[] = {{"x", &x}, {"y", &y}, {"z", &z}}; + int err; + + /* Compile the expression with variables. */ + te_expr *expr = te_compile(math_expr, vars, 3, &err); + x = vtx->P[0]; + y = vtx->P[1]; + z = vtx->P[2]; + temperature = te_eval(expr); + te_free(expr); + return temperature; } } @@ -141,7 +171,7 @@ solid_get_temperature ******************************************************************************/ struct interface { double hc; /* Convection coefficient */ - double temperature; /* < 0 means for unknown temperature */ + char* temperature; double epsilon; double alpha; }; @@ -159,7 +189,28 @@ 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; + + if (interface_props->temperature == NULL) { + return -1; + } else { + + double temperature = 0; + char* math_expr = interface_props->temperature; + double x, y, z, t; + /* Store variable names and pointers. */ + te_variable vars[] = {{"x", &x}, {"y", &y}, {"z", &z}, {"t", &t}}; + int err; + + /* Compile the expression with variables. */ + te_expr *expr = te_compile(math_expr, vars, 4, &err); + x = frag->P[0]; + y = frag->P[1]; + z = frag->P[2]; + t = frag->time; + temperature = te_eval(expr); + te_free(expr); + return temperature; + } } static double @@ -269,13 +320,13 @@ stardis_compute(struct stardis* stardis) if (bound_id > -1){ /* boundary interface */ double hc = stardis->boundary[bound_id].hc; - double T = stardis->boundary[bound_id].T; + char* 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; + interface_props->temperature = NULL; } else { interface_props->temperature = T; }