commit 723efee851af8446b2dc60c6cf2455a58dce779f
parent 2faf127e492e71f633c517df081d5ac616100bfb
Author: Benjamin Piaud <benjamin.piaud@meso-star.com>
Date: Thu, 26 Apr 2018 14:30:36 +0200
ajout de la fonction dump_vtk et de l'option -d pour appeler dump_vtk à la place de compute
Diffstat:
4 files changed, 83 insertions(+), 9 deletions(-)
diff --git a/src/args.h b/src/args.h
@@ -7,11 +7,10 @@
#include <rsys/rsys.h>
#include <rsys/cstr.h>
-static void
-print_help(char* prog)
-{
- printf("usage %s -m MEDIUM.txt -b BOUNDARY.txt [-p X:Y:Z:TIME] [-n NUM_OF_REALIZATIONS] [-t NUM_OF_THREADS]\n", prog);
-}
+enum stardis_mode{
+ PROBE_COMPUTE,
+ DUMP_VTK
+};
struct args{
char* medium_filename;
@@ -19,8 +18,16 @@ struct args{
size_t N;
unsigned nthreads;
double probe[4];
+ enum stardis_mode mode;
};
-#define ARGS_DEFAULT {NULL, NULL, 10000, SDIS_NTHREADS_DEFAULT, {0,0,0,INF}}
+#define ARGS_DEFAULT__ {NULL, NULL, 10000, SDIS_NTHREADS_DEFAULT, {0,0,0,INF}, PROBE_COMPUTE}
+static const struct args ARGS_DEFAULT = ARGS_DEFAULT__;
+
+static void
+print_help(char* prog)
+{
+ printf("usage %s -m MEDIUM.txt -b BOUNDARY.txt [-p X:Y:Z:TIME] [-d] [-n NUM_OF_REALIZATIONS] [-t NUM_OF_THREADS]\n", prog);
+}
static res_T
parse_args(const int argc, char** argv, struct args* args)
@@ -35,7 +42,7 @@ parse_args(const int argc, char** argv, struct args* args)
goto error;
}
- while((opt = getopt(argc, argv, "hn:t:b:m:p:")) != -1) {
+ while((opt = getopt(argc, argv, "hn:t:b:m:p:d")) != -1) {
switch(opt) {
case 'h':
print_help(argv[0]);
@@ -75,6 +82,9 @@ parse_args(const int argc, char** argv, struct args* args)
goto error;
}
break;
+ case 'd':
+ args->mode = DUMP_VTK;
+ break;
}
}
diff --git a/src/main.c b/src/main.c
@@ -53,6 +53,12 @@ int main(int argc, char** argv){
res = stardis_init(&args, &stardis);
if (res != RES_OK) goto error;
+ if (args.mode == DUMP_VTK){
+ res = dump_vtk(stdout, &stardis.geometry, stardis.geometry.boundary_count);
+ if (res != RES_OK) goto error;
+ goto exit;
+ }
+
res = stardis_compute(&stardis);
if (res != RES_OK) goto error;
diff --git a/src/stardis-app.c b/src/stardis-app.c
@@ -348,8 +348,10 @@ stardis_init
stardis->probe[2] = args->probe[2];
stardis->probe[3] = args->probe[3];
- res = check_consistency(stardis->boundary, stardis->probe);
- if (res != RES_OK) goto error;
+ if (args->mode == PROBE_COMPUTE){
+ res = check_consistency(stardis->boundary, stardis->probe);
+ if (res != RES_OK) goto error;
+ }
exit:
return res;
@@ -372,3 +374,55 @@ exit:
error:
goto exit;
}
+
+
+res_T
+dump_vtk
+(FILE* output,
+ const struct geometry* geometry,
+ int nbound)
+{
+ res_T res = RES_OK;
+ int i,j = 0;
+ struct vertex* vtx = geometry->vertex;
+ struct triangle* tri = geometry->triangle;
+
+ if (!output){
+ fprintf(stderr, "Invalid output file to dump vtk.\n");
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+ fprintf(output,"# vtk DataFile Version 2.0\nvtk output\nASCII\nDATASET POLYDATA\n");
+ fprintf(output,"POINTS %i float\n\n", sa_size(vtx));
+ for (i=0; i<sa_size(vtx); ++i){
+ fprintf(output,"%f %f %f\n",SPLIT3(vtx[i].xyz));
+ }
+ fprintf(output,"\nPOLYGONS %i %i\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));
+ }
+ fprintf(output,"\nCELL_DATA %i \n", sa_size(tri));
+ fprintf(output,"SCALARS medium_front float 1\n");
+ fprintf(output,"LOOKUP_TABLE default\n");
+ for (i=0; i<sa_size(tri); ++i){
+ fprintf(output,"%i\n",tri[i].medium_front);
+ }
+ fprintf(output,"SCALARS medium_back float 1\n");
+ fprintf(output,"LOOKUP_TABLE default\n");
+ for (i=0; i<sa_size(tri); ++i){
+ fprintf(output,"%i\n",tri[i].medium_back);
+ }
+ for (j=0; j<nbound; ++j){
+ fprintf(output,"SCALARS bound_id float 1\n");
+ fprintf(output,"LOOKUP_TABLE default\n");
+ for (i=0; i<sa_size(tri); ++i){
+ fprintf(output,"%i\n",tri[i].bound_id);
+ }
+ }
+
+exit:
+ return res;
+error:
+ goto exit;
+}
diff --git a/src/stardis-app.h b/src/stardis-app.h
@@ -106,6 +106,7 @@ struct boundary{
#define NULL_BOUNDARY__ {-1, NULL}
static const struct boundary NULL_BOUNDARY = NULL_BOUNDARY__;
+
struct stardis{
struct geometry geometry;
struct material* material; /*array of materials*/
@@ -129,4 +130,7 @@ stardis_compute(struct stardis* stardis);
extern res_T
stardis_release(struct stardis* stardis);
+extern res_T
+dump_vtk(FILE* output, const struct geometry* geometry, int nbound);
+
#endif /*STARDIS-APP_H*/