summaryrefslogtreecommitdiff
path: root/c++/descriptor.h
blob: fad9bf2f521337d7c881e206727304a3c2e3e009 (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
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once

#include <forstio/codec/data.hpp>

namespace kel {
namespace lbm {
namespace sch {
using namespace saw::schema;

template<uint64_t DV, uint64_t QV>
struct Descriptor {
	static constexpr uint64_t D = DV;
	static constexpr uint64_t Q = QV;
};

template<typename Sch, typename Desc, uint64_t SC_V, uint64_t DC_V, uint64_t QC_V>
struct Cell {
	using Descriptor = Desc;
	static constexpr uint64_t SC = SC_V;
	static constexpr uint64_t DC = DC_V;
	static constexpr uint64_t QC = QC_V;
	static constexpr uint64_t Size = SC + Desc::D * DC + Desc::Q * QC;
};

template<typename Desc, typename CellStruct>
struct Field;

template<typename Desc, typename... CellMembers>
struct Field<
	Desc,
	Struct<
		CellMembers...
	>
>;

}

template<typename T, typename Desc>
class df_info{};

template<typename T>
class df_info<T,sch::Descriptor<2, 5>> {
public:
	static constexpr uint64_t D = 2u;
	static constexpr uint64_t Q = 5u;

	static constexpr std::array<std::array<int32_t, D>, Q> directions = {{
		{ 0, 0},
		{-1, 0},
		{ 0,-1},
		{ 0, 1},
		{ 1, 0}
	}};

	static constexpr std::array<typename saw::native_data_type<T>::type,Q> weights = {
		1./3.,
		1./6.,
		1./6.,
		1./6.,
		1./6.
	};

	static constexpr std::array<uint64_t,Q> opposite_index = {
		0,
		3,
		4,
		1,
		2
	};

	static constexpr typename saw::native_data_type<T>::type cs2 = 1./3.;
};
}
}

namespace saw {
template<typename T, typename Desc, uint64_t S, uint64_t D, uint64_t Q>
struct meta_schema<kel::lbm::sch::Cell<T,Desc,S,D,Q>> {
  using MetaSchema = schema::Void;
	using Schema = kel::lbm::sch::Cell<T,Desc,S,D,Q>;
};

template<typename Desc, typename CellT>
struct meta_schema<kel::lbm::sch::Field<Desc, CellT>> {
  using MetaSchema = schema::FixedArray<schema::UInt64,Desc::D>;
	using Schema = kel::lbm::sch::Field<Desc, CellT>;
};

template<typename Sch, typename Desc, uint64_t S, uint64_t D, uint64_t Q, typename Encode>
class data<kel::lbm::sch::Cell<Sch, Desc, S, D, Q>, Encode> final {
public:
	using Schema = kel::lbm::sch::Cell<Sch,Desc,S,D,Q>;
	using MetaSchema = typename meta_schema<Schema>::MetaSchema;
private:
	data<schema::FixedArray<Sch, Schema::Size>, Encode> inner_;
public:
	data() = default;

	data<Sch, Encode>& operator()(const data<schema::UInt64>& index){
		return inner_.at(index);
	}
	const data<Sch, Encode>& operator()(const data<schema::UInt64>& index)const{
		return inner_.at(index);
	}
};

template<typename Desc, typename CellT, typename Encode>
class data<kel::lbm::sch::Field<Desc, CellT>, Encode> final {
public:
	using Schema = kel::lbm::sch::Field<Desc,CellT>;
	using MetaSchema = typename meta_schema<Schema>::MetaSchema;
private:
	data<schema::Array<CellT,Desc::D>, Encode> inner_;
public:
	data() = default;
	data(const data<schema::FixedArray<schema::UInt64, Desc::D>>& inner_meta__):
		inner_{inner_meta__}
	{}

	template<uint64_t i>
	data<schema::UInt64,Encode> get_dim_size() const {
		static_assert(i < Desc::D, "Not enough dimensions");
		return inner_.template get_dim_size<i>();
	}

	const data<CellT>& operator()(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index)const{
		return inner_.at(index);
	}

	data<CellT>& operator()(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index){
		return inner_.at(index);
	}
};
}