summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2023-09-02 18:04:18 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2023-09-02 18:04:18 +0200
commitf3dde8285baf87a89d2a9b79ac719573c47538ff (patch)
treecc023cb0486601f14a0f0523e0c49ebd0d06c5f7
parent0ba2bc42e7ffaf71983dc9a8a1c59853c50a2cc2 (diff)
c++: Generating example layouts
-rw-r--r--c++/collide_and_stream.h3
-rw-r--r--c++/descriptor.h24
-rw-r--r--c++/examples/cavity_2d.cpp57
3 files changed, 68 insertions, 16 deletions
diff --git a/c++/collide_and_stream.h b/c++/collide_and_stream.h
index 5682437..5cbb551 100644
--- a/c++/collide_and_stream.h
+++ b/c++/collide_and_stream.h
@@ -2,8 +2,5 @@
namespace kel {
namespace lbm {
-class bgk_dynamics {
-
-};
}
}
diff --git a/c++/descriptor.h b/c++/descriptor.h
index 4d29831..33fef9b 100644
--- a/c++/descriptor.h
+++ b/c++/descriptor.h
@@ -1,6 +1,6 @@
#pragma once
-#include <forstio/codec/schema.h>
+#include <forstio/codec/data.h>
namespace kel {
namespace lbm {
@@ -32,24 +32,24 @@ template<typename T>
class df_info{};
template<typename T>
-class df_info<Descriptor<T, 2, 5>> {
- static constexpr std::array<std::array<int32_t, 2>, 5> directions = {
+class df_info<schema::Descriptor<T, 2, 5>> {
+ static constexpr std::array<std::array<int32_t, 2>, 5> directions = {{
{ 0, 0},
{-1, 0},
{ 0,-1},
{ 0, 1},
{ 1, 0}
+ }};
+
+ static constexpr std::array<typename saw::native_data_type<T>::type,5> weights = {
+ 1./3.,
+ 1./6.,
+ 1./6.,
+ 1./6.,
+ 1./6.
};
- static constexpr std::array<std::ratio<int32_t>,5> weights = {
- {1,3},
- {1,6},
- {1,6},
- {1,6},
- {1,6}
- };
-
- static constexpr std::ratio<int32_t> cs2 = {1,3};
+ static constexpr typename saw::native_data_type<T>::type cs2 = 1./3.;
};
}
}
diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp
index e06ba2d..88e53fe 100644
--- a/c++/examples/cavity_2d.cpp
+++ b/c++/examples/cavity_2d.cpp
@@ -17,7 +17,8 @@ namespace schema {
* D factor
* Q factor
*/
-using DfCell2DType = CellType<Float32, 2, 5, 0, 0, 1>;
+using T = Float32;
+using DfCell2DType = CellType<T, 2, 5, 0, 0, 1>;
using CellInfo2DType = CellType<UInt8, 2, 5, 1, 0, 0>;
@@ -30,9 +31,59 @@ using Cell = CellData<
>;
}
+
+template<size_t D, size_t Q>
+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(
+ typename saw::native_data_type<schema::T>::type rho,
+ std::array<typename saw::native_data_type<schema::T>::type, D> vel
+ ){
+ using dfi = df_info<schema::Descriptor<schema::T, D, Q>>;
+
+ typename std::array<saw::native_data_type<schema::T>::type,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]);
+ auto vel_c_cs2 = vel_c / dfi::cs2;
+ eq[i] = dfi::weights[i] * rho * (
+ 1
+ + vel_c_cs2
+ + vel_c_cs2 * vel_c_cs2
+ - ( vel[0] * vel[0] + vel[1] * vel[1] ) / ( 2. * dfi::cs2 )
+ );
+ }
+
+ return eq;
+
+ }
+
+ void compute_rho_u(
+ saw::data<schema::DfCell2DType>& dfs,
+ typename saw::native_data_type<schema::T>::type& rho,
+ std::array<typename saw::native_data_type<schema::T>::type, 2>& vel
+ ){
+ using dfi = df_info<schema::Descriptor<schema::T, D, Q>>;
+
+ rho = 0;
+ std::fill(vel.begin(), vel.end(), 0);
+
+ for(size_t i = 0; i < Q; ++i){
+ rho += dfs[i];
+ vel[0] += dfi::directions[i][0] * dfs.at(i).get();
+ vel[1] += dfi::directions[i][1] * dfs.at(i).get();
+ }
+
+ vel[0] /= rho;
+ vel[1] /= rho;
+ }
+};
}
}
+constexpr size_t dim_size = 2;
constexpr size_t dim_x = 32;
constexpr size_t dim_y = 32;
@@ -96,6 +147,10 @@ int main(){
set_initial_conditions(lattice);
/**
+ * Timeloop
+ */
+
+ /**
* Print basic setup info
*/
apply_for_cells([](auto& cell, std::size_t i, std::size_t j){