/
cyclic_2d.hpp
152 lines (124 loc) · 4.59 KB
/
cyclic_2d.hpp
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// 2D cyclic boundary conditions for libmpdata++
//
// licensing: GPU GPL v3
// copyright: University of Warsaw
#pragma once
#include <libmpdata++/bcond/detail/bcond_common.hpp>
namespace libmpdataxx
{
namespace bcond
{
template <typename real_t, int halo, bcond_e knd, drctn_e dir, int n_dims, int d>
class bcond< real_t, halo, knd, dir, n_dims, d,
typename std::enable_if<
knd == cyclic &&
dir == left &&
n_dims == 2
>::type
> : public detail::bcond_common<real_t, halo, n_dims>
{
using parent_t = detail::bcond_common<real_t, halo, n_dims>;
using arr_t = blitz::Array<real_t, 2>;
using parent_t::parent_t; // inheriting ctor
public:
void fill_halos_sclr(arr_t &a, const rng_t &j, const bool deriv = false)
{
using namespace idxperm;
a(pi<d>(this->left_halo_sclr, j)) = a(pi<d>(this->rght_intr_sclr, j));
}
void fill_halos_pres(arr_t &a, const rng_t &j)
{
fill_halos_sclr(a, j);
}
void save_edge_vel(const arr_t &, const rng_t &) {}
void set_edge_pres(arr_t &, const rng_t &, int) {}
void fill_halos_vctr_alng(arrvec_t<arr_t> &av, const rng_t &j, const bool ad = false)
{
using namespace idxperm;
av[d](pi<d>(this->left_halo_vctr, j)) = av[d](pi<d>(this->rght_intr_vctr, j));
}
void fill_halos_sgs_div(arr_t &a, const rng_t &j)
{
fill_halos_sclr(a, j);
}
void fill_halos_sgs_vctr(arrvec_t<arr_t> &av, const arr_t &, const rng_t &j, const int offset = 0)
{
using namespace idxperm;
// the same logic as fill_halos_vctr_alng but have to consider offset ... TODO: find a way to reuse !
av[d + offset](pi<d>(this->left_halo_vctr, j)) = av[d + offset](pi<d>(this->rght_intr_vctr, j));
}
void fill_halos_sgs_tnsr(arrvec_t<arr_t> &av, const arr_t &, const arr_t &, const rng_t &j, const real_t)
{
fill_halos_vctr_alng(av, j);
}
void fill_halos_vctr_nrml(arr_t &a, const rng_t &j)
{
fill_halos_sclr(a, j);
}
void fill_halos_vctr_alng_cyclic(arrvec_t<arr_t> &av, const rng_t &j, const bool ad = false)
{
fill_halos_vctr_alng(av, j, ad);
}
void fill_halos_vctr_nrml_cyclic(arr_t &a, const rng_t &j)
{
fill_halos_vctr_nrml(a, j);
}
};
template <typename real_t, int halo, bcond_e knd, drctn_e dir, int n_dims, int d>
class bcond< real_t, halo, knd, dir, n_dims, d,
typename std::enable_if<
knd == cyclic &&
dir == rght &&
n_dims == 2
>::type
> : public detail::bcond_common<real_t, halo, n_dims>
{
using parent_t = detail::bcond_common<real_t, halo, n_dims>;
using arr_t = blitz::Array<real_t, 2>;
using parent_t::parent_t; // inheriting ctor
public:
void fill_halos_sclr(arr_t &a, const rng_t &j, const bool deriv = false)
{
using namespace idxperm;
a(pi<d>(this->rght_halo_sclr, j)) = a(pi<d>(this->left_intr_sclr, j));
}
void fill_halos_pres(arr_t &a, const rng_t &j)
{
fill_halos_sclr(a, j);
}
void save_edge_vel(const arr_t &, const rng_t &) {}
void set_edge_pres(arr_t &, const rng_t &, int) {}
void fill_halos_vctr_alng(arrvec_t<arr_t> &av, const rng_t &j, const bool ad = false)
{
using namespace idxperm;
av[d](pi<d>(this->rght_halo_vctr, j)) = av[d](pi<d>(this->left_intr_vctr, j));
}
void fill_halos_sgs_div(arr_t &a, const rng_t &j)
{
fill_halos_sclr(a, j);
}
void fill_halos_sgs_vctr(arrvec_t<arr_t> &av, const arr_t &, const rng_t &j, const int offset = 0)
{
using namespace idxperm;
// the same logic as fill_halos_vctr_alng but have to consider offset ... TODO: find a way to reuse !
av[d + offset](pi<d>(this->rght_halo_vctr, j)) = av[d + offset](pi<d>(this->left_intr_vctr, j));
}
void fill_halos_sgs_tnsr(arrvec_t<arr_t> &av, const arr_t &, const arr_t &, const rng_t &j, const real_t)
{
fill_halos_vctr_alng(av, j);
}
void fill_halos_vctr_nrml(arr_t &a, const rng_t &j)
{
fill_halos_sclr(a, j);
}
void fill_halos_vctr_alng_cyclic(arrvec_t<arr_t> &av, const rng_t &j, const bool ad = false)
{
fill_halos_vctr_alng(av, j, ad);
}
void fill_halos_vctr_nrml_cyclic(arr_t &a, const rng_t &j)
{
fill_halos_vctr_nrml(a, j);
}
};
} // namespace bcond
} // namespace libmpdataxx