diff --git a/BasicSolver/2D-seq/Makefile b/BasicSolver/2D-seq/Makefile index 2b144a6..f909c04 100644 --- a/BasicSolver/2D-seq/Makefile +++ b/BasicSolver/2D-seq/Makefile @@ -39,11 +39,9 @@ $(BUILD_DIR)/%.s: %.c .PHONY: clean distclean tags info asm format -clean: +clean: viz $(info ===> CLEAN) @rm -rf $(BUILD_DIR) - @rm -f vtk_files/particle*.vtk - @rm -f vis_files/particle*.dat @rm -f tags distclean: clean diff --git a/BasicSolver/2D-seq/src/vtkWriter.c b/BasicSolver/2D-seq/src/vtkWriter.c new file mode 100644 index 0000000..5a7cdbf --- /dev/null +++ b/BasicSolver/2D-seq/src/vtkWriter.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2022 NHR@FAU, University Erlangen-Nuremberg. + * All rights reserved. This file is part of nusif-solver. + * Use of this source code is governed by a MIT style + * license that can be found in the LICENSE file. + */ +#include +#include +#include + +#include "vtkWriter.h" + +static float floatSwap(float f) +{ + union { + float f; + char b[4]; + } dat1, dat2; + + dat1.f = f; + dat2.b[0] = dat1.b[3]; + dat2.b[1] = dat1.b[2]; + dat2.b[2] = dat1.b[1]; + dat2.b[3] = dat1.b[0]; + return dat2.f; +} + +static void writeHeader(VtkOptions* o, int ts) +{ + fprintf(o->fh, "# vtk DataFile Version 3.0\n"); + fprintf(o->fh, "PAMPI cfd solver particle tracing file\n"); + if (o->fmt == ASCII) { + fprintf(o->fh, "ASCII\n"); + } else if (o->fmt == BINARY) { + fprintf(o->fh, "BINARY\n"); + } + + fprintf(o->fh, "DATASET UNSTRUCTURED_GRID\n"); + fprintf(o->fh, "FIELD FieldData 2\n"); + fprintf(o->fh, "TIME 1 1 double\n"); + fprintf(o->fh, "%d\n", ts); + fprintf(o->fh, "CYCLE 1 1 int\n"); + fprintf(o->fh, "1\n"); +} + +void vtkOpen(VtkOptions* o, char* problem, int ts) +{ + o->fh = fopen(problem, "w"); + + if (o->fh == NULL) { + printf("vtkWriter not initialize! Call vtkOpen first!\n"); + exit(EXIT_FAILURE); + } + + writeHeader(o, ts); + + printf("Writing VTK output for %s\n", problem); +} + +void vtkParticle(VtkOptions* o, char* name) +{ + Particle* particlePool = o->particletracer->particlePool; + + int imax = o->solver->imax; + int jmax = o->solver->jmax; + + if (o->fh == NULL) { + printf("vtkWriter not initialize! Call vtkOpen first!\n"); + exit(EXIT_FAILURE); + } + + fprintf(o->fh, "POINTS %s float\n", o->particletracer->totalParticles); + + + for (int i = 0; i < o->particletracer->totalParticles; ++i) + { + if(particlePool[i].flag == true) + { + double x = particlePool[i].x; + double y = particlePool[i].y; + fprintf(o->fh, "%.2f %.2f 0.0\n", x, y); + } + } + + fprintf(o->fh, "CELLS %.0f float\n", o->particletracer->totalParticles); + + + for (int i = 0, j = 0; i < o->particletracer->totalParticles; ++i) + { + if(particlePool[i].flag == true) + { + fprintf(o->fh, "1 %d\n", j); + ++j; + } + } + + fprintf(o->fh, "CELL_TYPES %.0f\n", o->particletracer->totalParticles); + + + for (int i = 0; i < o->particletracer->totalParticles; ++i) + { + if(particlePool[i].flag == true) + { + fprintf(o->fh, "1\n"); + } + } + + /* + for (int k = 0; k < kmax; k++) { + for (int j = 0; j < jmax; j++) { + for (int i = 0; i < imax; i++) { + if (o->fmt == ASCII) { + fprintf(o->fh, + "%f %f %f\n", + G(vec.u, i, j, k), + G(vec.v, i, j, k), + G(vec.w, i, j, k)); + } else if (o->fmt == BINARY) { + fwrite((float[3]) { floatSwap(G(vec.u, i, j, k)), + floatSwap(G(vec.v, i, j, k)), + floatSwap(G(vec.w, i, j, k)) }, + sizeof(float), + 3, + o->fh); + } + } + } + } + if (o->fmt == BINARY) fprintf(o->fh, "\n"); + + */ +} + +void vtkClose(VtkOptions* o) +{ + fclose(o->fh); + o->fh = NULL; +} diff --git a/BasicSolver/2D-seq/particlePool b/BasicSolver/2D-seq/vis_files/particles_0.dat similarity index 100% rename from BasicSolver/2D-seq/particlePool rename to BasicSolver/2D-seq/vis_files/particles_0.dat diff --git a/BasicSolver/2D-seq/vis_files/particles_1.dat b/BasicSolver/2D-seq/vis_files/particles_1.dat new file mode 100644 index 0000000..e69de29 diff --git a/BasicSolver/2D-seq/vis_files/particles_2.dat b/BasicSolver/2D-seq/vis_files/particles_2.dat new file mode 100644 index 0000000..e69de29 diff --git a/BasicSolver/2D-seq/vtk_files/particles0.vtk b/BasicSolver/2D-seq/vtk_files/particles0.vtk new file mode 100644 index 0000000..a5c8cbd --- /dev/null +++ b/BasicSolver/2D-seq/vtk_files/particles0.vtk @@ -0,0 +1,12 @@ +# vtk DataFile Version 3.0 +PAMPI cfd solver particle tracing file +ASCII +DATASET UNSTRUCTURED_GRID +FIELD FieldData 2 +TIME 1 1 double +0 +CYCLE 1 1 int +1 +POINTS (null) float +CELLS 0 float +CELL_TYPES 0 diff --git a/BasicSolver/2D-seq/vtk_files/particles1.vtk b/BasicSolver/2D-seq/vtk_files/particles1.vtk new file mode 100644 index 0000000..a9ca353 --- /dev/null +++ b/BasicSolver/2D-seq/vtk_files/particles1.vtk @@ -0,0 +1,12 @@ +# vtk DataFile Version 3.0 +PAMPI cfd solver particle tracing file +ASCII +DATASET UNSTRUCTURED_GRID +FIELD FieldData 2 +TIME 1 1 double +1 +CYCLE 1 1 int +1 +POINTS (null) float +CELLS 0 float +CELL_TYPES 0 diff --git a/BasicSolver/2D-seq/vtk_files/particles2.vtk b/BasicSolver/2D-seq/vtk_files/particles2.vtk new file mode 100644 index 0000000..b08ca9e --- /dev/null +++ b/BasicSolver/2D-seq/vtk_files/particles2.vtk @@ -0,0 +1,12 @@ +# vtk DataFile Version 3.0 +PAMPI cfd solver particle tracing file +ASCII +DATASET UNSTRUCTURED_GRID +FIELD FieldData 2 +TIME 1 1 double +2 +CYCLE 1 1 int +1 +POINTS (null) float +CELLS 0 float +CELL_TYPES 0 diff --git a/BasicSolver/2D-seq/vtk_files/particles3.vtk b/BasicSolver/2D-seq/vtk_files/particles3.vtk new file mode 100644 index 0000000..e69de29