summaryrefslogtreecommitdiff
path: root/c++/examples
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 /c++/examples
parent0ba2bc42e7ffaf71983dc9a8a1c59853c50a2cc2 (diff)
c++: Generating example layouts
Diffstat (limited to 'c++/examples')
-rw-r--r--c++/examples/cavity_2d.cpp57
1 files changed, 56 insertions, 1 deletions
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){