85 lines
1.9 KiB
C
Raw Normal View History

2023-02-05 07:34:23 +01:00
/*
2024-02-05 08:46:13 +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"
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);
#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
}
2024-02-05 08:46:13 +01:00
size_t bytesize = s.imax * s.jmax * sizeof(double);
2023-02-05 07:34:23 +01:00
double* ug = allocate(64, bytesize);
double* vg = allocate(64, bytesize);
double* pg = allocate(64, bytesize);
2024-02-05 08:46:13 +01:00
commCollectResult(&s.comm, ug, vg, pg, s.u, s.v, s.p, s.jmax, s.imax);
writeResult(&s, ug, vg, pg);
2023-02-05 07:34:23 +01:00
2024-02-05 08:46:13 +01:00
commFinalize(&s.comm);
2023-02-05 07:34:23 +01:00
return EXIT_SUCCESS;
}