-
Notifications
You must be signed in to change notification settings - Fork 182
/
core.cpp
46 lines (33 loc) · 1.24 KB
/
core.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Main solver routines for heat equation solver
#include <mpi.h>
#include "heat.hpp"
// Exchange the boundary values
void exchange(Field& field, const ParallelData parallel)
{
double* sbuf;
double* rbuf;
// TODO start: implement halo exchange
// You can utilize the data() method of the Matrix class to obtain pointer
// to element, e.g. field.temperature.data(i, j)
// Send to up, receive from down
// Send to down, receive from up
// TODO end
}
// Update the temperature values using five-point stencil */
void evolve(Field& curr, const Field& prev, const double a, const double dt)
{
// Compilers do not necessarily optimize division to multiplication, so make it explicit
auto inv_dx2 = 1.0 / (prev.dx * prev.dx);
auto inv_dy2 = 1.0 / (prev.dy * prev.dy);
// Determine the temperature field at next time step
// As we have fixed boundary conditions, the outermost gridpoints
// are not updated.
for (int i = 1; i < curr.nx + 1; i++) {
for (int j = 1; j < curr.ny + 1; j++) {
curr(i, j) = prev(i, j) + a * dt * (
( prev(i + 1, j) - 2.0 * prev(i, j) + prev(i - 1, j) ) * inv_dx2 +
( prev(i, j + 1) - 2.0 * prev(i, j) + prev(i, j - 1) ) * inv_dy2
);
}
}
}