stardis

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

commit a864494d1164daedc31b98eac59569223ea5aee5
parent 8a08629b9346131c75ea47d06f101c4351f03be4
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 16 Jan 2019 17:13:26 +0100

Linux build

Diffstat:
Mcmake/CMakeLists.txt | 29+++++++++++++++--------------
Msrc/args.h | 2+-
Msrc/stardis-app.c | 51+++++++++++++++++++++++++++++----------------------
Msrc/stardis-app.h | 34++++++++++++++++++----------------
Msrc/stardis-compute.c | 25+++++++++++++------------
5 files changed, 76 insertions(+), 65 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -68,10 +68,6 @@ rcmake_prepend_path(SDIS_FILES_SRC ${SDIS_SOURCE_DIR}) rcmake_prepend_path(SDIS_FILES_INC ${SDIS_SOURCE_DIR}) rcmake_prepend_path(SDIS_FILES_DOC ${PROJECT_SOURCE_DIR}/../) -if(CMAKE_COMPILER_IS_GNUCC) - set(MATH_LIB m) -endif() - # Default is right to left pow and log is natural log # Build tinyExpr without closure support and with function_1 to function_3 support only # (these ones cannot be disabled as predefined functions require them). @@ -80,9 +76,13 @@ set(TE_DEFAULTS ADD_LIBRARY(tinyexpr STATIC ${TINYEXPR_SOURCE_DIR}/tinyexpr.c ${TINYEXPR_SOURCE_DIR}/tinyexpr.h) -set_target_properties(tinyexpr PROPERTIES COMPILE_FLAGS ${TE_DEFAULTS}) + if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(tinyexpr PROPERTIES COMPILE_FLAGS "-std=c99") + set_target_properties(tinyexpr PROPERTIES + COMPILE_FLAGS "-std=c99 ${TE_DEFAULTS}") +elseif(MSVC) + set_target_properties(tinyexpr PROPERTIES + COMPILE_FLAGS ${TE_DEFAULTS}) endif() add_executable(sdis-app @@ -90,16 +90,17 @@ add_executable(sdis-app ${SDIS_FILES_INC}) if(CMAKE_COMPILER_IS_GNUCC) - set_target_properties(sdis-app PROPERTIES COMPILE_FLAGS "-std=c99") -endif() -target_link_libraries(sdis-app Stardis StarSTL RSys tinyexpr ${MATH_LIB}) -if(MSVC) - target_link_libraries(sdis-app MuslGetopt) + set_target_properties(sdis-app PROPERTIES + COMPILE_FLAGS "-std=c99 ${TE_DEFAULTS}" + VERSION ${VERSION}) + target_link_libraries(sdis-app Stardis StarSTL RSys tinyexpr m) +elseif(MSVC) + set_target_properties(sdis-app PROPERTIES + COMPILE_FLAGS "${TE_DEFAULTS}" + VERSION ${VERSION}) + target_link_libraries(sdis-app Stardis StarSTL RSys tinyexpr MuslGetopt) endif() -set_target_properties(sdis-app PROPERTIES - COMPILE_FLAGS ${TE_DEFAULTS} - VERSION ${VERSION}) rcmake_copy_runtime_libraries(sdis-app) ################################################################################ diff --git a/src/args.h b/src/args.h @@ -86,7 +86,7 @@ print_help(char* prog) } -static inline res_T +static INLINE res_T parse_args(const int argc, char** argv, struct args* args) { int opt = 0; diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -2,6 +2,7 @@ #define _GNU_SOURCE 1 #include <string.h> +#include <ctype.h> #include "stardis-app.h" @@ -16,7 +17,7 @@ /******************************************************************************* * ******************************************************************************/ -static inline char* +static INLINE char* read_line(char** pb, FILE* stream) { const int chunk_sz = 32; @@ -103,8 +104,12 @@ static char** split_line(char* a_str, const char a_delim) static char* _strupr(char* s) { - char* tmp; - for (tmp = s; *tmp; ++tmp) *tmp = toupper((unsigned char)*tmp); + char* ptr; + for (ptr = s; *ptr; ++ptr) { + int tmp = toupper(*ptr); + ASSERT(tmp == (char)tmp); + *ptr = (char)tmp; + } return s; } #endif @@ -477,21 +482,21 @@ read_vertices } static int -indices_to_key(unsigned3 key, const unsigned3 indices) +indices_to_key(struct unsigned3* key, const struct unsigned3* indices) { int i, reversed = 0; - FOR_EACH(i, 0, 3) key[i] = indices[i]; - if (key[0] > key[1]) { + FOR_EACH(i, 0, 3) key->data[i] = indices->data[i]; + if (key->data[0] > key->data[1]) { reversed = !reversed; - SWAP(unsigned, key[0], key[1]); + SWAP(unsigned, key->data[0], key->data[1]); } - if (key[1] > key[2]) { + if (key->data[1] > key->data[2]) { reversed = !reversed; - SWAP(unsigned, key[1], key[2]); + SWAP(unsigned, key->data[1], key->data[2]); } - if (key[0] > key[1]) { + if (key->data[0] > key->data[1]) { reversed = !reversed; - SWAP(unsigned, key[0], key[1]); + SWAP(unsigned, key->data[0], key->data[1]); } return reversed; } @@ -511,15 +516,15 @@ read_triangles struct triangle tri = NULL_TRIANGLE; const unsigned *found_id = NULL; unsigned id; - unsigned3 key; + struct unsigned3 key; int reversed; enum sdis_side current_side = SDIS_FRONT; unsigned* side_desc_ptr = NULL; - tri.indices[0] = id2id[stl_desc->indices[3*tri_index + 0]]; - tri.indices[1] = id2id[stl_desc->indices[3*tri_index + 1]]; - tri.indices[2] = id2id[stl_desc->indices[3*tri_index + 2]]; - reversed = indices_to_key(key, tri.indices); + tri.indices.data[0] = id2id[stl_desc->indices[3*tri_index + 0]]; + tri.indices.data[1] = id2id[stl_desc->indices[3*tri_index + 1]]; + tri.indices.data[2] = id2id[stl_desc->indices[3*tri_index + 2]]; + reversed = indices_to_key(&key, &tri.indices); /* Find triangle if already known, or insert it in known list */ found_id = htable_triangle_find(triangle2id, &key); @@ -528,7 +533,7 @@ read_triangles int original_reversed; id = *found_id; original_tri = (*tri_list) + id; - original_reversed = indices_to_key(key, original_tri->indices); + original_reversed = indices_to_key(&key, &original_tri->indices); current_side = (reversed == original_reversed) ? SDIS_FRONT : SDIS_BACK; ASSERT(id < sa_size(*tri_list)); } else { @@ -566,7 +571,7 @@ static res_T read_stl (const unsigned desc_id, const int is_connection, - const char** stl_filename, + char* const* stl_filename, struct htable_vertex* vertex2id, struct htable_triangle* triangle2id, struct stardis* stardis) @@ -640,8 +645,9 @@ geometry_analyse /* loop on media */ while (read_line(&line, input)){ char* stl_filename = NULL; - struct description desc = NULL_DESCRIPTION__; - + struct description desc; + + desc.type = DESCRIPTION_TYPE_COUNT__; res = parse_medium_line(line, &stl_filename, &desc); if (res != RES_OK) goto error; @@ -676,8 +682,9 @@ geometry_analyse /* loop on boundaries */ while (read_line(&line, input)){ char* stl_filename = NULL; - struct description desc = NULL_DESCRIPTION__; + struct description desc; + desc.type = DESCRIPTION_TYPE_COUNT__; res = parse_boundary_line(line, &stl_filename, &desc); if (res != RES_OK) goto error; @@ -860,7 +867,7 @@ dump_vtk } fprintf(output,"\nPOLYGONS %i %i\n", (int)sa_size(tri), (int)(4*sa_size(tri))); for (i=0; i<sa_size(tri); ++i){ - fprintf(output,"3 %i %i %i\n",SPLIT3(tri[i].indices)); + fprintf(output,"3 %i %i %i\n",SPLIT3(tri[i].indices.data)); } fprintf(output,"\nCELL_DATA %i \n", (int)sa_size(tri)); fprintf(output,"SCALARS front_description float 1\n"); diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -40,7 +40,7 @@ struct vertex{ #define NULL_VERTEX__ {{0.0 ,0.0 ,0.0}} static const struct vertex NULL_VERTEX = NULL_VERTEX__; -static inline char +static INLINE char eq_vertex(const struct vertex* a, const struct vertex* b) { return (char)f3_eq(a->xyz, b->xyz); @@ -53,34 +53,36 @@ eq_vertex(const struct vertex* a, const struct vertex* b) #define HTABLE_KEY_FUNCTOR_EQ eq_vertex #include <rsys/hash_table.h> -typedef unsigned unsigned3[3]; +struct unsigned3 { unsigned data[3]; }; struct triangle { - unsigned3 indices; + struct unsigned3 indices; unsigned front_description; unsigned back_description; unsigned connection_description; }; -#define NULL_TRIANGLE__ {{0, 0, 0}, UINT_MAX, UINT_MAX, UINT_MAX } +#define NULL_TRIANGLE__ {{{0, 0, 0}}, UINT_MAX, UINT_MAX, UINT_MAX } static const struct triangle NULL_TRIANGLE = NULL_TRIANGLE__; -static char -eq_indices(const unsigned3* a, const unsigned3* b) +static INLINE char +eq_indices(const struct unsigned3* a, const struct unsigned3* b) { - return (*a)[0] == (*b)[0] && (*a)[1] == (*b)[1] && (*a)[2] == (*b)[2]; + return a->data[0] == b->data[0] + && a->data[1] == b->data[1] + && a->data[2] == b->data[2]; } -static res_T -cp_indices(unsigned3* dst, const unsigned3* src) +static INLINE res_T +cp_indices(struct unsigned3* dst, const struct unsigned3* src) { int i; - FOR_EACH(i, 0, 3) (*dst)[i] = (*src)[i]; + FOR_EACH(i, 0, 3) dst->data[i] = src->data[i]; return RES_OK; } /* Declare the hash table that maps a triangle id to its index */ #define HTABLE_NAME triangle #define HTABLE_DATA unsigned -#define HTABLE_KEY unsigned3 +#define HTABLE_KEY struct unsigned3 #define HTABLE_KEY_FUNCTOR_EQ eq_indices #define HTABLE_KEY_FUNCTOR_COPY cp_indices #include <rsys/hash_table.h> @@ -94,7 +96,7 @@ struct geometry { #define NULL_GEOMETRY__ {NULL, NULL, NULL, NULL } static const struct geometry NULL_GEOMETRY = NULL_GEOMETRY__; -static inline void +static INLINE void release_geometry(struct geometry* geom) { size_t i; @@ -709,9 +711,8 @@ struct description { struct solid_fluid_connect sf_connect; } d; }; -#define NULL_DESCRIPTION__ {DESCRIPTION_TYPE_COUNT__ }; -static char +static INLINE char eq_description(const struct description* a, const struct description* b) { if (a->type != b->type) return 0; @@ -734,7 +735,7 @@ eq_description(const struct description* a, const struct description* b) } } -static size_t +static INLINE size_t hash_description(const struct description* key) { switch (key->type) { @@ -779,7 +780,8 @@ struct stardis { struct camera camera; struct mem_allocator allocator; }; -#define NULL_STARDIS__ {NULL_GEOMETRY__, NULL, 0, 0, {0,0,0,0}, 0, {300,300}, NULL_CAMERA__} +#define NULL_ALLOCATOR__ {NULL} +#define NULL_STARDIS__ {NULL_GEOMETRY__, NULL, 0, 0, {0,0,0,0}, 0, {300,300}, NULL_CAMERA__, NULL_ALLOCATOR__} static const struct stardis NULL_STARDIS = NULL_STARDIS__; extern res_T diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -26,9 +26,9 @@ geometry_get_indices 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]; + ids[0] = geom->triangle[itri].indices.data[0]; + ids[1] = geom->triangle[itri].indices.data[1]; + ids[2] = geom->triangle[itri].indices.data[2]; } static void @@ -113,7 +113,8 @@ fluid_get_tinit return te_eval(fluid_props->temperature, vtx); } -void release_fluid_data(void* f) +static void +release_fluid_data(void* f) { struct fluid* fluid = (struct fluid*)f; te_free(fluid->temperature); @@ -217,7 +218,8 @@ solid_get_power return te_eval(solid_props->power, vtx); } -void release_solid_data(void* s) +static void +release_solid_data(void* s) { struct solid* solid = (struct solid*)s; te_free(solid->t_init); @@ -269,7 +271,8 @@ interface_get_flux return te_eval(interface_props->flux, frag); } -void release_interface_data(void* s) +static void +release_interface_data(void* s) { struct intface* intface = (struct intface*)s; te_free(intface->temperature); @@ -285,7 +288,7 @@ interface_get_emissivity return interface_props->emissivity; } -static double +static INLINE double interface_get_alpha (const struct sdis_interface_fragment* frag, struct sdis_data* data) { @@ -376,12 +379,12 @@ dump_image(const struct sdis_accum_buffer* buf) ******************************************************************************/ struct int_descs { - unsigned front, back, connect; unsigned id; + unsigned front, back, connect; }; -#define INT_DESCS_NULL__ { UINT_MAX, UINT_MAX, UINT_MAX }; +#define INT_DESCS_NULL__ { UINT_MAX, UINT_MAX, UINT_MAX } static const struct int_descs INT_DESCS_NULL = INT_DESCS_NULL__; -static inline char +static INLINE char eq_desc(const struct int_descs* a, const struct int_descs* b) { return (char)(a->front == b->front && a->back == b->back @@ -550,7 +553,6 @@ stardis_compute(struct stardis* stardis, enum stardis_mode mode) struct htable_intface htable_interfaces; int htable_interfaces_initialised = 0; - unsigned int_cpt = 0; double pos[3] = {0,0,0}; double time[2] = { 0, 0}; size_t nfailures; @@ -676,7 +678,6 @@ stardis_compute(struct stardis* stardis, enum stardis_mode mode) int front_defined = (fd != UINT_MAX); int back_defined = (bd != UINT_MAX); int connect_defined = (cd != UINT_MAX); - int_descs.id = int_cpt++; SDIS(data_create(dev, sizeof(struct intface), ALIGNOF(struct intface), release_interface_data, &data));