summaryrefslogtreecommitdiff
path: root/examples/stdkr_2d_bgk/init.hpp
blob: 3127c88b2a27bd76ec821b760c5eed621158c93a (plain)
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
#pragma once

#include "common.hpp"

namespace kel {
namespace lbm {

template<typename T, typename Desc, typename Coll>
saw::error_or<void> init(
		const converter<T>& conv,
		saw::data<sch::ChunkStruct<T,Desc>>& fields,
		saw::data<sch::MacroStruct<T,Desc>>& macros
){
	(void) conv;

	auto& info_f = fields.template get<"info">();
	// 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}}
	);
	
	// 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<"momentum">();
	
	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);
			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}}
	);

	iterator<Desc::D>::apply(
		[&](const auto& index){
			auto& info = info_f.at(index);
			saw::data<sch::Scalar<T>> radius_p;
			radius_p.at({}).set(conv.meter_si_to_lbm({{0.05}}).handle().get());
			saw::data<sch::Scalar<T>> dense_p;
			dense_p.at({}).set(1);

			saw::data<sch::Vector<T,Desc::D>> middle,ind_vec;
			middle.at({{0u}}) = conv.meter_si_to_lbm({{0.16}}).handle();
			middle.at({{1u}}) = conv.meter_si_to_lbm({{0.2}}).handle();

			for(uint64_t i{0u}; i < Desc::D; ++i){
				ind_vec.at({{i}}) = index.at({i}).template cast_to<T>();
			}

			auto dist = ind_vec - middle;
			auto dist_2 = saw::math::dot(dist,dist);

			if(dist_2.at({}) < radius_p.at({}) * radius_p.at({})){
				info_f.at(index) = 1u;
			}
		},
		{},// 0-index
		df_f.get_dims()
	);
	return saw::make_void();
}

}
}