Skip to content

Commit 61303f2

Browse files
authored
Merge pull request #33 from motrieu/feature/finalMpi/simon
Feature/final mpi/simon
2 parents d8d8864 + f57e53b commit 61303f2

27 files changed

+1908
-59
lines changed

src/CMakeLists.txt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
cmake_minimum_required(VERSION 3.8)
22

33
# Define the project name.
4-
project(numsim)
4+
project(numsim_parallel)
55

66
# Specify the name of the executable (${PROJECT_NAME} which is equal to what was set in the project() command).
77
# Also specify the source files.
88
add_executable(${PROJECT_NAME}
99
main.cpp
1010
computation/computation.cpp
11+
computation/computationParallel.cpp
1112
discretization/centralDifferences.cpp
1213
discretization/discretization.cpp
1314
discretization/donorCell.cpp
1415
discretization/staggeredGrid.cpp
15-
output_writer/output_writer.cpp
16+
output_writer/output_writer_paraview_parallel.cpp
1617
output_writer/output_writer_paraview.cpp
18+
output_writer/output_writer_text_parallel.cpp
1719
output_writer/output_writer_text.cpp
20+
output_writer/output_writer.cpp
21+
partitioning/partitioning.cpp
1822
pressure_solver/gaussSeidel.cpp
1923
pressure_solver/pressureSolver.cpp
24+
pressure_solver/pressureSolverParallel.cpp
2025
pressure_solver/sor.cpp
26+
pressure_solver/sorParallel.cpp
2127
settings/settings.cpp
2228
storage/array2d.cpp
2329
storage/fieldVariable.cpp
@@ -53,3 +59,19 @@ set(CMAKE_CXX_STANDARD 14)
5359
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5460

5561
message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
62+
63+
find_package(MPI REQUIRED)
64+
65+
include_directories(${MPI_INCLUDE_PATH})
66+
target_link_libraries(${PROJECT_NAME} ${MPI_LIBRARIES})
67+
68+
if(MPI_COMPILE_FLAGS)
69+
set_target_properties(${PROJECT_NAME} PROPERTIES
70+
COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
71+
endif()
72+
73+
if(MPI_LINK_FLAGS)
74+
set_target_properties(${PROJECT_NAME} PROPERTIES
75+
LINK_FLAGS "${MPI_LINK_FLAGS}")
76+
endif()
77+

src/computation/computation.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void Computation::runSimulation()
3232

3333
time += dt_;
3434

35-
(*outputWriterParaview_).writeFile(time);
35+
// (*outputWriterParaview_).writeFile(time);
3636
// (*outputWriterText_).writeFile(time);
3737
}
3838
}
@@ -48,9 +48,11 @@ void Computation::initialize(int argc, char *argv[])
4848
settings_.loadFromFile(filename);
4949

5050
// calculates mesh width in x- and y-direction based on given parameters
51-
const double meshWidthX = settings_.physicalSize[0] / settings_.nCells[0];
52-
const double meshWidthY = settings_.physicalSize[1] / settings_.nCells[1];
53-
meshWidth_ = {meshWidthX, meshWidthY};
51+
dx_ = settings_.physicalSize[0] / settings_.nCells[0];
52+
dy_ = settings_.physicalSize[1] / settings_.nCells[1];
53+
meshWidth_ = {dx_, dy_};
54+
dxSquared_ = dx_ * dx_;
55+
dySquared_ = dy_ * dy_;
5456

5557
// either the Central Differences or the Donor cell scheme is used
5658
if (settings_.useDonorCell)
@@ -66,7 +68,7 @@ void Computation::initialize(int argc, char *argv[])
6668
else
6769
throw std::invalid_argument("Only SOR and GaussSeidel are supported as pressure solvers.");
6870

69-
outputWriterParaview_ = std::make_unique<OutputWriterParaview>(discretization_);
71+
// outputWriterParaview_ = std::make_unique<OutputWriterParaview>(discretization_);
7072
// outputWriterText_ = std::make_unique<OutputWriterText>(discretization_);
7173

7274
// boundary conditions for u and v on the boundary faces only need to be set once in the beginning of the computation
@@ -137,9 +139,7 @@ void Computation::applyPreliminaryBCOnBoundary()
137139

138140
void Computation::computeTimeStepWidth()
139141
{
140-
const double dx = meshWidth_[0];
141-
const double dy = meshWidth_[1];
142-
const double dtDiffusive = (settings_.re/2.0) * (dx*dx * dy*dy) / (dx*dx + dy*dy);
142+
const double dtDiffusive = (settings_.re/2.0) * (dxSquared_ * dySquared_) / (dxSquared_ + dySquared_);
143143

144144
double uAbsMax = 0.0;
145145
for (int i=(*discretization_).uIBegin()-1; i < (*discretization_).uIEnd()+1; i++)
@@ -162,12 +162,17 @@ void Computation::computeTimeStepWidth()
162162
}
163163
}
164164

165-
const double dtConvectiveU = dx / uAbsMax;
166-
const double dtConvectiveV = dy / vAbsMax;
165+
double dtConvectiveU = settings_.maximumDt;
166+
double dtConvectiveV = settings_.maximumDt;
167+
if (uAbsMax > 0.0)
168+
dtConvectiveU = dx_ / uAbsMax;
169+
if (vAbsMax > 0.0)
170+
dtConvectiveV = dy_ / vAbsMax;
167171

168172
// makes sure that all stability conditions (the convective conditions and the diffusive condition) are fulfilled
169173
// and that the demanded maximal time step is not exceeded
170-
dt_ = settings_.tau * std::min({dtDiffusive, dtConvectiveU, dtConvectiveV, settings_.maximumDt});
174+
dt_ = settings_.tau * std::min({dtDiffusive, dtConvectiveU, dtConvectiveV});
175+
dt_ = std::min(dt_, settings_.maximumDt);
171176
}
172177

173178
void Computation::computePreliminaryVelocities()
@@ -204,8 +209,8 @@ void Computation::computeRightHandSide()
204209
{
205210
for (int j=(*discretization_).pJBegin(); j < (*discretization_).pJEnd(); j++)
206211
{
207-
const double fDiffQuotient = ((*discretization_).f(i,j) - (*discretization_).f(i-1,j)) / meshWidth_[0];
208-
const double gDiffQuotient = ((*discretization_).g(i,j) - (*discretization_).g(i,j-1)) / meshWidth_[1];
212+
const double fDiffQuotient = ((*discretization_).f(i,j) - (*discretization_).f(i-1,j)) / dx_;
213+
const double gDiffQuotient = ((*discretization_).g(i,j) - (*discretization_).g(i,j-1)) / dy_;
209214
(*discretization_).rhs(i,j) = (1.0/dt_) * (fDiffQuotient + gDiffQuotient);
210215
}
211216
}
@@ -222,15 +227,15 @@ void Computation::computeVelocities()
222227
{
223228
for (int j=(*discretization_).uJBegin(); j < (*discretization_).uJEnd(); j++)
224229
{
225-
(*discretization_).u(i,j) = (*discretization_).f(i,j) - (dt_/meshWidth_[0])
230+
(*discretization_).u(i,j) = (*discretization_).f(i,j) - (dt_/dx_)
226231
* ((*discretization_).p(i+1,j) - (*discretization_).p(i,j));
227232
}
228233
}
229234
for (int i=(*discretization_).vIBegin(); i < (*discretization_).vIEnd(); i++)
230235
{
231236
for (int j=(*discretization_).vJBegin(); j < (*discretization_).vJEnd(); j++)
232237
{
233-
(*discretization_).v(i,j) = (*discretization_).g(i,j) - (dt_/meshWidth_[1])
238+
(*discretization_).v(i,j) = (*discretization_).g(i,j) - (dt_/dy_)
234239
* ((*discretization_).p(i,j+1) - (*discretization_).p(i,j));
235240
}
236241
}

src/computation/computation.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Computation
3232
/// pressure p, preliminary velocities F and G and the right hand side of the pressure Poisson problem (rhs)
3333
void runSimulation();
3434

35-
private:
35+
protected:
3636

3737
/// @brief applies boundary conditions of u and v on the actual boundary faces
3838
/// manipulates the in the data structure stored values such that they are overwritten
@@ -70,6 +70,7 @@ class Computation
7070
/// manipulates the in the data structure stored values such that they are overwritten
7171
void computeVelocities();
7272

73+
7374
/// @brief contains parameters used for the current scenario
7475
Settings settings_;
7576

@@ -84,11 +85,23 @@ class Computation
8485

8586
/// @brief unique pointer to the output writer which produces readable txt-files
8687
std::unique_ptr<OutputWriterText> outputWriterText_;
88+
8789

8890
/// @brief array of doubles that contains the mesh width in x- and y-direction
8991
std::array<double,2> meshWidth_;
9092

9193
/// @brief current time step width, is set in each time iteration
9294
double dt_;
9395

96+
/// @brief mesh width in x-direction
97+
double dx_;
98+
99+
/// @brief squared mesh width in x-direction
100+
double dxSquared_;
101+
102+
/// @brief mesh width in y-direction
103+
double dy_;
104+
105+
/// @brief squared mesh width in y-direction
106+
double dySquared_;
94107
};

0 commit comments

Comments
 (0)