stardis

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

commit 88a4ed8616e2132175c1632fd2bb3e55c04d66c1
parent 961fdadf2fdef288f450c3f357156b8058185850
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Thu, 18 Jul 2019 17:55:03 +0200

Add compute temperature maps on 2D shapes feature

Diffstat:
Msrc/main.c | 4+---
Msrc/stardis-app.c | 19++++++++-----------
Msrc/stardis-app.h | 10+++++++---
Msrc/stardis-compute.c | 92++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
Msrc/stardis-compute.h | 3+--
Msrc/stardis-fluid.c | 2++
Msrc/stardis-intface.c | 14++++++--------
Msrc/stardis-output.c | 163++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Msrc/stardis-output.h | 14++++++++------
Msrc/stardis-parsing.c | 90+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/stardis-parsing.h | 7++-----
Msrc/stardis-solid.c | 5+++--
12 files changed, 276 insertions(+), 147 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -42,9 +42,7 @@ main if (res != RES_OK) goto error; if (args.mode & DUMP_VTK) { - res = dump_vtk(stdout, &stardis.geometry); - if (res != RES_OK) goto error; - goto exit; + dump_vtk(&stardis.geometry); } else if (args.mode & COMPUTE_MODES) { res = stardis_compute(&stardis, args.mode); diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -11,9 +11,7 @@ #define HTABLE_KEY_FUNCTOR_HASH hash_description #include <rsys/hash_table.h> -#define _GNU_SOURCE 1 #include <string.h> -#include <ctype.h> /******************************************************************************* * Local Functions @@ -239,8 +237,7 @@ read_triangles stl_desc->indices = packed_indices; stl_desc->normals = packed_normals; stl_desc->triangles_count = sa_size(stl_desc->indices) / 3; - } - else { + } else { sa_release(packed_indices); sa_release(packed_normals); packed_indices = NULL; @@ -272,13 +269,13 @@ read_stl ASSERT(stl_filename && vertex2id && triangle2id && stardis); - if (!stl_filename) return RES_BAD_ARG; - - SSTL(create(NULL, &stardis->allocator, 0, &sstl)); + res = sstl_create(NULL, &stardis->allocator, 0, &sstl); + if (res != RES_OK) goto error; res = sstl_load(sstl, stl_filename); if (res != RES_OK) { - fprintf(stderr, "Cannot read STL file: %s\n", stl_filename); + if (res == RES_IO_ERR) + fprintf(stderr, "Cannot read STL file: %s\n", stl_filename); goto error; } SSTL(get_desc(sstl, &stl_desc)); @@ -406,7 +403,7 @@ geometry_analyse fclose(input); input = NULL; - /* Process vtk file describing boundary compute */ + /* Process STL file describing boundary compute */ if (bound_filename) { res = read_stl(0, CONTENT_BOUNDARY, bound_filename, &vertex2id, &triangle2id, stardis); @@ -470,7 +467,7 @@ stardis_init else if (args->mode & MEDIUM_COMPUTE) { strcpy(stardis->solve_name, args->medium_name); } - else if (args->mode & BOUNDARY_COMPUTE) { + else if (args->mode & (BOUNDARY_COMPUTE | MAP_COMPUTE)) { strcpy(stardis->solve_name, args->solve_boundary_filename); } @@ -534,7 +531,7 @@ stardis_release(struct stardis* stardis) char dump[4096] = { '\0' }; MEM_DUMP(&stardis->allocator, dump, sizeof(dump)); fprintf(stderr, "%s\n", dump); - fprintf(stderr, "Memory leaks: %lu Bytes\n", (unsigned long)memsz); + fprintf(stderr, "Memory leaks: %zu Bytes\n", memsz); } if (stardis->allocator_initialized) { mem_shutdown_proxy_allocator(&stardis->allocator); diff --git a/src/stardis-app.h b/src/stardis-app.h @@ -13,6 +13,8 @@ #include <sdis.h> #include <tinyexpr.h> +#include <limits.h> + #define FREE_AARRAY(ARRAY) if (ARRAY) {\ int i = 0; \ for (i=0; *(ARRAY+i);i++){\ @@ -746,16 +748,18 @@ enum content_type { CONTENT_TYPES_COUNT }; - extern res_T stardis_init (const struct args* args, struct stardis* stardis); extern res_T -stardis_compute(struct stardis* stardis, enum stardis_mode mode); +stardis_compute + (struct stardis* stardis, + const int mode); extern void -stardis_release(struct stardis* stardis); +stardis_release + (struct stardis* stardis); #endif /*STARDIS-APP_H*/ diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -226,8 +226,7 @@ create_holder if (dummies->dummy_fluid) { /* Reuse external dummy fluid */ description->d.t_boundary.mat_id = dummies->dummy_fluid_id; - } - else { + } else { /* Create dummy fluid */ res = create_fluid(dev, NULL, 1, 1, is_green, 1, NULL, NULL, media, &description->d.t_boundary.mat_id); @@ -249,8 +248,7 @@ create_holder if (dummies->dummy_solid) { /* Reuse external dummy solid */ description->d.t_boundary.mat_id = dummies->dummy_solid_id; - } - else { + } else { /* Create dummy solid */ res = create_solid(dev, NULL, 1, 1, 1, 1, is_green, 1, NULL, NULL, NULL, media, NULL, &description->d.t_boundary.mat_id); @@ -272,8 +270,7 @@ create_holder if (dummies->dummy_fluid) { /* Reuse external dummy fluid */ description->d.f_boundary.mat_id = dummies->dummy_fluid_id; - } - else { + } else { /* Create dummy fluid */ res = create_fluid(dev, NULL, 1, 1, is_green, 1, NULL, NULL, media, &description->d.f_boundary.mat_id); @@ -392,7 +389,7 @@ compute_probe_on_interface (struct sdis_scene* scn, const struct counts* counts, struct stardis* stardis, - enum stardis_mode mode) + const int mode) { res_T res = RES_OK; double time[2], pos[3], uv[2] = { 0,0 }; @@ -451,7 +448,7 @@ compute_camera (struct sdis_device* dev, struct sdis_scene* scn, const struct stardis* stardis, - const enum stardis_mode mode) + const int mode) { res_T res = RES_OK; double time[2]; @@ -509,7 +506,7 @@ compute_medium (struct sdis_scene* scn, struct sdis_medium** media, struct stardis* stardis, - enum stardis_mode mode) + const int mode) { res_T res = RES_OK; double time[2]; @@ -584,7 +581,7 @@ compute_boundary (struct sdis_scene* scn, const struct counts* counts, struct stardis* stardis, - enum stardis_mode mode) + const int mode) { res_T res = RES_OK; double time[2], pos[3]; @@ -604,7 +601,6 @@ compute_boundary d3_set(pos, stardis->probe); if (mode & GREEN_MODE) { - ASSERT(iprim == SIZE_MAX); res = sdis_solve_boundary_green_function(scn, stardis->N, stardis->boundary.primitives, @@ -619,7 +615,6 @@ compute_boundary stardis->radiative_temp); if (res != RES_OK) goto error; } else { - ASSERT(iprim == SIZE_MAX); d2_splat(time, stardis->probe[3]); res = sdis_solve_boundary(scn, stardis->N, @@ -644,6 +639,64 @@ error: goto end; } +static res_T +compute_map + (struct sdis_scene* scn, + struct stardis* stardis, + const int mode) +{ + res_T res = RES_OK; + double time[2], pos[3]; + struct sdis_green_function* green = NULL; + struct sdis_estimator** estimators = NULL; + size_t p; + + ASSERT(scn && stardis && (mode & MAP_COMPUTE) + && !(mode & GREEN_MODE)); + (void)mode; + + /* FIXME: MOVE TO BOUNDARY SETTING */ + ASSERT(sa_size(stardis->boundary.primitives) + == sa_size(stardis->boundary.sides)); + if (sa_size(stardis->boundary.sides) == 0) { + fprintf(stderr, "Cannot solve boundary %s (empty geometry)\n", + stardis->solve_name); + } + + d3_set(pos, stardis->probe); + d2_splat(time, stardis->probe[3]); + + sa_add(estimators, sa_size(stardis->boundary.sides)); + + FOR_EACH(p, 0, sa_size(stardis->boundary.sides)) { + res = sdis_solve_boundary(scn, + stardis->N, + stardis->boundary.primitives + p, + stardis->boundary.sides + p, + 1, + time, + stardis->scale_factor, + stardis->radiative_temp[0], + stardis->radiative_temp[1], + stardis->dump_paths, + estimators + p); + if (res != RES_OK) goto error; + } + dump_map(stardis, estimators); + +end: + if (estimators) { + FOR_EACH(p, 0, sa_size(stardis->boundary.sides)) { + SDIS(estimator_ref_put(estimators[p])); + } + sa_release(estimators); + } + if (green) SDIS(green_function_ref_put(green)); + return res; +error: + goto end; +} + /******************************************************************************* * Public Functions ******************************************************************************/ @@ -692,7 +745,7 @@ compile_expr_to_fn res_T stardis_compute (struct stardis* stardis, - enum stardis_mode mode) + const int mode) { res_T res = RES_OK; struct sdis_device* dev = NULL; @@ -703,10 +756,17 @@ stardis_compute int htable_interfaces_initialised = 0; struct counts counts = COUNTS_NULL; unsigned i = 0; + int verbose; + + ASSERT(stardis && (mode & COMPUTE_MODES)); - ASSERT(stardis); +#ifdef NDEBUG + verbose = 0; +#else + verbose = 1; +#endif - res = sdis_device_create(NULL, &stardis->allocator, stardis->nthreads, 1, &dev); + res = sdis_device_create(NULL, &stardis->allocator, stardis->nthreads, verbose, &dev); if (res != RES_OK) goto error; /* Create media and property holders found in descriptions */ @@ -748,6 +808,8 @@ stardis_compute res = compute_medium(scn, media, stardis, mode); else if (mode & BOUNDARY_COMPUTE) res = compute_boundary(scn, &counts, stardis, mode); + else if (mode & MAP_COMPUTE) + res = compute_map(scn, stardis, mode); else FATAL("Unknown mode.\n"); if (res != RES_OK) goto error; diff --git a/src/stardis-compute.h b/src/stardis-compute.h @@ -13,7 +13,6 @@ struct te_expr; struct stardis; -enum stardis_mode; struct counts { size_t smed_count, fmed_count, tbound_count, hbound_count, @@ -42,6 +41,6 @@ compile_expr_to_fn extern res_T stardis_compute (struct stardis* stardis, - enum stardis_mode mode); + const int mode); #endif \ No newline at end of file diff --git a/src/stardis-fluid.c b/src/stardis-fluid.c @@ -5,6 +5,8 @@ #include <tinyexpr.h> #include<rsys/stretchy_array.h> +#include <limits.h> + /******************************************************************************* * Local Functions ******************************************************************************/ diff --git a/src/stardis-intface.c b/src/stardis-intface.c @@ -117,8 +117,7 @@ create_intface p_intface = htable_intface_find(htable_interfaces, &int_descs); if (p_intface) { intface = *p_intface; - } - else { + } else { /* create new interface and register */ struct sdis_interface_shader interface_shader = SDIS_INTERFACE_SHADER_NULL; struct intface* interface_props = NULL; @@ -180,8 +179,7 @@ create_intface res = RES_BAD_ARG; goto error; } - } - else { + } else { if (front_defined == back_defined) { fprintf(stderr, "Cannot define a boundary between 2 %s regions\n", @@ -228,6 +226,7 @@ create_intface fluid_side_shader = front_defined ? &interface_shader.back : &interface_shader.front; fluid_side_shader->emissivity = interface_get_emissivity; + fluid_side_shader->specular_fraction = interface_get_alpha; interface_props->emissivity = connect->d.h_boundary.emissivity; interface_props->alpha = connect->d.h_boundary.specular_fraction; } @@ -259,8 +258,7 @@ create_intface /* We set the known T inside * TODO: should be outside to allow contact resistances */ interface_shader.front.temperature = interface_get_temperature; - } - else { + } else { front_med = media[ext_id]; /* We set the known T inside * TODO: should be outside to allow contact resistances */ @@ -288,8 +286,7 @@ create_intface if (front_defined) { back_med = media[connect->d.f_boundary.mat_id]; interface_shader.front.flux = interface_get_flux; - } - else { + } else { front_med = media[connect->d.f_boundary.mat_id]; interface_shader.back.flux = interface_get_flux; } @@ -309,6 +306,7 @@ create_intface } if (connect->d.sf_connect.has_emissivity) { fluid_side_shader->emissivity = interface_get_emissivity; + fluid_side_shader->specular_fraction = interface_get_alpha; interface_props->emissivity = connect->d.sf_connect.emissivity; interface_props->alpha = connect->d.sf_connect.specular_fraction; } diff --git a/src/stardis-output.c b/src/stardis-output.c @@ -102,7 +102,7 @@ get_flux_terms return res; } -res_T +static res_T dump_path (const struct sdis_heat_path* path, void* context) @@ -120,7 +120,7 @@ dump_path fprintf(stream, "DATASET POLYDATA\n"); /* Write path positions */ sdis_heat_path_get_vertices_count(path, &vcount); - fprintf(stream, "POINTS %lu double\n", (unsigned long)vcount); + fprintf(stream, "POINTS %zu double\n", vcount); FOR_EACH(i, 0, vcount) { struct sdis_heat_vertex vtx; res = sdis_heat_path_get_vertex(path, i, &vtx); @@ -128,11 +128,11 @@ dump_path fprintf(stream, "%g %g %g\n", SPLIT3(vtx.P)); } /* Write the segment of the path */ - fprintf(stream, "LINES %lu %lu\n", 1lu, (unsigned long)(1 + vcount)); - fprintf(stream, "%lu", (unsigned long)vcount); - FOR_EACH(i, 0, vcount) fprintf(stream, " %lu", (unsigned long)i); + fprintf(stream, "LINES %u %zu\n", 1u, 1 + vcount); + fprintf(stream, "%zu", vcount); + FOR_EACH(i, 0, vcount) fprintf(stream, " %zu", i); fprintf(stream, "\n"); - fprintf(stream, "POINT_DATA %lu\n", (unsigned long)vcount); + fprintf(stream, "POINT_DATA %zu\n", vcount); /* Write the type of the random walk vertices */ fprintf(stream, "SCALARS Vertex_Type float 1\n"); fprintf(stream, "LOOKUP_TABLE vertex_type\n"); @@ -170,7 +170,7 @@ dump_path fprintf(stream, "%g\n", IS_INF(vtx.time) ? FLT_MAX : vtx.time); } /* Write path type */ - fprintf(stream, "CELL_DATA %lu\n", 1lu); + fprintf(stream, "CELL_DATA %u\n", 1u); fprintf(stream, "SCALARS Path_Type float 1\n"); fprintf(stream, "LOOKUP_TABLE path_type\n"); res = sdis_heat_path_get_status(path, &status); @@ -264,9 +264,7 @@ print_sample printf("H\t%u", id); /* In a standard fluid with known temperature */ else printf("F\t%u", id); - - } - else { + } else { struct solid* d__ = sdis_data_get(data); ASSERT(type == SDIS_SOLID); id = d__->id; @@ -384,7 +382,7 @@ dump_image fprintf(stdout, "%f\n", time.SE); } } - fprintf(stdout, "SCALARS temperature_failures_count int 1\n"); + fprintf(stdout, "SCALARS temperature_failures_count unsigned_long_long 1\n"); fprintf(stdout, "LOOKUP_TABLE default\n"); FOR_EACH(iy, 0, definition[1]) { FOR_EACH(ix, 0, definition[0]) { @@ -577,8 +575,7 @@ create_edge_file_if p_rank = htable_vrtx_rank_find(&ranks, edge + v); if (p_rank) { rk[v] = *p_rank; - } - else { + } else { /* First appearance: allocate a rank and exit it */ unsigned rank; size_t tmp = htable_vrtx_rank_size_get(&ranks); @@ -601,8 +598,7 @@ create_edge_file_if unsigned w = 1 - v; /* The other vertex */ if (cc[rk[v]] == UINT_MAX) cc[rk[v]] = cc[rk[w]]; } - } - else { + } else { /* None are in a know component: create a new one */ cc[rk[0]] = cc[rk[1]] = cc_count++; } @@ -661,7 +657,7 @@ error: res_T print_single_MC_result - (const enum stardis_mode mode, + (const int mode, struct sdis_estimator* estimator, struct stardis* stardis) { @@ -700,13 +696,9 @@ print_single_MC_result break; default: FATAL("Invalid mode."); } - printf("#failures: %lu/%lu\n", - (unsigned long)nfailures, - (unsigned long)stardis->N); + printf("#failures: %zu/%zu\n", nfailures, stardis->N); if (nfailures) - fprintf(stderr, "#failures: %lu/%lu\n", - (unsigned long)nfailures, - (unsigned long)stardis->N); + fprintf(stderr, "#failures: %zu/%zu\n", nfailures, stardis->N); /* Dump paths according to user settings */ res = sdis_estimator_for_each_path(estimator, dump_path, stdout); @@ -717,48 +709,117 @@ error: goto end; } -/* TODO: rewrite dump! */ -res_T +void dump_vtk - (FILE* output, - const struct geometry* geometry) + (const struct geometry* geometry) { - res_T res = RES_OK; - unsigned i; - struct vertex* vtx = geometry->vertex; - struct triangle* tri = geometry->triangle; + size_t i; + struct vertex* vtx; + struct triangle* tri; - if (!output) { - fprintf(stderr, "Invalid output file to dump vtk.\n"); - res = RES_BAD_ARG; - goto error; - } + ASSERT(geometry); - fprintf(output, "# vtk DataFile Version 2.0\nvtk output\nASCII\nDATASET POLYDATA\n"); - fprintf(output, "POINTS %i float\n\n", (int)sa_size(vtx)); + vtx = geometry->vertex; + tri = geometry->triangle; + + printf("# vtk DataFile Version 2.0\nvtk output\nASCII\nDATASET POLYDATA\n"); + printf("POINTS %zu float\n\n", sa_size(vtx)); for (i = 0; i < sa_size(vtx); ++i) { - fprintf(output, "%f %f %f\n", SPLIT3(vtx[i].xyz)); + printf("%f %f %f\n", SPLIT3(vtx[i].xyz)); } - fprintf(output, "\nPOLYGONS %i %i\n", (int)sa_size(tri), (int)(4 * sa_size(tri))); + printf("\nPOLYGONS %zu %zu\n", sa_size(tri), 4 * sa_size(tri)); for (i = 0; i < sa_size(tri); ++i) { - fprintf(output, "3 %i %i %i\n", SPLIT3(tri[i].indices.data)); + printf("3 %u %u %u\n", SPLIT3(tri[i].indices.data)); } - fprintf(output, "\nCELL_DATA %i \n", (int)sa_size(tri)); - fprintf(output, "SCALARS front_description float 1\n"); - fprintf(output, "LOOKUP_TABLE default\n"); + printf("\nCELL_DATA %zu\n", sa_size(tri)); + printf("SCALARS front_description long_long_int 1\n"); + printf("LOOKUP_TABLE default\n"); for (i = 0; i < sa_size(tri); ++i) { - fprintf(output, "%i\n", tri[i].front_description); + printf("%lld\n", (long long int)tri[i].front_description); } - fprintf(output, "SCALARS back_description float 1\n"); - fprintf(output, "LOOKUP_TABLE default\n"); + printf("SCALARS back_description long_long_int 1\n"); + printf("LOOKUP_TABLE default\n"); for (i = 0; i < sa_size(tri); ++i) { - fprintf(output, "%i\n", tri[i].back_description); + printf("%lld\n", (long long int)tri[i].back_description); } +} -exit: - return res; -error: - goto exit; +void +dump_map + (const struct stardis* stardis, + struct sdis_estimator** estimators) +{ + size_t i, last_v = 0; + size_t* idx; + struct vertex* vtx; + struct triangle* tri; + + ASSERT(stardis); + + idx = stardis->boundary.primitives; + vtx = stardis->geometry.vertex; + tri = stardis->geometry.triangle; + + /* Find last used vertex */ + for (i = 0; i < sa_size(idx); ++i) { + size_t t = idx[i]; + last_v = MMAX(MMAX(last_v, tri[t].indices.data[0]), + MMAX(tri[t].indices.data[1], tri[t].indices.data[2])); + } + + /* Dump vertices up to last_v, even unused ones, to avoid reindexing */ + printf("# vtk DataFile Version 2.0\nvtk output\nASCII\nDATASET POLYDATA\n"); + printf("POINTS %zu float\n\n", last_v + 1); + for (i = 0; i <= last_v; ++i) { + printf("%f %f %f\n", SPLIT3(vtx[i].xyz)); + } + /* Dump only primitives in boundary */ + printf("\nPOLYGONS %zu %zu\n", sa_size(idx), 4 * sa_size(idx)); + for (i = 0; i < sa_size(idx); ++i) { + size_t t = idx[i]; + printf("3 %u %u %u\n", SPLIT3(tri[t].indices.data)); + } + printf("\nCELL_DATA %zu\n", sa_size(idx)); + printf("SCALARS temperature_estimate float 1\n"); + printf("LOOKUP_TABLE default\n"); + for (i = 0; i < sa_size(idx); ++i) { + const struct sdis_estimator* estimator = estimators[i]; + struct sdis_mc T; + SDIS(estimator_get_temperature(estimator, &T)); + printf("%f\n", T.E); + } + printf("SCALARS temperature_std_dev float 1\n"); + printf("LOOKUP_TABLE default\n"); + for (i = 0; i < sa_size(idx); ++i) { + const struct sdis_estimator* estimator = estimators[i]; + struct sdis_mc T; + SDIS(estimator_get_temperature(estimator, &T)); + printf("%f\n", T.SE); + } + printf("SCALARS temperature_failures_count unsigned_long_long 1\n"); + printf("LOOKUP_TABLE default\n"); + for (i = 0; i < sa_size(idx); ++i) { + const struct sdis_estimator* estimator = estimators[i]; + size_t nfails; + SDIS(estimator_get_failure_count(estimator, &nfails)); + printf("%zu\n", nfails); + } + printf("SCALARS computation_time_estimate float 1\n"); + printf("LOOKUP_TABLE default\n"); + for (i = 0; i < sa_size(idx); ++i) { + const struct sdis_estimator* estimator = estimators[i]; + struct sdis_mc time; + SDIS(estimator_get_realisation_time(estimator, &time)); + printf("%f\n", time.E); + } + printf("SCALARS computation_time_std_dev float 1\n"); + printf("LOOKUP_TABLE default\n"); + for (i = 0; i < sa_size(idx); ++i) { + const struct sdis_estimator* estimator = estimators[i]; + struct sdis_mc time; + SDIS(estimator_get_realisation_time(estimator, &time)); + printf("%f\n", time.SE); + } } void diff --git a/src/stardis-output.h b/src/stardis-output.h @@ -14,7 +14,6 @@ struct counts; struct description; struct sdis_scene; struct mem_allocator; -enum stardis_mode; struct sdis_estimator; struct stardis; struct geometry; @@ -43,15 +42,18 @@ create_edge_file_if extern res_T print_single_MC_result - (const enum stardis_mode mode, + (const int mode, struct sdis_estimator* estimator, struct stardis* stardis); -/* TODO: rewrite dump! */ -extern res_T +extern void dump_vtk - (FILE* output, - const struct geometry* geometry); + (const struct geometry* geometry); + +extern void +dump_map + (const struct stardis* stardis, + struct sdis_estimator** estimators); extern void print_trg_as_obj diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -1,3 +1,4 @@ +#define _GNU_SOURCE 1 #include "stardis-parsing.h" #include "stardis-app.h" #include "stardis-version.h" @@ -8,11 +9,28 @@ #include <getopt.h> #include <stdlib.h> #include <stdio.h> +#include <ctype.h> +#include <string.h> /******************************************************************************* * Local Functions ******************************************************************************/ +#ifdef COMPILER_GCC +static char* +_strupr + (char* s) +{ + char* ptr; + for (ptr = s; *ptr; ++ptr) { + int tmp = toupper(*ptr); + ASSERT(tmp == (char)tmp); + *ptr = (char)tmp; + } + return s; +} +#endif + static char** split_line (char* a_str, @@ -70,20 +88,14 @@ split_line return result; } -#ifdef COMPILER_GCC -static char* -_strupr - (char* s) +static void +print_version + () { - char* ptr; - for (ptr = s; *ptr; ++ptr) { - int tmp = toupper(*ptr); - ASSERT(tmp == (char)tmp); - *ptr = (char)tmp; - } - return s; + printf("stardis-app version %i.%i.%i built on stardis library version %i.%i.%i\n", + StardisApp_VERSION_MAJOR, StardisApp_VERSION_MINOR, StardisApp_VERSION_PATCH, + Stardis_VERSION_MAJOR, Stardis_VERSION_MINOR, Stardis_VERSION_PATCH); } -#endif /******************************************************************************* * Public Functions @@ -100,6 +112,7 @@ mode_option if (m & MEDIUM_COMPUTE) { found++; res = 'm'; } if (m & BOUNDARY_COMPUTE) { found++; res = 's'; } if (m & IR_COMPUTE) { found++; res = 'R'; } + if (m & MAP_COMPUTE) { found++; res = 'S'; } if (m & DUMP_VTK) { found++; res = 'd'; } ASSERT(found == 1); return res; @@ -110,7 +123,7 @@ void print_multiple_modes const int modes) { int b = 0, fst = 1; - enum stardis_mode m = UNDEF_MODE; + int m = UNDEF_MODE; ASSERT(stream); do { m = BIT(b++); @@ -122,15 +135,6 @@ void print_multiple_modes } void -print_version - () -{ - printf("stardis-app version %i.%i.%i built on stardis library version %i.%i.%i\n", - StardisApp_VERSION_MAJOR, StardisApp_VERSION_MINOR, StardisApp_VERSION_PATCH, - Stardis_VERSION_MAJOR, Stardis_VERSION_MINOR, Stardis_VERSION_PATCH); -} - -void print_help (char* prog) { @@ -138,7 +142,7 @@ print_help print_version(); printf("\nusage: \n%s -M MEDIUM.txt -B BOUNDARY.txt\n", prog); printf("[ -p X,Y,Z,TIME | -m MEDIUM_NAME,TIME | -d \n"); - printf(" | -s SURFACE.vtk,TIME\n"); + printf(" | -s SURFACE.vtk,TIME | -S SURFACE.vtk,TIME\n"); printf(" | -R t=TIME:spp=SPP:fov=FOV:up=XUP,YUP,ZUP:pos=X,Y,Z:tgt=XT,YT,ZT:img=WxH ]\n"); printf("[ -g] [-f SCALE_FACTOR] [-D {all | error | success}] -d\n"); printf("[-n NUM_OF_REALIZATIONS] [-t NUM_OF_THREADS]\n"); @@ -172,6 +176,12 @@ print_help printf(" listed in SURFACE.vtk. These primitives are not added to the geometry,\n"); printf(" but must be already known. The shape doesn't need to be connex.\n"); printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n"); + printf("\n -S SURFACE.vtk,TIME:\n"); + printf(" Compute by-primitives mean temperature on a given 2D shape at a given time.\n"); + printf(" Mean temperature is computed on the front sides of the primitives\n"); + printf(" listed in SURFACE.vtk. These primitives are not added to the geometry,\n"); + printf(" but must be already known. The shape doesn't need to be connex.\n"); + printf(" If some boundary conditions are time-dependant, TIME cannot be INF.\n"); printf("\n -R t=TIME:spp=SPP:fov=FOV:up=XUP,YUP,ZUP:pos=X,Y,Z:tgt=XT,YT,ZT:img=WxH:\n"); printf(" The infra-red rendering mode.\n"); printf(" t is the rendering time (default: INF).\n"); @@ -226,7 +236,7 @@ parse_args } opterr = 0; /* No default error messages */ - while ((opt = getopt(argc, argv, "hvgn:t:b:B:M:m:p:P:dD:s:S:f:r:R:")) != -1) { + while ((opt = getopt(argc, argv, "hvgn:t:B:M:m:p:P:dD:s:S:f:r:R:")) != -1) { switch (opt) { case '?': /* Unreconised option */ res = RES_BAD_ARG; @@ -252,7 +262,7 @@ parse_args res = cstr_to_ulong(optarg, &n); if (res != RES_OK || n == 0) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } args->N = n; @@ -272,7 +282,7 @@ parse_args if (res != RES_OK || args->nthreads <= 0) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; @@ -291,7 +301,7 @@ parse_args || args->u.probe[3] < 0) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; @@ -310,12 +320,13 @@ parse_args || args->u.probe[3] < 0) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; - case 's':{ + case 's': + case 'S': { int err = 0; char *ptr; if (args->mode & EXCLUSIVE_MODES) { @@ -324,7 +335,7 @@ parse_args (char)opt, mode_option(args->mode)); goto error; } - args->mode |= BOUNDARY_COMPUTE; + args->mode |= (opt == 's' ? BOUNDARY_COMPUTE : MAP_COMPUTE); ptr = strrchr(optarg, ','); /* Single ',' allowed */ if (!ptr || ptr != strchr(optarg, ',')) @@ -337,7 +348,7 @@ parse_args } if (err) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; @@ -357,7 +368,7 @@ parse_args res = RES_BAD_ARG; else res = cstr_to_double(ptr + 1, args->u.probe + 3); if (res != RES_OK) { - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } *ptr = '\0'; @@ -384,10 +395,9 @@ parse_args } else if (0 == strcmp(optarg, "success")) { args->dump_paths = DUMP_SUCCESS; - } - else { + } else { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; @@ -397,7 +407,7 @@ parse_args if (res != RES_OK || args->scale_factor <= 0) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; @@ -409,7 +419,7 @@ parse_args || args->radiative_temp[0] <= 0 || args->radiative_temp[1] <= 0) { res = RES_BAD_ARG; - fprintf(stderr, "Invalid argument -%c %s\n", opt, optarg); + fprintf(stderr, "Invalid argument for option -%c: %s\n", opt, optarg); goto error; } break; @@ -643,8 +653,7 @@ parse_medium_line } desc->d.fluid.Tinit = malloc(strlen(tk) + 1); strcpy(desc->d.fluid.Tinit, tk); - } - else { + } else { res = RES_BAD_ARG; fprintf(stderr, "Invalid medium type: %s\n", tk); } @@ -886,8 +895,7 @@ parse_boundary_line res = RES_BAD_ARG; goto exit; } - } - else { + } else { fprintf(stderr, "Invalid boundary type: %s", tk); res = RES_BAD_ARG; goto exit; diff --git a/src/stardis-parsing.h b/src/stardis-parsing.h @@ -17,13 +17,14 @@ enum stardis_mode { MEDIUM_COMPUTE = BIT(2), BOUNDARY_COMPUTE = BIT(3), IR_COMPUTE = BIT(4), + MAP_COMPUTE = BIT(5), DUMP_VTK = BIT(6), GREEN_MODE = BIT(7), GREEN_COMPATIBLE_MODES = PROBE_COMPUTE | PROBE_COMPUTE_ON_INTERFACE | MEDIUM_COMPUTE | BOUNDARY_COMPUTE, - COMPUTE_MODES = GREEN_COMPATIBLE_MODES | IR_COMPUTE, + COMPUTE_MODES = GREEN_COMPATIBLE_MODES | IR_COMPUTE | MAP_COMPUTE, NON_COMPUTE_MODES = UNDEF_MODE | DUMP_VTK | GREEN_MODE, @@ -81,10 +82,6 @@ print_multiple_modes const int modes); extern void -print_version - (); - -extern void print_help (char* prog); diff --git a/src/stardis-solid.c b/src/stardis-solid.c @@ -5,6 +5,8 @@ #include <tinyexpr.h> #include<rsys/stretchy_array.h> +#include <limits.h> + /******************************************************************************* * Local Functions ******************************************************************************/ @@ -195,8 +197,7 @@ create_solid } if (out_has_power) *out_has_power = has_power; if (has_power) solid_shader.volumic_power = solid_get_power; - } - else { + } else { if (out_has_power) *out_has_power = 0; } res = sdis_solid_create(dev, &solid_shader, data, sa_add(*media_ptr, 1));