Add VTK output for sequential case

This commit is contained in:
Jan Eitzinger 2024-01-09 14:36:42 +00:00
parent 5b50590faf
commit 1fcddc91b7
3 changed files with 76 additions and 46 deletions

View File

@ -18,6 +18,56 @@
#include "timing.h" #include "timing.h"
#include "vtkWriter.h" #include "vtkWriter.h"
#ifndef _MPI
#define G(v, i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
static void createBulkArrays(Solver* s, double* pg, double* ug, double* vg, double* wg)
{
int imax = s->grid.imax;
int jmax = s->grid.jmax;
int kmax = s->grid.kmax;
int idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
pg[idx++] = G(s->p, i, j, k);
}
}
}
idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
ug[idx++] = (G(s->u, i, j, k) + G(s->u, i - 1, j, k)) / 2.0;
}
}
}
idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
vg[idx++] = (G(s->v, i, j, k) + G(s->v, i, j - 1, k)) / 2.0;
}
}
}
idx = 0;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
wg[idx++] = (G(s->w, i, j, k) + G(s->w, i, j, k - 1)) / 2.0;
}
}
}
}
#endif /* ifndef _MPI */
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
double timeStart, timeStop; double timeStart, timeStop;
@ -84,6 +134,7 @@ int main(int argc, char** argv)
wg = allocate(64, bytesize); wg = allocate(64, bytesize);
} }
#ifdef _MPI
commCollectResult(&s.comm, commCollectResult(&s.comm,
ug, ug,
vg, vg,
@ -96,12 +147,17 @@ int main(int argc, char** argv)
s.grid.kmax, s.grid.kmax,
s.grid.jmax, s.grid.jmax,
s.grid.imax); s.grid.imax);
#else
createBulkArrays(&s, pg, ug, vg, wg);
#endif /* ifdef _MPI */
VtkOptions opts = { .grid = s.grid, .comm = s.comm }; if (commIsMaster(&s.comm)) {
VtkOptions opts = { .grid = s.grid };
vtkOpen(&opts, s.problem); vtkOpen(&opts, s.problem);
vtkScalar(&opts, "pressure", pg); vtkScalar(&opts, "pressure", pg);
vtkVector(&opts, "velocity", (VtkVector) { ug, vg, wg }); vtkVector(&opts, "velocity", (VtkVector) { ug, vg, wg });
vtkClose(&opts); vtkClose(&opts);
}
commFinalize(&s.comm); commFinalize(&s.comm);
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -55,16 +55,11 @@ void vtkOpen(VtkOptions* o, char* problem)
{ {
char filename[50]; char filename[50];
if (o->mode == UNIX) { snprintf(filename, 50, "%s.vtk", problem);
if (commIsMaster(&o->comm)) {
snprintf(filename, 50, "%s-p%d.vtk", problem, o->comm.size);
o->fh = fopen(filename, "w"); o->fh = fopen(filename, "w");
writeHeader(o); writeHeader(o);
}
} else if (o->mode == MPI) {
}
if (commIsMaster(&o->comm)) printf("Writing VTK output for %s\n", problem); printf("Writing VTK output for %s\n", problem);
} }
static void writeScalar(VtkOptions* o, double* s) static void writeScalar(VtkOptions* o, double* s)
@ -101,17 +96,11 @@ static bool isInitialized(FILE* ptr)
void vtkScalar(VtkOptions* o, char* name, double* s) void vtkScalar(VtkOptions* o, char* name, double* s)
{ {
if (commIsMaster(&o->comm)) printf("Register scalar %s\n", name); printf("Register scalar %s\n", name);
if (o->mode == UNIX) {
if (commIsMaster(&o->comm)) {
if (!isInitialized(o->fh)) return; if (!isInitialized(o->fh)) return;
fprintf(o->fh, "SCALARS %s double 1\n", name); fprintf(o->fh, "SCALARS %s double 1\n", name);
fprintf(o->fh, "LOOKUP_TABLE default\n"); fprintf(o->fh, "LOOKUP_TABLE default\n");
writeScalar(o, s); writeScalar(o, s);
}
} else if (o->mode == MPI) {
}
} }
static void writeVector(VtkOptions* o, VtkVector vec) static void writeVector(VtkOptions* o, VtkVector vec)
@ -145,25 +134,14 @@ static void writeVector(VtkOptions* o, VtkVector vec)
void vtkVector(VtkOptions* o, char* name, VtkVector vec) void vtkVector(VtkOptions* o, char* name, VtkVector vec)
{ {
if (commIsMaster(&o->comm)) printf("Register vector %s\n", name); printf("Register vector %s\n", name);
if (o->mode == UNIX) {
if (commIsMaster(&o->comm)) {
if (!isInitialized(o->fh)) return; if (!isInitialized(o->fh)) return;
fprintf(o->fh, "VECTORS %s double\n", name); fprintf(o->fh, "VECTORS %s double\n", name);
writeVector(o, vec); writeVector(o, vec);
}
} else if (o->mode == MPI) {
}
} }
void vtkClose(VtkOptions* o) void vtkClose(VtkOptions* o)
{ {
if (o->mode == UNIX) {
if (commIsMaster(&o->comm)) {
fclose(o->fh); fclose(o->fh);
o->fh = NULL; o->fh = NULL;
}
} else if (o->mode == MPI) {
}
} }

View File

@ -8,18 +8,14 @@
#define __VTKWRITER_H_ #define __VTKWRITER_H_
#include <stdio.h> #include <stdio.h>
#include "comm.h"
#include "grid.h" #include "grid.h"
typedef enum VtkFormat { ASCII = 0, BINARY } VtkFormat; typedef enum VtkFormat { ASCII = 0, BINARY } VtkFormat;
typedef enum VtkMode { UNIX = 0, MPI } VtkMode;
typedef struct VtkOptions { typedef struct VtkOptions {
VtkFormat fmt; VtkFormat fmt;
VtkMode mode;
Grid grid; Grid grid;
FILE* fh; FILE* fh;
Comm comm;
} VtkOptions; } VtkOptions;
typedef struct VtkVector { typedef struct VtkVector {