solstice-pp

Post-processing utilities for the solstice app
git clone git://git.meso-star.com/solstice-pp.git
Log | Files | Refs | README | LICENSE

commit cdb6c36776ccc776926e26629dd13a03cef31585
parent dfc0c0db65930b49cebed1e799179407bd255d8f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 27 Jul 2017 16:14:52 +0200

Rename post-process files and tune the Makefile

Diffstat:
Msrc/Makefile | 33++++++++++++++++++++-------------
Dsrc/solpath.c | 47-----------------------------------------------
Asrc/solpaths.c | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/solpp.c | 532+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Asrc/solppraw.c | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/solvtk.c | 338-------------------------------------------------------------------------------
6 files changed, 499 insertions(+), 642 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -13,19 +13,19 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -NEXPERIMENTS=100000 +NEXPERIMENTS=10000000 NPATHS=100 -SUN_DIRS=270,45 +SUN_DIRS=270,45:180,60 RCV=themis-rcv.yaml INPUT=themis.yaml GEOM=geom SIMUL=simul -CFLAGS = -g -std=c99 -pedantic -Wall -SCRIPT = themis.c solsplit.c solpp.c solvtk.c solpath.c +CFLAGS = -O2 -std=c99 -pedantic -Wall +SCRIPT = themis.c solpp.c solppraw.c solpaths.c PROG = $(SCRIPT:%.c=%) -PATH := $(PATH):$(STAR_ENGINE)/bin:. +PATH := $(PATH):. .PHONY: all all: $(PROG) @@ -35,25 +35,32 @@ receiver: @echo "- {name: target, side: BACK, per_primitive: 1}" > $(RCV) .PHONY: simul -simul: $(INPUT) receiver - solstice -D$(SUN_DIRS) -n$(NEXPERIMENTS) -R$(RCV) -fo $(SIMUL) $(INPUT) - solstice -D$(SUN_DIRS) -g format=obj:split=geometry -fo $(GEOM) $(INPUT) - solvtk $(GEOM) $(SIMUL) +simul: $(INPUT) receiver $(PROG) + @tput bold + @echo -e ">>> Run simulation: Sun dirs = $(SUN_DIRS); #Experiments = $(NEXPERIMENTS)" + @tput sgr0 + @solstice -D$(SUN_DIRS) -n$(NEXPERIMENTS) -R$(RCV) -fo $(SIMUL) $(INPUT) + @solstice -D$(SUN_DIRS) -g format=obj:split=geometry -fo $(GEOM) $(INPUT) + @solppraw $(SIMUL) + @solpp $(GEOM) $(SIMUL) .PHONY: paths paths: $(PROG) $(INPUT) receiver - solstice -D$(SUN_DIRS) -q -n$(NPATHS) -R$(RCV) -p default $(INPUT) | solpath + @tput bold + @echo -e ">>> Sample paths: Sun dirs = $(SUN_DIRS); #Paths = $(NPATHS)" + @tput sgr0 + @solstice -D$(SUN_DIRS) -q -n$(NPATHS) -R$(RCV) -p default $(INPUT) | solpaths .PHONY: run run: paths simul .PHONY: clean clean: - rm -rf $(PROG) $(INPUT) $(GEOM) $(SIMUL) $(RCV) *.obj *.vtk *simulation*.txt + @rm -rf $(PROG) $(INPUT) $(GEOM) $(SIMUL) $(RCV) *.obj *.vtk *raw-results.txt $(PROG): %: %.c solpp.h - $(CC) -o $@ $(CFLAGS) $< + @echo -e " CC $<"; $(CC) -o $@ $(CFLAGS) $< $(INPUT): $(PROG) - themis > $@ + @themis > $@ diff --git a/src/solpath.c b/src/solpath.c @@ -1,47 +0,0 @@ -/* Copyright (C) |Meso|Star> 2017 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#include "solpp.h" - -int -main(int argc, char** argv) -{ - char s[128]; - buf_char_T buf = BUF_NULL; - FILE* input = stdin; - FILE* output = NULL; - char* line = NULL; - double azim = 0; - double elev = 0; - - if(argc > 1 && !(input = fopen(argv[1], "r"))) { - fprintf(stderr, "Could not open the file `%s'.\n", argv[1]); - return 1; - } - while((line = read_line(&buf, input))) { - if(strncmp(line, "#--- Sun direction:", 19)) { - CHK(output != NULL); - fprintf(output, "%s\n", line); - } else { - CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &azim, &elev) == 2); - CHK(snprintf(s, sizeof(s), "%g-%g-paths.vtk", azim, elev) < sizeof(s)); - if(output) fclose(output); - CHK(output = fopen(s, "w")); - } - } - BUF_RELEASE(buf); - if(output) fclose(output); - return 0; -} diff --git a/src/solpaths.c b/src/solpaths.c @@ -0,0 +1,49 @@ +/* Copyright (C) |Meso|Star> 2017 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "solpp.h" + +int +main(int argc, char** argv) +{ + char s[128]; + buf_char_T buf = BUF_NULL; + FILE* input = stdin; + FILE* output = NULL; + char* line = NULL; + double azim = 0; + double elev = 0; + + if(argc > 1 && !(input = fopen(argv[1], "r"))) { + fprintf(stderr, "Could not open the file `%s'.\n", argv[1]); + return 1; + } + while((line = read_line(&buf, input))) { + if(strncmp(line, "#--- Sun direction:", 19)) { + CHK(output != NULL); + fprintf(output, "%s\n", line); + } else { + CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &azim, &elev) == 2); + CHK(snprintf(s, sizeof(s), "%g-%g-paths.vtk", azim, elev) < sizeof(s)); + if(output) fclose(output); + printf("Write `%s'\n", s); + CHK(output = fopen(s, "w")); + } + } + BUF_RELEASE(buf); + if(output) fclose(output); + if(input && input!=stdin) fclose(input); + return 0; +} diff --git a/src/solpp.c b/src/solpp.c @@ -13,285 +13,329 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define _ISOC99_SOURCE /* snprintf support */ -#define _POSIX_C_SOURCE 200809L /* strdup support */ -#include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#define CHK(A, B) { \ - if((A) != (B)) { \ - fprintf(stderr, "error:%s:%u\n", __FILE__, __LINE__); \ - assert(0); \ - exit(0); \ - } \ -} (void)0 -#define NCHK(A, B) { \ - if((A) == (B)) { \ - fprintf(stderr, "error:%s:%u\n", __FILE__, __LINE__); \ - assert(0); \ - exit(0); \ - } \ -} (void)0 - -struct estimation { - float E; /* Expected value */ - float SE; /* Standard error */ -}; -struct buf { - char* mem; - size_t sz; -}; +#include "solpp.h" + +struct mesh { -struct entity { - char* name; - int id; + BUF(double) coords; + BUF(size_t) ids; + BUF(size_t) entities; + BUF(size_t) ncells; + size_t voffset; }; +static const struct mesh MESH_NULL = {BUF_NULL, BUF_NULL, BUF_NULL, BUF_NULL, 0}; + +static inline void +mesh_release(struct mesh* msh) +{ + BUF_RELEASE(msh->coords); + BUF_RELEASE(msh->ids); + BUF_RELEASE(msh->entities); + BUF_RELEASE(msh->ncells); + memset(msh, 0, sizeof(struct mesh)); +} -static char* -read_line(struct buf* buf, FILE* stream) +static inline void +mesh_write_vtk(FILE* output, struct mesh* msh) { - char* c; + size_t i, n; - if(!fgets(buf->mem, (int)buf->sz, stream)) return NULL; + fprintf(output, "# vtk DataFile Version 2.0\n"); + fprintf(output, "Test\n"); + fprintf(output, "ASCII\n"); + fprintf(output, "DATASET POLYDATA\n"); - /* Ensure that the whole line is read */ - while(!strrchr(buf->mem, '\n') && !feof(stream)) { - NCHK(buf->mem = realloc(buf->mem, (buf->sz*=2)), NULL); - NCHK(fgets(buf->mem+strlen(buf->mem), (int)buf->sz-strlen(buf->mem), stream), NULL); + n = BUF_SZ(msh->coords)/3; + fprintf(output, "POINTS %zu float\n", n); + FOR_EACH(i, 0, n) { + fprintf(output, "%g %g %g\n", + BUF_AT(msh->coords, i*3+0), + BUF_AT(msh->coords, i*3+1), + BUF_AT(msh->coords, i*3+2)); + } + n = BUF_SZ(msh->ids)/3; + fprintf(output, "POLYGONS %zu %zu\n", n, n*4); + FOR_EACH(i, 0, n) { + fprintf(output, "3 %zu %zu %zu\n", + BUF_AT(msh->ids, i*3+0), + BUF_AT(msh->ids, i*3+1), + BUF_AT(msh->ids, i*3+2)); } - - /* Remove the carriage return */ - if((c=strrchr(buf->mem, '\n'))) *c = '\0'; - return buf->mem; } -static void -print_receiver_side_estimations(FILE* output, struct estimation mc[5]) +static inline void +mesh_write_obj(FILE* output, struct mesh* msh) { - fprintf(output, " Absorbed irradiance | %16g +/- %-16g\n", mc[0].E, mc[0].SE); - fprintf(output, " Irradiance | %16g +/- %-16g\n", mc[1].E, mc[1].SE); - fprintf(output, " Reflectivity loss | %16g +/- %-16g\n", mc[2].E, mc[2].SE); - fprintf(output, " Absorptivity loss | %16g +/- %-16g\n", mc[3].E, mc[3].SE); - fprintf(output, " Efficiency | %16g +/- %-16g\n", mc[4].E, mc[4].SE); -} + size_t i, n; -static void -print_rcvXprim_side_estimations(FILE* output, struct estimation mc[4]) -{ - fprintf(output, " Absorbed irradiance | %16g +/- %-16g\n", mc[0].E, mc[0].SE); - fprintf(output, " Irradiance | %16g +/- %-16g\n", mc[1].E, mc[1].SE); - fprintf(output, " Reflectivity loss | %16g +/- %-16g\n", mc[2].E, mc[2].SE); - fprintf(output, " Absorptivity loss | %16g +/- %-16g\n", mc[3].E, mc[3].SE); + n = BUF_SZ(msh->coords)/3; + FOR_EACH(i, 0, n) { + fprintf(output, "v %g %g %g\n", + BUF_AT(msh->coords, i*3+0), + BUF_AT(msh->coords, i*3+1), + BUF_AT(msh->coords, i*3+2)); + } + + n = BUF_SZ(msh->ids)/3; + FOR_EACH(i, 0, n) { + fprintf(output, "f %zu %zu %zu\n", + BUF_AT(msh->ids, i*3+0) + 1, + BUF_AT(msh->ids, i*3+1) + 1, + BUF_AT(msh->ids, i*3+2) + 1); + } } -static void -format_simulation_results(FILE* input, FILE* output) +static inline void +mesh_write_prim_data_vtk + (FILE* output, const struct mesh* msh, struct simul* simul) { - struct buf buf; - struct estimation mc[10]; - struct entity* rcvs = NULL; - struct entity* prims = NULL; - char* line; - int nrcvs, nprims, nsamps; - int i; - - NCHK(buf.mem = malloc(buf.sz=32), NULL); - - /* Counters */ - line = read_line(&buf, input); - CHK(sscanf(line, "%*d %d %d %d %*d", &nrcvs, &nprims, &nsamps), 3); - - /* Global results */ - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[0].E, &mc[0].SE), 2); - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[1].E, &mc[1].SE), 2); - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[2].E, &mc[2].SE), 2); - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[3].E, &mc[3].SE), 2); - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[4].E, &mc[4].SE), 2); - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[5].E, &mc[5].SE), 2); - CHK(sscanf(read_line(&buf, input), "%f %f", &mc[6].E, &mc[6].SE), 2); - fprintf(output, " Overall results (#Samples = %d)\n", nsamps); - fprintf(output, "------------------------------------------------------------\n"); - fprintf(output, "Potential irradiance | %16g +/- %-16g\n", mc[0].E, mc[0].SE); - fprintf(output, " Absorbed irradiance | %16g +/- %-16g\n", mc[1].E, mc[1].SE); - fprintf(output, " Cosine factor | %16g +/- %-16g\n", mc[2].E, mc[2].SE); - fprintf(output, " Shadow loss | %16g +/- %-16g\n", mc[3].E, mc[3].SE); - fprintf(output, " Missing loss | %16g +/- %-16g\n", mc[4].E, mc[4].SE); - fprintf(output, " Reflectivity loss | %16g +/- %-16g\n", mc[5].E, mc[5].SE); - fprintf(output, " Absorptivity loss | %16g +/- %-16g\n", mc[6].E, mc[6].SE); - fprintf(output, "\n"); - - /* Per receivers results */ - NCHK(rcvs = malloc(sizeof(struct entity)*nrcvs), NULL); - for(i=0; i<nrcvs; ++i) { - const char* name = strtok(read_line(&buf, input), " \t"); - float area; - line = strtok(NULL, ""); - NCHK(rcvs[i].name = strdup(name), NULL); - CHK(sscanf - (line, - "%d %f " - "%f %f %f %f %f %f %f %f %f %f " - "%f %f %f %f %f %f %f %f %f %f", - &rcvs[i].id, &area, - &mc[0].E, &mc[0].SE, - &mc[1].E, &mc[1].SE, - &mc[2].E, &mc[2].SE, - &mc[3].E, &mc[3].SE, - &mc[4].E, &mc[4].SE, - &mc[5].E, &mc[5].SE, - &mc[6].E, &mc[6].SE, - &mc[7].E, &mc[7].SE, - &mc[8].E, &mc[8].SE, - &mc[9].E, &mc[9].SE), 22); - fprintf(output, " Receiver `%s' (Area = %g)\n", name, area); - if(mc[0].E >= 0) { - fprintf(output, "------------------[Front]-----------------------------------\n"); - print_receiver_side_estimations(output, mc + 0); - } - if(mc[5].E >= 0) { - fprintf(output, "-------------------[Back]-----------------------------------\n"); - print_receiver_side_estimations(output, mc + 5); + struct prim* prim; + struct rcvXprim* rcvXprim; + size_t ircv; + size_t iprim; + size_t icell; + size_t n; + + n = BUF_SZ(msh->ids) / 3; + fprintf(output, "CELL_DATA %zu\n", n); + + fprintf(output, "FIELD PrimaryData %zu\n", 2 + BUF_SZ(simul->rcvs)*8); + fprintf(output, "cos_factor 2 %zu float\n", n); + FOR_EACH(iprim, 0, BUF_SZ(msh->entities)) { + CHK(prim = find_primary_by_id(simul, BUF_AT(msh->entities, iprim))); + FOR_EACH(icell, 0, BUF_AT(msh->ncells, iprim)) { + fprintf(output, "%g %g\n", prim->cos_factor.E, prim->cos_factor.SE); } - fprintf(output, "\n"); } - /* Per primary results */ - NCHK(prims = malloc(sizeof(struct entity)*nprims), NULL); - for(i=0; i<nprims; ++i) { - const char* name = strtok(read_line(&buf, input), " \t"); - int nsamples; - float area; - line = strtok(NULL, ""); - NCHK(prims[i].name = strdup(name), NULL); - CHK(sscanf(line, "%d %f %d %f %f %f %f", - &prims[i].id, &area, &nsamples, - &mc[0].E, &mc[0].SE, - &mc[1].E, &mc[1].SE), 7); - - fprintf(output, " Primary `%s' (Area = %g; #Samples = %d)\n", - name, area, nsamples); - fprintf(output, "------------------------------------------------------------\n"); - fprintf(output, " Cosine factor | %16g +/- %-16g\n", mc[0].E, mc[0].SE); - fprintf(output, " Shadow loss | %16g +/- %-16g\n", mc[1].E, mc[1].SE); - fprintf(output, "\n"); + fprintf(output, "shadow_loss 2 %zu float\n", n); + FOR_EACH(iprim, 0, BUF_SZ(msh->entities)) { + CHK(prim = find_primary_by_id(simul, BUF_AT(msh->entities, iprim))); + FOR_EACH(icell, 0, BUF_AT(msh->ncells, iprim)) { + fprintf(output, "%g %g\n", prim->shadow_loss.E, prim->shadow_loss.SE); + } } - /* Per receiverXprimary results */ - for(i=0; i<nrcvs*nprims; ++i) { - int ircv, iprim; - int isearch; - line = read_line(&buf, input); - CHK(sscanf - (line, - "%d %d " - "%f %f %f %f %f %f %f %f " - "%f %f %f %f %f %f %f %f", - &ircv, &iprim, - &mc[0].E, &mc[0].SE, - &mc[1].E, &mc[1].SE, - &mc[2].E, &mc[2].SE, - &mc[3].E, &mc[3].SE, - &mc[4].E, &mc[4].SE, - &mc[5].E, &mc[5].SE, - &mc[6].E, &mc[6].SE, - &mc[7].E, &mc[7].SE), 18); - /* Look for the receiver */ - for(isearch=0; isearch<nrcvs && rcvs[isearch].id != ircv; ++isearch); - NCHK(isearch, nrcvs); - ircv = isearch; - /* Look for the primary */ - for(isearch=0; isearch<nprims && prims[isearch].id != iprim; ++isearch); - NCHK(isearch, nprims); - iprim = isearch; - fprintf(output, " Receiver `%s' X Primary `%s'\n", - rcvs[ircv].name, prims[iprim].name); - if(mc[0].E >= 0) { - fprintf(output, "------------------[Front]-----------------------------------\n"); - print_rcvXprim_side_estimations(output, mc + 0); - } - if(mc[4].E >= 0) { - fprintf(output, "-------------------[Back]-----------------------------------\n"); - print_rcvXprim_side_estimations(output, mc + 4); - } - fprintf(output, "\n"); + #define WRITE(Side, Name) { \ + fprintf(output, "%s_"STR(Side)"_"STR(Name)" 2 %zu float\n", rcv->name, n); \ + FOR_EACH(iprim, 0, BUF_SZ(msh->entities)) { \ + CHK(rcvXprim = find_rcvXprim(simul,rcv->id,BUF_AT(msh->entities,iprim)));\ + FOR_EACH(icell, 0, BUF_AT(msh->ncells, iprim)) { \ + fprintf(output, "%g %g\n", \ + rcvXprim->Name[Side].E, \ + rcvXprim->Name[Side].SE); \ + } \ + } \ + } (void)0 + FOR_EACH(ircv, 0, BUF_SZ(simul->rcvs)) { + const struct rcv* rcv = &BUF_AT(simul->rcvs, ircv); + WRITE(FRONT, absorbed_irradiance); + WRITE(FRONT, irradiance); + WRITE(FRONT, reflectivity_loss); + WRITE(FRONT, absorptivity_loss); + WRITE(BACK, absorbed_irradiance); + WRITE(BACK, irradiance); + WRITE(BACK, reflectivity_loss); + WRITE(BACK, absorptivity_loss); } + #undef WRITE +} + +static inline void +mesh_write_rcv_data_vtk + (FILE* output, const struct mesh* msh, struct simul* simul) +{ + struct rcv* rcv; + size_t ircv; + size_t icell; + size_t n; + + n = BUF_SZ(msh->ids)/3; + fprintf(output, "CELL_DATA %zu\n", n); + fprintf(output, "FIELD PrimaryData 12\n"); + + #define WRITE(Side, Name) { \ + fprintf(output, STR(Side)"_"STR(Name)" 2 %zu float\n", n); \ + FOR_EACH(ircv, 0, BUF_SZ(msh->entities)) { \ + CHK(rcv = find_receiver_by_id(simul, BUF_AT(msh->entities, ircv))); \ + FOR_EACH(icell, 0, BUF_AT(msh->ncells, ircv)) { \ + fprintf(output, "%g %g\n", rcv->Name[Side].E, rcv->Name[Side].SE); \ + } \ + } \ + } (void)0 + WRITE(FRONT, absorbed_irradiance); + WRITE(FRONT, irradiance); + WRITE(FRONT, reflectivity_loss); + WRITE(FRONT, absorptivity_loss); + WRITE(FRONT, efficiency); + WRITE(BACK, absorbed_irradiance); + WRITE(BACK, irradiance); + WRITE(BACK, reflectivity_loss); + WRITE(BACK, absorptivity_loss); + WRITE(BACK, efficiency); + #undef WRITE - /* Free temporary data */ - for(i=0; i<nrcvs; free(rcvs[i].name), ++i); - for(i=0; i<nprims; free(prims[i].name), ++i); - free(rcvs); - free(prims); - free(buf.mem); + #define WRITE_MAP(Side) { \ + fprintf(output, STR(Side)"_map 2 %zu float\n", n); \ + FOR_EACH(ircv, 0, BUF_SZ(msh->entities)) { \ + CHK(rcv = find_receiver_by_id(simul, BUF_AT(msh->entities, ircv))); \ + if(!BUF_SZ(rcv->map[Side])) { \ + FOR_EACH(icell, 0, BUF_AT(msh->ncells,ircv)) fprintf(output,"-1 -1\n");\ + } else { \ + FOR_EACH(icell, 0, BUF_AT(msh->ncells,ircv)) { \ + const struct mc* mc = &BUF_AT(rcv->map[Side], icell); \ + fprintf(output, "%g %g\n", mc->E, mc->SE); \ + } \ + } \ + } \ + } (void)0 + WRITE_MAP(FRONT); + WRITE_MAP(BACK); + #undef WRITE_MAP } int main(int argc, char** argv) { - struct buf buf = {0}; - struct buf str = {0}; - FILE* input = stdin; - FILE* output = NULL; - float azim = 0; - float elev = 0; + buf_char_T buf = BUF_NULL; char* line = NULL; - int err = 0; - int n; - - if(argc > 1) { - input = fopen(argv[1], "r"); - if(!input) { - fprintf(stderr, "Could not open the file `%s'.\n", argv[1]); - goto error; - } + + FILE* input; + FILE* geom; + FILE* output; + + if(argc < 3) { + fprintf(stderr, "Usage: %s solstice-geometry solstice-simulation\n", argv[0]); + return 1; } - NCHK(buf.mem = malloc(buf.sz=32), NULL); - NCHK(str.mem = malloc(str.sz=32), NULL); + CHK(geom = fopen(argv[1], "r")); + CHK(input = fopen(argv[2], "r")); + CHK(read_line(&buf, geom)); /* Skip the sun direction of the geometry */ while((line = read_line(&buf, input))) { + struct simul simul; - if(!strncmp(line, "#--- Sun direction:", 19)) { - CHK(sscanf(line+5, "Sun direction: %f %f (%*f %*f %*f)", &azim, &elev), 2); - for(;;) { - n = snprintf(str.mem, str.sz, "%g-%g-simulation.txt", azim, elev); - if(n < str.sz) break; - NCHK(str.mem = realloc(str.mem, (str.sz*=2)), NULL); - } - if(output) fclose(output); - NCHK(output = fopen(str.mem, "w"), NULL); - format_simulation_results(input, output); - } else if(!strncmp(line, "# vtk", 5)) { - char* header = strdup(line); - NCHK(header, NULL); - line = read_line(&buf, input); - for(;;) { - n = snprintf(str.mem, str.sz, "%g-%g-map-%s.vtk", azim, elev, line); - if(n < str.sz) break; - NCHK(str.mem = realloc(str.mem, (str.sz*=2)), NULL); + const struct rcv* rcv = NULL; + const struct prim* prim = NULL; + + struct mesh msh_rcv = MESH_NULL; + struct mesh msh_prim = MESH_NULL; + struct mesh msh_misc = MESH_NULL; + + char filename[128]; + char prefix[64]; + size_t ntris_grp = 0, nverts_grp = 0; + size_t nverts_obj = 0, off_obj = 0, off_grp = 0; + + simul_init(&simul); + + CHK(!strncmp(line, "#--- Sun direction:", 19)); + CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &simul.azimuth, &simul.elevation)==2); + CHK(snprintf(prefix, sizeof(prefix), "%g-%g-", + simul.azimuth, simul.elevation) < sizeof(prefix)); + read_simulation(&simul, input); + + while((line = read_line(&buf, geom)) && strncmp(line, "#--- Sun", 8)) { + if(!strncmp(line, "g ", 2)) { + if(prim) { + BUF_PUSH(msh_prim.ncells, ntris_grp); + msh_prim.voffset += nverts_grp; + } + if(rcv) { + BUF_PUSH(msh_rcv.ncells, ntris_grp); + msh_rcv.voffset += nverts_grp; + } + if(!prim && !rcv) msh_misc.voffset += nverts_grp; + prim = find_primary(&simul, line+2); + rcv = find_receiver(&simul, line+2); + if(prim) BUF_PUSH(msh_prim.entities, prim->id); + if(rcv) BUF_PUSH(msh_rcv.entities, rcv->id); + ntris_grp = 0; + nverts_grp = 0; + off_grp = 0; + off_obj = nverts_obj; + + } else if(!strncmp(line, "v ", 2)) { + double pos[3]; + CHK(sscanf(line+2, "%lf %lf %lf", pos+0, pos+1, pos+2) == 3); + if(prim) { + BUF_PUSH(msh_prim.coords, pos[0]); + BUF_PUSH(msh_prim.coords, pos[1]); + BUF_PUSH(msh_prim.coords, pos[2]); + } + if(rcv) { + BUF_PUSH(msh_rcv.coords, pos[0]); + BUF_PUSH(msh_rcv.coords, pos[1]); + BUF_PUSH(msh_rcv.coords, pos[2]); + } + if(!prim && !rcv) { + BUF_PUSH(msh_misc.coords, pos[0]); + BUF_PUSH(msh_misc.coords, pos[1]); + BUF_PUSH(msh_misc.coords, pos[2]); + } + ++nverts_grp; + ++nverts_obj; + } else if(!strncmp(line, "f ", 2)) { + size_t tri[3]; + CHK(sscanf(line+2, "%zu %zu %zu", tri+0, tri+1, tri+2) == 3); + if(prim) { + BUF_PUSH(msh_prim.ids, tri[0]-1 + msh_prim.voffset + off_grp - off_obj); + BUF_PUSH(msh_prim.ids, tri[1]-1 + msh_prim.voffset + off_grp - off_obj); + BUF_PUSH(msh_prim.ids, tri[2]-1 + msh_prim.voffset + off_grp - off_obj); + } + if(rcv) { + BUF_PUSH(msh_rcv.ids, tri[0]-1 + msh_rcv.voffset + off_grp - off_obj); + BUF_PUSH(msh_rcv.ids, tri[1]-1 + msh_rcv.voffset + off_grp - off_obj); + BUF_PUSH(msh_rcv.ids, tri[2]-1 + msh_rcv.voffset + off_grp - off_obj); + } + if(!prim && !rcv) { + BUF_PUSH(msh_misc.ids, tri[0]-1 + msh_misc.voffset + off_grp - off_obj); + BUF_PUSH(msh_misc.ids, tri[1]-1 + msh_misc.voffset + off_grp - off_obj); + BUF_PUSH(msh_misc.ids, tri[2]-1 + msh_misc.voffset + off_grp - off_obj); + } + ++ntris_grp; + } else if(!strcmp(line, "---")) { + nverts_obj = 0; + off_obj = 0; + off_grp = nverts_grp; } - if(output) fclose(output); - NCHK(output = fopen(str.mem, "w"), NULL); - fprintf(output, "%s\n", header); - fprintf(output, "%s\n", str.mem); - free(header); - } else if(!output) { - fprintf(stderr, "Parsing error.\n"); - goto error; - } else { - fprintf(output, "%s\n", line); } + if(prim) BUF_PUSH(msh_prim.ncells, ntris_grp); + if(rcv) BUF_PUSH(msh_rcv.ncells, ntris_grp); + + CHK(snprintf(filename, sizeof(filename), + "%sprimaries.vtk", prefix) < sizeof(prefix)); + printf("Write `%s'\n", filename); + CHK(output = fopen(filename, "w")); + mesh_write_vtk(output, &msh_prim); + mesh_write_prim_data_vtk(output, &msh_prim, &simul); + fclose(output); + + CHK(snprintf(filename, sizeof(filename), + "%sreceivers.vtk", prefix) < sizeof(prefix)); + printf("Write `%s'\n", filename); + CHK(output = fopen(filename, "w")); + mesh_write_vtk(output, &msh_rcv); + mesh_write_rcv_data_vtk(output, &msh_rcv, &simul); + fclose(output); + + CHK(snprintf(filename, sizeof(filename), + "%smiscellaneous.obj", prefix) < sizeof(prefix)); + printf("Write `%s'\n", filename); + CHK(output = fopen(filename, "w")); + mesh_write_obj(output, &msh_misc); + fclose(output); + + mesh_release(&msh_prim); + mesh_release(&msh_rcv); + mesh_release(&msh_misc); + simul_release(&simul); } -exit: - if(buf.mem) free(buf.mem); - if(str.mem) free(str.mem); - if(output) fclose(output); - if(input && input != stdin) fclose(input); - return err; -error: - err = 1; - goto exit; + fclose(geom); + fclose(input); + BUF_RELEASE(buf); + return 0; } diff --git a/src/solppraw.c b/src/solppraw.c @@ -0,0 +1,142 @@ +/* Copyright (C) |Meso|Star> 2017 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "solpp.h" + +static inline void +print_rcv_side(FILE* output, const enum side side, struct rcv* rcv) +{ + #define W(Name) rcv->Name[side].E, rcv->Name[side].SE + fprintf(output, " Absorbed irradiance | %16g +/- %-16g\n", W(absorbed_irradiance)); + fprintf(output, " Irradiance | %16g +/- %-16g\n", W(irradiance)); + fprintf(output, " Reflectivity loss | %16g +/- %-16g\n", W(reflectivity_loss)); + fprintf(output, " Absorptivity loss | %16g +/- %-16g\n", W(absorptivity_loss)); + fprintf(output, " Efficiency | %16g +/- %-16g\n", W(efficiency)); + #undef W +} + +static inline void +print_rcvXprim_side(FILE* output, const enum side side, struct rcvXprim* rXp) +{ + #define W(Name) rXp->Name[side].E, rXp->Name[side].SE + fprintf(output, " Absorbed irradiance | %16g +/- %-16g\n", W(absorbed_irradiance)); + fprintf(output, " Irradiance | %16g +/- %-16g\n", W(irradiance)); + fprintf(output, " Reflectivity loss | %16g +/- %-16g\n", W(reflectivity_loss)); + fprintf(output, " Absorptivity loss | %16g +/- %-16g\n", W(absorptivity_loss)); + #undef W +} + +static inline void +print_simulation(FILE* output, struct simul* simul) +{ + size_t i; + + /* Global results */ + #define W(Name) simul->Name.E, simul->Name.SE + fprintf(output, " Overall results (#Samples = %zu)\n", simul->nsamps); + fprintf(output, "------------------------------------------------------------\n"); + fprintf(output, "Potential irradiance | %16g +/- %-16g\n", W(potential_irradiance)); + fprintf(output, " Absorbed irradiance | %16g +/- %-16g\n", W(absorbed_irradiance)); + fprintf(output, " Cosine factor | %16g +/- %-16g\n", W(cos_factor)); + fprintf(output, " Shadow loss | %16g +/- %-16g\n", W(shadow_loss)); + fprintf(output, " Missing loss | %16g +/- %-16g\n", W(missing_loss)); + fprintf(output, " Reflectivity loss | %16g +/- %-16g\n", W(reflectivity_loss)); + fprintf(output, " Absorptivity loss | %16g +/- %-16g\n", W(absorptivity_loss)); + fprintf(output, "\n"); + #undef W + /* Per receivers results */ + FOR_EACH(i, 0, BUF_SZ(simul->rcvs)) { + struct rcv* rcv = &BUF_AT(simul->rcvs, i); + fprintf(output, " Receiver `%s' (Area = %g)\n", rcv->name, rcv->area); + if(rcv->irradiance[FRONT].E >= 0) { + fprintf(output, "------------------[Front]-----------------------------------\n"); + print_rcv_side(output, FRONT, rcv); + } + if(rcv->irradiance[BACK].E >= 0) { + fprintf(output, "-------------------[Back]-----------------------------------\n"); + print_rcv_side(output, BACK, rcv); + } + fprintf(output, "\n"); + } + /* Per primary results */ + FOR_EACH(i, 0, BUF_SZ(simul->prims)) { + struct prim* prim = &BUF_AT(simul->prims, i); + fprintf(output, " Primary `%s' (Area = %g; #Samples = %zu)\n", + prim->name, prim->area, prim->nsamps); + #define W(Name) prim->Name.E, prim->Name.SE + fprintf(output, "------------------------------------------------------------\n"); + fprintf(output, " Cosine factor | %16g +/- %-16g\n", W(cos_factor)); + fprintf(output, " Shadow loss | %16g +/- %-16g\n", W(shadow_loss)); + fprintf(output, "\n"); + #undef W + } + /* Per receiverXprimary results */ + FOR_EACH(i, 0, BUF_SZ(simul->rcvXprims)) { + struct rcvXprim* rXp = &BUF_AT(simul->rcvXprims, i); + struct rcv* rcv = find_receiver_by_id(simul, rXp->rcv_id); + struct prim* prim = find_primary_by_id(simul, rXp->prim_id); + fprintf(output, " Receiver `%s' X Primary `%s'\n", rcv->name, prim->name); + if(rXp->irradiance[FRONT].E >= 0) { + fprintf(output, "------------------[Front]-----------------------------------\n"); + print_rcvXprim_side(output, FRONT, rXp); + } + if(rXp->irradiance[BACK].SE >= 0) { + fprintf(output, "-------------------[Back]-----------------------------------\n"); + print_rcvXprim_side(output, BACK, rXp); + } + fprintf(output, "\n"); + } +} + +int +main(int argc, char** argv) +{ + char s[128]; + buf_char_T buf = BUF_NULL; + FILE* input = stdin; + char* line = NULL; + + if(argc > 1 && !(input = fopen(argv[1], "r"))) { + fprintf(stderr, "Could not open the file `%s'.\n", argv[1]); + return 1; + } + while((line = read_line(&buf, input))) { + struct simul simul; + FILE* output = NULL; + + if(strncmp(line, "#--- Sun direction:", 19)) continue; + + simul_init(&simul); + + CHK(!strncmp(line, "#--- Sun direction:", 19)); + CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", + &simul.azimuth, &simul.elevation)==2); + CHK(snprintf(s, sizeof(s), "%g-%g-raw-results.txt", + simul.azimuth, simul.elevation) < sizeof(s)); + read_simulation(&simul, input); + + printf("Write `%s'\n", s); + CHK(output = fopen(s, "w")); + print_simulation(output, &simul); + fclose(output); + + simul_release(&simul); + } + + BUF_RELEASE(buf); + if(input && input != stdin) fclose(input); + return 0; +} + diff --git a/src/solvtk.c b/src/solvtk.c @@ -1,338 +0,0 @@ -/* Copyright (C) |Meso|Star> 2017 - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. */ - -#include "solpp.h" - -struct mesh { - - BUF(double) coords; - BUF(size_t) ids; - BUF(size_t) entities; - BUF(size_t) ncells; - size_t voffset; -}; -static const struct mesh MESH_NULL = {BUF_NULL, BUF_NULL, BUF_NULL, BUF_NULL, 0}; - -static inline void -mesh_release(struct mesh* msh) -{ - BUF_RELEASE(msh->coords); - BUF_RELEASE(msh->ids); - BUF_RELEASE(msh->entities); - BUF_RELEASE(msh->ncells); - memset(msh, 0, sizeof(struct mesh)); -} - -static inline void -mesh_write_vtk(FILE* output, struct mesh* msh) -{ - size_t i, n; - - fprintf(output, "# vtk DataFile Version 2.0\n"); - fprintf(output, "Test\n"); - fprintf(output, "ASCII\n"); - fprintf(output, "DATASET POLYDATA\n"); - - n = BUF_SZ(msh->coords)/3; - fprintf(output, "POINTS %zu float\n", n); - FOR_EACH(i, 0, n) { - fprintf(output, "%g %g %g\n", - BUF_AT(msh->coords, i*3+0), - BUF_AT(msh->coords, i*3+1), - BUF_AT(msh->coords, i*3+2)); - } - n = BUF_SZ(msh->ids)/3; - fprintf(output, "POLYGONS %zu %zu\n", n, n*4); - FOR_EACH(i, 0, n) { - fprintf(output, "3 %zu %zu %zu\n", - BUF_AT(msh->ids, i*3+0), - BUF_AT(msh->ids, i*3+1), - BUF_AT(msh->ids, i*3+2)); - } -} - -static inline void -mesh_write_obj(FILE* output, struct mesh* msh) -{ - size_t i, n; - - n = BUF_SZ(msh->coords)/3; - FOR_EACH(i, 0, n) { - fprintf(output, "v %g %g %g\n", - BUF_AT(msh->coords, i*3+0), - BUF_AT(msh->coords, i*3+1), - BUF_AT(msh->coords, i*3+2)); - } - - n = BUF_SZ(msh->ids)/3; - FOR_EACH(i, 0, n) { - fprintf(output, "f %zu %zu %zu\n", - BUF_AT(msh->ids, i*3+0) + 1, - BUF_AT(msh->ids, i*3+1) + 1, - BUF_AT(msh->ids, i*3+2) + 1); - } -} - -static inline void -mesh_write_prim_data_vtk - (FILE* output, const struct mesh* msh, struct simul* simul) -{ - struct prim* prim; - struct rcvXprim* rcvXprim; - size_t ircv; - size_t iprim; - size_t icell; - size_t n; - - n = BUF_SZ(msh->ids) / 3; - fprintf(output, "CELL_DATA %zu\n", n); - - fprintf(output, "FIELD PrimaryData %zu\n", 2 + BUF_SZ(simul->rcvs)*8); - fprintf(output, "cos_factor 2 %zu float\n", n); - FOR_EACH(iprim, 0, BUF_SZ(msh->entities)) { - CHK(prim = find_primary_by_id(simul, BUF_AT(msh->entities, iprim))); - FOR_EACH(icell, 0, BUF_AT(msh->ncells, iprim)) { - fprintf(output, "%g %g\n", prim->cos_factor.E, prim->cos_factor.SE); - } - } - - fprintf(output, "shadow_loss 2 %zu float\n", n); - FOR_EACH(iprim, 0, BUF_SZ(msh->entities)) { - CHK(prim = find_primary_by_id(simul, BUF_AT(msh->entities, iprim))); - FOR_EACH(icell, 0, BUF_AT(msh->ncells, iprim)) { - fprintf(output, "%g %g\n", prim->shadow_loss.E, prim->shadow_loss.SE); - } - } - - #define WRITE(Side, Name) { \ - fprintf(output, "%s_"STR(Side)"_"STR(Name)" 2 %zu float\n", rcv->name, n); \ - FOR_EACH(iprim, 0, BUF_SZ(msh->entities)) { \ - CHK(rcvXprim = find_rcvXprim(simul,rcv->id,BUF_AT(msh->entities,iprim)));\ - FOR_EACH(icell, 0, BUF_AT(msh->ncells, iprim)) { \ - fprintf(output, "%g %g\n", \ - rcvXprim->Name[Side].E, \ - rcvXprim->Name[Side].SE); \ - } \ - } \ - } (void)0 - FOR_EACH(ircv, 0, BUF_SZ(simul->rcvs)) { - const struct rcv* rcv = &BUF_AT(simul->rcvs, ircv); - WRITE(FRONT, absorbed_irradiance); - WRITE(FRONT, irradiance); - WRITE(FRONT, reflectivity_loss); - WRITE(FRONT, absorptivity_loss); - WRITE(BACK, absorbed_irradiance); - WRITE(BACK, irradiance); - WRITE(BACK, reflectivity_loss); - WRITE(BACK, absorptivity_loss); - } - #undef WRITE -} - -static inline void -mesh_write_rcv_data_vtk - (FILE* output, const struct mesh* msh, struct simul* simul) -{ - struct rcv* rcv; - size_t ircv; - size_t icell; - size_t n; - - n = BUF_SZ(msh->ids)/3; - fprintf(output, "CELL_DATA %zu\n", n); - fprintf(output, "FIELD PrimaryData 12\n"); - - #define WRITE(Side, Name) { \ - fprintf(output, STR(Side)"_"STR(Name)" 2 %zu float\n", n); \ - FOR_EACH(ircv, 0, BUF_SZ(msh->entities)) { \ - CHK(rcv = find_receiver_by_id(simul, BUF_AT(msh->entities, ircv))); \ - FOR_EACH(icell, 0, BUF_AT(msh->ncells, ircv)) { \ - fprintf(output, "%g %g\n", rcv->Name[Side].E, rcv->Name[Side].SE); \ - } \ - } \ - } (void)0 - WRITE(FRONT, absorbed_irradiance); - WRITE(FRONT, irradiance); - WRITE(FRONT, reflectivity_loss); - WRITE(FRONT, absorptivity_loss); - WRITE(FRONT, efficiency); - WRITE(BACK, absorbed_irradiance); - WRITE(BACK, irradiance); - WRITE(BACK, reflectivity_loss); - WRITE(BACK, absorptivity_loss); - WRITE(BACK, efficiency); - #undef WRITE - - #define WRITE_MAP(Side) { \ - fprintf(output, STR(Side)"_map 2 %zu float\n", n); \ - FOR_EACH(ircv, 0, BUF_SZ(msh->entities)) { \ - CHK(rcv = find_receiver_by_id(simul, BUF_AT(msh->entities, ircv))); \ - if(!BUF_SZ(rcv->map[Side])) { \ - FOR_EACH(icell, 0, BUF_AT(msh->ncells,ircv)) fprintf(output,"-1 -1\n");\ - } else { \ - FOR_EACH(icell, 0, BUF_AT(msh->ncells,ircv)) { \ - const struct mc* mc = &BUF_AT(rcv->map[Side], icell); \ - fprintf(output, "%g %g\n", mc->E, mc->SE); \ - } \ - } \ - } \ - } (void)0 - WRITE_MAP(FRONT); - WRITE_MAP(BACK); - #undef WRITE_MAP -} - -int -main(int argc, char** argv) -{ - buf_char_T buf = BUF_NULL; - char* line = NULL; - - FILE* input; - FILE* geom; - FILE* output; - - if(argc < 3) { - fprintf(stderr, "Usage: %s solstice-geometry solstice-simulation\n", argv[0]); - return 1; - } - - CHK(geom = fopen(argv[1], "r")); - CHK(input = fopen(argv[2], "r")); - - CHK(read_line(&buf, geom)); /* Skip the sun direction of the geometry */ - while((line = read_line(&buf, input))) { - struct simul simul; - - const struct rcv* rcv = NULL; - const struct prim* prim = NULL; - - struct mesh msh_rcv = MESH_NULL; - struct mesh msh_prim = MESH_NULL; - struct mesh msh_misc = MESH_NULL; - - char filename[128]; - char prefix[64]; - size_t ntris_grp = 0, nverts_grp = 0; - size_t nverts_obj = 0, off_obj = 0, off_grp = 0; - - simul_init(&simul); - - CHK(!strncmp(line, "#--- Sun direction:", 19)); - CHK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &simul.azimuth, &simul.elevation)==2); - CHK(snprintf(prefix, sizeof(prefix), "%g-%g-", - simul.azimuth, simul.elevation) < sizeof(prefix)); - read_simulation(&simul, input); - - while((line = read_line(&buf, geom)) && strncmp(line, "#--- Sun", 8)) { - if(!strncmp(line, "g ", 2)) { - if(prim) { - BUF_PUSH(msh_prim.ncells, ntris_grp); - msh_prim.voffset += nverts_grp; - } - if(rcv) { - BUF_PUSH(msh_rcv.ncells, ntris_grp); - msh_rcv.voffset += nverts_grp; - } - if(!prim && !rcv) msh_misc.voffset += nverts_grp; - prim = find_primary(&simul, line+2); - rcv = find_receiver(&simul, line+2); - if(prim) BUF_PUSH(msh_prim.entities, prim->id); - if(rcv) BUF_PUSH(msh_rcv.entities, rcv->id); - ntris_grp = 0; - nverts_grp = 0; - off_grp = 0; - off_obj = nverts_obj; - - } else if(!strncmp(line, "v ", 2)) { - double pos[3]; - CHK(sscanf(line+2, "%lf %lf %lf", pos+0, pos+1, pos+2) == 3); - if(prim) { - BUF_PUSH(msh_prim.coords, pos[0]); - BUF_PUSH(msh_prim.coords, pos[1]); - BUF_PUSH(msh_prim.coords, pos[2]); - } - if(rcv) { - BUF_PUSH(msh_rcv.coords, pos[0]); - BUF_PUSH(msh_rcv.coords, pos[1]); - BUF_PUSH(msh_rcv.coords, pos[2]); - } - if(!prim && !rcv) { - BUF_PUSH(msh_misc.coords, pos[0]); - BUF_PUSH(msh_misc.coords, pos[1]); - BUF_PUSH(msh_misc.coords, pos[2]); - } - ++nverts_grp; - ++nverts_obj; - } else if(!strncmp(line, "f ", 2)) { - size_t tri[3]; - CHK(sscanf(line+2, "%zu %zu %zu", tri+0, tri+1, tri+2) == 3); - if(prim) { - BUF_PUSH(msh_prim.ids, tri[0]-1 + msh_prim.voffset + off_grp - off_obj); - BUF_PUSH(msh_prim.ids, tri[1]-1 + msh_prim.voffset + off_grp - off_obj); - BUF_PUSH(msh_prim.ids, tri[2]-1 + msh_prim.voffset + off_grp - off_obj); - } - if(rcv) { - BUF_PUSH(msh_rcv.ids, tri[0]-1 + msh_rcv.voffset + off_grp - off_obj); - BUF_PUSH(msh_rcv.ids, tri[1]-1 + msh_rcv.voffset + off_grp - off_obj); - BUF_PUSH(msh_rcv.ids, tri[2]-1 + msh_rcv.voffset + off_grp - off_obj); - } - if(!prim && !rcv) { - BUF_PUSH(msh_misc.ids, tri[0]-1 + msh_misc.voffset + off_grp - off_obj); - BUF_PUSH(msh_misc.ids, tri[1]-1 + msh_misc.voffset + off_grp - off_obj); - BUF_PUSH(msh_misc.ids, tri[2]-1 + msh_misc.voffset + off_grp - off_obj); - } - ++ntris_grp; - } else if(!strcmp(line, "---")) { - nverts_obj = 0; - off_obj = 0; - off_grp = nverts_grp; - } - } - if(prim) BUF_PUSH(msh_prim.ncells, ntris_grp); - if(rcv) BUF_PUSH(msh_rcv.ncells, ntris_grp); - - CHK(snprintf(filename, sizeof(filename), - "%sprimaries.vtk", prefix) < sizeof(prefix)); - CHK(output = fopen(filename, "w")); - mesh_write_vtk(output, &msh_prim); - mesh_write_prim_data_vtk(output, &msh_prim, &simul); - fclose(output); - - CHK(snprintf(filename, sizeof(filename), - "%sreceivers.vtk", prefix) < sizeof(prefix)); - CHK(output = fopen(filename, "w")); - mesh_write_vtk(output, &msh_rcv); - mesh_write_rcv_data_vtk(output, &msh_rcv, &simul); - fclose(output); - - CHK(snprintf(filename, sizeof(filename), - "%smiscellaneous.obj", prefix) < sizeof(prefix)); - CHK(output = fopen(filename, "w")); - mesh_write_obj(output, &msh_misc); - fclose(output); - - mesh_release(&msh_prim); - mesh_release(&msh_rcv); - mesh_release(&msh_misc); - simul_release(&simul); - } - - fclose(geom); - fclose(input); - BUF_RELEASE(buf); - return 0; -} -