109 lines
2.3 KiB
C
Raw Normal View History

2023-02-05 07:34:23 +01:00
/*
* Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
2023-02-05 07:34:23 +01:00
* All rights reserved.
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE file.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "allocate.h"
2024-02-05 08:46:13 +01:00
#include "comm.h"
2023-02-05 07:34:23 +01:00
#include "parameter.h"
#include "progress.h"
#include "solver.h"
#include "timing.h"
static void writeResults(Solver* s)
{
#ifdef _MPI
size_t bytesize = (s->imax + 2) * (s->jmax + 2) * sizeof(double);
double* ug = allocate(64, bytesize);
double* vg = allocate(64, bytesize);
double* pg = allocate(64, bytesize);
commCollectResult(&s->comm, ug, vg, pg, s->u, s->v, s->p, s->imax, s->jmax);
writeResult(s, ug, vg, pg);
free(ug);
free(vg);
free(pg);
#else
writeResult(s, s->u, s->v, s->p);
#endif
}
2023-02-05 07:34:23 +01:00
int main(int argc, char** argv)
{
int rank;
2024-02-05 08:46:13 +01:00
double timeStart, timeStop;
Parameter p;
Solver s;
2023-02-05 07:34:23 +01:00
2024-02-05 08:46:13 +01:00
commInit(&s.comm, argc, argv);
initParameter(&p);
2023-02-05 07:34:23 +01:00
if (argc != 2) {
printf("Usage: %s <configFile>\n", argv[0]);
exit(EXIT_SUCCESS);
}
2024-02-05 08:46:13 +01:00
readParameter(&p, argv[1]);
commPartition(&s.comm, p.jmax, p.imax);
if (commIsMaster(&s.comm)) {
printParameter(&p);
2023-02-05 07:34:23 +01:00
}
2024-02-05 08:46:13 +01:00
initSolver(&s, &p);
#ifdef TEST
commPrintConfig(&s.comm);
commTestInit(&s.comm, s.p, s.f, s.g);
commExchange(&s.comm, s.p);
commShift(&s.comm, s.f, s.g);
commTestWrite(&s.comm, s.p, s.f, s.g);
writeResults(&s);
commFinalize(&s.comm);
exit(EXIT_SUCCESS);
#endif
2024-02-05 08:46:13 +01:00
#ifndef VERBOSE
initProgress(s.te);
#endif
2023-02-05 07:34:23 +01:00
2024-02-05 08:46:13 +01:00
double tau = s.tau;
double te = s.te;
2023-02-05 07:34:23 +01:00
double t = 0.0;
2024-02-05 08:46:13 +01:00
timeStart = getTimeStamp();
2023-02-05 07:34:23 +01:00
while (t <= te) {
2024-02-05 08:46:13 +01:00
if (tau > 0.0) computeTimestep(&s);
setBoundaryConditions(&s);
setSpecialBoundaryCondition(&s);
computeFG(&s);
computeRHS(&s);
solve(&s);
adaptUV(&s);
t += s.dt;
2023-02-05 07:34:23 +01:00
#ifdef VERBOSE
2024-02-05 08:46:13 +01:00
if (commIsMaster(&s.comm)) {
printf("TIME %f , TIMESTEP %f\n", t, s.dt);
2023-02-05 07:34:23 +01:00
}
#else
printProgress(t);
#endif
}
2024-02-05 08:46:13 +01:00
timeStop = getTimeStamp();
#ifndef VERBOSE
2023-02-05 07:34:23 +01:00
stopProgress();
2024-02-05 08:46:13 +01:00
#endif
if (commIsMaster(&s.comm)) {
printf("Solution took %.2fs\n", timeStop - timeStart);
2023-02-05 07:34:23 +01:00
}
writeResults(&s);
2024-02-05 08:46:13 +01:00
commFinalize(&s.comm);
2023-02-05 07:34:23 +01:00
return EXIT_SUCCESS;
}