summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2023-08-14 03:55:48 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2023-08-14 03:55:48 +0200
commit0ba2bc42e7ffaf71983dc9a8a1c59853c50a2cc2 (patch)
tree5e27fd07eb9c93c07493b34121f0b5c2036d9d9e
parenta8f3da04b7d924d6bc8a38b15c7f0def4240a76a (diff)
c++: Going into the area of simple BGK Dynamics
-rw-r--r--c++/collide_and_stream.h9
-rw-r--r--c++/descriptor.h24
-rw-r--r--c++/examples/cavity_2d.cpp80
3 files changed, 110 insertions, 3 deletions
diff --git a/c++/collide_and_stream.h b/c++/collide_and_stream.h
new file mode 100644
index 0000000..5682437
--- /dev/null
+++ b/c++/collide_and_stream.h
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace kel {
+namespace lbm {
+class bgk_dynamics {
+
+};
+}
+}
diff --git a/c++/descriptor.h b/c++/descriptor.h
index c09b312..4d29831 100644
--- a/c++/descriptor.h
+++ b/c++/descriptor.h
@@ -27,5 +27,29 @@ using CellData = Struct<
template<typename T, size_t D>
using Lattice = Array<T, D>;
}
+
+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 = {
+ { 0, 0},
+ {-1, 0},
+ { 0,-1},
+ { 0, 1},
+ { 1, 0}
+ };
+
+ 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};
+};
}
}
diff --git a/c++/examples/cavity_2d.cpp b/c++/examples/cavity_2d.cpp
index 0f96a65..e06ba2d 100644
--- a/c++/examples/cavity_2d.cpp
+++ b/c++/examples/cavity_2d.cpp
@@ -2,6 +2,8 @@
#include <forstio/codec/data.h>
+#include <iostream>
+
namespace kel {
namespace lbm {
namespace schema {
@@ -31,8 +33,23 @@ using Cell = CellData<
}
}
+constexpr size_t dim_x = 32;
+constexpr size_t dim_y = 32;
+
+struct rectangle {
+ std::array<size_t,4> data_;
+
+ rectangle(size_t x, size_t y, size_t w, size_t h):
+ data_{x,y,w,h}
+ {}
+
+ bool inside(size_t i, size_t j) const {
+ return !(i < data_[0] || i > (data_[0]+data_[2]) || j < data_[1] || j > (data_[1] +data_[3]));
+ }
+};
+
template<typename Func, typename Schema, size_t Dim>
-void apply_for_cells(Func&& func, saw::data<saw::schema::Array<Schema, Dim>, saw::encode::Native>& dat ){
+void apply_for_cells(Func&& func, saw::data<saw::schema::Array<Schema, Dim>>& dat){
for(std::size_t i = 0; i < dat.get_dim_size(0); ++i){
for(std::size_t j = 0; j < dat.get_dim_size(1); ++j){
func(dat.at(i,j), i, j);
@@ -40,14 +57,71 @@ void apply_for_cells(Func&& func, saw::data<saw::schema::Array<Schema, Dim>, saw
}
}
+void set_geometry(saw::data<kel::lbm::schema::Lattice<kel::lbm::schema::Cell,2>>& latt){
+ using namespace kel::lbm;
+ apply_for_cells([](auto& cell, std::size_t i, std::size_t j){
+ uint8_t val = 0;
+ if(i == 1){
+ val = 2;
+ }
+ if(j == 1 || (i+2) == dim_x || (j+2) == dim_y){
+ val = 3;
+ }
+ if(i == 0 || j == 0 || (i+1) == dim_x || (j+1) == dim_y){
+ val = 1;
+ }
+ cell.template get<"info">().at(0).set(val);
+ }, latt);
+}
+
+void set_initial_conditions(saw::data<kel::lbm::schema::Lattice<kel::lbm::schema::Cell,2>>& latt){
+ using namespace kel::lbm;
+ apply_for_cells([](auto& cell, std::size_t i, std::size_t j){
+ cell.template get<"dfs">().at(0).set(1.0);
+ }, latt);
+}
+
int main(){
using namespace kel::lbm;
- saw::data<schema::Lattice<kel::lbm::schema::Cell,2>, saw::encode::Native> lattice{512, 512};
+ saw::data<schema::Lattice<kel::lbm::schema::Cell,2>, saw::encode::Native> lattice{dim_x, dim_y};
+
+ /**
+ * Set meta information describing what this cell is
+ */
+ set_geometry(lattice);
+ /**
+ *
+ */
+ set_initial_conditions(lattice);
+ /**
+ * Print basic setup info
+ */
apply_for_cells([](auto& cell, std::size_t i, std::size_t j){
- // cell.get<"info">();
+ // Not needed
+ (void) i;
+ std::cout<<static_cast<uint32_t>(cell.template get<"info">().at(0).get());
+ if( (j+1) < dim_y){
+ std::cout<<" ";
+ }else{
+ std::cout<<"\n";
+ }
}, lattice);
+
+ std::cout<<"\n";
+ apply_for_cells([](auto& cell, std::size_t i, std::size_t j){
+ // Not needed
+ (void) i;
+ std::cout<<cell.template get<"dfs">().at(0).get();
+ if( (j+1) < dim_y){
+ std::cout<<" ";
+ }else{
+ std::cout<<"\n";
+ }
+ }, lattice);
+
+ std::cout<<std::endl;
return 0;
}