stardis

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

commit ead09b5bf8a1225dbd53598f63bccf94ed298dd0
parent 7aeabaec632f9e1ab6621ad2e88fac482760050d
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Tue, 20 Sep 2022 15:27:09 +0200

Fix misleading path output

As we attach segment type to vertices, we need to locate type changes along the path on zero-length segments, or coloring will show misleading color gradient

The field vertex type is then renamed to segment type

Diffstat:
Mdoc/stardis-output.5.txt | 10+++++-----
Msrc/stardis-output.c | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 89 insertions(+), 23 deletions(-)

diff --git a/doc/stardis-output.5.txt b/doc/stardis-output.5.txt @@ -827,9 +827,9 @@ _______ "LOOKUP_TABLE default" <path-failures> "POINT_DATA" #vertices - "SCALARS Vertex_Type unsigned_char 1" + "SCALARS Segment_Type unsigned_char 1" "LOOKUP_TABLE default" - <vertices-types> + <segments-types> "SCALARS Weight double 1" "LOOKUP_TABLE default" <weights> @@ -847,8 +847,8 @@ _______ <heat-strips> ::= <heat-strip> <heat-strips> # #strips strips -<vertices-types> ::= <vertice-type> - <vertices-types> # #vertices types +<segments-types> ::= <segment-type> + <segments-types> # #segments types <weights> ::= <weight> <weights> # #vertices weights @@ -869,7 +869,7 @@ _______ <heat-strip> ::= #strip_vertices <vtx_idx 1> ... <vtx_idx #strip_vertices> -<vertice-type> ::= "0" # CONDUCTION +<segment-type> ::= "0" # CONDUCTION | "1" # CONVECTION | "2" # RADIATIVE diff --git a/src/stardis-output.c b/src/stardis-output.c @@ -253,7 +253,7 @@ dump_path char* name = NULL; enum sdis_heat_path_flag status = SDIS_HEAT_PATH_NONE; size_t vcount_, scount_, offset, name_sz, istrip; - unsigned long scount, vcount, strip_1; + unsigned long scount, vcount, strip_1, type_changes, *strip_type_changes = NULL; ASSERT(path && dump_ctx && dump_ctx->stardis @@ -285,12 +285,35 @@ dump_path scount = (unsigned long)scount_; vcount_ = 0; strip_1 = 0; + type_changes = 0; + strip_type_changes = MEM_CALLOC(dump_ctx->stardis->allocator, scount, + sizeof(*strip_type_changes)); + if(!strip_type_changes) { + res = RES_MEM_ERR; + goto error; + } + FOR_EACH(istrip, 0, scount_) { - size_t n; - ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &n)); - if(n == 0 || n > ULONG_MAX) goto abort; - if(n == 1) strip_1++; - vcount_+= n; + size_t ivert, nverts; + enum sdis_heat_vertex_type prev_type; + ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); + if(nverts == 0 || nverts > ULONG_MAX) goto abort; + if(nverts == 1) strip_1++; + FOR_EACH(ivert, 0, nverts) { + struct sdis_heat_vertex vtx; + ERR(sdis_heat_path_line_strip_get_vertex(path, istrip, ivert, &vtx)); + /* Count changes in vertex type along strips + * As we use vertex type instead of segment type, the vertices where type + * change are duplicated (with the only difference of their types) so that + * segments where type change are zero-length. + * This way Paraview displays segments with no misleading color gradient */ + if(ivert != 0 && vtx.type != prev_type) { + type_changes++; + strip_type_changes[istrip]++; + } + prev_type = vtx.type; + } + vcount_+= nverts; } if(vcount_ > ULONG_MAX) goto abort; vcount = (unsigned long)vcount_; @@ -300,66 +323,84 @@ dump_path fprintf(stream, "ASCII\n"); fprintf(stream, "DATASET POLYDATA\n"); /* Write path positions */ - fprintf(stream, "POINTS %lu double\n", vcount); + fprintf(stream, "POINTS %lu double\n", vcount + type_changes); FOR_EACH(istrip, 0, scount_) { size_t ivert, nverts; + enum sdis_heat_vertex_type prev_type; ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); FOR_EACH(ivert, 0, nverts) { struct sdis_heat_vertex vtx; ERR(sdis_heat_path_line_strip_get_vertex(path, istrip, ivert, &vtx)); + if(ivert != 0 && vtx.type != prev_type) { + /* duplicate the previous vertex */ + struct sdis_heat_vertex v; + ERR(sdis_heat_path_line_strip_get_vertex(path, istrip, ivert-1, &v)); + fprintf(stream, "%g %g %g\n", SPLIT3(v.P)); + } fprintf(stream, "%g %g %g\n", SPLIT3(vtx.P)); + prev_type = vtx.type; } } /* Write the strips of the path * Workaround a Paraview crash by creating 2-vertices-long paths from * single-vertex paths */ - fprintf(stream, "LINES %lu %lu\n", scount, scount + vcount + strip_1); + fprintf(stream, "LINES %lu %lu\n", + scount, scount + vcount + strip_1 + type_changes); offset = 0; - FOR_EACH(istrip, 0, scount) { + FOR_EACH(istrip, 0, scount_) { size_t nverts; ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); if(nverts == 1) { fprintf(stream, "2 %lu %lu\n", (unsigned long)offset, (unsigned long)offset); } else { size_t ivert; - fprintf(stream, "%lu", (unsigned long)nverts); - FOR_EACH(ivert, 0, nverts) { + fprintf(stream, "%lu", (unsigned long)nverts + strip_type_changes[istrip]); + FOR_EACH(ivert, 0, nverts + strip_type_changes[istrip]) { if(ivert + offset > ULONG_MAX) goto abort; fprintf(stream, " %lu", (unsigned long)(ivert + offset)); } fprintf(stream, "\n"); } - offset += nverts; + offset += nverts + strip_type_changes[istrip]; } /* Write path status on strips */ fprintf(stream, "CELL_DATA %lu\n", scount); fprintf(stream, "SCALARS Path_Failure unsigned_char 1\n"); fprintf(stream, "LOOKUP_TABLE default\n"); - FOR_EACH(istrip, 0, scount) { + FOR_EACH(istrip, 0, scount_) { switch (status) { case SDIS_HEAT_PATH_SUCCESS: fprintf(stream, "0\n"); break; case SDIS_HEAT_PATH_FAILURE: fprintf(stream, "1\n"); break; default: FATAL("Unreachable code.\n"); break; } } - fprintf(stream, "POINT_DATA %lu\n", vcount); + fprintf(stream, "POINT_DATA %lu\n", vcount + type_changes); /* Write the type of the random walk vertices */ - fprintf(stream, "SCALARS Vertex_Type unsigned_char 1\n"); + fprintf(stream, "SCALARS Segment_Type unsigned_char 1\n"); fprintf(stream, "LOOKUP_TABLE default\n"); FOR_EACH(istrip, 0, scount_) { size_t ivert, nverts; + enum sdis_heat_vertex_type prev_type; ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); FOR_EACH(ivert, 0, nverts) { struct sdis_heat_vertex vtx; + int t; ERR(sdis_heat_path_line_strip_get_vertex(path, istrip, ivert, &vtx)); if((size_t)vtx.type > UCHAR_MAX) goto abort; switch(vtx.type) { - case SDIS_HEAT_VERTEX_CONDUCTION: fprintf(stream, "%d\n", 0); break; - case SDIS_HEAT_VERTEX_CONVECTION: fprintf(stream, "%d\n", 1); break; - case SDIS_HEAT_VERTEX_RADIATIVE: fprintf(stream, "%d\n", 2); break; + case SDIS_HEAT_VERTEX_CONDUCTION: t = 0; break; + case SDIS_HEAT_VERTEX_CONVECTION: t = 1; break; + case SDIS_HEAT_VERTEX_RADIATIVE: t = 2; break; default: FATAL("Unreachable code.\n"); break; } + fprintf(stream, "%d\n", t); + if(ivert != 0 && vtx.type != prev_type) { + /* duplicate the previous vertex, but its type that is set to the type + * of the current vertex */ + fprintf(stream, "%d\n", t); + } + prev_type = vtx.type; } } /* Write the weights of the random walk vertices */ @@ -367,11 +408,19 @@ dump_path fprintf(stream, "LOOKUP_TABLE default\n"); FOR_EACH(istrip, 0, scount_) { size_t ivert, nverts; + enum sdis_heat_vertex_type prev_type; + double prev_w; ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); FOR_EACH(ivert, 0, nverts) { struct sdis_heat_vertex vtx; ERR(sdis_heat_path_line_strip_get_vertex(path, istrip, ivert, &vtx)); fprintf(stream, "%g\n", vtx.weight); + if(ivert != 0 && vtx.type != prev_type) { + /* duplicate the previous vertex */ + fprintf(stream, "%g\n", prev_w); + } + prev_type = vtx.type; + prev_w = vtx.weight; } } /* Write the branch_id of the random walk vertices */ @@ -379,17 +428,27 @@ dump_path fprintf(stream, "LOOKUP_TABLE default\n"); FOR_EACH(istrip, 0, scount_) { size_t ivert, nverts; + enum sdis_heat_vertex_type prev_type; + int prev_id; ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); FOR_EACH(ivert, 0, nverts) { struct sdis_heat_vertex vtx; ERR(sdis_heat_path_line_strip_get_vertex(path, istrip, ivert, &vtx)); fprintf(stream, "%d\n", vtx.branch_id); + if(ivert != 0 && vtx.type != prev_type) { + /* duplicate the previous vertex */ + fprintf(stream, "%d\n", prev_id); + } + prev_type = vtx.type; + prev_id = vtx.branch_id; } } /* If computation time is not INF, * write the time of the random walk vertices */ FOR_EACH(istrip, 0, scount_) { size_t ivert, nverts; + enum sdis_heat_vertex_type prev_type; + double prev_time; ERR(sdis_heat_path_line_strip_get_vertices_count(path, istrip, &nverts)); FOR_EACH(ivert, 0, nverts) { struct sdis_heat_vertex vtx; @@ -403,12 +462,19 @@ dump_path fprintf(stream, "LOOKUP_TABLE default\n"); } fprintf(stream, "%g\n", vtx.time); + if(ivert != 0 && vtx.type != prev_type) { + /* duplicate the previous vertex */ + fprintf(stream, "%g\n", prev_time); + } + prev_type = vtx.type; + prev_time = vtx.time; } } end_prt_time: end: MEM_RM(dump_ctx->stardis->allocator, name); + MEM_RM(dump_ctx->stardis->allocator, strip_type_changes); if(stream) fclose(stream); return res; error: