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 125de52f3b847bb10a3f04bd0b9fe0d8bb19380a
parent 554134654ba0c98402492fe1bad6144024d1010e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 27 Jul 2017 11:02:18 +0200

Add the solpath program

Split the submitted VTK-RADIATIVE-PATHS output in several VTK files, one
per sun direction.

Diffstat:
Msrc/Makefile | 43+++++++++++++++++++++++++++----------------
Asrc/solpath.c | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 93 insertions(+), 16 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -14,36 +14,47 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. STAR_ENGINE=/home/moi/code/star-engine-solstice/local -NEXPERIMENTS=1000000 -NPATHS=1000 +NEXPERIMENTS=100000 +NPATHS=100 SUN_DIRS=270,45:290,30:160,60 -RCV_FILE=themis-rcv.yaml + +RCV=themis-rcv.yaml +INPUT=themis.yaml +GEOM=geom +SIMUL=simul CFLAGS = -O2 -std=c99 -pedantic -Wall -SCRIPT = themis.c solsplit.c solpp.c solvtk.c +SCRIPT = themis.c solsplit.c solpp.c solvtk.c solpath.c PROG = $(SCRIPT:%.c=%) PATH := $(PATH):$(STAR_ENGINE)/bin:. .PHONY: all all: $(PROG) -.PHONY: input -input: $(PROG) - @./themis +.PHONY: receiver +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) + +.PHONY: paths +paths: $(PROG) $(INPUT) receiver + solstice -D$(SUN_DIRS) -q -n$(NPATHS) -R$(RCV) -p default $(INPUT) | solpath .PHONY: run -run: $(PROG) receiver - themis | solstice -D$(SUN_DIRS) -q -n$(NEXPERIMENTS) -R $(RCV_FILE) -fo simul - themis | solstice -D$(SUN_DIRS) -qg format=obj:split=geometry -fo geom - solvtk geom simul +run: paths simul .PHONY: clean clean: - rm -rf $(PROG) themis*.yaml *.obj *.vtk *simulation*.txt *map*.txt - -.PHONY: receiver -receiver: - @echo "- {name: target, side: BACK, per_primitive: 1}" > $(RCV_FILE) + rm -rf $(PROG) $(INPUT) $(GEOM) $(SIMUL) $(RCV) *.obj *.vtk *simulation*.txt $(PROG): %: %.c solpp.h $(CC) -o $@ $(CFLAGS) $< -I$(STAR_ENGINE)/include -L$(STAR_ENGINE)/lib -lrsys + +$(INPUT): $(PROG) + themis > $@ + diff --git a/src/solpath.c b/src/solpath.c @@ -0,0 +1,66 @@ +/* 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 <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define CHK(Cond) if(!(Cond)) \ + {fprintf(stderr, "error:%s:%d\n", __FILE__, __LINE__); abort();} (void)0 + +struct buf { char* mem; size_t sz; }; + +static char* +read_line(struct buf* b, FILE* stream) +{ + if(!b->sz) b->mem = malloc((b->sz=32)); + if(!fgets(b->mem, (int)b->sz, stream)) return NULL; + while(!strrchr(b->mem, '\n') && !feof(stream)) { + b->mem = realloc(b->mem, (b->sz*=2)); + CHK(fgets(b->mem+strlen(b->mem), (int)(b->sz-strlen(b->mem)), stream)); + } + return b->mem; +} + +int +main(int argc, char** argv) +{ + char s[128]; + struct buf buf = {NULL, 0}; + 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); + CHK(fwrite(line, strlen(line), 1, output) == 1); + } 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")); + } + } + if(buf.mem) free(buf.mem); + if(output) fclose(output); + return 0; +}