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
|
#pragma once
#include "macroscopic.hpp"
#include "component.hpp"
#include "equilibrium.hpp"
namespace kel {
namespace lbm {
namespace cmpt {
struct HLBM {};
}
/**
* HLBM collision operator for LBM
*/
template<typename T, typename Descriptor, typename Encode>
class component<T, Descriptor, cmpt::HLBM, Encode> final {
private:
typename saw::native_data_type<T>::type relaxation_;
saw::data<T> frequency_;
public:
component(typename saw::native_data_type<T>::type relaxation__):
relaxation_{relaxation__},
frequency_{typename saw::native_data_type<T>::type(1) / relaxation_}
{}
template<typename CellFieldSchema, typename MacroFieldSchema>
void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> index, saw::data<sch::UInt64> time_step) const {
bool is_even = ((time_step.get() % 2) == 0);
auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
auto& particle_N_f = field.template get<"particle_N">();
auto& particle_D_f = field.template get<"particle_D">();
auto& porosity_f = macros.template get<"porosity">();
auto& rho_f = macros.template get<"density">();
auto& vel_f = macros.template get<"velocity">();
saw::data<sch::Scalar<T>>& rho = rho_f.at(index);
saw::data<sch::Vector<T,Descriptor::D>> vel = vel_f.at(index);
compute_rho_u<T,Descriptor>(dfs_old_f.at(index), rho, vel);
auto& porosity = porosity_f.at(index);
saw::data<sch::Scalar<T>> one;
one.at({}) = 1.0;
auto flip_porosity = one - porosity;
auto& N = particle_N_f.at(index);
auto& D = particle_D_f.at(index);
// Convex combination of velocities
vel = vel * porosity + N * flip_porosity / D;
// Equilibrium
auto eq = equilibrium<T,Descriptor>(rho,vel);
for(uint64_t i = 0u; i < Descriptor::Q; ++i){
dfs_old_f.at(index).at({i}) = dfs_old_f.at(index).at({i}) + frequency_ * (eq.at(i) - dfs_old_f.at(index).at({i}));
}
porosity.at({}) = 1.0;
D.at({}) = 0.0;
}
};
}
}
|