Add VTK output for sequential case

This commit is contained in:
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 "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)
{
double timeStart, timeStop;
@@ -84,6 +134,7 @@ int main(int argc, char** argv)
wg = allocate(64, bytesize);
}
#ifdef _MPI
commCollectResult(&s.comm,
ug,
vg,
@@ -96,12 +147,17 @@ int main(int argc, char** argv)
s.grid.kmax,
s.grid.jmax,
s.grid.imax);
#else
createBulkArrays(&s, pg, ug, vg, wg);
#endif /* ifdef _MPI */
VtkOptions opts = { .grid = s.grid, .comm = s.comm };
vtkOpen(&opts, s.problem);
vtkScalar(&opts, "pressure", pg);
vtkVector(&opts, "velocity", (VtkVector) { ug, vg, wg });
vtkClose(&opts);
if (commIsMaster(&s.comm)) {
VtkOptions opts = { .grid = s.grid };
vtkOpen(&opts, s.problem);
vtkScalar(&opts, "pressure", pg);
vtkVector(&opts, "velocity", (VtkVector) { ug, vg, wg });
vtkClose(&opts);
}
commFinalize(&s.comm);
return EXIT_SUCCESS;