summaryrefslogtreecommitdiff
path: root/c++
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-03-03 11:11:01 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-03-03 11:11:01 +0100
commit1b553907f0d09671f7036a5cca1ff93021582d5c (patch)
treea114e1f9ec5c0631c3ddf3a123a630e55386822c /c++
parent53dbb79af414806508748f045f5defd89e93eade (diff)
wip
Diffstat (limited to 'c++')
-rw-r--r--c++/descriptor.h25
-rw-r--r--c++/examples/cavity_2d.cpp28
2 files changed, 31 insertions, 22 deletions
diff --git a/c++/descriptor.h b/c++/descriptor.h
index 1d22f91..e1be1e9 100644
--- a/c++/descriptor.h
+++ b/c++/descriptor.h
@@ -4,14 +4,23 @@
namespace kel {
namespace lbm {
-namespace schema {
+namespace sch {
using namespace saw::schema;
-template<typename T, uint64_t D, uint64_t Q>
-struct Descriptor {};
+template<uint64_t D, uint64_t Q>
+struct Descriptor {
+ static constexpr uint64_t D = D;
+ static constexpr uint64_t Q = Q;
+};
-template<typename T, uint64_t D, uint64_t Q, uint64_t SC, uint64_t DC, uint64_t QC>
-using CellType = FixedArray<T,SC+D*DC+Q*QC>;
+template<typename Sch, typename Desc, uint64_t SC, uint64_t DC, uint64_t QC>
+struct Field {
+ using Alias = Sch;
+ using Descriptor = Desc;
+ static constexpr uint64_t SC = SC;
+ static constexpr uint64_t DC = DC;
+ static constexpr uint64_t QC = QC;
+};
/**
* T... is restricted to Member schemas
@@ -20,7 +29,7 @@ template<typename... CellT>
using CellData = Struct<
CellT...
>;
-
+^
/**
* T is an array of CellData
*/
@@ -28,11 +37,11 @@ template<typename T, size_t D>
using Lattice = Array<T, D>;
}
-template<typename T>
+template<typename T, typename Desc>
class df_info{};
template<typename T>
-class df_info<schema::Descriptor<T, 2, 5>> {
+class df_info<T,sch::Descriptor<2, 5>> {
static constexpr std::array<std::array<int32_t, 2>, 5> directions = {{
{ 0, 0},
{-1, 0},
diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp
index b681eea..aaf6ba3 100644
--- a/c++/examples/cavity_2d.cpp
+++ b/c++/examples/cavity_2d.cpp
@@ -18,23 +18,23 @@ namespace schema {
* Q factor
*/
using T = Float32;
-using DfCell2DType = CellType<T, 2, 5, 0, 0, 1>;
+using DfCell2D = Field<T, D2Q5, 0, 0, 1>;
-using CellInfo2DType = CellType<UInt8, 2, 5, 1, 0, 0>;
+using CellInfo2D = Field<UInt8, D2Q5, 1, 0, 0>;
/**
* Basic type for simulation
*/
using Cell = CellData<
- Member<DfCell2DType, "dfs">,
- Member<CellInfo2DType, "info">
+ Member<DfCell2D, "dfs">,
+ Member<CellInfo2D, "info">
>;
}
-template<typename T, size_t D, size_t Q, size_t SN, size_t DN, size_t QN>
+template<typename T, typename Desc, size_t SN, size_t DN, size_t QN>
struct cell_type {
- using Type = schema::CellType<T, D, Q, SN, DN, QN>;
+ using Type = schema::Field<T, Desc, SN, DN, QN>;
};
template<typename T>
@@ -43,8 +43,8 @@ class df_cell_view;
/**
* Minor helper for the AA-Pull Pattern
*/
-template<size_t D, size_t Q, size_t SN, size_t DN, size_t QN>
-class df_cell_view<cell_type<schema::T, D, Q, SN, DN, QN>> {
+template<typename Desc, size_t SN, size_t DN, size_t QN>
+class df_cell_view<cell_type<schema::T, Desc, SN, DN, QN>> {
private:
std::array<std::decay_t<typename saw::native_data_type<schema::T>::type>*, QN> view_;
public:
@@ -53,18 +53,18 @@ public:
{}
};
-template<size_t D, size_t Q>
+template<typename Desc>
class collision {
public:
typename saw::native_data_type<schema::T>::type relaxation_;
public:
- std::array<typename saw::native_data_type<schema::T>::type,Q> equilibrium(
+ std::array<typename saw::native_data_type<schema::T>::type,Desc::Q> equilibrium(
typename saw::native_data_type<schema::T>::type rho,
- std::array<typename saw::native_data_type<schema::T>::type, D> vel
+ std::array<typename saw::native_data_type<schema::T>::type, Desc::D> vel
){
- using dfi = df_info<schema::Descriptor<schema::T, D, Q>>;
+ using dfi = df_info<schema::T, Desc>;
- typename std::array<saw::native_data_type<schema::T>::type,Q> eq;
+ typename std::array<saw::native_data_type<schema::T>::type,Desc::Q> eq;
for(std::size_t i = 0; i < eq.size(); ++i){
auto vel_c = (vel[0]*dfi::directions[i][0] + vel[1]*dfi::directions[i][1]);
@@ -81,7 +81,7 @@ public:
}
void compute_rho_u(
- saw::data<schema::DfCell2DType>& dfs,
+ saw::data<sch::DfCell2D>& dfs,
typename saw::native_data_type<schema::T>::type& rho,
std::array<typename saw::native_data_type<schema::T>::type, 2>& vel
){