commit 83af9caaea454c554f23d165bfe578950364ec84
parent aff12ec445b19c0effbcaed0e5b462b72d691602
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 26 Jul 2017 16:00:18 +0200
Handle the split=object -g suboption in solvtk
Add the sun direction as prefix of the output files
Diffstat:
2 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -16,10 +16,10 @@
STAR_ENGINE=/home/moi/code/star-engine-solstice/local
NEXPERIMENTS=1000000
NPATHS=1000
-SUN_DIRS=270,45
+SUN_DIRS=290,30
RCV_FILE=themis-rcv.yaml
-CFLAGS = -g -std=c99 -pedantic -Wall
+CFLAGS = -O2 -std=c99 -pedantic -Wall
SCRIPT = themis.c solsplit.c solpp.c solvtk.c
PROG = $(SCRIPT:%.c=%)
PATH := $(PATH):$(STAR_ENGINE)/bin:.
@@ -34,7 +34,7 @@ input: $(PROG)
.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=none -fo geom
+ themis | solstice -D$(SUN_DIRS) -qg format=obj:split=geometry -fo geom
solvtk geom simul
.PHONY: clean
diff --git a/src/solvtk.c b/src/solvtk.c
@@ -25,6 +25,7 @@ struct mesh {
size_t* entities;
size_t* ncells;
size_t voffset;
+ size_t off;
};
static const struct mesh MESH_NULL = {NULL, NULL, NULL, NULL, 0};
@@ -209,11 +210,13 @@ main(int argc, char** argv)
const struct rcv* rcv = NULL;
const struct prim* prim = NULL;
+ char filename[128];
+ char prefix[64];
char* line = NULL;
char* buf = NULL;
char* str = NULL;
size_t ntris_grp = 0, nverts_grp = 0;
- size_t nverts_obj = 0, offset_obj = 0;
+ size_t nverts_obj = 0, off_obj = 0, off_grp = 0;
float azim, elev;
int err = 0;
@@ -229,20 +232,27 @@ main(int argc, char** argv)
NCHECK(line = read_line(&buf, input), NULL);
CHECK(strncmp(line, "#--- Sun direction:", 19), 0);
CHECK(sscanf(line+19, "%lf %lf (%*f %*f %*f)", &simul.azimuth, &simul.elevation), 2);
+ CHECK(snprintf(prefix, sizeof(prefix), "%g-%g-",
+ simul.azimuth, simul.elevation) < sizeof(prefix), 1);
read_simulation(&simul, input);
fclose(input);
NCHECK(input = fopen(argv[1], "r"), NULL);
while((line = read_line(&buf, input))) {
if(!strcmp(line, "#--- No Sun direction")) {
- azim = elev = -1;
+ FATAL("Unexpected geometry file with no sun direction\n");
} else if(!strncmp(line, "#--- Sun direction:", 19)) {
CHECK(sscanf(line+19, "%f %f (%*f %*f %*f)", &azim, &elev), 2);
+ if(azim != simul.azimuth || elev != simul.elevation) {
+ FATAL("The geometry is not consistent with the the simulation.\n");
+ }
+
} else if(!strncmp(line, "g ", 2)) {
CHECK(str_set(&name, line+2), RES_OK);
if(prim) {
sa_push(msh_prim.ncells, ntris_grp);
msh_prim.voffset += nverts_grp;
+ msh_prim.off = 0;
}
if(rcv) {
sa_push(msh_rcv.ncells, ntris_grp);
@@ -255,7 +265,8 @@ main(int argc, char** argv)
if(rcv) sa_push(msh_rcv.entities, rcv->id);
ntris_grp = 0;
nverts_grp = 0;
- offset_obj = nverts_obj;
+ off_grp = 0;
+ off_obj = nverts_obj;
} else if(!strncmp(line, "v ", 2)) {
double pos[3];
@@ -281,40 +292,48 @@ main(int argc, char** argv)
size_t tri[3];
CHECK(sscanf(line+2, "%zu %zu %zu", tri+0, tri+1, tri+2), 3);
if(prim) {
- sa_push(msh_prim.ids, tri[0] - 1 + msh_prim.voffset - offset_obj);
- sa_push(msh_prim.ids, tri[1] - 1 + msh_prim.voffset - offset_obj);
- sa_push(msh_prim.ids, tri[2] - 1 + msh_prim.voffset - offset_obj);
+ sa_push(msh_prim.ids, tri[0]-1 + msh_prim.voffset + off_grp - off_obj);
+ sa_push(msh_prim.ids, tri[1]-1 + msh_prim.voffset + off_grp - off_obj);
+ sa_push(msh_prim.ids, tri[2]-1 + msh_prim.voffset + off_grp - off_obj);
}
if(rcv) {
- sa_push(msh_rcv.ids, tri[0] - 1 + msh_rcv.voffset - offset_obj);
- sa_push(msh_rcv.ids, tri[1] - 1 + msh_rcv.voffset - offset_obj);
- sa_push(msh_rcv.ids, tri[2] - 1 + msh_rcv.voffset - offset_obj);
+ sa_push(msh_rcv.ids, tri[0]-1 + msh_rcv.voffset + off_grp - off_obj);
+ sa_push(msh_rcv.ids, tri[1]-1 + msh_rcv.voffset + off_grp - off_obj);
+ sa_push(msh_rcv.ids, tri[2]-1 + msh_rcv.voffset + off_grp - off_obj);
}
if(!prim && !rcv) {
- sa_push(msh_misc.ids, tri[0] - 1 + msh_misc.voffset - offset_obj);
- sa_push(msh_misc.ids, tri[1] - 1 + msh_misc.voffset - offset_obj);
- sa_push(msh_misc.ids, tri[2] - 1 + msh_misc.voffset - offset_obj);
+ sa_push(msh_misc.ids, tri[0]-1 + msh_misc.voffset + off_grp - off_obj);
+ sa_push(msh_misc.ids, tri[1]-1 + msh_misc.voffset + off_grp - off_obj);
+ sa_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) sa_push(msh_prim.ncells, ntris_grp);
if(rcv) sa_push(msh_rcv.ncells, ntris_grp);
fclose(input);
- NCHECK(output = fopen("primaries.vtk", "w"), NULL);
+ CHECK(snprintf(filename, sizeof(filename),
+ "%sprimaries.vtk", prefix) < sizeof(prefix), 1);
+ NCHECK(output = fopen(filename, "w"), NULL);
mesh_write_vtk(output, &msh_prim);
mesh_write_prim_data_vtk(output, &msh_prim, &simul);
fclose(output);
- NCHECK(output = fopen("receivers.vtk", "w"), NULL);
+ CHECK(snprintf(filename, sizeof(filename),
+ "%sreceivers.vtk", prefix) < sizeof(prefix), 1);
+ NCHECK(output = fopen(filename, "w"), NULL);
mesh_write_vtk(output, &msh_rcv);
mesh_write_rcv_data_vtk(output, &msh_rcv, &simul);
fclose(output);
- NCHECK(output = fopen("miscellaneous.obj", "w"), NULL);
+ CHECK(snprintf(filename, sizeof(filename),
+ "%smiscellaneous.obj", prefix) < sizeof(prefix), 1);
+ NCHECK(output = fopen(filename, "w"), NULL);
mesh_write_obj(output, &msh_misc);
fclose(output);
@@ -330,3 +349,4 @@ exit:
error:
goto exit;
}
+