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
|
#include "../c++/lbm.hpp"
#include "../c++/collision.hpp"
#include "../c++/boundary.hpp"
#include "../c++/iterator.hpp"
#include <forstio/codec/data.hpp>
namespace kel {
namespace lbm {
namespace sch {
using namespace saw::schema;
/**
* Basic distribution function
* Base type
* D
* Q
* Scalar factor
* D factor
* Q factor
*/
using T = Float32;
using D2Q5 = Descriptor<2u,5u>;
using D2Q9 = Descriptor<2u,9u>;
template<typename Desc>
using DfCell = Cell<T, Desc, 0u, 0u, 1u>;
template<typename Desc>
using CellInfo = Cell<UInt8, D2Q9, 1u, 0u, 0u>;
/**
* Basic type for simulation
*/
template<typename Desc>
using CellStruct = Struct<
Member<DfCell<Desc>, "dfs">,
Member<DfCell<Desc>, "dfs_old">,
Member<CellInfo<Desc>, "info">
>;
template<typename T, uint64_t D>
using MacroStruct = Struct<
Member<FixedArray<T,D>, "velocity">,
Member<T, "pressure">
>;
using CavityFieldD2Q9 = CellField<D2Q9, CellStruct<D2Q9>>;
}
}
}
void set_geometry(saw::data<kel::lbm::sch::CavityFieldD2Q9>& latt){
using namespace kel::lbm;
auto meta = latt.meta();
/**
* Set ghost
*/
iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){
auto& cell = latt(index);
auto& info = cell.template get<"info">();
info({0u}).set(0u);
}, {{0u,0u}}, meta);
/**
* Set wall
*/
iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){
auto& cell = latt(index);
auto& info = cell.template get<"info">();
info({0u}).set(2u);
}, {{0u,0u}}, meta, {{1u,1u}});
/**
* Set fluid
*/
iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){
auto& cell = latt(index);
auto& info = cell.template get<"info">();
info({0u}).set(1u);
}, {{0u,0u}}, meta, {{2u,2u}});
/**
* Set inflow
*/
iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){
auto& cell = latt(index);
auto& info = cell.template get<"info">();
info({0u}).set(3u);
}, {{1u,0u}}, {{2u,meta.at({1u})}}, {{0u,2u}});
/**
* Set outflow
*/
iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){
auto& cell = latt(index);
auto& info = cell.template get<"info">();
info({0u}).set(4u);
}, {{meta.at({0u})-2u,0u}}, {{meta.at({0u})-1u, meta.at({1u})}}, {{0u,2u}});
}
void set_initial_conditions(saw::data<kel::lbm::sch::CavityFieldD2Q9>& latt){
using namespace kel::lbm;
auto meta = latt.meta();
}
int main(int argc, char** argv){
using namespace kel::lbm;
std::string_view cfg_file_name = "config.json";
if(argc > 1){
cfg_file_name = argv[1];
}
auto eo_conf = load_lbm_config<sch::Float64,sch::Descriptor<2u,9u>>(cfg_file_name);
if(eo_conf.is_error()){
auto& err = eo_conf.get_error();
std::cerr<<"[Error]: "<<err.get_category();
auto err_msg = err.get_message();
if(!err_msg.empty()){
std::cerr<<" - "<<err_msg;
}
std::cerr<<std::endl;
return err.get_id();
}
auto& conf = eo_conf.get_value();
converter<sch::Float64> conv {
{conf.template get<"delta_x">()},
{conf.template get<"delta_t">()}
};
print_lbm_meta<sch::Float64,sch::Descriptor<2u,9u>>(conv, {conf.template get<"kinematic_viscosity">()});
saw::data<sch::FixedArray<sch::UInt64,sch::D2Q9::D>> dim{{32u, 8u}};
saw::data<sch::CavityFieldD2Q9, saw::encode::Native> lattice{dim};
set_geometry(lattice);
/**
* Print basic setup info
*/
iterate_over([&](const saw::data<sch::FixedArray<sch::UInt64,2u>>& index){
auto& cell = lattice(index);
auto& info = cell.template get<"info">();
auto info_v = info({0u}).get();
std::cout<<(static_cast<uint32_t>(info_v));
if( (index.at({1u}).get()+1u) < dim.at({1u}).get()){
std::cout<<" ";
}else{
std::cout<<"\n";
}
}, {{0u,0u}}, dim);
saw::data<sch::Array<sch::MacroStruct<sch::T,sch::D2Q9::D>,sch::D2Q9::D>> macros{dim};
for(uint64_t i = 0u; i < 256u; ++i){
{
std::string vtk_f_name{"tmp/poiseulle_2d_"};
vtk_f_name += std::to_string(i) + ".vtk";
write_vtk_file(vtk_f_name, macros);
}
// lbm_step(lattice, i);
}
return 0;
}
|