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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
#pragma once
#include <forstio/codec/data.hpp>
#include <forstio/codec/data_math.hpp>
#include <forstio/codec/schema_factory.hpp>
#include "descriptor/d1q3.hpp"
#include "descriptor/d2q5.hpp"
#include "descriptor/d2q9.hpp"
#include "descriptor/d3q19.hpp"
#include "descriptor/d3q27.hpp"
namespace kel {
namespace lbm {
namespace sch {
using namespace saw::schema;
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 Cell>
struct CellField{
using Descriptor = Desc;
};
template<typename Desc, typename... CellFieldTypes, saw::string_literal... CellFieldNames>
struct CellField<
Desc,
Struct<
Member<CellFieldTypes, CellFieldNames>...
>
> {
using Descriptor = Desc;
};
template<typename Desc, typename... CellFieldMembers>
struct CellFieldStruct {
using Descriptor = Desc;
// using MetaSchema = FixedArray<UInt64, Desc::D>;
};
}
/*
namespace impl {
template<typename Desc>
struct df_ct_helper {
template<uint64_t i>
static constexpr uint64_t apply_i(const std::array<std::array<int32_t,Desc::D>,Desc::Q>& dirs, const std::array<T,Desc::D+1u>& inp){
if constexpr ( i < Desc::Q ){
for(uint64_t j = 0u; j < Desc::D; ++j){
}
}
return 0u;
}
};
}
*/
template<typename Schema>
class cell_schema_builder {
private:
saw::schema_factory<Schema> factory_struct_;
public:
cell_schema_builder() = default;
cell_schema_builder(saw::schema_factory<Schema> inp):
factory_struct_{inp}
{}
/*
template<typename TA, saw::string_literal KA>
constexpr auto require() const noexcept {
return {factory_struct_.add_maybe()};
}
*/
};
}
}
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::CellField<Desc, CellT>> {
using MetaSchema = schema::FixedArray<schema::UInt64,Desc::D>;
using Schema = kel::lbm::sch::CellField<Desc, CellT>;
};
template<typename Desc, typename... CellFieldsT>
struct meta_schema<kel::lbm::sch::CellFieldStruct<Desc,schema::Struct<CellFieldsT...>>> {
using MetaSchema = schema::FixedArray<schema::UInt64,Desc::D>;
using Schema = kel::lbm::sch::CellFieldStruct<Desc,schema::Struct<CellFieldsT...>>;
};
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);
}
const data<kel::lbm::sch::Cell<Sch, Desc, S, D, Q>, Encode> copy() const {
return *this;
}
};
/*
* Create a cellfield
*/
template<typename Desc, typename CellT, typename Encode>
class data<kel::lbm::sch::CellField<Desc, CellT>, Encode> final {
public:
using Schema = kel::lbm::sch::CellField<Desc,CellT>;
using MetaSchema = typename meta_schema<Schema>::MetaSchema;
private:
data<schema::Array<CellT,Desc::D>, Encode> inner_;
public:
data() = default;
data(const data<MetaSchema,Encode>& inner_meta__):
inner_{inner_meta__}
{}
const data<MetaSchema, Encode> meta() const {
return inner_.dims();
}
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);
}
const data<CellT>& at(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index)const{
return inner_.at(index);
}
data<CellT>& at(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index){
return inner_.at(index);
}
data<schema::UInt64,Encode> internal_size() const {
return inner_.internal_size();
}
data<CellT,Encode>* internal_data() {
return inner_.internal_data();
}
};
/**
* Is basically a struct, but additionally has members for meta() calls. It technically is a Field of a struct, but organized through a struct of fields.
*/
template<typename Desc, typename... CellFieldsT, typename Encode>
class data<kel::lbm::sch::CellFieldStruct<Desc, schema::Struct<CellFieldsT...>>, Encode> final {
public:
using Schema = kel::lbm::sch::CellFieldStruct<Desc,schema::Struct<CellFieldsT...>>;
/// @TODO Add MetaSchema to Schema
using MetaSchema = typename meta_schema<Schema>::MetaSchema;
private:
static_assert(sizeof...(CellFieldsT) > 0u, "");
data<schema::Struct<CellFieldsT...>, Encode> inner_;
template<uint64_t i>
saw::error_or<void> helper_constructor(const data<schema::FixedArray<schema::UInt64,Desc::D>>& grid_size){
using MemT = saw::parameter_pack_type<i,CellFieldsT...>::type;
{
inner_.template get<MemT::KeyLiteral>() = {grid_size};
}
if constexpr (sizeof...(CellFieldsT) > (i+1u)){
return helper_constructor<i+1u>(grid_size);
}
return saw::make_void();
}
public:
data() = delete;
data(const data<schema::FixedArray<schema::UInt64,Desc::D>>& grid_size__){
auto eov = helper_constructor<0u>(grid_size__);
(void)eov;
}
const data<MetaSchema, Encode> meta() const {
using MemT = saw::parameter_pack_type<0u,CellFieldsT...>::type;
return inner_.template get<MemT::KeyLiteral>().meta();
}
template<saw::string_literal Key>
auto& get() {
return inner_.template get<Key>();
}
template<saw::string_literal Key>
const auto& get() const {
return inner_.template get<Key>();
}
};
}
|