forked from mdelorme/fv2d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundaryConditions.h
126 lines (104 loc) · 3.61 KB
/
BoundaryConditions.h
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include <map>
#include <cassert>
#include "SimInfo.h"
namespace fv2d {
namespace {
/**
* @brief Absorbing conditions
*/
KOKKOS_INLINE_FUNCTION
State fillAbsorbing(Array Q, int iref, int jref) {
return getStateFromArray(Q, iref, jref);
};
/**
* @brief Reflecting boundary conditions
*/
KOKKOS_INLINE_FUNCTION
State fillReflecting(Array Q, int i, int j, int iref, int jref, IDir dir, const Params ¶ms) {
int isym, jsym;
if (dir == IX) {
int ipiv = (i < iref ? params.ibeg : params.iend);
isym = 2*ipiv - i - 1;
jsym = j;
}
else {
int jpiv = (j < jref ? params.jbeg : params.jend);
isym = i;
jsym = 2*jpiv - j - 1;
}
State q = getStateFromArray(Q, isym, jsym);
if (dir == IX)
q[IU] *= -1.0;
else
q[IV] *= -1.0;
return q;
}
/**
* @brief Periodic boundary conditions
*
*/
KOKKOS_INLINE_FUNCTION
State fillPeriodic(Array Q, int i, int j, IDir dir, const Params ¶ms) {
if (dir == IX) {
if (i < params.ibeg)
i += params.Nx;
else
i -= params.Nx;
}
else {
if (j < params.jbeg)
j += params.Ny;
else
j -= params.Ny;
}
return getStateFromArray(Q, i, j);
}
} // anonymous namespace
class BoundaryManager {
public:
Params params;
BoundaryManager(const Params ¶ms)
: params(params) {};
~BoundaryManager() = default;
void fillBoundaries(Array Q) {
auto bc_x = params.boundary_x;
auto bc_y = params.boundary_y;
auto params = this->params;
Kokkos::parallel_for( "Filling X-boundary",
params.range_xbound,
KOKKOS_LAMBDA(int i, int j) {
int ileft = i;
int iright = params.iend+i;
int iref_left = params.ibeg;
int iref_right = params.iend-1;
auto fill = [&](int i, int iref) {
switch (bc_x) {
case BC_ABSORBING: return fillAbsorbing(Q, iref, j); break;
case BC_REFLECTING: return fillReflecting(Q, i, j, iref, j, IX, params); break;
case BC_PERIODIC: return fillPeriodic(Q, i, j, IX, params); break;
}
};
setStateInArray(Q, ileft, j, fill(ileft, iref_left));
setStateInArray(Q, iright, j, fill(iright, iref_right));
});
Kokkos::parallel_for( "Filling Y-boundary",
params.range_ybound,
KOKKOS_LAMBDA(int i, int j) {
int jtop = j;
int jbot = params.jend+j;
int jref_top = params.jbeg;
int jref_bot = params.jend-1;
auto fill = [&](int j, int jref) {
switch (bc_y) {
case BC_ABSORBING: return fillAbsorbing(Q, i, jref); break;
case BC_REFLECTING: return fillReflecting(Q, i, j, i, jref, IY, params); break;
case BC_PERIODIC: return fillPeriodic(Q, i, j, IY, params); break;
}
};
setStateInArray(Q, i, jtop, fill(jtop, jref_top));
setStateInArray(Q, i, jbot, fill(jbot, jref_bot));
});
}
};
}