EnhancedSolver port complete

This commit is contained in:
2024-07-27 02:19:56 +02:00
parent 8091c714e2
commit d81313f293
199 changed files with 16030 additions and 310 deletions

View File

@@ -9,7 +9,7 @@
#include <unistd.h>
#include "allocate.h"
#include "comm.h"
#include "discretization.h"
#include "parameter.h"
#include "progress.h"
#include "solver.h"
@@ -21,9 +21,12 @@ int main(int argc, char** argv)
double timeStart, timeStop;
Parameter p;
Solver s;
Discretization d;
commInit(&s.comm, argc, argv);
commInit(&d.comm, argc, argv);
initParameter(&p);
FILE* fp;
if (commIsMaster(&d.comm)) fp = initResidualWriter();
if (argc != 2) {
printf("Usage: %s <configFile>\n", argv[0]);
@@ -31,33 +34,44 @@ int main(int argc, char** argv)
}
readParameter(&p, argv[1]);
commPartition(&s.comm, p.kmax, p.jmax, p.imax);
if (commIsMaster(&s.comm)) {
commPartition(&d.comm, p.kmax, p.jmax, p.imax);
if (commIsMaster(&d.comm)) {
printParameter(&p);
}
initSolver(&s, &p);
initDiscretization(&d, &p);
initSolver(&s, &d, &p);
#ifndef VERBOSE
initProgress(s.te);
initProgress(d.te);
#endif
double tau = s.tau;
double te = s.te;
double tau = d.tau;
double te = d.te;
double t = 0.0;
int nt = 0;
double res = 0.0;
timeStart = getTimeStamp();
while (t <= te) {
if (tau > 0.0) computeTimestep(&s);
setBoundaryConditions(&s);
setSpecialBoundaryCondition(&s);
computeFG(&s);
computeRHS(&s);
solve(&s);
adaptUV(&s);
t += s.dt;
if (tau > 0.0) computeTimestep(&d);
setBoundaryConditions(&d);
setSpecialBoundaryCondition(&d);
computeFG(&d);
computeRHS(&d);
if (nt % 100 == 0) normalizePressure(&d);
res = solve(&s, d.p, d.rhs);
adaptUV(&d);
if (commIsMaster(&d.comm)) writeResidual(fp, t, res);
t += d.dt;
nt++;
#ifdef VERBOSE
if (commIsMaster(&s.comm)) {
printf("TIME %f , TIMESTEP %f\n", t, s.dt);
if (commIsMaster(s.comm)) {
printf("TIME %f , TIMESTEP %f\n", t, d.dt);
}
#else
printProgress(t);
@@ -67,7 +81,7 @@ int main(int argc, char** argv)
#ifndef VERBOSE
stopProgress();
#endif
if (commIsMaster(&s.comm)) {
if (commIsMaster(s.comm)) {
printf("Solution took %.2fs\n", timeStop - timeStart);
}
@@ -75,14 +89,16 @@ int main(int argc, char** argv)
#ifdef _VTK_WRITER_MPI
VtkOptions opts = { .grid = s.grid, .comm = s.comm };
vtkOpen(&opts, s.problem);
vtkScalar(&opts, "pressure", s.p);
vtkVector(&opts, "velocity", (VtkVector) { s.u, s.v, s.w });
vtkScalar(&opts, "pressure", d.p);
vtkVector(&opts, "velocity", (VtkVector) { d.u, d.v, d.w });
vtkClose(&opts);
#else
if (commIsMaster(&d.comm)) fclose(fp);
double *pg, *ug, *vg, *wg;
if (commIsMaster(&s.comm)) {
size_t bytesize = s.grid.imax * s.grid.jmax * s.grid.kmax * sizeof(double);
if (commIsMaster(s.comm)) {
size_t bytesize = s.grid->imax * s.grid->jmax * s.grid->kmax * sizeof(double);
pg = allocate(64, bytesize);
ug = allocate(64, bytesize);
@@ -90,34 +106,35 @@ int main(int argc, char** argv)
wg = allocate(64, bytesize);
}
commCollectResult(&s.comm,
commCollectResult(s.comm,
ug,
vg,
wg,
pg,
s.u,
s.v,
s.w,
s.p,
s.grid.kmax,
s.grid.jmax,
s.grid.imax);
d.u,
d.v,
d.w,
d.p,
s.grid->kmax,
s.grid->jmax,
s.grid->imax);
if (commIsMaster(&s.comm)) {
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);
}
#endif
timeStop = getTimeStamp();
if (commIsMaster(&s.comm)) {
if (commIsMaster(s.comm)) {
printf("Result output took %.2fs\n", timeStop - timeStart);
}
commFinalize(&s.comm);
commFinalize(s.comm);
return EXIT_SUCCESS;
}