summaryrefslogtreecommitdiff
path: root/c++/macroscopic.hpp
blob: 51368e949e253f0b4eb386eae8b957219ec02a21 (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
#pragma once

#include "descriptor.hpp"

namespace kel {
namespace lbm {
/**
 * Calculate the macroscopic variables rho and u in Lattice Units.
 */
template<typename T, typename Desc>
void compute_rho_u (
		const saw::data<sch::Cell<T, Desc, 0, 0, 1>>& dfs,
		typename saw::native_data_type<T>::type& rho,
		std::array<typename saw::native_data_type<T>::type, 2>& vel
	)
{
	using dfi = df_info<T, Desc>;

	rho = 0;
	std::fill(vel.begin(), vel.end(), 0);

	for(size_t j = 0; j < Desc::Q; ++j){
		rho += dfs(j).get();
		for(size_t i = 0; i < Desc::D; ++i){
			vel[i] += dfi::directions[j][i] * dfs(j).get();
		}
	}

	for(size_t i = 0; i < Desc::D; ++i){
		vel[i] /= rho;
	}
}

/**
 * Calculate the macroscopic variables rho and u in Lattice Units.
 */
template<typename T, typename Desc>
void compute_rho_u (
		const saw::data<sch::Cell<T, Desc, 0, 0, 1>>& dfs,
		saw::ref<saw::data<T>> rho,
		saw::ref<saw::data<sch::FixedArray<T,Desc::D>>> vel
	)
{
	using dfi = df_info<T, Desc>;

	rho().set(0);
	for(uint64_t i = 0; i < Desc::D; ++i){
		vel().at({i}).set(0);
	}

	for(size_t j = 0; j < Desc::Q; ++j){
		rho() = rho() + dfs(j);
		for(size_t i = 0; i < Desc::D; ++i){
			vel().at({i}) = vel().at({i}) + saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[j][i])} * dfs(j);
		}
	}

	for(size_t i = 0; i < Desc::D; ++i){
		vel().at({i}) = vel().at({i}) / rho();
	}
}

/**
 * Calculate the macroscopic variables rho and u in Lattice Units.
 */
template<typename T, typename Desc>
void compute_rho_u (
		const saw::data<sch::Cell<T, Desc, 0, 0, 1>>& dfs,
		saw::ref<saw::data<T>> rho,
		saw::ref<saw::data<sch::Vector<T,Desc::D>>> vel
	)
{
	using dfi = df_info<T, Desc>;

	rho().set(0);
	for(uint64_t i = 0; i < Desc::D; ++i){
		vel().at({{i}}).set(0);
	}

	for(size_t j = 0; j < Desc::Q; ++j){
		rho() = rho() + dfs(j);
		for(size_t i = 0; i < Desc::D; ++i){
			vel().at({{i}}) = vel().at({{i}}) + saw::data<T>{static_cast<typename saw::native_data_type<T>::type>(dfi::directions[j][i])} * dfs(j);
		}
	}

	for(size_t i = 0; i < Desc::D; ++i){
		vel().at({{i}}) = vel().at({{i}}) / rho();
	}
}
}
}