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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
#pragma once
#include "component.hpp"
#include "equilibrium.hpp"
namespace kel {
namespace lbm {
namespace cmpt {
struct BounceBack {};
template<uint64_t i>
struct AntiBounceBack {};
template<bool East>
struct ZouHeHorizontal{};
struct Equilibrium {};
template<bool North>
struct ZouHePressureY{};
template<bool East>
struct ZouHeVelocityX {};
}
/**
* Full-Way BounceBack.
*/
template<typename T, typename Descriptor, typename Encode>
class component<T, Descriptor, cmpt::BounceBack, Encode> {
private:
public:
component() = default;
using Component = cmpt::BounceBack;
/**
* Thoughts regarding automating order setup
*/
using access = cmpt::access_tuple<
cmpt::access<"dfs", 1, true, true, true>
>;
/**
* Thoughts regarding automating order setup
*/
static constexpr saw::string_literal name = "full_way_bounce_back";
static constexpr saw::string_literal after = "";
static constexpr saw::string_literal before = "streaming";
/**
* Raw setup
*/
template<typename CellFieldSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>>& index, saw::data<sch::UInt64> time_step)const{
bool is_even = ((time_step.get() % 2u) == 0u);
// This is a ref
// auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">();
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
using dfi = df_info<T,Descriptor>;
// Technically use .copy()
auto& dfs_old = dfs_old_f.at(index);
auto df_cpy = dfs_old;
for(uint64_t i = 0u; i < Descriptor::Q; ++i){
dfs_old.at({i}) = df_cpy.at({dfi::opposite_index.at(i)});
}
}
};
/**
* Anti Full-Way BounceBack.
*/
template<typename T, typename Descriptor, uint64_t D, typename Encode>
class component<T, Descriptor, cmpt::AntiBounceBack<D>, Encode> {
private:
public:
component() = default;
using Component = cmpt::AntiBounceBack<D>;
/**
* Thoughts regarding automating order setup
*/
using access = cmpt::access_tuple<
cmpt::access<"dfs", 1, true, true, true>
>;
/**
* Thoughts regarding automating order setup
*/
static constexpr saw::string_literal name = "full_way_anti_bounce_back";
static constexpr saw::string_literal after = "";
static constexpr saw::string_literal before = "streaming";
/**
* Raw setup
*/
template<typename CellFieldSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>>& index, saw::data<sch::UInt64> time_step)const{
bool is_even = ((time_step.get() % 2u) == 0u);
// This is a ref
// auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">();
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
using dfi = df_info<T,Descriptor>;
// Technically use .copy()
auto& dfs_old = dfs_old_f.at(index);
auto df_cpy = dfs_old;
static_assert(Descriptor::D == 2u and Descriptor::Q == 9u, "Some parts are hard coded sadly");
dfs_old.at({0u}) = df_cpy.at({0u});
dfs_old.at({1u}) = df_cpy.at({1u});
dfs_old.at({2u}) = df_cpy.at({2u});
dfs_old.at({3u}) = df_cpy.at({4u});
dfs_old.at({4u}) = df_cpy.at({3u});
dfs_old.at({5u}) = df_cpy.at({7u});
dfs_old.at({6u}) = df_cpy.at({8u});
dfs_old.at({7u}) = df_cpy.at({5u});
dfs_old.at({8u}) = df_cpy.at({6u});
}
};
template<typename FP, typename Descriptor, typename Encode>
class component<FP, Descriptor, cmpt::Equilibrium, Encode> final {
private:
saw::data<sch::Scalar<FP>> density_;
saw::data<sch::Vector<FP,Descriptor::D>> velocity_;
public:
component(
saw::data<sch::Scalar<FP>> density__,
saw::data<sch::Vector<FP,Descriptor::D>> velocity__
):
density_{density__},
velocity_{velocity__}
{}
template<typename CellFieldSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>>& index, saw::data<sch::UInt64> time_step) const {
bool is_even = ((time_step.get() % 2u) == 0u);
using dfi = df_info<FP,Descriptor>;
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
auto eq = equilibrium<FP,Descriptor>(density_,velocity_);
dfs_old_f.at(index) = eq;
}
};
/**
* This is massively hacky and expects a lot of conditions
* Either this or mirrored along the horizontal line works
*
* 0 - 2 - 2
* 0 - 3 - 1
* 0 - 3 - 1
* .........
* 0 - 3 - 1
* 0 - 2 - 2
*
*/
template<typename FP, typename Descriptor, bool Dir, typename Encode>
class component<FP, Descriptor, cmpt::ZouHeHorizontal<Dir>, Encode> final {
private:
saw::data<FP> rho_setting_;
public:
component(const saw::data<FP>& density_setting__):
rho_setting_{density_setting__}
{}
template<typename CellFieldSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const {
using dfi = df_info<FP,Descriptor>;
constexpr int known_dir = Dir ? 1 : -1;
bool is_even = ((time_step.get() % 2) == 0);
auto& info_f = field.template get<"info">();
// auto& dfs_f = (is_even) ? field.template get<"dfs">() : field.template get<"dfs_old">();
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
auto& dfs_old = dfs_old_f.at(index);
/**
* Sum all known DFs
*/
saw::data<FP> sum_df{0};
for(saw::data<sch::UInt64> k{0u}; k < saw::data<sch::UInt64>{Descriptor::Q}; ++k){
auto c_k = dfi::directions[k.get()];
if(c_k[0u]*known_dir <= 0){
sum_df += dfs_old.at({k});
}
}
/**
* Get the sum of the unknown dfs and precalculate the direction
*/
auto sum_unknown_dfs = (rho_setting_ - sum_df) * saw::data<FP>{known_dir};
for(saw::data<sch::UInt64> k{0u}; k < saw::data<sch::UInt64>{Descriptor::Q}; ++k){
auto c_k = dfi::directions[k.get()];
if(c_k[0u]*known_dir < 0){
sum_unknown_dfs += dfs_old.at({k}) * c_k[0u];
}
}
auto vel_x = sum_unknown_dfs / rho_setting_;
static_assert(Descriptor::D == 2u and Descriptor::Q == 9u, "Some parts are hard coded sadly");
if constexpr (Dir) {
dfs_old.at({2u}) = dfs_old.at({1u}) + saw::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x;
dfs_old.at({6u}) = dfs_old.at({5u}) + saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old.at({4u}) - dfs_old.at({3u}));
dfs_old.at({8u}) = dfs_old.at({7u}) + saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old.at({3u}) - dfs_old.at({4u}));
}else if constexpr (not Dir){
dfs_old.at({1u}) = dfs_old.at({2u}) - saw::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x;
dfs_old.at({5u}) = dfs_old.at({6u}) - saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old.at({3u}) - dfs_old.at({4u}));
dfs_old.at({7u}) = dfs_old.at({8u}) - saw::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + saw::data<FP>{0.5} * (dfs_old.at({4u}) - dfs_old.at({3u}));
}
}
};
/*
template<typename FP, typename Descriptor, bool East, typename Encode>
class component<FP, Descriptor, cmpt::ZouHeVelocityX<East>, Encode> final {
private:
saw::data<sch::Vector<FP,Descriptor::D>> velocity_;
public:
component(
saw::data<sch::Vector<FP,Descriptor::D>> velocity__
):
velocity_{velocity__}
{}
template<typename CellFieldSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>>& index, saw::data<sch::UInt64> time_step) const {
bool is_even = ((time_step.get() % 2u) == 0u);
using dfi = df_info<FP,Descriptor>;
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
}
};
*/
}
}
|