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
|
#pragma once
#include "common.hpp"
namespace kel {
namespace lbm {
template<typename T, typename Desc, typename Coll>
kel::lbm::error_or<void> init(
const converter<T>& conv,
kel::lbm::data<sch::ChunkStruct<T,Desc>>& fields,
kel::lbm::data<sch::MacroStruct<T,Desc>>& macros,
kel::lbm::data<sch::ParticleSpheroidGroup<T,Desc>>& particles
){
(void) conv;
auto& info_f = fields.template get<"info">();
auto& porous_f = macros.template get<"porosity">();
// Set everything as walls
iterator<Desc::D>::apply(
[&](auto& index){
info_f.at(index).set(1u);
},
{},
info_f.get_dims(),
{}
);
// Fluid
iterator<Desc::D>::apply(
[&](auto& index){
info_f.at(index).set(2u);
},
{},
info_f.get_dims(),
{{1u,1u}}
);
auto dims = info_f.get_dims();
auto width = dims.at({{0u}});
auto height = dims.at({{1u}});
//
auto w = width.template cast_to<T>();
auto h = height.template cast_to<T>();
auto w2 = w * 0.5;
auto h4 = h * 0.25;
kel::lbm::data<T> e{0.1};
kel::lbm::data<T> c = w * (kel::lbm::data<T>{1.0} - e) * 0.5;
kel::lbm::data<T> d{0.2};
auto b = h * (kel::lbm::data<T>{1.0} - d) * 0.5;
auto p_r = (c*c + b*b) / (b*2);
auto p_r_2 = p_r * p_r;
std::cout<<"p²_r: "<<p_r_2.get()<<std::endl;
auto p_i = p_r - b;
// Circle Top
kel::lbm::data<sch::FixedArray<sch::Int64,Desc::D>> top_pos;
{
top_pos.at({0u}) = w2.get();
top_pos.at({1u}) = (h + p_i).get();
}
// Circle Bot
kel::lbm::data<sch::FixedArray<sch::Int64,Desc::D>> bot_pos;
{
bot_pos.at({0u}) = w2.get();
bot_pos.at({1u}) = -p_i.get();
}
iterator<Desc::D>::apply(
[&](auto& index){
auto& info = info_f.at(index);
auto tp_diff = top_pos;
auto bp_diff = bot_pos;
for(uint64_t i{0u}; i < Desc::D; ++i){
tp_diff.at(i) = top_pos.at(i) - index.at(i).template cast_to<sch::Int64>();
bp_diff.at(i) = bot_pos.at(i) - index.at(i).template cast_to<sch::Int64>();
}
auto tpd_v = kel::lbm::math::vectorize_data(tp_diff);
auto tpd_dot = kel::lbm::math::dot(tpd_v,tpd_v);
auto bpd_v = kel::lbm::math::vectorize_data(bp_diff);
auto bpd_dot = kel::lbm::math::dot(bpd_v,bpd_v);
if(
(tpd_dot.at({}).template cast_to<T>() <= p_r_2 ) or
(bpd_dot.at({}).template cast_to<T>() <= p_r_2 )
){
info.set({1u});
}
},
{},
info_f.get_dims(),
{}
);
// Inflow
iterator<Desc::D>::apply(
[&](auto& index){
info_f.at(index).set(3u);
},
{{0u,0u}},
{{1u,dim_y}},
{{0u,1u}}
);
// Outflow
iterator<Desc::D>::apply(
[&](auto& index){
info_f.at(index).set(4u);
},
{{dim_x-1u,0u}},
{{dim_x, dim_y}},
{{0u,1u}}
);
//
auto& df_f = fields.template get<"dfs_old">();
auto& rho_f = macros.template get<"density">();
auto& vel_f = macros.template get<"velocity">();
auto& por_f = macros.template get<"porosity">();
iterator<Desc::D>::apply(
[&](auto& index){
auto& df = df_f.at(index);
auto& rho = rho_f.at(index);
por_f.at(index).at({}) = {1};
rho.at({}) = {1};
auto& vel = vel_f.at(index);
auto eq = equilibrium<T,Desc>(rho,vel);
df = eq;
},
{},// 0-index
df_f.get_dims()
);
iterator<Desc::D>::apply(
[&](auto& index){
auto& df = df_f.at(index);
auto& rho = rho_f.at(index);
rho.at({}) = {1};
auto& vel = vel_f.at(index);
if(info_f.at(index).get() == 2u){
vel.at({{0u}}) = 0.0;
}
auto eq = equilibrium<T,Desc>(rho,vel);
df = eq;
},
{},// 0-index
df_f.get_dims(),
{{1u,1u}}
);
{
kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radius_p;
radius_p.at({}).set(conv.meter_si_to_lbm({0.05}).handle().get());
std::cout<<"RADIUS: "<<radius_p.at({}).get()<<std::endl;
kel::lbm::data<sch::Scalar<T>> dense_p;
dense_p.at({}).set(1);
particles = create_spheroid_particle_group<T,Desc::D,particle_amount>(radius_p, dense_p, {{64u}});
auto& parts = particles.template get<"particles">();
/**
* Seed the particles upstream of the throat on a staggered grid.
*
* Spacing is 2.4 radii, so they start clear of one another -- any
* initial overlap would be resolved as a contact on the first step and
* fire them apart.
*/
const auto radius = radius_p.at({}).get();
const auto pitch = radius * 2.4;
const auto x0 = conv.meter_si_to_lbm({0.10}).handle().get();
const auto y_mid = conv.meter_si_to_lbm({0.25}).handle().get();
constexpr uint64_t per_column = 4ul;
for(uint64_t i = 0u; i < particle_amount; ++i){
auto col = i / per_column;
auto row = i % per_column;
// Offset alternate columns by half a pitch so they interleave.
auto y_off = (static_cast<double>(row) - (per_column - 1u) * 0.5) * pitch
+ ((col % 2u == 1u) ? pitch * 0.5 : 0.0);
auto& p = parts.at({i});
auto& prb = p.template get<"rigid_body">();
auto& p_pos = prb.template get<"position">();
auto& p_pos_old = prb.template get<"position_old">();
p_pos.at({{0u}}).set(x0 + static_cast<double>(col) * pitch);
p_pos.at({{1u}}).set(y_mid + y_off);
// Start at rest: position_old defaults to zero, which would read
// as an enormous velocity.
p_pos_old = p_pos;
}
}
return kel::lbm::make_void();
}
}
}
|