summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/cavity_2d/.nix/derivation.nix33
-rw-r--r--examples/cavity_2d/SConscript32
-rw-r--r--examples/cavity_2d/SConstruct79
-rw-r--r--examples/cavity_2d/cavity_2d.cpp456
-rw-r--r--examples/cavity_2d_gpu/.nix/derivation.nix3
-rw-r--r--examples/cavity_2d_gpu/SConstruct2
-rw-r--r--examples/cavity_2d_gpu/cavity_2d_gpu.cpp698
-rw-r--r--examples/heterogeneous_computing/.nix/derivation.nix41
-rw-r--r--examples/heterogeneous_computing/README.md7
-rw-r--r--examples/heterogeneous_computing/SConscript34
-rw-r--r--examples/heterogeneous_computing/SConstruct82
-rw-r--r--examples/heterogeneous_computing/sim.cpp95
-rw-r--r--examples/meta/.nix/derivation.nix33
-rw-r--r--examples/meta/SConscript32
-rw-r--r--examples/meta/SConstruct79
-rw-r--r--examples/meta/meta.cpp133
-rw-r--r--examples/particles_gpu/.nix/derivation.nix37
-rw-r--r--examples/particles_gpu/SConscript34
-rw-r--r--examples/particles_gpu/SConstruct82
-rw-r--r--examples/particles_gpu/particles_gpu.cpp136
-rw-r--r--examples/poiseulle_2d_gpu/.nix/derivation.nix2
-rw-r--r--examples/poiseulle_2d_gpu/SConstruct4
-rw-r--r--examples/poiseulle_2d_gpu/poiseulle_2d_gpu.cpp658
-rw-r--r--examples/poiseulle_3d/.nix/derivation.nix4
-rw-r--r--examples/poiseulle_3d/SConstruct2
-rw-r--r--examples/poiseulle_3d/poiseulle_3d.cpp695
-rw-r--r--examples/stdkr_2d_bgk/sim.cpp5
-rw-r--r--examples/stdkr_2d_bgk/step.hpp2
-rw-r--r--examples/throat_clog_2d/init.hpp36
-rw-r--r--examples/throat_clog_2d/sim.cpp80
-rw-r--r--examples/throat_clog_2d/step.hpp32
31 files changed, 1169 insertions, 2479 deletions
diff --git a/examples/cavity_2d/.nix/derivation.nix b/examples/cavity_2d/.nix/derivation.nix
deleted file mode 100644
index d0660e9..0000000
--- a/examples/cavity_2d/.nix/derivation.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-{ lib
-, stdenv
-, scons
-, clang-tools
-, forstio
-, pname
-, version
-, kel
-}:
-
-stdenv.mkDerivation {
- pname = pname + "-examples-" + "cavity_2d";
- inherit version;
- src = ./..;
-
- nativeBuildInputs = [
- scons
- clang-tools
- ];
-
- buildInputs = [
- forstio.core
- forstio.async
- forstio.codec
- forstio.codec-unit
- forstio.codec-json
- kel.lbm.core
- ];
-
- preferLocalBuild = true;
-
- outputs = [ "out" "dev" ];
-}
diff --git a/examples/cavity_2d/SConscript b/examples/cavity_2d/SConscript
deleted file mode 100644
index 3fabe4b..0000000
--- a/examples/cavity_2d/SConscript
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/false
-
-import os
-import os.path
-import glob
-
-
-Import('env')
-
-dir_path = Dir('.').abspath
-
-# Environment for base library
-examples_env = env.Clone();
-
-examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
-examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
-
-env.sources += examples_env.sources;
-env.headers += examples_env.headers;
-
-# Cavity2D
-examples_objects = [];
-examples_env.add_source_files(examples_objects, ['cavity_2d.cpp'], shared=False);
-examples_env.cavity_2d = examples_env.Program('#bin/cavity_2d', [examples_objects]);
-
-# Set Alias
-env.examples = [
- examples_env.cavity_2d
-];
-env.Alias('examples', env.examples);
-env.targets += ['examples'];
-env.Install('$prefix/bin/', env.examples);
diff --git a/examples/cavity_2d/SConstruct b/examples/cavity_2d/SConstruct
deleted file mode 100644
index a7201cb..0000000
--- a/examples/cavity_2d/SConstruct
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-import os
-import os.path
-import glob
-import re
-
-
-if sys.version_info < (3,):
- def isbasestring(s):
- return isinstance(s,basestring)
-else:
- def isbasestring(s):
- return isinstance(s, (str,bytes))
-
-def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
-
- if isbasestring(filetype):
- dir_path = self.Dir('.').abspath
- filetype = sorted(glob.glob(dir_path+"/"+filetype))
-
- for path in filetype:
- target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
- if shared:
- target_name+='.os'
- sources.append( self.SharedObject( target=target_name, source=path ) )
- else:
- target_name+='.o'
- sources.append( self.StaticObject( target=target_name, source=path ) )
- pass
-
-def isAbsolutePath(key, dirname, env):
- assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
-
-env_vars = Variables(
- args=ARGUMENTS
-)
-
-env_vars.Add('prefix',
- help='Installation target location of build results and headers',
- default='/usr/local/',
- validator=isAbsolutePath
-)
-
-env_vars.Add('build_examples',
- help='If examples should be built',
- default="true"
-)
-
-env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
- CPPDEFINES=['SAW_UNIX'],
- CXXFLAGS=[
- '-std=c++20',
- '-g',
- '-Wall',
- '-Wextra'
- ],
- LIBS=[
- 'forstio-core'
- ]
-);
-env.__class__.add_source_files = add_kel_source_files
-env.Tool('compilation_db');
-env.cdb = env.CompilationDatabase('compile_commands.json');
-
-env.objects = [];
-env.sources = [];
-env.headers = [];
-env.targets = [];
-
-Export('env')
-SConscript('SConscript')
-
-env.Alias('cdb', env.cdb);
-env.Alias('all', [env.targets]);
-env.Default('all');
-
-env.Alias('install', '$prefix')
diff --git a/examples/cavity_2d/cavity_2d.cpp b/examples/cavity_2d/cavity_2d.cpp
deleted file mode 100644
index ea63745..0000000
--- a/examples/cavity_2d/cavity_2d.cpp
+++ /dev/null
@@ -1,456 +0,0 @@
-#include <kel/lbm/lbm.hpp>
-
-#include <forstio/codec/data.hpp>
-
-#include <iostream>
-#include <fstream>
-#include <cmath>
-
-namespace kel {
-namespace lbm {
-namespace sch {
-
-/**
- * Basic distribution function
- * Base type
- * D
- * Q
- * Scalar factor
- * D factor
- * Q factor
- */
-using T = Float32;
-using D2Q5 = Descriptor<2u,5u>;
-using D2Q9 = Descriptor<2u,9u>;
-
-template<typename Desc>
-using DfCell = Cell<T, Desc, 0u, 0u, 1u>;
-
-template<typename Desc>
-using CellInfo = Cell<UInt8, D2Q9, 1u, 0u, 0u>;
-
-/**
- * Basic type for simulation
- */
-template<typename Desc>
-using CellStruct = Struct<
- Member<DfCell<Desc>, "dfs">,
- Member<DfCell<Desc>, "dfs_old">,
- Member<CellInfo<Desc>, "info">
->;
-
-/**
- * Macroscopic fields, one chunk per quantity.
- *
- * This used to be an Array of per cell structs. The VTK writer takes a Struct
- * whose members are all Chunks of the same extent, and compute_rho_u wants
- * Scalar/Vector rather than a bare primitive and a FixedArray, so the layout
- * moved from array-of-struct to struct-of-arrays.
- */
-template<typename T, uint64_t D, uint64_t DimX, uint64_t DimY>
-using MacroStruct = Struct<
- Member<Chunk<Vector<T,D>, 0u, DimX, DimY>, "velocity">,
- Member<Chunk<Scalar<T>, 0u, DimX, DimY>, "density">
->;
-
-using CavityFieldD2Q9 = CellField<D2Q9, CellStruct<D2Q9>>;
-}
-
-
-/*
-template<typename T, typename Encode>
-class df_cell_view;
-*/
-/**
- * Minor helper for the AA-Pull Pattern, so I can use only one lattice
- *
- * Am I sure I want to use AA this way?
- * Esoteric Twist technically reduces the needed memory access footprint
- */
-/*
-template<typename Desc, size_t SN, size_t DN, size_t QN, typename Encode>
-class df_cell_view<sch::Cell<sch::T, Desc, SN, DN, QN>, Encode> {
-public:
- using Schema = sch::Cell<sch::T,Desc,SN,DN,QN>;
-private:
- std::array<std::decay_t<typename kel::lbm::native_data_type<sch::T>::type>*, QN> view_;
-public:
- df_cell_view(const std::array<std::decay_t<typename kel::lbm::native_data_type<sch::T>::type>*, QN>& view):
- view_{view}
- {}
-};
-*/
-namespace cmpt {
-struct MovingWall {};
-}
-
-/**
- * Full-Way moving wall Bounce back, something is not right here.
- * Technically it should reflect properly.
- */
-template<typename Desc>
-class component<sch::T, Desc, cmpt::MovingWall> {
-public:
- std::array<typename kel::lbm::native_data_type<sch::T>::type, Desc::D> lid_vel;
-
-public:
- void apply(
- kel::lbm::data<sch::DfCell<Desc>>& dfs
- ){
- using dfi = df_info<sch::T,Desc>;
-
- // Technically use .copy()
- /*
- auto dfs_cpy = dfs;
-
- for(uint64_t i = 0u; i < Desc::Q; ++i){
- dfs({dfi::opposite_index.at(i)}) = dfs_cpy({i}) - 2.0 * dfi::weights[i] * 1.0 * ( lid_vel[0] * dfi::directions[i][0] + lid_vel[1] * dfi::directions[i][1]) * dfi::inv_cs2;
- }
- */
- }
-};
-}
-}
-
-constexpr size_t dim_size = 2;
-constexpr size_t dim_x = 128;
-constexpr size_t dim_y = 128;
-
-
-template<typename Func>
-void apply_for_cells(Func&& func, kel::lbm::data<kel::lbm::sch::CavityFieldD2Q9>& dat){
- for(std::size_t i = 0; i < dat.meta().at({1u}).get(); ++i){
- for(std::size_t j = 0; j < dat.meta().at({0u}).get(); ++j){
- kel::lbm::data<kel::lbm::sch::UInt64> di{i};
- kel::lbm::data<kel::lbm::sch::UInt64> dj{j};
- auto& cell_v = dat({{dj,di}});
- func(cell_v, j, i);
- }
- }
-}
-
-void set_geometry(kel::lbm::data<kel::lbm::sch::CavityFieldD2Q9>& latt){
- using namespace kel::lbm;
- apply_for_cells([](auto& cell, std::size_t i, std::size_t j){
- uint8_t val = 0;
- if(j == 1){
- val = 2u;
- }
- if(i == 1 || (i+2) == dim_x || (j+2) == dim_y){
- val = 3u;
- }
- if(i > 1 && (i+2) < dim_x && j > 1 && (j+2) < dim_y){
- val = 1u;
- }
- if(i == 0 || j == 0 || (i+1) == dim_x || (j+1) == dim_y){
- val = 0u;
- }
- cell.template get<"info">()(0u).set(val);
- }, latt);
-}
-
-void set_initial_conditions(kel::lbm::data<kel::lbm::sch::CavityFieldD2Q9>& latt){
- using namespace kel::lbm;
-
- kel::lbm::data<sch::T> rho{1.0};
- {
- kel::lbm::data<sch::FixedArray<sch::T,sch::D2Q9::D>> vel{{0.0,0.0}};
- auto eq = equilibrium<sch::T,sch::D2Q9>(rho, vel);
-
- apply_for_cells([&eq](auto& cell, std::size_t i, std::size_t j){
- (void) i;
- (void) j;
- auto& dfs = cell.template get<"dfs">();
- auto& dfs_old = cell.template get<"dfs_old">();
- auto info = cell.template get<"info">()(0u).get();
- for(uint64_t k = 0; k < sch::D2Q9::Q; ++k){
- dfs(k) = eq.at({k});
- dfs_old(k) = eq.at({k});
- }
- }, latt);
- }
-
- {
- kel::lbm::data<sch::FixedArray<sch::T,sch::D2Q9::D>> vel{{0.1,0.0}};
- auto eq = equilibrium<sch::T,sch::D2Q9>(rho, vel);
-
- apply_for_cells([&eq](auto& cell, std::size_t i, std::size_t j){
- (void) i;
- (void) j;
- auto& dfs = cell.template get<"dfs">();
- auto& dfs_old = cell.template get<"dfs_old">();
- auto info = cell.template get<"info">()(0u).get();
- if(info == 2u){
- for(uint64_t k = 0; k < sch::D2Q9::Q; ++k){
- dfs(k) = eq.at({k});
- dfs_old(k) = eq.at({k});
- }
- }
- }, latt);
- }
-}
-
-void lbm_step(
- kel::lbm::data<kel::lbm::sch::CavityFieldD2Q9>& latt,
- bool even_step,
- uint64_t time_step
-){
- using namespace kel::lbm;
- using dfi = df_info<sch::T,sch::D2Q9>;
-
- /**
- * 1. Relaxation parameter \tau
- */
- component<sch::T, sch::D2Q9, cmpt::BGK> coll{0.5384};
- component<sch::T, sch::D2Q9, cmpt::BounceBack> bb;
-
- component<sch::T, sch::D2Q9, cmpt::MovingWall> bb_lid;
- bb_lid.lid_vel = {0.1,0.0};
-
- auto meta = latt.meta();
-
- // Collide
- for(kel::lbm::data<sch::UInt64> i{0u}; i < meta.at(0u); ++i){
- for(kel::lbm::data<sch::UInt64> j{0u}; j < meta.at(1u); ++j ){
- auto& cell = latt({{i,j}});
- auto& info = cell.template get<"info">();
-
- switch(info({0u}).get()){
- case 1u: {
- coll.apply(latt, {{i,j}}, time_step);
- break;
- }
- case 2u: {
- auto& df = even_step ? cell.template get<"dfs_old">() : cell.template get<"dfs">();
- bb_lid.apply(df);
- break;
- }
- case 3u: {
- bb.apply(latt, {{i,j}}, time_step);
- break;
- }
- default:
- break;
- }
- }
- }
-
- // Stream
- for(uint64_t i = 1u; (i+1u) < latt.template get_dim_size<0>().get(); ++i){
- for(uint64_t j = 1u; (j+1u) < latt.template get_dim_size<1>().get(); ++j){
- auto& cell = latt({{i,j}});
- auto& df_new = even_step ? cell.template get<"dfs">() : cell.template get<"dfs_old">();
- auto& info_new = cell.template get<"info">();
-
- if(info_new({0u}).get() > 0u && info_new({0u}).get() != 2u){
- for(uint64_t k = 0u; k < sch::D2Q9::Q; ++k){
- auto dir = dfi::directions[dfi::opposite_index[k]];
- auto& cell_dir_old = latt({{i+dir[0],j+dir[1]}});
-
- auto& df_old = even_step ? cell_dir_old.template get<"dfs_old">() : cell_dir_old.template get<"dfs">();
- auto& info_old = cell_dir_old.template get<"info">();
-
- if( info_old({0}).get() == 2u ){
- auto& df_old_loc = even_step ? latt({{i,j}}).template get<"dfs_old">() : latt({{i,j}}).template get<"dfs">();
- df_new({k}) = df_old_loc({dfi::opposite_index.at(k)}) - 2.0 * dfi::inv_cs2 * dfi::weights.at(k) * 1.0 * ( bb_lid.lid_vel[0] * dir[0] + bb_lid.lid_vel[1] * dir[1]);
- // dfs({dfi::opposite_index.at(i)}) = dfs_cpy({i}) - 2.0 * dfi::weights[i] * 1.0 * ( lid_vel[0] * dfi::directions[i][0] + lid_vel[1] * dfi::directions[i][1]) * dfi::inv_cs2;
- } else {
- df_new({k}) = df_old({k});
- }
- }
- }
- }
- }
-}
-
-int main(){
- using namespace kel::lbm;
-
- kel::lbm::data<sch::FixedArray<sch::UInt64,sch::D2Q9::D>> dim{{dim_x, dim_y}};
-
- kel::lbm::data<sch::CavityFieldD2Q9, kel::lbm::enc::Native> lattice{dim};
-
- converter<sch::T> conv{
- {0.1},
- {0.1}
- };
-
- // Lid driven cavity: the lid velocity and the cavity height are the
- // characteristic scales.
- print_lbm_meta<sch::T, sch::D2Q9>(conv, {1e-3}, {0.1}, {dim_y});
-
- //auto& df_field = lattices.at(0).template get<"dfs">();
- //for(uint64_t i = 0; i < df_field.get_dim_size<0u>(); ++i){
- // lattices.at(i) = {dim_x, dim_y};
- //}
-
- /**
- * Set meta information describing what this cell is
- */
- set_geometry(lattice);
-
- /**
- *
- */
- set_initial_conditions(lattice);
-
- /**
- * Timeloop
- */
-
- /**
- * Print basic setup info
- */
- apply_for_cells([](auto& cell, std::size_t i, std::size_t j){
- // Not needed
- (void) j;
- std::cout<<(static_cast<uint32_t>(cell.template get<"info">()({0}).get()));
- if( (i+1) < dim_x){
- std::cout<<" ";
- }else{
- std::cout<<"\n";
- }
- }, lattice);
-
- uint64_t lattice_steps = 512000u;
- bool even_step = true;
-
- uint64_t print_every = 256u;
- uint64_t file_no = 0u;
-
- // Chunks carry their extent in the type, so no runtime dim argument.
- kel::lbm::data<sch::MacroStruct<sch::T,sch::D2Q9::D,dim_x,dim_y>> macros;
-
- for(uint64_t step = 0; step < lattice_steps; ++step){
-
- if(step % print_every == 0u){
- std::cout<<"\n";
- typename kel::lbm::native_data_type<sch::T>::type sum = 0.0;
-
-
- apply_for_cells([&](auto& cell, std::size_t i, std::size_t j){
- auto& dfs = cell.template get<"dfs">();
- // compute_rho_u takes a FixedArray of populations now, while this
- // example still stores them in a Cell. Same Q values, different
- // schema, so copy across rather than reinterpret.
- kel::lbm::data<sch::FixedArray<sch::T,sch::D2Q9::Q>> dfs_arr;
- for(uint64_t q{0u}; q < sch::D2Q9::Q; ++q){
- dfs_arr.at({q}) = dfs({q});
- }
-
- kel::lbm::data<sch::Scalar<sch::T>> rho_d;
- kel::lbm::data<sch::Vector<sch::T,sch::D2Q9::D>> vel_d;
- compute_rho_u<sch::T,sch::D2Q9>(dfs_arr,rho_d,vel_d);
-
- const auto rho = rho_d.at({}).get();
- const typename kel::lbm::native_data_type<sch::T>::type vel[sch::D2Q9::D] = {
- vel_d.at({{0u}}).get(), vel_d.at({{1u}}).get()};
-
- if(i > 1 && (i+2) < dim_x && j > 1 && (j+2) < dim_y){
- sum += rho;
- }
- auto angle = std::atan2(vel[1],vel[0]);
- double vel_mag = vel[1] * vel[1] + vel[0] * vel[0];
-
- auto dir_char = [&]() -> std::string_view {
- /**
- * Flipped y due to print order
- */
- constexpr auto pi = M_PI;
- return "■";
- if(vel_mag < 1e-4){
- return "•";
- }
- if(angle > 7.0 / 8.0 * pi){
- return "←";
- }
- if(angle > 5.0 / 8.0 * pi){
- return "↙";
- }
- if(angle > 3.0 / 8.0 * pi){
- return "↓";
- }
- if(angle > 1.0 / 8.0 * pi){
- return "↘";
- }
- if(angle > -1.0 / 8.0 * pi){
- return "→";
- }
- if(angle > -3.0 / 8.0 * pi){
- return "↗";
- }
- if(angle > -5.0 / 8.0 * pi){
- return "↑";
- }
- if(angle > -7.0 / 8.0 * pi){
- return "↖";
- }
- return "←";
- }();
-
- std::array<uint32_t,3u> rgb_start{64,64,255};
- std::array<uint32_t,3u> rgb_stop{255,64,64};
- std::array<uint32_t,3u> rgb_middle{255,255,255};
-
-
- auto col_interpol = [&](){
- std::array<uint32_t, 3u> rgb_interpol = rgb_start;
- double vel_mag_cut = std::min(1.0,std::max(vel_mag/(0.07*0.07),0.0));
-
- if(vel_mag_cut < 0.5){
- uint32_t vel_mag_i = static_cast<uint32_t>(2.0 * vel_mag_cut * 256);
- for(uint8_t i = 0u; i < 3u; ++i){
- rgb_interpol[i] = (rgb_middle[i] * vel_mag_i + (256-vel_mag_i) * rgb_start[i]) / 256;
- }
- }else{
- uint32_t vel_mag_i = static_cast<uint32_t>((2.0*(vel_mag_cut-0.5)) * 256);
- for(uint8_t i = 0u; i < 3u; ++i){
- rgb_interpol[i] = (rgb_stop[i] * vel_mag_i + (256-vel_mag_i) * rgb_middle[i]) / 256;
- }
- }
- return rgb_interpol;
- };
- auto rgb_interpol = col_interpol();
-
- std::cout<<"\x1b[38;2;"<<rgb_interpol[0]<<";"<<rgb_interpol[1]<<";"<<rgb_interpol[2]<<"m"<<dir_char;
- if( (i+1) < dim_x){
- std::cout<<" ";
- }else{
- std::cout<<"\n";
- }
- }, lattice);
- std::cout<<"\x1b[38;2;255;255;255m";
-
- /// std::cout<<"Average rho: "<<(sum / ((dim_x-4)*(dim_y-4)))<<std::endl;
- std::cout.flush();
-
- apply_for_cells([&](auto& cell, std::size_t i, std::size_t j){
- auto dfs = even_step ? cell.template get<"dfs_old">() : cell.template get<"dfs">();
-
- kel::lbm::data<sch::FixedArray<sch::T,sch::D2Q9::Q>> dfs_arr;
- for(uint64_t q{0u}; q < sch::D2Q9::Q; ++q){
- dfs_arr.at({q}) = dfs({q});
- }
-
- auto& rho = macros.template get<"density">().at({{i,j}});
- auto& vel = macros.template get<"velocity">().at({{i,j}});
- compute_rho_u<sch::T,sch::D2Q9>(dfs_arr,rho,vel);
- }, lattice);
-
- write_vtk_file("tmp", "cavity_2d", file_no, macros);
-
- ++file_no;
- }
-
- lbm_step(lattice, even_step, step);
-
- even_step = not even_step;
- }
-
- /**
- * Flush cout
- */
- std::cout<<"\n\n";
- std::cout.flush();
- return 0;
-}
diff --git a/examples/cavity_2d_gpu/.nix/derivation.nix b/examples/cavity_2d_gpu/.nix/derivation.nix
index 8724d96..3b210a3 100644
--- a/examples/cavity_2d_gpu/.nix/derivation.nix
+++ b/examples/cavity_2d_gpu/.nix/derivation.nix
@@ -23,13 +23,16 @@ stdenv.mkDerivation {
buildInputs = [
forstio.core
+ forstio.io
forstio.async
forstio.codec
forstio.codec-unit
forstio.remote
+ forstio.remote-filesystem
forstio.codec-json
adaptive-cpp
kel.lbm.core
+ kel.lbm.sycl
# kel-lbm.sycl
];
diff --git a/examples/cavity_2d_gpu/SConstruct b/examples/cavity_2d_gpu/SConstruct
index fe206e1..7882265 100644
--- a/examples/cavity_2d_gpu/SConstruct
+++ b/examples/cavity_2d_gpu/SConstruct
@@ -59,6 +59,8 @@ env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
],
LIBS=[
'forstio-core',
+ 'forstio-async',
+ 'forstio-io',
'acpp-rt',
'omp'
]
diff --git a/examples/cavity_2d_gpu/cavity_2d_gpu.cpp b/examples/cavity_2d_gpu/cavity_2d_gpu.cpp
index 55225d1..6b71db3 100644
--- a/examples/cavity_2d_gpu/cavity_2d_gpu.cpp
+++ b/examples/cavity_2d_gpu/cavity_2d_gpu.cpp
@@ -1,384 +1,464 @@
+#include <kel/lbm/sycl/lbm.hpp>
#include <kel/lbm/lbm.hpp>
-#include <forstio/codec/data.hpp>
-#include <AdaptiveCpp/sycl/sycl.hpp>
-
-#include <iostream>
-#include <fstream>
-#include <vector>
-#include <chrono>
-#include <cmath>
+#include <forstio/io/io.hpp>
+#include <forstio/remote/filesystem/easy.hpp>
+#include <forstio/codec/json/json.hpp>
+#include <forstio/codec/simple.hpp>
+#include <forstio/codec/args.hpp>
namespace kel {
namespace lbm {
-namespace sch {
-/**
- * Basic distribution function
- * Base type
- * D
- * Q
- * Scalar factor
- * D factor
- * Q factor
- */
-using T = Float32;
-using D2Q9 = Descriptor<2u,9u>;
+// Square cavity, as this case has always used.
+constexpr uint64_t dim_x = 128ul;
+constexpr uint64_t dim_y = 128ul;
-template<typename Desc>
-using DfCell = Cell<T, Desc, 0u, 0u, 1u>;
+// Lid velocity, tangential along +x on the top row.
+constexpr double lid_velocity = 0.1;
-template<typename Desc>
-using CellInfo = Cell<UInt8, Desc, 1u, 0u, 0u>;
-
-/**
- * Basic type for simulation
- */
-template<typename Desc>
-using CellStruct = CellFieldStruct<
- Desc,
- Struct<
- Member<CellField<Desc,DfCell<Desc>>, "dfs">,
- Member<CellField<Desc,DfCell<Desc>>, "dfs_old">,
- Member<CellField<Desc,CellInfo<Desc>>, "info">
- >
->;
+namespace sch {
-template<typename T, uint64_t D>
-using MacroStruct = Struct<
- Member<FixedArray<T,D>, "velocity">,
- Member<T, "pressure">
->;
+using InfoChunk = Chunk<UInt8, 0u, dim_x, dim_y>;
-using CavityFieldD2Q9 = CellStruct<D2Q9>;
-}
+template<typename T, typename Desc>
+using DfChunk = Chunk<FixedArray<T,Desc::Q>, 1u, dim_x, dim_y>;
+template<typename T, typename Desc>
+using ScalarChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
-/*
-template<typename T, typename Encode>
-class df_cell_view;
-*/
-/**
- * Minor helper for the AA-Pull Pattern, so I can use only one lattice
- *
- * Am I sure I want to use AA this way?
- * Esoteric Twist technically reduces the needed memory access footprint
- */
-/*
-template<typename Desc, size_t SN, size_t DN, size_t QN, typename Encode>
-class df_cell_view<sch::Cell<sch::T, Desc, SN, DN, QN>, Encode> {
-public:
- using Schema = sch::Cell<sch::T,Desc,SN,DN,QN>;
-private:
- std::array<std::decay_t<typename kel::lbm::native_data_type<sch::T>::type>*, QN> view_;
-public:
- df_cell_view(const std::array<std::decay_t<typename kel::lbm::native_data_type<sch::T>::type>*, QN>& view):
- view_{view}
- {}
-};
-*/
-namespace cmpt {
-struct MovingWall {};
-}
+template<typename T, typename Desc>
+using VectorChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
-/**
- * Full-Way moving wall Bounce back, something is not right here.
- * Technically it should reflect properly.
- */
-template<typename Desc>
-class component<sch::T, Desc, cmpt::MovingWall> {
-public:
- std::array<typename kel::lbm::native_data_type<sch::T>::type, Desc::D> lid_vel;
+template<typename T, typename Desc>
+using ChunkStruct = Struct<
+ Member<InfoChunk, "info">,
+ Member<DfChunk<T,Desc>, "dfs">,
+ Member<DfChunk<T,Desc>, "dfs_old">
+>;
-public:
- void apply(
- kel::lbm::data<sch::DfCell<Desc>>& dfs
- ){
- using dfi = df_info<sch::T,Desc>;
+template<typename T, typename Desc>
+using VelChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
- // Technically use .copy()
- /*
- auto dfs_cpy = dfs;
+template<typename T>
+using RhoChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
- for(uint64_t i = 0u; i < Desc::Q; ++i){
- dfs({dfi::opposite_index.at(i)}) = dfs_cpy({i}) - 2.0 * dfi::weights[i] * 1.0 * ( lid_vel[0] * dfi::directions[i][0] + lid_vel[1] * dfi::directions[i][1]) * dfi::inv_cs2;
- }
- */
- }
-};
+template<typename T, typename Desc>
+using MacroStruct = Struct<
+ Member<VelChunk<T,Desc>, "velocity">,
+ Member<RhoChunk<T>, "density">
+>;
-constexpr size_t dim_x = 128;
-constexpr size_t dim_y = 128;
+//template<typename T, typename Desc>
+//using ParticleArray = Array<
+// Particle<T,Desc::D>
+//>;
+}
-template<typename Desc>
-void set_geometry(
- kel::lbm::data<sch::CellInfo<Desc>>* info_field
+template<typename T, typename Desc>
+kel::lbm::error_or<void> setup_initial_conditions(
+ kel::lbm::data<sch::ChunkStruct<T,Desc>>& fields,
+ kel::lbm::data<sch::MacroStruct<T,Desc>>& macros
){
- using namespace kel::lbm;
- using namespace acpp;
- kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
- /**
- * Set ghost
- */
- iterate_over([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){
- size_t i = index.at({0u}).get() * dim_x + index.at({1u}).get();
- auto& info = info_field[i];
-
- info({0u}).set(0u);
-
- }, {{0u,0u}}, meta);
-
- /**
- * Set wall
- */
- iterate_over([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){
- size_t i = index.at({0u}).get() * dim_x + index.at({1u}).get();
- auto& info = info_field[i];
-
- info({0u}).set(1u);
-
- }, {{0u,0u}}, meta, {{1u,1u}});
-
- /**
- * Set fluid
- */
- iterate_over([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){
- size_t i = index.at({0u}).get() * dim_x + index.at({1u}).get();
- auto& info = info_field[i];
-
- info({0u}).set(2u);
-
- }, {{0u,0u}}, meta, {{2u,2u}});
-
- /**
- * Set top lid
- */
- iterate_over([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,2u>>& index){
- size_t i = index.at({0u}).get() * dim_x + index.at({1u}).get();
- auto& info = info_field[i];
- info({0u}).set(3u);
+ auto& info_f = fields.template get<"info">();
+ // Set everything as walls
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(1u);
+ },
+ {},
+ info_f.get_dims(),
+ {}
+ );
+ // Fluid
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(2u);
+ },
+ {},
+ info_f.get_dims(),
+ {{1u,1u}}
+ );
+
+ // The lid: the top row, moving tangentially. Corners stay plain walls.
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(5u);
+ },
+ {{0u,dim_y-1u}},
+ {{dim_x,dim_y}},
+ {{1u,0u}}
+ );
+ //
+ auto& df_f = fields.template get<"dfs_old">();
+ auto& rho_f = macros.template get<"density">();
+ auto& vel_f = macros.template get<"velocity">();
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ rho.at({}) = {1};
+ auto& vel = vel_f.at(index);
+ auto eq = equilibrium<T,Desc>(rho,vel);
- }, {{0u,1u}}, {{meta.at({0u}), 2u}}, {{2u,0u}});
-}
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
-template<typename Desc>
-void set_initial_conditions(
- kel::lbm::data<sch::CellInfo<Desc>>* info_field,
- kel::lbm::data<sch::DfCell<Desc>>* dfs_field,
- kel::lbm::data<sch::DfCell<Desc>>* dfs_old_field
-){
- using namespace kel::lbm;
- using namespace acpp;
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ rho.at({}) = {1};
+ auto& vel = vel_f.at(index);
+ if(info_f.at(index).get() == 2u){
+ vel.at({{0u}}) = 0.0;
+ }
+ auto eq = equilibrium<T,Desc>(rho,vel);
- kel::lbm::data<sch::T> rho{1.0};
- kel::lbm::data<sch::FixedArray<sch::T,Desc::D>> vel{{0.0,0.0}};
- auto eq = equilibrium<sch::T,Desc>(rho, vel);
- kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims(),
+ {{1u,1u}}
+ );
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ kel::lbm::data<sch::Vector<T,Desc::D>> middle, ind_vec;
+ middle.at({{0u}}) = dim_x * 0.25;
+ middle.at({{1u}}) = dim_y * 0.5;
- /**
- * Set distribution
- */
- iterate_over([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>>& index){
- size_t i = index.at({0u}).get() * dim_x + index.at({1u}).get();
- auto& dfs = dfs_field[i];
- auto& dfs_old = dfs_old_field[i];
+ ind_vec.at({{0u}}) = index.at({{0u}}).template cast_to<T>();
+ ind_vec.at({{1u}}) = index.at({{1u}}).template cast_to<T>();
- for(kel::lbm::data<sch::UInt64> k = 0; k < kel::lbm::data<sch::UInt64>{Desc::Q}; ++k){
- dfs(k) = eq.at(k);
- dfs_old(k) = eq.at(k);
- }
+ auto dist = middle - ind_vec;
+ auto dist_2 = kel::lbm::math::dot(dist,dist);
+ if(dist_2.at({}).get() < dim_y*dim_y*0.01){
+ info_f.at(index) = 1u;
+ }
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
- }, {{0u,0u}}, meta);
+ return kel::lbm::make_void();
}
template<typename T, typename Desc>
-void lbm_step(
- kel::lbm::data<sch::CellInfo<Desc>>* info_r,
- kel::lbm::data<sch::DfCell<Desc>>* dfs_r,
- kel::lbm::data<sch::DfCell<Desc>>* dfs_r_old,
- bool is_even,
- uint64_t time_step,
- acpp::sycl::queue& sycl_q
+kel::lbm::error_or<void> step(
+ kel::lbm::data<sch::Ptr<sch::ChunkStruct<T,Desc>>,encode::Sycl<kel::lbm::enc::Native>>& fields,
+ kel::lbm::data<sch::Ptr<sch::MacroStruct<T,Desc>>,encode::Sycl<kel::lbm::enc::Native>>& macros,
+ kel::lbm::data<sch::UInt64> t_i,
+ device& dev
){
- using namespace kel::lbm;
- using namespace acpp;
-
- using dfi = df_info<T,Desc>;
+ auto& q = dev.get_handle();
+ auto& info_f = fields.template get<"info">();
- //component<T, Desc, cmpt::BGK> coll{0.59};
- constexpr kel::lbm::data<T> frequency{1.0 / 0.59};
- //component<T, Desc, cmpt::BounceBack> bb;
- component<T, Desc, cmpt::MovingWall> bb_lid;
- bb_lid.lid_vel = {0.1, 0.0};
+ // auto coll_ev =
+ q.submit([&](acpp::sycl::handler& h){
+ // Need nicer things to handle the flow. I see improvement here
+ component<T,Desc,cmpt::BGK, encode::Sycl<kel::lbm::enc::Native>> collision{0.8};
+ component<T,Desc,cmpt::BounceBack,encode::Sycl<kel::lbm::enc::Native>> bb;
+ component<T,Desc,cmpt::AntiBounceBack<0u>,encode::Sycl<kel::lbm::enc::Native>> abb;
- // Submit collision kernel
- sycl_q.submit([&](sycl::handler& cgh) {
- // Accessor for latt with read/write
+ kel::lbm::data<sch::Scalar<T>> rho_b;
+ rho_b.at({}) = 1.0;
+ kel::lbm::data<sch::Vector<T,Desc::D>> vel_b;
+ vel_b.at({{0u}}) = 0.015;
- cgh.parallel_for(
- sycl::range<2>{dim_x, dim_y}, [=](sycl::id<2> idx) {
- size_t i = idx[0];
- size_t j = idx[1];
+ component<T,Desc,cmpt::Equilibrium,encode::Sycl<kel::lbm::enc::Native>> equi{rho_b,vel_b};
- size_t acc_id = i * dim_x + j;
-
- // Read cell info
- auto& info = info_r[acc_id];
-
- switch (info({0u}).get()) {
- case 1u: {
- // bb.apply(latt_acc, {i, j}, time_step);
-
- auto& dfs_old = is_even ? dfs_r_old[acc_id] : dfs_r[acc_id];
- auto df_cpy = dfs_old.copy();
-
- for(uint64_t i = 1u; i < Desc::Q; ++i){
- dfs_old({i}) = df_cpy({dfi::opposite_index.at(i)});
+ component<T,Desc,cmpt::ZouHeHorizontal<true>,encode::Sycl<kel::lbm::enc::Native>> flow_in{
+ [&](){
+ uint64_t target_t_i = 32u;
+ if(t_i.get() < target_t_i){
+ return 1.0 + (0.0002 / target_t_i) * t_i.get();
}
+ return 1.0002;
+ }()
+ };
+ component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<kel::lbm::enc::Native>> flow_out{1.0};
- break;
- }
- case 2u: {
- // coll.apply(latt_acc, {i, j}, time_step);
- auto& dfs_old = is_even ? dfs_r_old[acc_id] : dfs_r[acc_id];
- kel::lbm::data<T> rho;
- kel::lbm::data<sch::FixedArray<T,Desc::D>> vel;
- compute_rho_u<T,Desc>(dfs_old,rho,vel);
- auto eq = equilibrium<T,Desc>(rho,vel);
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
- for(uint64_t i = 0u; i < Desc::Q; ++i){
- dfs_old({i}) = dfs_old({i}) + frequency * (eq.at(i) - dfs_old({i}));
- }
+ auto info = info_f.at(index);
+
+ switch(info.get()){
+ case 0u:
break;
- }
- default:
- // Do nothing
+ case 1u:
+ bb.apply(fields,index,t_i);
break;
- }
- });
- });
-
- // Submit streaming kernel
- sycl_q.submit([&](sycl::handler& cgh) {
-
- cgh.parallel_for(
- sycl::range<2>{dim_x - 2, dim_y - 2}, [=](sycl::id<2> idx) {
- size_t i = idx[0] + 1; // avoid boundary
- size_t j = idx[1] + 1;
-
- size_t acc_id = i * dim_x + j;
-
- auto& dfs_new = is_even ? dfs_r[acc_id] : dfs_r_old[acc_id];
- auto& info = info_r[acc_id];
+ case 2u:
+ collision.apply(fields,macros,index,t_i);
+ break;
+ case 5u: {
+ /**
+ * Moving wall: bounce back plus the tangential momentum the
+ * lid injects.
+ *
+ * f_i = f_opp + 2 w_i rho_w (e_i . u_w) / cs^2
+ *
+ * written from f_opp because that is the direction the
+ * library's BounceBack writes in. There is no component for a
+ * y normal moving wall, and the original example had this
+ * commented out, so it is implemented here.
+ */
+ using dfi = df_info<T,Desc>;
+ const bool is_even = ((t_i.get() % 2u) == 0u);
+ auto& dfs_f = (is_even)
+ ? fields.template get<"dfs_old">()
+ : fields.template get<"dfs">();
+ auto& dfs = dfs_f.at(index);
+ auto df_cpy = dfs;
- if (info({0u}).get() > 0u && info({0u}).get() != 3u) {
- for (uint64_t k = 0u; k < Desc::Q; ++k) {
- auto dir = dfi::directions[dfi::opposite_index[k]];
- // auto& cell_dir_old = latt_acc({i + dir[0], j + dir[1]});
- //
- size_t acc_old_id = (i+dir[0]) * dim_x + (j+dir[1]);
+ for(uint64_t i = 0u; i < Desc::Q; ++i){
+ const auto e_dot_u =
+ static_cast<typename kel::lbm::native_data_type<T>::type>(
+ dfi::directions[i][0]) * lid_velocity;
- auto& dfs_old = is_even ? dfs_r_old[acc_old_id] : dfs_r[acc_old_id];
- auto& info_old = info_r[acc_old_id];
-
- if (info_old({0}).get() == 3u) {
- auto& dfs_old_loc = is_even ? dfs_r_old[acc_id] : dfs_r[acc_id];
- dfs_new({k}) = dfs_old_loc({dfi::opposite_index.at(k)}) - 2.0 * dfi::inv_cs2 * dfi::weights.at(k) * 1.0 * (bb_lid.lid_vel[0] * dir[0] + bb_lid.lid_vel[1] * dir[1]);
- } else {
- dfs_new({k}) = dfs_old({k});
+ dfs.at({i}) = df_cpy.at({dfi::opposite_index.at(i)})
+ + kel::lbm::data<T>{
+ static_cast<typename kel::lbm::native_data_type<T>::type>(
+ 2.0 * dfi::weights[i] * dfi::inv_cs2 * e_dot_u)};
}
- }
+ } break;
+ default:
+ break;
}
});
- });
+ }).wait();
+
+
+ // Step
+ /*
+ q.submit([&](acpp::sycl::handler& h){
+ // h.depends_on(collision_ev);
+ }).wait();
+ */
+
+ return kel::lbm::make_void();
}
}
}
-int main(){
+template<typename T, typename Desc>
+kel::lbm::error_or<void> lbm_main(int argc, char** argv){
using namespace kel::lbm;
- using namespace acpp;
- kel::lbm::data<sch::FixedArray<sch::UInt64,sch::D2Q9::D>> meta{{dim_x, dim_y}};
- constexpr size_t dim_size = dim_x * dim_y;
-
- converter<sch::T> conv{
- {0.1},
- {0.1}
- };
+ /*
+ auto eo_lbm_args = setup_lbm_env<sch::Args<sch::Struct<>,sch::Tuple<>>>(argc,argv);
+ if(eo_lbm_args.is_error()){
+ return std::move(eo_lbm_args.get_error());
+ }
+ auto& lbm_args = eo_lbm_args.get_value();
+ */
- // Lid driven cavity: the lid velocity and the cavity height are the
- // characteristic scales.
- print_lbm_meta<sch::T, sch::D2Q9>(conv, {1e-3}, {0.1}, {dim_y});
+ using dfi = df_info<T,Desc>;
auto eo_lbm_dir = output_directory();
if(eo_lbm_dir.is_error()){
- return -1;
+ return std::move(eo_lbm_dir.get_error());
}
auto& lbm_dir = eo_lbm_dir.get_value();
- auto out_dir = lbm_dir / "cavity_gpu_2d";
- sycl::queue sycl_q{sycl::default_selector_v, sycl::property::queue::in_order{}};
+ auto out_dir = lbm_dir / "cavity_2d_gpu";
- constexpr size_t num_cells = dim_x * dim_y;
+ {
+ std::error_code ec;
+ std::filesystem::create_directories(out_dir,ec);
+ if(ec != std::errc{}){
+ return kel::lbm::make_error<kel::lbm::err::critical>("Could not create output directory");
+ }
+ }
- // Allocate USM shared memory for your main data
- auto* info = sycl::malloc_shared<kel::lbm::data<sch::CellInfo<sch::D2Q9>>>(num_cells, sycl_q);
- auto* dfs = sycl::malloc_shared<kel::lbm::data<sch::DfCell<sch::D2Q9>>>(num_cells, sycl_q);
- auto* dfs_old = sycl::malloc_shared<kel::lbm::data<sch::DfCell<sch::D2Q9>>>(num_cells, sycl_q);
+ converter<T> conv {
+ // delta_x
+ {1.0},
+ // delta_t
+ {1.0}
+ };
+
+ print_lbm_meta<T,Desc>(conv,{0.1},{1e-4},{0.4 * dim_y});
- /**
- * Set meta information describing what this cell is
- */
- set_geometry(info);
+ // kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
+ auto lbm_data_ptr = kel::lbm::heap<kel::lbm::data<sch::ChunkStruct<T,Desc>>>();
+ auto lbm_macro_data_ptr = kel::lbm::heap<kel::lbm::data<sch::MacroStruct<T,Desc>>>();
+
+ std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl;
- /**
- *
- */
- set_initial_conditions(info,dfs,dfs_old);
+ auto eo_aio = saw::setup_async_io();
+ if(eo_aio.is_error()){
+ return kel::lbm::make_error<kel::lbm::err::critical>(
+ std::string{eo_aio.get_error().get_message()});
+ }
+ auto& aio = eo_aio.get_value();
+ saw::wait_scope wait{aio.event_loop};
- /**
- * Timeloop
- */
- uint64_t lattice_steps = 512000u;
- bool even_step = true;
+ bool krun = true;
+ bool print_status = false;
+ aio.event_port.on_signal(saw::Signal::Terminate).then([&](){
+ krun = false;
+ }).detach();
+ aio.event_port.on_signal(saw::Signal::User1).then([&](){
+ print_status = true;
+ }).detach();
- uint64_t print_every = 256u;
- uint64_t file_no = 0u;
+ device dev;
- kel::lbm::data<sch::Array<sch::MacroStruct<sch::T,sch::D2Q9::D>,sch::D2Q9::D>> macros{meta};
+ auto& sycl_q = dev.get_handle();
- std::cout<<"Start"<<std::endl;
+ sycl_q.wait();
+ {
+ auto eov = setup_initial_conditions<T,Desc>(*lbm_data_ptr,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"initial_state",0u,*lbm_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
- auto start = std::chrono::steady_clock::now();
+ kel::lbm::data<sch::ChunkStruct<T,Desc>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_data{sycl_q};
+ kel::lbm::data<sch::MacroStruct<T,Desc>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_macro_data{sycl_q};
+ sycl_q.wait();
+
+ {
+ auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
sycl_q.wait();
- for(uint64_t i = 0u; i < lattice_steps; ++i){
- lbm_step<sch::T,sch::D2Q9>(info, dfs, dfs_old, even_step, i, sycl_q);
- if(i % 1024u == 0u){
- sycl_q.wait();
- iterate_over([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::D2Q9::D>>& index){
- size_t j = index.at({0u}).get() * dim_x + index.at({1u}).get();
- auto dfs_field = even_step ? dfs_old : dfs;
+ auto lsd_view = make_view(lbm_sycl_data);
+ auto lsdm_view = make_view(lbm_sycl_macro_data);
+ kel::lbm::data<sch::UInt64> time_steps{16u*4096ul};
+
+ auto& info_f = lsd_view.template get<"info">();
+
+ for(kel::lbm::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){
+ // BC + Collision
+ {
+ auto eov = step<T,Desc>(lsd_view,lsdm_view,i,dev);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ sycl_q.wait();
+ /*
+ if(i.get() % 128u == 0u){
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"m",i.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+ */
+ /*
+ if(i.get() % 32u == 0u){
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_csv_file(out_dir,"m",i.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+ */
+ // Stream
+ sycl_q.submit([&](acpp::sycl::handler& h){
+ component<T,Desc,cmpt::Stream,encode::Sycl<kel::lbm::enc::Native>> stream;
- auto& rho = macros.at(index).template get<"pressure">();
- auto& vel = macros.at(index).template get<"velocity">();
- compute_rho_u<sch::T,sch::D2Q9>(dfs_field[j],rho,vel);
- }, {{0u,0u}}, meta);
- std::string vtk_f_name{"tmp/cavity_2d_gpu_"};
- vtk_f_name += std::to_string(i) + ".vtk";
- write_vtk_file(vtk_f_name, macros);
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ auto info = info_f.at(index);
+
+ if(info.get() > 0u){
+ stream.apply(lsd_view,index,i);
+ }
+ });
+ }).wait();
+ wait.poll();
+ if(print_status){
+ std::cout<<"Status: "<<i.get()<<" of "<<time_steps.get()<<" - "<<(i.template cast_to<sch::Float64>().get() * 100 / time_steps.get())<<"%"<<std::endl;
+ print_status = false;
}
+ print_progress_bar(i.get(), time_steps.get()-1u);
+ }
- even_step = not even_step;
+ // After Loop
+ sycl_q.wait();
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_csv_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
}
- auto stop = std::chrono::steady_clock::now();
- std::cout<<std::format("{:%H:%M:%S}",(stop-start))<<std::endl;
sycl_q.wait();
- sycl::free(info,sycl_q);
- sycl::free(dfs,sycl_q);
- sycl::free(dfs_old,sycl_q);
+ return kel::lbm::make_void();
+}
+
+using FloatT = kel::lbm::sch::Float32;
+
+int main(int argc, char** argv){
+ auto eov = lbm_main<FloatT,kel::lbm::sch::D2Q9>(argc, argv);
+ if(eov.is_error()){
+ auto& err = eov.get_error();
+ std::cerr<<"[Error] "<<err.get_category();
+ auto err_msg = err.get_message();
+ if(err_msg.size() > 0u){
+ std::cerr<<" - "<<err_msg;
+ }
+ std::cerr<<std::endl;
+ return err.get_id();
+ }
return 0;
-}_
+}
diff --git a/examples/heterogeneous_computing/.nix/derivation.nix b/examples/heterogeneous_computing/.nix/derivation.nix
deleted file mode 100644
index bf824bf..0000000
--- a/examples/heterogeneous_computing/.nix/derivation.nix
+++ /dev/null
@@ -1,41 +0,0 @@
-{ lib
-, stdenv
-, scons
-, clang-tools
-, forstio
-, pname
-, version
-, adaptive-cpp
-, kel
-}:
-
-stdenv.mkDerivation {
- pname = pname + "-examples-" + "heterogeneous_computing";
- inherit version;
- src = ./..;
-
- nativeBuildInputs = [
- scons
- clang-tools
- ];
-
- buildInputs = [
- forstio.core
- forstio.async
- forstio.io
- forstio.io_codec
- forstio.codec
- forstio.codec-unit
- forstio.codec-json
- forstio.remote
- forstio.remote-filesystem
- forstio.remote-io
- forstio.remote-sycl
- kel.lbm.core
- adaptive-cpp
- ];
-
- preferLocalBuild = true;
-
- outputs = [ "out" "dev" ];
-}
diff --git a/examples/heterogeneous_computing/README.md b/examples/heterogeneous_computing/README.md
deleted file mode 100644
index 16463e6..0000000
--- a/examples/heterogeneous_computing/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# Heterogeneous
-
-This is more intended as a thinking ground for a solution to LBM integrations for distributed computing.
-In the end MPI does it correctly in a sense I would almost ask to separate in blocks.
-But I want to learn, so no MPI.
-Or rather MPI abstracted away.
-MPI also has some discovery issues in edge cases where the network is a bit more complex.
diff --git a/examples/heterogeneous_computing/SConscript b/examples/heterogeneous_computing/SConscript
deleted file mode 100644
index 226185b..0000000
--- a/examples/heterogeneous_computing/SConscript
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/false
-
-import os
-import os.path
-import glob
-
-
-Import('env')
-
-dir_path = Dir('.').abspath
-
-# Environment for base library
-examples_env = env.Clone();
-examples_env['CXX'] = 'syclcc-clang';
-examples_env['CXXFLAGS'] += ['-O3'];
-
-examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
-examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
-
-env.sources += examples_env.sources;
-env.headers += examples_env.headers;
-
-# Cavity2D
-examples_objects = [];
-examples_env.add_source_files(examples_objects, ['sim.cpp'], shared=False);
-examples_env.heterogeneous_computing = examples_env.Program('#bin/heterogeneous_computing', [examples_objects]);
-
-# Set Alias
-env.examples = [
- examples_env.heterogeneous_computing
-];
-env.Alias('examples', env.examples);
-env.targets += ['examples'];
-env.Install('$prefix/bin/', env.examples);
diff --git a/examples/heterogeneous_computing/SConstruct b/examples/heterogeneous_computing/SConstruct
deleted file mode 100644
index fe206e1..0000000
--- a/examples/heterogeneous_computing/SConstruct
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-import os
-import os.path
-import glob
-import re
-
-
-if sys.version_info < (3,):
- def isbasestring(s):
- return isinstance(s,basestring)
-else:
- def isbasestring(s):
- return isinstance(s, (str,bytes))
-
-def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
-
- if isbasestring(filetype):
- dir_path = self.Dir('.').abspath
- filetype = sorted(glob.glob(dir_path+"/"+filetype))
-
- for path in filetype:
- target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
- if shared:
- target_name+='.os'
- sources.append( self.SharedObject( target=target_name, source=path ) )
- else:
- target_name+='.o'
- sources.append( self.StaticObject( target=target_name, source=path ) )
- pass
-
-def isAbsolutePath(key, dirname, env):
- assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
-
-env_vars = Variables(
- args=ARGUMENTS
-)
-
-env_vars.Add('prefix',
- help='Installation target location of build results and headers',
- default='/usr/local/',
- validator=isAbsolutePath
-)
-
-env_vars.Add('build_examples',
- help='If examples should be built',
- default="true"
-)
-
-env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
- CPPDEFINES=['SAW_UNIX'],
- CXXFLAGS=[
- '-std=c++20',
- '-g',
- '-Wall',
- '-Wextra',
- '-isystem', 'AdaptiveCpp'
- ],
- LIBS=[
- 'forstio-core',
- 'acpp-rt',
- 'omp'
- ]
-);
-env.__class__.add_source_files = add_kel_source_files
-env.Tool('compilation_db');
-env.cdb = env.CompilationDatabase('compile_commands.json');
-
-env.objects = [];
-env.sources = [];
-env.headers = [];
-env.targets = [];
-
-Export('env')
-SConscript('SConscript')
-
-env.Alias('cdb', env.cdb);
-env.Alias('all', [env.targets]);
-env.Default('all');
-
-env.Alias('install', '$prefix')
diff --git a/examples/heterogeneous_computing/sim.cpp b/examples/heterogeneous_computing/sim.cpp
deleted file mode 100644
index 61058be..0000000
--- a/examples/heterogeneous_computing/sim.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-#include <forstio/error.hpp>
-#include <iostream>
-
-#include <kel/lbm/lbm.hpp>
-
-namespace kel {
-namespace lbm {
-namespace sch {
-
-/**
- * struct lbm_data {
- * std::array<std::array<float,9>, 64u*64u> dfs;
- * std::array<uint8_t, 64u*64u> info;
- * };
- *
- * which leads to the form
- *
- * template<uint64_t Dim, uint64_t Size>
- * struct lbm_data {
- * std::array<std::array<float,9>, Size*Size> dfs;
- * std::array<uint8_t, Size*Size> info;
- * };
- *
- * which transferred into sycl requires us to go to
- *
- * template<uint64_t Dim, uint64_t Size>
- * struct lbm_sycl_data {
- * std::array<float,9>* dfs;
- * uint8_t* info;
- * };
- *
- * in data form on host
- *
- * template<uint64_t Dim, uint64_t Size>
- * using LbmData = Struct<
- * Member<FixedArray<FixedArray<Float32,9u>, Size*Size>, "dfs">,
- * Member<FixedArray<UInt8, Size*Size>, "info">
- * >;
- *
- * If we specialize the encode::Sycl<Encoding> data type, then we get
- * With a helper class we can copy single values back and forth and the whole block is guaranteed
- * to be allocated. And this one can be dynamic while the host definition might be compile time.
- *
- * template<...>
- * class data<LbmData<...>,encode::Sycl<Encoding>> final {
- * kel::lbm::data<sch::FixedArray<sch::UInt64,Dim>> meta;
- * kel::lbm::data<FixedArray<Float32u,9>>* dfs;
- * kel::lbm::data<UInt8>* info;
- * };
- */
-
-template<typename T, typename Desc>
-using CellStruct = Struct<
- Member<Chunk<FixedArray<T,Desc::Q>,Desc::D, "dfs">,
- Member<FixedArray<T,Desc::Q>, "dfs_old">,
- Member<UInt8, "info">
->;
-
-}
-template<typename T, typename Desc>
-kel::lbm::error_or<void> simulate(int argc, char** argv,
- const kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>>& meta
-{
- constexpr auto cell_size = sizeof(kel::lbm::data<sch::CellStruct<T,Desc>>);
-
- auto lbm_data = kel::lbm::heap<kel::lbm::data<sch::Chunk<CellStruct<>,Desc::D, 64u>>>{meta};
-
- return kel::lbm::make_void();
-}
-
-}
-
-kel::lbm::error_or<void> lbm_main(int argc, char** argv){
- using namespace lbm;
- return simulate<sch::Float64,sch::D2Q9>(argc, argv);
-}
-}
-
-int main(int argc, char** argv){
- auto eov = kel::lbm_main(argc, argv);
- if(eov.is_error()){
- auto& err = eov.get_error();
- auto err_msg = err.get_message();
- std::cerr<<"[Error]: "<<err.get_category();
-
- if(not err_msg.empty()){
- std::cerr<<" - "<<err_msg;
- }
- std::cerr<<std::endl;
-
- return err.get_id();
- }
-
- return 0;
-}
diff --git a/examples/meta/.nix/derivation.nix b/examples/meta/.nix/derivation.nix
deleted file mode 100644
index 26706e6..0000000
--- a/examples/meta/.nix/derivation.nix
+++ /dev/null
@@ -1,33 +0,0 @@
-{ lib
-, stdenv
-, scons
-, clang-tools
-, forstio
-, pname
-, version
-, kel
-}:
-
-stdenv.mkDerivation {
- pname = pname + "-examples-" + "meta_2d";
- inherit version;
- src = ./..;
-
- nativeBuildInputs = [
- scons
- clang-tools
- ];
-
- buildInputs = [
- forstio.core
- forstio.async
- forstio.codec
- forstio.codec-unit
- forstio.codec-json
- kel.lbm.core
- ];
-
- preferLocalBuild = true;
-
- outputs = [ "out" "dev" ];
-}
diff --git a/examples/meta/SConscript b/examples/meta/SConscript
deleted file mode 100644
index 066a741..0000000
--- a/examples/meta/SConscript
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/false
-
-import os
-import os.path
-import glob
-
-
-Import('env')
-
-dir_path = Dir('.').abspath
-
-# Environment for base library
-examples_env = env.Clone();
-
-examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
-examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
-
-env.sources += examples_env.sources;
-env.headers += examples_env.headers;
-
-# Cavity2D
-examples_objects = [];
-examples_env.add_source_files(examples_objects, ['meta.cpp'], shared=False);
-examples_env.meta_2d = examples_env.Program('#bin/meta', [examples_objects]);
-
-# Set Alias
-env.examples = [
- examples_env.meta_2d
-];
-env.Alias('examples', env.examples);
-env.targets += ['examples'];
-env.Install('$prefix/bin/', env.examples);
diff --git a/examples/meta/SConstruct b/examples/meta/SConstruct
deleted file mode 100644
index a7201cb..0000000
--- a/examples/meta/SConstruct
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-import os
-import os.path
-import glob
-import re
-
-
-if sys.version_info < (3,):
- def isbasestring(s):
- return isinstance(s,basestring)
-else:
- def isbasestring(s):
- return isinstance(s, (str,bytes))
-
-def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
-
- if isbasestring(filetype):
- dir_path = self.Dir('.').abspath
- filetype = sorted(glob.glob(dir_path+"/"+filetype))
-
- for path in filetype:
- target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
- if shared:
- target_name+='.os'
- sources.append( self.SharedObject( target=target_name, source=path ) )
- else:
- target_name+='.o'
- sources.append( self.StaticObject( target=target_name, source=path ) )
- pass
-
-def isAbsolutePath(key, dirname, env):
- assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
-
-env_vars = Variables(
- args=ARGUMENTS
-)
-
-env_vars.Add('prefix',
- help='Installation target location of build results and headers',
- default='/usr/local/',
- validator=isAbsolutePath
-)
-
-env_vars.Add('build_examples',
- help='If examples should be built',
- default="true"
-)
-
-env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
- CPPDEFINES=['SAW_UNIX'],
- CXXFLAGS=[
- '-std=c++20',
- '-g',
- '-Wall',
- '-Wextra'
- ],
- LIBS=[
- 'forstio-core'
- ]
-);
-env.__class__.add_source_files = add_kel_source_files
-env.Tool('compilation_db');
-env.cdb = env.CompilationDatabase('compile_commands.json');
-
-env.objects = [];
-env.sources = [];
-env.headers = [];
-env.targets = [];
-
-Export('env')
-SConscript('SConscript')
-
-env.Alias('cdb', env.cdb);
-env.Alias('all', [env.targets]);
-env.Default('all');
-
-env.Alias('install', '$prefix')
diff --git a/examples/meta/meta.cpp b/examples/meta/meta.cpp
deleted file mode 100644
index 3e573e5..0000000
--- a/examples/meta/meta.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-#include <kel/lbm/lbm.hpp>
-
-#include <iostream>
-
-namespace kel {
-namespace lbm {
-namespace sch {
-
-using MetaArgsStruct = Struct<
- Member<Float64, "dx">,
- Member<Float64, "dt">,
- Member<Float64, "kin_vis">,
- Member<Float64, "char_vel">,
- Member<Float64, "char_len">
->;
-
-using MetaArgs = Args<
- MetaArgsStruct,
- Tuple<UInt64,UInt64>
->;
-
-using Prec = Float64;
-}
-}
-}
-
-template<typename T, typename Desc>
-kel::lbm::error_or<void> meta_lbm_info(const kel::lbm::data<kel::lbm::sch::MetaArgsStruct>& args_str){
- using namespace kel::lbm;
- converter<T> conv{
- as_unit<typename unit_division<sch::SiMeter<T>, sch::LbmMeter<T>>::Schema>(
- args_str.template get<"dx">()),
- as_unit<typename unit_division<sch::SiSecond<T>, sch::LbmSecond<T>>::Schema>(
- args_str.template get<"dt">())
- };
- print_lbm_meta<T,Desc>(
- conv,
- as_unit<sch::SiKinematicViscosity<T>>(args_str.template get<"kin_vis">()),
- as_unit<sch::SiVelocity<T>>(args_str.template get<"char_vel">()),
- as_unit<sch::SiMeter<T>>(args_str.template get<"char_len">()));
-
- return kel::lbm::make_void();
-}
-
-
-kel::lbm::error_or<void> meta_main(int argc, char** argv){
- using namespace kel::lbm;
-
- kel::lbm::data<sch::MetaArgs> args_dat;
- auto& args_str = args_dat.template get<"args">();
-
- // Defaults for anything the caller leaves out.
- args_str.template get<"dx">().set(1);
- args_str.template get<"dt">().set(1);
-
- {
- auto eov = parse_args(args_dat, argc, argv);
- if(eov.is_error()){
- return eov;
- }
- }
-
- auto& args_pos = args_dat.template get<"positionals">();
-
- switch(args_pos.template get<0u>().get()){
- case 1u:
- {
- switch(args_pos.template get<1u>().get()){
- case 3u:
- meta_lbm_info<sch::Prec,sch::Descriptor<1u,3u>>(args_str);
- break;
- default:
- return kel::lbm::make_error<kel::lbm::err::critical>("Second positional needs to be a valid momentum set");
- }
- }
- break;
- case 2u:
- {
- switch(args_pos.template get<1u>().get()){
- case 5u:
- meta_lbm_info<sch::Prec,sch::Descriptor<2u,5u>>(args_str);
- break;
- case 9u:
- meta_lbm_info<sch::Prec,sch::Descriptor<2u,9u>>(args_str);
- break;
- default:
- return kel::lbm::make_error<kel::lbm::err::critical>("Second positional needs to be a valid momentum set");
- }
- }
- break;
- case 3u:
- {
- switch(args_pos.template get<1u>().get()){
- case 7u:
- return kel::lbm::make_error<kel::lbm::err::not_implemented>("D3Q7 Velocity Set is not implemented");
- // meta_lbm_info<sch::Prec,sch::Descriptor<3u,19u>>(args_str);
- break;
- case 19u:
- return kel::lbm::make_error<kel::lbm::err::not_implemented>("D3Q17 Velocity Set is not implemented");
- // meta_lbm_info<sch::Prec,sch::Descriptor<3u,19u>>(args_str);
- break;
- case 27u:
- meta_lbm_info<sch::Prec,sch::Descriptor<3u,27u>>(args_str);
- break;
- default:
- return kel::lbm::make_error<kel::lbm::err::critical>("Second positional needs to be a valid momentum set");
- }
- }
- break;
- default:
- return kel::lbm::make_error<kel::lbm::err::critical>("First positional needs to be Dimension 1,2 or 3");
- }
-
- return kel::lbm::make_void();
-}
-
-int main(int argc, char** argv){
- auto eov = meta_main(argc,argv);
- if(eov.is_error()){
- auto& err = eov.get_error();
-
- std::cerr<<"[Error]: "<<err.get_category();
-
- auto err_msg = err.get_message();
- if(not err_msg.empty()){
- std::cerr<<" - "<<err_msg;
- }
-
- std::cerr<<std::endl;
- }
-
- return 0;
-}
diff --git a/examples/particles_gpu/.nix/derivation.nix b/examples/particles_gpu/.nix/derivation.nix
deleted file mode 100644
index 6ab8825..0000000
--- a/examples/particles_gpu/.nix/derivation.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ lib
-, stdenv
-, scons
-, clang-tools
-, forstio
-, python3
-, pname
-, version
-, kel
-, adaptive-cpp
-}:
-
-stdenv.mkDerivation {
- pname = pname + "-examples-" + "particles";
- inherit version;
- src = ./..;
-
- nativeBuildInputs = [
- scons
- clang-tools
- python3
- ];
-
- buildInputs = [
- forstio.core
- forstio.async
- forstio.codec
- forstio.codec-unit
- forstio.codec-json
- kel.lbm.core
- adaptive-cpp
- ];
-
- preferLocalBuild = true;
-
- outputs = [ "out" "dev" ];
-}
diff --git a/examples/particles_gpu/SConscript b/examples/particles_gpu/SConscript
deleted file mode 100644
index f22fdf2..0000000
--- a/examples/particles_gpu/SConscript
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/bin/false
-
-import os
-import os.path
-import glob
-
-
-Import('env')
-
-dir_path = Dir('.').abspath
-
-# Environment for base library
-examples_env = env.Clone();
-examples_env['CXX'] = 'syclcc-clang';
-examples_env['CXXFLAGS'] += ['-O3'];
-
-examples_env.sources = sorted(glob.glob(dir_path + "/*.cpp"))
-examples_env.headers = sorted(glob.glob(dir_path + "/*.hpp"))
-
-env.sources += examples_env.sources;
-env.headers += examples_env.headers;
-
-# Cavity2D
-examples_objects = [];
-examples_env.add_source_files(examples_objects, ['particles_gpu.cpp'], shared=False);
-examples_env.particles_gpu = examples_env.Program('#bin/particles_gpu', [examples_objects]);
-
-# Set Alias
-env.examples = [
- examples_env.particles_gpu
-];
-env.Alias('examples', env.examples);
-env.targets += ['examples'];
-env.Install('$prefix/bin/', env.examples);
diff --git a/examples/particles_gpu/SConstruct b/examples/particles_gpu/SConstruct
deleted file mode 100644
index fe206e1..0000000
--- a/examples/particles_gpu/SConstruct
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-import os
-import os.path
-import glob
-import re
-
-
-if sys.version_info < (3,):
- def isbasestring(s):
- return isinstance(s,basestring)
-else:
- def isbasestring(s):
- return isinstance(s, (str,bytes))
-
-def add_kel_source_files(self, sources, filetype, lib_env=None, shared=False, target_post=""):
-
- if isbasestring(filetype):
- dir_path = self.Dir('.').abspath
- filetype = sorted(glob.glob(dir_path+"/"+filetype))
-
- for path in filetype:
- target_name = re.sub( r'(.*?)(\.cpp|\.c\+\+)', r'\1' + target_post, path )
- if shared:
- target_name+='.os'
- sources.append( self.SharedObject( target=target_name, source=path ) )
- else:
- target_name+='.o'
- sources.append( self.StaticObject( target=target_name, source=path ) )
- pass
-
-def isAbsolutePath(key, dirname, env):
- assert os.path.isabs(dirname), "%r must have absolute path syntax" % (key,)
-
-env_vars = Variables(
- args=ARGUMENTS
-)
-
-env_vars.Add('prefix',
- help='Installation target location of build results and headers',
- default='/usr/local/',
- validator=isAbsolutePath
-)
-
-env_vars.Add('build_examples',
- help='If examples should be built',
- default="true"
-)
-
-env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
- CPPDEFINES=['SAW_UNIX'],
- CXXFLAGS=[
- '-std=c++20',
- '-g',
- '-Wall',
- '-Wextra',
- '-isystem', 'AdaptiveCpp'
- ],
- LIBS=[
- 'forstio-core',
- 'acpp-rt',
- 'omp'
- ]
-);
-env.__class__.add_source_files = add_kel_source_files
-env.Tool('compilation_db');
-env.cdb = env.CompilationDatabase('compile_commands.json');
-
-env.objects = [];
-env.sources = [];
-env.headers = [];
-env.targets = [];
-
-Export('env')
-SConscript('SConscript')
-
-env.Alias('cdb', env.cdb);
-env.Alias('all', [env.targets]);
-env.Default('all');
-
-env.Alias('install', '$prefix')
diff --git a/examples/particles_gpu/particles_gpu.cpp b/examples/particles_gpu/particles_gpu.cpp
deleted file mode 100644
index 94ec5f1..0000000
--- a/examples/particles_gpu/particles_gpu.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-#include <kel/lbm/lbm.hpp>
-#include <AdaptiveCpp/sycl/sycl.hpp>
-
-
-#include <kel/lbm/particle/particle.hpp>
-#include <iostream>
-
-namespace kel{
-namespace lbm {
-namespace sch {
-}
-}
-
-kel::lbm::error_or<void> lbm_main(int argc, char** argv){
- (void) argc;
- (void) argv;
-
- using namespace lbm;
- using namespace acpp;
-
- kel::lbm::data<sch::Array<sch::Particle<sch::Float32,2u>>> particles{1024u};
-
- for(kel::lbm::data<sch::UInt64> i{0u}; i < kel::lbm::data<sch::UInt64>{32u}; ++i){
- for(kel::lbm::data<sch::UInt64> j{0u}; j < kel::lbm::data<sch::UInt64>{32u}; ++j){
-
- auto& part = particles.at(i*32ul+j);
- auto& body = part.template get<"rigid_body">();
-
- auto& pos = body.template get<"position">();
- auto& old_pos = body.template get<"position_old">();
- auto& acceleration = body.template get<"acceleration">();
- auto& p_rad = part.template get<"collision">().template get<"radius">();
- // Scalar<T> base, so the value goes through the element rather than a
- // braced whole-unit assignment.
- p_rad.at({}).set(0.4f);
-
- if(j.get() % 2u == 0) acceleration.at({{1u}}) = {-9.81};
-
- pos.at({{0u}}) = {i.template cast_to<sch::Float32>()+0.5f};
- pos.at({{1u}}) = {j.template cast_to<sch::Float32>()+64.0f};
-
- old_pos = pos;
- }
- }
-
- // A timestep is a lattice time, which makes (pos - pos_old)/time_step a
- // velocity rather than an unlabelled vector.
- kel::lbm::data<sch::LbmSecond<sch::Scalar<sch::Float32>>> time_step;
- time_step.at({}).set(0.05f);
-
- for(kel::lbm::data<sch::UInt64> dt{0u}; dt < kel::lbm::data<sch::UInt64>{32ul}; ++dt){
- // Do Verlet Step
- for(kel::lbm::data<sch::UInt64> i{0u}; i < particles.size(); ++i){
- auto& part_i = particles.at(i);
-
- verlet_step_lambda<sch::Float32,2u>(part_i,time_step);
- auto& body_i = part_i.template get<"rigid_body">();
- auto& acc_i = body_i.template get<"acceleration">();
-
- acc_i.at({{0u}}) = 0.0;
- acc_i.at({{1u}}) = -9.81;
- }
-
- //
- for(kel::lbm::data<sch::UInt64> i{0u}; i < particles.size(); ++i){
- auto& part_i = particles.at(i);
- auto& body_i = part_i.template get<"rigid_body">();
- auto& pos_i = body_i.template get<"position">();
- auto& pos_old_i = body_i.template get<"position_old">();
- /**
- * Test against other particles
- */
- for(kel::lbm::data<sch::UInt64> j{i+1ul}; j < particles.size(); ++j){
- auto& part_j = particles.at(j);
- auto& body_j = part_j.template get<"rigid_body">();
- auto& pos_j = body_j.template get<"position">();
- auto& pos_old_j = body_j.template get<"position_old">();
-
- auto res = broadphase_collision_distance_squared<sch::Float32,2u>(part_i, part_j);
- if(res.first){
- //std::cout<<"Collision"<<std::endl;
- // Do collision
-
- auto vel_i = (pos_i - pos_old_i)/time_step;
- auto vel_j = (pos_j - pos_old_j)/time_step;
-
- auto vel_rel = vel_i - vel_j;
- auto pos_rel = pos_i - pos_j;
-
- auto vel_pos_rel_dot = kel::lbm::math::dot(vel_rel,pos_rel);
- if(vel_pos_rel_dot.at({}).get() < 0.0){
- auto pos_rel_normed = pos_rel / kel::lbm::math::sqrt(res.second);
- }
-
- // auto vel_ij = kel::lbm::math::dot(vel_i,vel_j);
-
- }
- }
- /**
- * Test against walls
- */
- if(pos_i.at({{0u}}).get() <= 0 or pos_i.at({{0u}}).get() >= 40 ){
- auto pos_i_0 = pos_i.at({{0u}});
- pos_i.at({{0u}}) = pos_old_i.at({{0u}});
- pos_old_i.at({{0u}}) = pos_i_0;
- }
- if(pos_i.at({{1u}}).get() <= 0 ){
- auto pos_i_1 = pos_i.at({{1u}});
- pos_i.at({{1u}}) = pos_old_i.at({{1u}});
- pos_old_i.at({{1u}}) = pos_i_1;
- }
- }
- auto& pos = particles.at({0u}).template get<"rigid_body">().template get<"position">();
-
- std::cout<<pos.at({{0u}}).get()<<" "<<pos.at({{1u}}).get()<<std::endl;
- }
-
- return kel::lbm::make_void();
-}
-}
-
-int main(int argc, char** argv){
- auto eov = kel::lbm_main(argc, argv);
- if(eov.is_error()){
- auto& err = eov.get_error();
- std::cerr<<"[Error] "<<err.get_category();
- auto err_msg = err.get_message();
- if(err_msg.size() > 0u){
- std::cerr<<" - "<<err_msg;
- }
- std::cerr<<std::endl;
- return err.get_id();
- }
-
- return 0;
-}
diff --git a/examples/poiseulle_2d_gpu/.nix/derivation.nix b/examples/poiseulle_2d_gpu/.nix/derivation.nix
index cc132ee..56f5cae 100644
--- a/examples/poiseulle_2d_gpu/.nix/derivation.nix
+++ b/examples/poiseulle_2d_gpu/.nix/derivation.nix
@@ -27,10 +27,12 @@ stdenv.mkDerivation {
forstio.codec
forstio.codec-unit
forstio.remote
+ forstio.remote-filesystem
forstio.codec-json
forstio.io
adaptive-cpp
kel.lbm.core
+ kel.lbm.sycl
# kel-lbm.sycl
];
diff --git a/examples/poiseulle_2d_gpu/SConstruct b/examples/poiseulle_2d_gpu/SConstruct
index a7201cb..0611b67 100644
--- a/examples/poiseulle_2d_gpu/SConstruct
+++ b/examples/poiseulle_2d_gpu/SConstruct
@@ -57,7 +57,9 @@ env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
'-Wextra'
],
LIBS=[
- 'forstio-core'
+ 'forstio-core',
+ 'forstio-async',
+ 'forstio-io'
]
);
env.__class__.add_source_files = add_kel_source_files
diff --git a/examples/poiseulle_2d_gpu/poiseulle_2d_gpu.cpp b/examples/poiseulle_2d_gpu/poiseulle_2d_gpu.cpp
index 5959506..7e4d901 100644
--- a/examples/poiseulle_2d_gpu/poiseulle_2d_gpu.cpp
+++ b/examples/poiseulle_2d_gpu/poiseulle_2d_gpu.cpp
@@ -1,395 +1,439 @@
+#include <kel/lbm/sycl/lbm.hpp>
#include <kel/lbm/lbm.hpp>
-#include <AdaptiveCpp/sycl/sycl.hpp>
-#include <forstio/codec/data.hpp>
-
-template<typename T>
-using SyclHostAlloc = acpp::sycl::usm_allocator<kel::lbm::data<T>, acpp::sycl::usm::alloc::host>;
+#include <forstio/io/io.hpp>
+#include <forstio/remote/filesystem/easy.hpp>
+#include <forstio/codec/json/json.hpp>
+#include <forstio/codec/simple.hpp>
+#include <forstio/codec/args.hpp>
namespace kel {
namespace lbm {
-namespace sch {
-
-/**
- * Basic distribution function
- * Base type
- * D
- * Q
- * Scalar factor
- * D factor
- * Q factor
- */
-using T = Float64;
-using D2Q9 = Descriptor<2u,9u>;
-
-using DfCell = Cell<T, D2Q9, 0u, 0u, 1u>;
-using CellInfo = Cell<UInt8, D2Q9, 1u, 0u, 0u>;
-/**
- * Basic type for simulation
- */
-using CellStruct = Struct<
- Member<DfCell, "dfs">,
- Member<DfCell, "dfs_old">,
- Member<CellInfo, "info">
->;
+// The channel this case has always used.
+constexpr uint64_t dim_x = 1024ul;
+constexpr uint64_t dim_y = 512ul;
-using MacroStruct = Struct<
- Member<FixedArray<Float64,D2Q9::D>, "velocity">,
- Member<Float64, "pressure">
->;
+namespace sch {
-}
+using InfoChunk = Chunk<UInt8, 0u, dim_x, dim_y>;
-namespace cmpt {
-template<bool East>
-struct PressureBoundaryRestrictedVelocityTo {};
-}
+template<typename T, typename Desc>
+using DfChunk = Chunk<FixedArray<T,Desc::Q>, 1u, dim_x, dim_y>;
-template<typename FP,typename Desc, bool East>
-struct component<FP,Desc, cmpt::PressureBoundaryRestrictedVelocityTo<East>> {
-private:
- kel::lbm::data<FP> pressure_setting_;
- kel::lbm::data<FP> rho_setting_;
-public:
- component(const kel::lbm::data<FP>& pressure_setting__):
- pressure_setting_{pressure_setting__},
- rho_setting_{pressure_setting__ * df_info<FP,Desc>::inv_cs2}
- {}
+template<typename T, typename Desc>
+using ScalarChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
- template<typename CellFieldSchema>
- void apply(
- kel::lbm::data<CellFieldSchema>* field,
- kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index,
- const kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>>& meta,
- uint64_t time_step
- ) const {
+template<typename T, typename Desc>
+using VectorChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
- using dfi = df_info<FP,Desc>;
+template<typename T, typename Desc>
+using ChunkStruct = Struct<
+ Member<InfoChunk, "info">,
+ Member<DfChunk<T,Desc>, "dfs">,
+ Member<DfChunk<T,Desc>, "dfs_old">
+>;
- auto flat_ind = flatten_index<sch::UInt64,Desc::D>::apply(index,meta);
+template<typename T, typename Desc>
+using VelChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
- bool is_even = ((time_step % 2u) == 0u);
- auto& cell = field[flat_ind.get()];
+template<typename T>
+using RhoChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
- auto& info = cell.template get<"info">();
- if(info({0u}).get() == 0u){
- return;
- }
- auto& dfs_old = (is_even) ? cell.template get<"dfs_old">() : cell.template get<"dfs">();
+template<typename T, typename Desc>
+using MacroStruct = Struct<
+ Member<VelChunk<T,Desc>, "velocity">,
+ Member<RhoChunk<T>, "density">
+>;
- /**
- * Sum all known DFs
- */
- kel::lbm::data<FP> sum_df{0u};
- for(kel::lbm::data<sch::UInt64> k{0u}; k < kel::lbm::data<sch::UInt64>{Desc::Q}; ++k){
- auto c_k = dfi::directions[k.get()];
- auto flat_ind_n = flatten_index<sch::UInt64,Desc::D>::apply({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}},meta);
- auto& cell_n = field[flat_ind_n.get()];
- auto& info_n = cell_n.template get<"info">();
- auto info_n_val = info_n({0u});
- auto k_opp = dfi::opposite_index[k.get()];
+//template<typename T, typename Desc>
+//using ParticleArray = Array<
+// Particle<T,Desc::D>
+//>;
+}
- if(info_n_val.get() > 0u){
- sum_df += dfs_old({k_opp});
- }
- }
- /**
- * Get the sum of the unknown dfs and precalculate the direction
- */
- constexpr int known_dir = East ? 1 : -1;
- auto sum_unknown_dfs = (rho_setting_ - sum_df) * kel::lbm::data<FP>{known_dir};
+template<typename T, typename Desc>
+kel::lbm::error_or<void> setup_initial_conditions(
+ kel::lbm::data<sch::ChunkStruct<T,Desc>>& fields,
+ kel::lbm::data<sch::MacroStruct<T,Desc>>& macros
+){
+ auto& info_f = fields.template get<"info">();
+ // Set everything as walls
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(1u);
+ },
+ {},
+ info_f.get_dims(),
+ {}
+ );
+ // Fluid
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(2u);
+ },
+ {},
+ info_f.get_dims(),
+ {{1u,1u}}
+ );
+
+ // Inflow
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(3u);
+ },
+ {{0u,0u}},
+ {{1u,dim_y}},
+ {{0u,1u}}
+ );
+
+ // Outflow
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(4u);
+ },
+ {{dim_x-1u,0u}},
+ {{dim_x, dim_y}},
+ {{0u,1u}}
+ );
+ //
+ auto& df_f = fields.template get<"dfs_old">();
+ auto& rho_f = macros.template get<"density">();
+ auto& vel_f = macros.template get<"velocity">();
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ rho.at({}) = {1};
+ auto& vel = vel_f.at(index);
+ auto eq = equilibrium<T,Desc>(rho,vel);
- for(kel::lbm::data<sch::UInt64> k{0u}; k < kel::lbm::data<sch::UInt64>{Desc::Q}; ++k){
- auto c_k = dfi::directions[k.get()];
- auto flat_ind_n = flatten_index<sch::UInt64,Desc::D>::apply({{index.at({0u})+c_k[0u], index.at({1u})+c_k[1u]}},meta);
- auto& cell_n = field[flat_ind_n.get()];
- auto& info_n = cell_n.template get<"info">();
- auto info_n_val = info_n({0u});
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
- if(info_n_val.get() > 0u){
- sum_unknown_dfs += dfs_old({k}) * c_k[0u];
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ rho.at({}) = {1};
+ auto& vel = vel_f.at(index);
+ if(info_f.at(index).get() == 2u){
+ vel.at({{0u}}) = 0.0;
}
- }
+ auto eq = equilibrium<T,Desc>(rho,vel);
- auto vel_x = sum_unknown_dfs / rho_setting_;
-
- if constexpr (East) {
- dfs_old({2u}) = dfs_old({1u}) + kel::lbm::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x;
- dfs_old({6u}) = dfs_old({5u}) + kel::lbm::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + kel::lbm::data<FP>{0.5} * (dfs_old({4u}) - dfs_old({3u}));
- dfs_old({8u}) = dfs_old({7u}) + kel::lbm::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + kel::lbm::data<FP>{0.5} * (dfs_old({3u}) - dfs_old({4u}));
- }else if constexpr (not East){
- dfs_old({1u}) = dfs_old({2u}) - kel::lbm::data<FP>{2.0 / 3.0} * rho_setting_ * vel_x;
- dfs_old({5u}) = dfs_old({6u}) - kel::lbm::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + kel::lbm::data<FP>{0.5} * (dfs_old({3u}) - dfs_old({4u}));
- dfs_old({7u}) = dfs_old({8u}) - kel::lbm::data<FP>{1.0 / 6.0} * rho_setting_ * vel_x + kel::lbm::data<FP>{0.5} * (dfs_old({4u}) - dfs_old({3u}));
- }
- }
-};
-
-/**
- * This is massively hacky and expects a lot of conditions
- * Either this or mirrored along the horizontal line works
- *
- * 0 - 2 - 2
- * 0 - 3 - 1
- * 0 - 3 - 1
- * .........
- * 0 - 3 - 1
- * 0 - 2 - 2
- *
- */
-
-template<typename Desc>
-kel::lbm::error_or<void> set_geometry(
- kel::lbm::data<sch::CellStruct>* cells,
- const kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>>& meta,
- acpp::sycl::queue& sycl_q
-){
- using namespace kel::lbm;
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims(),
+ {{1u,1u}}
+ );
- kel::lbm::data<sch::T> rho{1.0};
- kel::lbm::data<sch::FixedArray<sch::T,Desc::D>> vel{{0.0,0.0}};
- auto eq = equilibrium<sch::T,Desc>(rho, vel);
-
- sycl_q.submit([&](acpp::sycl::handler& h){
- h.parallel_for(acpp::sycl::range<2>{meta.at({0}).get(), meta.at({1}).get()},[=](acpp::sycl::id<2> idx){
- size_t i = idx[0];
- size_t j = idx[1];
- size_t acc_id = j * meta.at({0u}).get() + i;
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ kel::lbm::data<sch::Vector<T,Desc::D>> middle, ind_vec;
+ middle.at({{0u}}) = dim_x * 0.25;
+ middle.at({{1u}}) = dim_y * 0.5;
- auto& c = cells[acc_id];
- auto& info = c.template get<"info">()({0});
- auto& dfs = c.template get<"dfs">();
- auto& dfs_old = c.template get<"dfs_old">();
+ ind_vec.at({{0u}}) = index.at({{0u}}).template cast_to<T>();
+ ind_vec.at({{1u}}) = index.at({{1u}}).template cast_to<T>();
- if(i >= 2u and j >= 2u and (i+2u) < meta.at({0u}).get() and (j+2u) < meta.at({1u}).get()){
- // Fluid
- info.set({2u});
- }else if(((j+2u) == meta.at({1u}).get() or j == 1u) and (i>=1u and (i+1u)<meta.at({0u}).get() )){
- // Wall
- info.set({1u});
- }else if((i==1u) and (j >= 1 and (j+1 < meta.at({1u}).get()) ) ){
- // Left input
- info.set({3u});
- }else if((i+2u) == meta.at({0u}).get() and (j >= 1 and (j+1) < meta.at({1u}).get() )){
- // Right output
- info.set({4u});
- }else {
- info.set({0u});
- }
- for(kel::lbm::data<sch::UInt64> k{0u}; k < kel::lbm::data<sch::UInt64>{Desc::Q}; ++k){
- dfs(k) = eq.at(k);
- dfs_old(k) = eq.at(k);
+ auto dist = middle - ind_vec;
+ auto dist_2 = kel::lbm::math::dot(dist,dist);
+ if(dist_2.at({}).get() < dim_y*dim_y*0.01){
+ info_f.at(index) = 1u;
}
- });
- }).wait();
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
return kel::lbm::make_void();
}
-template<typename Desc>
-void step(
- kel::lbm::data<sch::CellStruct>* cells,
- kel::lbm::data<sch::MacroStruct>* macro_cells,
- const kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>>& meta,
- uint64_t time_step,
- acpp::sycl::queue& sycl_q
+template<typename T, typename Desc>
+kel::lbm::error_or<void> step(
+ kel::lbm::data<sch::Ptr<sch::ChunkStruct<T,Desc>>,encode::Sycl<kel::lbm::enc::Native>>& fields,
+ kel::lbm::data<sch::Ptr<sch::MacroStruct<T,Desc>>,encode::Sycl<kel::lbm::enc::Native>>& macros,
+ kel::lbm::data<sch::UInt64> t_i,
+ device& dev
){
- using namespace kel::lbm;
- using dfi = df_info<sch::T,Desc>;
-
- constexpr kel::lbm::data<sch::T> frequency{1.0 / 0.6};
+ auto& q = dev.get_handle();
+ auto& info_f = fields.template get<"info">();
- bool is_even = ((time_step % 2u) == 0u);
- /**
- * 1. Relaxation parameter \tau
- */
- /*
- component<sch::T, sch::D2Q9, cmpt::BGK> coll{0.5384};
- component<sch::T, sch::D2Q9, cmpt::BounceBack> bb;
- */
- component<sch::T, Desc, cmpt::PressureBoundaryRestrictedVelocityTo<true>> inlet{1.01 * dfi::cs2 * 2.0/3.0};
- component<sch::T, Desc, cmpt::PressureBoundaryRestrictedVelocityTo<false>> outlet{1.0 * dfi::cs2 * 2.0/3.0};
+ // auto coll_ev =
+ q.submit([&](acpp::sycl::handler& h){
+ // Need nicer things to handle the flow. I see improvement here
+ component<T,Desc,cmpt::BGK, encode::Sycl<kel::lbm::enc::Native>> collision{0.8};
+ component<T,Desc,cmpt::BounceBack,encode::Sycl<kel::lbm::enc::Native>> bb;
+ component<T,Desc,cmpt::AntiBounceBack<0u>,encode::Sycl<kel::lbm::enc::Native>> abb;
-
- // auto collision_ev =
- sycl_q.submit([&](acpp::sycl::handler& h){
-
- /// Collision
- h.parallel_for(acpp::sycl::range<2>{meta.at({0}).get(), meta.at({1}).get()},[=](acpp::sycl::id<Desc::D> idx){
- size_t i = idx[0];
- size_t j = idx[1];
- size_t acc_id = j * meta.at({0u}).get() + i;
-
- auto& c = cells[acc_id];
- auto& info = cells[acc_id].template get<"info">();
+ kel::lbm::data<sch::Scalar<T>> rho_b;
+ rho_b.at({}) = 1.0;
+ kel::lbm::data<sch::Vector<T,Desc::D>> vel_b;
+ vel_b.at({{0u}}) = 0.015;
- switch (info({0u}).get()) {
- // Bounce Back
- case 1u: {
- auto& dfs_old = is_even ? c.template get<"dfs_old">() : c.template get<"dfs">();
- auto df_cpy = dfs_old.copy();
+ component<T,Desc,cmpt::Equilibrium,encode::Sycl<kel::lbm::enc::Native>> equi{rho_b,vel_b};
- for(uint64_t k = 1u; k < Desc::Q; ++k){
- dfs_old({k}) = df_cpy({dfi::opposite_index.at(k)});
+ component<T,Desc,cmpt::ZouHeHorizontal<true>,encode::Sycl<kel::lbm::enc::Native>> flow_in{
+ [&](){
+ uint64_t target_t_i = 32u;
+ if(t_i.get() < target_t_i){
+ return 1.0 + (0.0002 / target_t_i) * t_i.get();
}
+ return 1.0002;
+ }()
+ };
+ component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<kel::lbm::enc::Native>> flow_out{1.0};
- break;
- }
- // Collision
- case 2u: {
- // coll.apply(latt_acc, {i, j}, time_step);
- auto& dfs_old = is_even ? c.template get<"dfs_old">() : c.template get<"dfs">();
-
- auto& macro_c = macro_cells[acc_id];
-
- kel::lbm::data<sch::T>& rho = macro_c.template get<"pressure">();
- kel::lbm::data<sch::FixedArray<sch::T,Desc::D>>& vel = macro_c.template get<"velocity">();
- compute_rho_u<sch::T,Desc>(dfs_old,rho,vel);
- auto eq = equilibrium<sch::T,Desc>(rho,vel);
-
- for(uint64_t k = 0u; k < Desc::Q; ++k){
- dfs_old({k}) = dfs_old({k}) + frequency * (eq.at({k}) - dfs_old({k}));
- }
- break;
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
}
- case 3u: {
- inlet.apply(cells, {{i,j}}, meta, time_step);
- auto& dfs_old = is_even ? c.template get<"dfs_old">() : c.template get<"dfs">();
-
- auto& macro_c = macro_cells[acc_id];
- kel::lbm::data<sch::T>& rho = macro_c.template get<"pressure">();
- kel::lbm::data<sch::FixedArray<sch::T,Desc::D>>& vel = macro_c.template get<"velocity">();
-
- compute_rho_u<sch::T,Desc>(dfs_old,rho,vel);
- auto eq = equilibrium<sch::T,Desc>(rho,vel);
-
- for(uint64_t k = 0u; k < Desc::Q; ++k){
- dfs_old({k}) = dfs_old({k}) + frequency * (eq.at({k}) - dfs_old({k}));
- }
+ auto info = info_f.at(index);
+
+ switch(info.get()){
+ case 0u:
break;
- }
- case 4u: {
- outlet.apply(cells, {{i,j}}, meta, time_step);
- auto& dfs_old = is_even ? c.template get<"dfs_old">() : c.template get<"dfs">();
-
- auto& macro_c = macro_cells[acc_id];
-
- kel::lbm::data<sch::T>& rho = macro_c.template get<"pressure">();
- kel::lbm::data<sch::FixedArray<sch::T,Desc::D>>& vel = macro_c.template get<"velocity">();
-
- compute_rho_u<sch::T,Desc>(dfs_old,rho,vel);
- auto eq = equilibrium<sch::T,Desc>(rho,vel);
-
- for(uint64_t k = 0u; k < Desc::Q; ++k){
- dfs_old({k}) = dfs_old({k}) + frequency * (eq.at({k}) - dfs_old({k}));
- }
+ case 1u:
+ bb.apply(fields,index,t_i);
break;
- }
- default:
- // Do nothing
+ case 2u:
+ collision.apply(fields,macros,index,t_i);
+ break;
+ case 3u:
+ flow_in.apply(fields,index,t_i);
+ //equi.apply(fields,index,t_i);
+ collision.apply(fields,macros,index,t_i);
+ break;
+ case 4u:
+ flow_out.apply(fields,index,t_i);
+ collision.apply(fields,macros,index,t_i);
+ break;
+ default:
break;
}
});
}).wait();
-
- //auto stream_ev =
- sycl_q.submit([&](acpp::sycl::handler& h){
- /// Stream
- h.parallel_for(acpp::sycl::range<2>{meta.at({0}).get(), meta.at({1}).get()},[=](acpp::sycl::id<Desc::D> idx){
- size_t i = idx[0];
- size_t j = idx[1];
- size_t acc_id = j * meta.at({0u}).get() + i;
-
- auto& c = cells[acc_id];
- auto& info = c.template get<"info">();
- auto& dfs_new = is_even ? c.template get<"dfs">() : c.template get<"dfs_old">();
- if (info({0u}).get() > 0u) {
- for (uint64_t k = 0u; k < Desc::Q; ++k) {
- auto dir = dfi::directions[dfi::opposite_index[k]];
- size_t acc_old_id = (j+dir[1]) * meta.at({0u}).get() + (i+dir[0]);
-
- auto& dfs_old = is_even ? cells[acc_old_id].template get<"dfs_old">() : cells[acc_old_id].template get<"dfs">();
- auto& info_old = cells[acc_old_id].template get<"info">();
-
- dfs_new({k}) = dfs_old({k});
- }
- }
-
- });
+
+ // Step
+ /*
+ q.submit([&](acpp::sycl::handler& h){
+ // h.depends_on(collision_ev);
}).wait();
+ */
+
+ return kel::lbm::make_void();
}
}
}
template<typename T, typename Desc>
-kel::lbm::error_or<void> kel_main(int argc, char** argv){
- using namespace kel;
+kel::lbm::error_or<void> lbm_main(int argc, char** argv){
+ using namespace kel::lbm;
+
+ /*
+ auto eo_lbm_args = setup_lbm_env<sch::Args<sch::Struct<>,sch::Tuple<>>>(argc,argv);
+ if(eo_lbm_args.is_error()){
+ return std::move(eo_lbm_args.get_error());
+ }
+ auto& lbm_args = eo_lbm_args.get_value();
+ */
- using dfi = lbm::df_info<T,Desc>;
+ using dfi = df_info<T,Desc>;
- auto eo_lbm_dir = lbm::output_directory();
+ auto eo_lbm_dir = output_directory();
if(eo_lbm_dir.is_error()){
return std::move(eo_lbm_dir.get_error());
}
auto& lbm_dir = eo_lbm_dir.get_value();
- auto out_dir = lbm_dir / "poiseulle_channel_2d_gpu";
- std::filesystem::create_directories(out_dir);
- //
- lbm::converter<lbm::sch::Float64> conv {
+
+ auto out_dir = lbm_dir / "poiseulle_2d_gpu";
+
+ {
+ std::error_code ec;
+ std::filesystem::create_directories(out_dir,ec);
+ if(ec != std::errc{}){
+ return kel::lbm::make_error<kel::lbm::err::critical>("Could not create output directory");
+ }
+ }
+
+ converter<T> conv {
// delta_x
{1.0},
// delta_t
{1.0}
};
+
+ print_lbm_meta<T,Desc>(conv,{0.1},{1e-4},{0.4 * dim_y});
- uint64_t x_d = 1024u;
- uint64_t y_d = 512u;
+ // kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
+ auto lbm_data_ptr = kel::lbm::heap<kel::lbm::data<sch::ChunkStruct<T,Desc>>>();
+ auto lbm_macro_data_ptr = kel::lbm::heap<kel::lbm::data<sch::MacroStruct<T,Desc>>>();
+
+ std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl;
- kel::lbm::data<lbm::sch::FixedArray<lbm::sch::UInt64,Desc::D>> meta{{x_d,y_d}};
+ auto eo_aio = saw::setup_async_io();
+ if(eo_aio.is_error()){
+ return kel::lbm::make_error<kel::lbm::err::critical>(
+ std::string{eo_aio.get_error().get_message()});
+ }
+ auto& aio = eo_aio.get_value();
+ saw::wait_scope wait{aio.event_loop};
- acpp::sycl::queue sycl_q;
- SyclHostAlloc<lbm::sch::MacroStruct> sycl_host_alloc{sycl_q};
- // SyclDeviceAlloc<lbm::sch::CellStruct> sycl_dev_alloc{sycl_q};
+ bool krun = true;
+ bool print_status = false;
+ aio.event_port.on_signal(saw::Signal::Terminate).then([&](){
+ krun = false;
+ }).detach();
+ aio.event_port.on_signal(saw::Signal::User1).then([&](){
+ print_status = true;
+ }).detach();
- std::vector<kel::lbm::data<lbm::sch::MacroStruct>, SyclHostAlloc<lbm::sch::MacroStruct>> host_cells{x_d * y_d,sycl_host_alloc};
+ device dev;
- kel::lbm::data<lbm::sch::CellStruct>* cells = acpp::sycl::malloc_device<kel::lbm::data<lbm::sch::CellStruct>>(x_d * y_d,sycl_q);
- kel::lbm::data<lbm::sch::MacroStruct>* macro_cells = acpp::sycl::malloc_device<kel::lbm::data<lbm::sch::MacroStruct>>(x_d * y_d,sycl_q);
+ auto& sycl_q = dev.get_handle();
+
+ sycl_q.wait();
{
- auto eov = lbm::set_geometry<Desc>(cells,meta,sycl_q);
+ auto eov = setup_initial_conditions<T,Desc>(*lbm_data_ptr,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"initial_state",0u,*lbm_data_ptr);
if(eov.is_error()){
return eov;
}
}
+ kel::lbm::data<sch::ChunkStruct<T,Desc>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_data{sycl_q};
+ kel::lbm::data<sch::MacroStruct<T,Desc>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_macro_data{sycl_q};
+ sycl_q.wait();
- uint64_t time_max = 1024u*128u;
- for(uint64_t i = 0u; i < time_max; ++i){
- lbm::step<Desc>(cells,macro_cells,meta,i,sycl_q);
+ {
+ auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ sycl_q.wait();
+ auto lsd_view = make_view(lbm_sycl_data);
+ auto lsdm_view = make_view(lbm_sycl_macro_data);
+ kel::lbm::data<sch::UInt64> time_steps{16u*4096ul};
+
+ auto& info_f = lsd_view.template get<"info">();
+
+ for(kel::lbm::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){
+ // BC + Collision
+ {
+ auto eov = step<T,Desc>(lsd_view,lsdm_view,i,dev);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
sycl_q.wait();
- if(i%4u == 0u){
- std::string vtk_f_name{"tmp/poiseulle_2d_gpu_"};
- vtk_f_name += std::to_string(i) + ".vtk";
- // write_vtk_file(vtk_f_name,host_cells);
- sycl_q.memcpy(&host_cells[0u], macro_cells, x_d * y_d * sizeof(kel::lbm::data<lbm::sch::MacroStruct>) ).wait();
- lbm::write_vtk_file<lbm::sch::MacroStruct,Desc::D>(vtk_f_name, &host_cells[0], meta);
+ /*
+ if(i.get() % 128u == 0u){
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"m",i.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+ */
+ /*
+ if(i.get() % 32u == 0u){
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_csv_file(out_dir,"m",i.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ }
+ */
+ // Stream
+ sycl_q.submit([&](acpp::sycl::handler& h){
+ component<T,Desc,cmpt::Stream,encode::Sycl<kel::lbm::enc::Native>> stream;
+
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){
+ kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ auto info = info_f.at(index);
+
+ if(info.get() > 0u){
+ stream.apply(lsd_view,index,i);
+ }
+ });
+ }).wait();
+ wait.poll();
+ if(print_status){
+ std::cout<<"Status: "<<i.get()<<" of "<<time_steps.get()<<" - "<<(i.template cast_to<sch::Float64>().get() * 100 / time_steps.get())<<"%"<<std::endl;
+ print_status = false;
}
+ print_progress_bar(i.get(), time_steps.get()-1u);
}
+ // After Loop
sycl_q.wait();
- acpp::sycl::free(cells, sycl_q);
- acpp::sycl::free(macro_cells, sycl_q);
- sycl_q.wait();
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_vtk_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = write_csv_file(out_dir,"m",time_steps.get(), *lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ sycl_q.wait();
return kel::lbm::make_void();
}
+using FloatT = kel::lbm::sch::Float32;
+
int main(int argc, char** argv){
- auto eov = kel_main<kel::lbm::sch::T,kel::lbm::sch::D2Q9>(argc, argv);
+ auto eov = lbm_main<FloatT,kel::lbm::sch::D2Q9>(argc, argv);
if(eov.is_error()){
auto& err = eov.get_error();
std::cerr<<"[Error] "<<err.get_category();
diff --git a/examples/poiseulle_3d/.nix/derivation.nix b/examples/poiseulle_3d/.nix/derivation.nix
index b090add..02fcb8c 100644
--- a/examples/poiseulle_3d/.nix/derivation.nix
+++ b/examples/poiseulle_3d/.nix/derivation.nix
@@ -21,14 +21,16 @@ stdenv.mkDerivation {
buildInputs = [
forstio.core
+ forstio.remote-filesystem
+ forstio.io
forstio.async
forstio.codec
forstio.codec-unit
forstio.codec-json
forstio.remote
- forstio.remote-sycl
adaptive-cpp
kel.lbm.core
+ kel.lbm.sycl
];
preferLocalBuild = true;
diff --git a/examples/poiseulle_3d/SConstruct b/examples/poiseulle_3d/SConstruct
index fe206e1..7882265 100644
--- a/examples/poiseulle_3d/SConstruct
+++ b/examples/poiseulle_3d/SConstruct
@@ -59,6 +59,8 @@ env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[],
],
LIBS=[
'forstio-core',
+ 'forstio-async',
+ 'forstio-io',
'acpp-rt',
'omp'
]
diff --git a/examples/poiseulle_3d/poiseulle_3d.cpp b/examples/poiseulle_3d/poiseulle_3d.cpp
index 141dc5f..34d1fbc 100644
--- a/examples/poiseulle_3d/poiseulle_3d.cpp
+++ b/examples/poiseulle_3d/poiseulle_3d.cpp
@@ -1,428 +1,431 @@
+#include <kel/lbm/sycl/lbm.hpp>
#include <kel/lbm/lbm.hpp>
+#include <kel/lbm/particle.hpp>
-#include <forstio/remote/sycl/sycl.hpp>
-
-namespace saw {
-/*
-template<typename Desc, typename CellT, typename Encode>
-class data<kel::lbm::sch::CellField<Desc, CellT>, encode::Sycl<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::Sycl<Encode>> inner_;
-public:
- data() = delete;
- data(const data<MetaSchema,Encode>& inner_meta__, acpp::sycl::queue& q):
- inner_{inner_meta__,q}
- {}
-
- 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);
- }
-
- ref<data<schema::Array<CellT,Desc::D>, encode::Sycl<Encode> >> inner_data() {
- return {inner_};
- }
-
- data<schema::UInt64,Encode> internal_size() const {
- return inner_.internal_size();
- }
-
- data<CellT,Encode>* internal_data() {
- return inner_.internal_data();
- }
-};
-*/
-/*
-template<typename T, uint64_t D, typename Encode>
-class data<schema::Ref<schema::Array<T, D>>, encode::Sycl<Encode>> final {
-public:
- using Schema = schema::Ref<schema::Array<T, D>>;
-private:
- data<schema::Ref<schema::Array<CellT,Desc::D>>, encode::Sycl<Encode>>> inner_ref_;
-public:
- data() = delete;
- data(ref<data<kel::lbm::sch::CellField<Desc,CellT>,encode::Sycl<Encode>>> inner_ref__):
- inner_ref_{inner_ref__().inner_data()}
- {}
-
- const data<MetaSchema, Encode> meta() const {
- return inner_ref_().dims();
- }
-
- const data<CellT>& operator()(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index)const{
- return inner_ref_().at(index);
- }
-
- data<CellT>& operator()(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index){
- return inner_ref_().at(index);
- }
-
- const data<CellT>& at(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index)const{
- return inner_ref_().at(index);
- }
-
- data<CellT>& at(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index){
- return inner_ref_().at(index);
- }
-
- data<schema::UInt64,Encode> internal_size() const {
- return inner_ref_().internal_size();
- }
-
- data<CellT,Encode>* internal_data() {
- return inner_ref_().internal_data();
- }
-};
-
-
-template<typename Desc, typename CellT, typename Encode>
-class data<schema::Ref<kel::lbm::sch::CellField<Desc, CellT>>, encode::Sycl<Encode>> final {
-public:
- using Schema = schema::Ref<kel::lbm::sch::CellField<Desc,CellT>>;
-private:
- data<schema::Ref<schema::Array<CellT,Desc::D>>, encode::Sycl<Encode>>> inner_ref_;
-public:
- data() = delete;
- data(ref<data<kel::lbm::sch::CellField<Desc,CellT>,encode::Sycl<Encode>>> inner_ref__):
- inner_ref_{inner_ref__().inner_data()}
- {}
-
- const data<MetaSchema, Encode> meta() const {
- return inner_ref_().dims();
- }
-
- const data<CellT>& operator()(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index)const{
- return inner_ref_().at(index);
- }
-
- data<CellT>& operator()(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index){
- return inner_ref_().at(index);
- }
-
- const data<CellT>& at(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index)const{
- return inner_ref_().at(index);
- }
-
- data<CellT>& at(const data<schema::FixedArray<schema::UInt64, Desc::D>, Encode>& index){
- return inner_ref_().at(index);
- }
-
- data<schema::UInt64,Encode> internal_size() const {
- return inner_ref_().internal_size();
- }
-
- data<CellT,Encode>* internal_data() {
- return inner_ref_().internal_data();
- }
-};
-*/
-
-}
+#include <forstio/io/io.hpp>
+#include <forstio/remote/filesystem/easy.hpp>
+#include <forstio/codec/json/json.hpp>
+#include <forstio/codec/simple.hpp>
namespace kel {
namespace lbm {
-namespace sch {
-using T = Float32;
-using Desc = Descriptor<3u,27u>;
-using DfCell = Cell<T, Desc, 0u, 0u, 1u>;
+// The channel this case has always used.
+constexpr uint64_t dim_x = 2048ul;
+constexpr uint64_t dim_y = 128ul;
+constexpr uint64_t dim_z = 128ul;
+constexpr uint64_t particle_size = 4ul;
-using CellInfo = Cell<UInt8, Desc, 1u, 0u, 0u>;
+namespace sch {
-using CellStruct = Struct<
- Member<DfCell, "dfs">,
- Member<DfCell, "dfs_old">,
- //Member<CellForceField<Desc>, "force">,
- Member<CellInfo, "info">
+using LbmArgs = Args<
+ Struct<
+ Member<String, "name">,
+ Member<UInt64, "time_steps">
+ >,
+ Tuple<>
>;
-}
-using SyclKelAllocator = acpp::sycl::usm_allocator<kel::lbm::data<sch::CellStruct>, acpp::sycl::usm::alloc::shared>;
-uint64_t to_flat_index(const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index, const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& meta){
- auto flat = index.at({2u}) + meta.at({2u})*(index.at({1u}) + index.at({0u})*meta.at({1u}));
- return flat.get();
-}
-
-template<typename StructFieldSchema>
-kel::lbm::error_or<void> set_geometry(std::vector<kel::lbm::data<StructFieldSchema>,SyclKelAllocator>& latt, const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& meta){
- using namespace kel::lbm;
+using InfoChunk = Chunk<UInt8, 0u, dim_x, dim_y, dim_z>;
- /**
- * Set ghost
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& info = cell.template get<"info">();
+template<typename T, typename Desc>
+using DfChunk = Chunk<FixedArray<T,Desc::Q>, 1u, dim_x, dim_y, dim_z>;
- info({0u}).set(0u);
- }, {{0u,0u}}, meta);
+template<typename T, typename Desc>
+using ScalarChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y, dim_z>;
- kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>> distance;
-
- /**
- * Set wall
- */
- iterator<1u>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,1u>>& index){
- distance.at(index.at({0u})) = {1u};
- },{{0u}},{{sch::Desc::D}});
- /*
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& info = cell.template get<"info">();
+template<typename T, typename Desc>
+using VectorChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y, dim_z>;
- info({0u}).set(2u);
- }, {}, meta, distance);
-
- /**
- * Set fluid
- */
- iterator<1u>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,1u>>& index){
- distance.at(index.at({0u})) = {2u};
- },{{0u}},{{sch::Desc::D}});
- /*
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& info = cell.template get<"info">();
+template<typename T, typename Desc>
+using ChunkStruct = Struct<
+ Member<InfoChunk, "info">,
+ Member<DfChunk<T,Desc>, "dfs">,
+ Member<DfChunk<T,Desc>, "dfs_old">,
+ Member<VectorChunk<T,Desc>, "particle_N">,
+ Member<ScalarChunk<T,Desc>, "particle_D">
+>;
- info({0u}).set(1u);
+template<typename T, typename Desc>
+using MomChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y, dim_z>;
- }, {}, meta, distance);
+template<typename T>
+using RhoChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y, dim_z>;
- /**
- * Set inflow
- */
+template<typename T, typename Desc>
+using MacroStruct = Struct<
+ Member<MomChunk<T,Desc>, "velocity">,
+ Member<RhoChunk<T>, "density">,
+ Member<ScalarChunk<T,Desc>, "porosity">
+>;
+}
- kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>> shifted_point;
- iterator<1u>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,1u>>& index){
- distance.at(index.at({0u})) = (index.at({0u}).get() == 0u)?1u:2u;
- shifted_point.at(index.at({0u})) = (index.at({0u}).get() == 0u)?3u:meta.at({index.at({0u})});
- },{{0u}},{{sch::Desc::D}});
- /*
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& info = cell.template get<"info">();
+template<typename T, typename Desc>
+kel::lbm::error_or<void> setup_initial_conditions(
+ converter<T>& conv,
+ kel::lbm::data<sch::ChunkStruct<T,Desc>>& fields,
+ kel::lbm::data<sch::MacroStruct<T,Desc>>& macros,
+ kel::lbm::data<sch::FixedArray<sch::Particle<T,Desc::D>, particle_size>>& particles
+){
+ // Unit conversion is not exercised in this reduced case.
+ (void) conv;
- info({0u}).set(3u);
+ auto& info_f = fields.template get<"info">();
+ // Set everything as walls
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(1u);
+ },
+ {},
+ info_f.get_dims(),
+ {}
+ );
+ // Fluid
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(2u);
+ },
+ {},
+ info_f.get_dims(),
+ {{1u,1u,1u}}
+ );
+
+ // Inflow
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(3u);
+ },
+ {{0u,0u,0u}},
+ {{1u,dim_y,dim_z}},
+ {{0u,1u,1u}}
+ );
+
+ // Outflow
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ info_f.at(index).set(4u);
+ },
+ {{dim_x-1u,0u,0u}},
+ {{dim_x,dim_y,dim_z}},
+ {{0u,1u,1u}}
+ );
+ //
+ auto& df_f = fields.template get<"dfs_old">();
+ auto& rho_f = macros.template get<"density">();
+ auto& mom_f = macros.template get<"velocity">();
+ auto& por_f = macros.template get<"porosity">();
+
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ por_f.at(index).at({}) = {1};
+ rho.at({}) = {1};
+ auto& mom = mom_f.at(index);
+ auto eq = equilibrium<T,Desc>(rho,mom);
- }, {}, shifted_point, distance);
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims()
+ );
- /**
- * Set outflow
- */
- iterator<1u>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,1u>>& index){
- distance.at(index.at({0u})) = (index.at({0u}).get() == 0u)?1u:2u;
- shifted_point.at(index.at({0u})) = (index.at({0u}).get() == 0u)?(meta.at({0u})-3u):0u;
- },{{0u}},{{sch::Desc::D}});
- /*
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& info = cell.template get<"info">();
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ auto& df = df_f.at(index);
+ auto& rho = rho_f.at(index);
+ rho.at({}) = {1};
+ auto& mom = mom_f.at(index);
+ mom.at({{0u}}) = 0.01;
+ auto eq = equilibrium<T,Desc>(rho,mom);
- info({0u}).set(4u);
+ df = eq;
+ },
+ {},// 0-index
+ df_f.get_dims(),
+ {{1u,1u,1u}}
+ );
- }, shifted_point, meta, distance);
+ // No particles in this case -- the array is carried only so the schema
+ // matches poiseulle_3d_gpu.
+ (void) particles;
return kel::lbm::make_void();
}
-template<typename StructFieldSchema>
-kel::lbm::error_or<void> set_initial_conditions(std::vector<kel::lbm::data<StructFieldSchema>,SyclKelAllocator>& latt, const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& meta){
-
- kel::lbm::data<sch::T> rho{1.0};
- kel::lbm::data<sch::FixedArray<sch::T,sch::Desc::D>> vel{};
- vel.at({0u}) = {0.1f};
- auto eq = equilibrium<sch::T,sch::Desc>(rho, vel);
-
- /**
- * Set distribution
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& dfs = cell.template get<"dfs">();
- auto& dfs_old = cell.template get<"dfs_old">();
-
- for(kel::lbm::data<sch::UInt64> k = 0; k < kel::lbm::data<sch::UInt64>{sch::Desc::Q}; ++k){
- dfs(k) = eq.at(k);
- dfs_old(k) = eq.at(k);
- }
- }, {}, meta);
- return kel::lbm::make_void();
-}
-
-template<typename StructFieldSchema>
-kel::lbm::error_or<void> lbm_step(
- std::vector<kel::lbm::data<StructFieldSchema>,SyclKelAllocator>& latt,
- const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& meta,
- kel::lbm::data<sch::UInt64> time_step,
- acpp::sycl::queue& sycl_q
+template<typename T, typename Desc>
+kel::lbm::error_or<void> step(
+ converter<T>& conv,
+ kel::lbm::data<sch::Ptr<sch::ChunkStruct<T,Desc>>,encode::Sycl<kel::lbm::enc::Native>>& fields,
+ kel::lbm::data<sch::Ptr<sch::MacroStruct<T,Desc>>,encode::Sycl<kel::lbm::enc::Native>>& macros,
+ kel::lbm::data<sch::UInt64> t_i,
+ device& dev
){
- using dfi = df_info<sch::T,sch::Desc>;
- bool even_step = ((time_step.get() % 2u) == 0u);
+ auto& q = dev.get_handle();
+ auto& info_f = fields.template get<"info">();
- component<sch::T, sch::Desc, cmpt::BGK, kel::lbm::enc::Native> coll{0.5384};
- component<sch::T, sch::Desc, cmpt::BounceBack, kel::lbm::enc::Native> bb;
+ // auto coll_ev =
+ q.submit([&](acpp::sycl::handler& h){
+ // Need nicer things to handle the flow. I see improvement here
+ component<T,Desc,cmpt::BGK, encode::Sycl<kel::lbm::enc::Native>> collision{conv.template kinematic_viscosity_si_to_tau<Desc>({0.1})};
+ // component<T,Desc,cmpt::HLBM,encode::Sycl<kel::lbm::enc::Native>> collision{0.6};
+ component<T,Desc,cmpt::BounceBack,encode::Sycl<kel::lbm::enc::Native>> bb;
- /**
- * Collision
- */
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& info = cell.template get<"info">();
+ component<T,Desc,cmpt::ZouHeHorizontal<true>,encode::Sycl<kel::lbm::enc::Native>> flow_in{
+ [&](){
+ uint64_t target_t_i = 256u;
+ if(t_i.get() < target_t_i){
+ return 1.0 + (0.001 / target_t_i) * t_i.get();
+ }
+ return 1.001;
+ }()
+ };
+ component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<kel::lbm::enc::Native>> flow_out{1.0};
- switch(info({0u}).get()){
- case 1u: {
- bb.apply(&latt[0u], meta, index, time_step);
- break;
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y,dim_z}, [=](acpp::sycl::id<Desc::D> idx){
+ kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
}
- case 2u: {
- coll.apply(&latt[0u], meta, index, time_step);
+
+ auto info = info_f.at(index);
+
+ switch(info.get()){
+ case 0u:
break;
- }
- case 3u: {
- //inlet.apply(latt, index, time_step);
+ case 1u:
+ bb.apply(fields,index,t_i);
break;
- }
- case 4u: {
- //outlet.apply(latt, index, time_step);
+ case 2u:
+ collision.apply(fields,macros,index,t_i);
break;
- }
- default:
+ case 3u:
+ flow_in.apply(fields,index,t_i);
+ collision.apply(fields,macros,index,t_i);
break;
- }
+ case 4u:
+ flow_out.apply(fields,index,t_i);
+ collision.apply(fields,macros,index,t_i);
+ break;
+ default:
+ break;
+ }
+ });
+ }).wait();
- }, {}, meta);
+ q.submit([&](acpp::sycl::handler& h){
+ component<T,Desc,cmpt::Stream,encode::Sycl<kel::lbm::enc::Native>> stream;
- // Stream
- iterator<sch::Desc::D>::apply([&](const kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>>& index){
- auto findex = to_flat_index(index,meta);
- auto& cell = latt.at(findex);
- auto& df_new = even_step ? cell.template get<"dfs">() : cell.template get<"dfs_old">();
- auto& info_new = cell.template get<"info">();
+ h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y,dim_z}, [=](acpp::sycl::id<Desc::D> idx){
+ kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> index;
+ for(uint64_t i = 0u; i < Desc::D; ++i){
+ index.at({{i}}).set(idx[i]);
+ }
+
+ auto info = info_f.at(index);
+
+ if(info.get() > 0u){
+ stream.apply(fields,index,t_i);
+ }
+ });
+ }).wait();
- if(info_new({0u}).get() > 0u){
- for(uint64_t k = 0u; k < sch::Desc::Q; ++k){
- auto dir = dfi::directions[dfi::opposite_index[k]];
- auto index_dir = index;
- for(uint64_t i = 0; i < sch::Desc::D; ++i){
- index_dir.at({i}) = index_dir.at({i}) + dir[i];
- }
+ // Step
+ /*
+ q.submit([&](acpp::sycl::handler& h){
+ // h.depends_on(collision_ev);
+ }).wait();
+ */
- auto findex_dir = to_flat_index(index_dir,meta);
- auto& cell_dir_old = latt.at(findex_dir);
+ return kel::lbm::make_void();
+}
+}
+}
- auto& df_old = even_step ? cell_dir_old.template get<"dfs_old">() : cell_dir_old.template get<"dfs">();
+template<typename T, typename Desc>
+kel::lbm::error_or<void> lbm_main(int argc, char** argv){
+ using namespace kel::lbm;
- df_new({k}) = df_old({k});
- }
+ kel::lbm::data<sch::LbmArgs> args;
+ {
+ auto& args_n = args.template get<"args">();
+ auto& name = args_n.template get<"name">();
+ name.set("poiseulle_3d");
+ auto& steps_arg = args_n.template get<"time_steps">();
+ steps_arg.set(64u);
+ }
+ {
+ auto eov = kel::lbm::parse_args(args,argc,argv);
+ if(eov.is_error()){
+ return eov;
}
- }, {}, meta);
- return kel::lbm::make_void();
-}
+ }
+ auto eo_lbm_env = init_lbm_env(args);
+ if(eo_lbm_env.is_error()){
+ return std::move(eo_lbm_env.get_error());
+ }
+ const auto& lbm_env = eo_lbm_env.get_value();
+
+ auto& out_dir = lbm_env.name_dir;
-kel::lbm::error_or<void> real_main(int argc, char** argv){
- using dfi = df_info<sch::T,sch::Desc>;
+ {
+ std::error_code ec;
+ std::filesystem::create_directories(out_dir,ec);
+ if(ec != std::errc{}){
+ return kel::lbm::make_error<kel::lbm::err::critical>("Could not create output directory");
+ }
+ }
- converter<sch::T> conv {
- {0.1f},
- {0.1f}
+ converter<T> conv {
+ // delta_x
+ {1.0},
+ // delta_t
+ {1.0}
};
- print_lbm_meta<sch::T,sch::Desc>(conv, {1e-3f});
- acpp::sycl::queue sycl_q;
+ print_lbm_meta<T,Desc>(conv,{0.1},{0.01},{1024.0});
+
+ auto lbm_data_ptr = kel::lbm::heap<kel::lbm::data<sch::ChunkStruct<T,Desc>>>();
+ auto lbm_macro_data_ptr = kel::lbm::heap<kel::lbm::data<sch::MacroStruct<T,Desc>>>();
+ auto lbm_particle_data_ptr = kel::lbm::heap<kel::lbm::data<sch::FixedArray<sch::Particle<T,Desc::D>, particle_size>>>();
+
+ std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl;
+
+ auto eo_aio = saw::setup_async_io();
+ if(eo_aio.is_error()){
+ return kel::lbm::make_error<kel::lbm::err::critical>(
+ std::string{eo_aio.get_error().get_message()});
+ }
+ auto& aio = eo_aio.get_value();
+ saw::wait_scope wait{aio.event_loop};
+
+ bool krun = true;
+ bool print_status = false;
+ aio.event_port.on_signal(saw::Signal::Terminate).then([&](){
+ krun = false;
+ }).detach();
+ aio.event_port.on_signal(saw::Signal::User1).then([&](){
+ print_status = true;
+ }).detach();
- /**
- * Set the meta and initialize the lattice
- */
- kel::lbm::data<sch::FixedArray<sch::UInt64,sch::Desc::D>> meta{{2048u,128u,128u}};
+ device dev;
- SyclKelAllocator sycl_shared_alloc{sycl_q};
- std::vector<kel::lbm::data<sch::CellStruct>,SyclKelAllocator> lattice{(meta.at({0u})*meta.at({1u})*meta.at({2u})).get(), sycl_shared_alloc};
+ auto& sycl_q = dev.get_handle();
- /**
- * Set the geometry
- */
+ sycl_q.wait();
{
- auto eov = set_geometry(lattice, meta);
+ auto eov = setup_initial_conditions<T,Desc>(conv,*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_data_ptr);
if(eov.is_error()){
return eov;
}
}
- /**
- * Set initial conditions in the simulations
- */
+ kel::lbm::data<sch::ChunkStruct<T,Desc>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_data{sycl_q};
+ kel::lbm::data<sch::MacroStruct<T,Desc>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_macro_data{sycl_q};
+ kel::lbm::data<sch::FixedArray<sch::Particle<T,Desc::D>, particle_size>, encode::Sycl<kel::lbm::enc::Native>> lbm_sycl_particle_data{sycl_q};
+ sycl_q.wait();
+
+ auto lsd_view = make_view(lbm_sycl_data);
+ auto lsdm_view = make_view(lbm_sycl_macro_data);
+ {
+ auto eov = dev.copy_to_device(*lbm_data_ptr,lbm_sycl_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
{
- auto eov = set_initial_conditions(lattice, meta);
+ auto eov = dev.copy_to_device(*lbm_macro_data_ptr,lbm_sycl_macro_data);
if(eov.is_error()){
return eov;
}
}
+ {
+ auto eov = dev.copy_to_device(*lbm_particle_data_ptr,lbm_sycl_particle_data);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ sycl_q.wait();
+ kel::lbm::data<sch::UInt64> time_steps = args.template get<"args">().template get<"time_steps">();
- for(kel::lbm::data<sch::UInt64> ts{0u}; ts < kel::lbm::data<sch::UInt64>{1024u*32u}; ++ts){
- auto eov = lbm_step(lattice,meta,ts,sycl_q);
+ for(kel::lbm::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){
+ {
+ {
+ auto eov = write_vtk_file(out_dir,"t",i.get(),*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ /*{
+ std::string file_name = "p_";
+ file_name += std::to_string(i.get());
+ file_name += ".json";
+ auto eov = saw::easy::encode_and_write_file<sch::FixedArray<sch::Particle<T,Desc::D>,particle_size>,saw::encode::Json>(out_dir, *lbm_particle_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }*/
+ }
+ {
+ auto eov = step<T,Desc>(conv,lsd_view,lsdm_view,i,dev);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+ {
+ auto eov = dev.copy_to_host(lbm_sycl_data,*lbm_data_ptr);
+ if(eov.is_error()){
+ return eov;
+ }
+ }
+
+ wait.poll();
+ if(print_status){
+ std::cout<<"Status: "<<i.get()<<" of "<<time_steps.get()<<" - "<<(i.template cast_to<sch::Float64>().get() * 100 / time_steps.get())<<"%"<<std::endl;
+ print_status = false;
+ }
+ }
+ sycl_q.wait();
+ {
+ auto eov = write_vtk_file(out_dir,"t",time_steps.get(),*lbm_macro_data_ptr);
if(eov.is_error()){
return eov;
}
}
+ /*
+ iterator<Desc::D>::apply(
+ [&](auto& index){
+ std::cout<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<" "<<lbm_data.get<"info">().at(index).template cast_to<sch::UInt16>().get()<<"\n";
+ },
+ {{0u,0u}},
+ {{dim_x, dim_y}}
+ );
+ */
+
+ sycl_q.wait();
return kel::lbm::make_void();
}
-} // lbm
-} // kel
+using FloatT = kel::lbm::sch::Float32;
-/**
- * main, but I don't like the error handling
- */
int main(int argc, char** argv){
- auto eov = kel::lbm::real_main(argc, argv);
+ auto eov = lbm_main<FloatT,kel::lbm::sch::D3Q27>(argc, argv);
if(eov.is_error()){
auto& err = eov.get_error();
+ std::cerr<<"[Error] "<<err.get_category();
auto err_msg = err.get_message();
- std::cerr<<"[Error]: "<<err.get_category();
-
- if(not err_msg.empty()){
+ if(err_msg.size() > 0u){
std::cerr<<" - "<<err_msg;
}
std::cerr<<std::endl;
-
return err.get_id();
}
-
return 0;
}
diff --git a/examples/stdkr_2d_bgk/sim.cpp b/examples/stdkr_2d_bgk/sim.cpp
index b388e3c..d455c55 100644
--- a/examples/stdkr_2d_bgk/sim.cpp
+++ b/examples/stdkr_2d_bgk/sim.cpp
@@ -2,13 +2,14 @@
#include "init.hpp"
#include "step.hpp"
-#include <forstio/codec/args.hpp>
/**
* For deciding what parameters to use maybe?
*/
namespace args {
+using namespace kel::lbm::sch;
+
using LbmArgsStruct = Struct<
>;
@@ -193,7 +194,7 @@ kel::lbm::error_or<void> k_main(int argc, char** argv){
kel::lbm::data<args::LbmArgs> args;
{
- auto eov = saw::parse_args(args,argc,argv);
+ auto eov = kel::lbm::parse_args(args,argc,argv);
if(eov.is_error()){
return eov;
}
diff --git a/examples/stdkr_2d_bgk/step.hpp b/examples/stdkr_2d_bgk/step.hpp
index d7d4fd4..a127bf6 100644
--- a/examples/stdkr_2d_bgk/step.hpp
+++ b/examples/stdkr_2d_bgk/step.hpp
@@ -47,7 +47,7 @@ kel::lbm::error_or<void> step(
[&]() -> kel::lbm::data<sch::Vector<T,Desc::D>> {
kel::lbm::data<sch::Vector<T,Desc::D>> vel;
{
- auto y_si = conv.meter_lbm_to_si(index.at({{1u}}).template cast_to<T>()).handle();
+ auto y_si = conv.meter_lbm_to_si(as_unit<sch::LbmMeter<T>>(index.at({{1u}}).template cast_to<T>())).handle();
vel.at({{0u}}) = conv.velocity_si_to_lbm({static_cast<typename kel::lbm::native_data_type<T>::type>((1.2 / 0.41) * y_si.get() - (1.2 / (0.41*0.41)) * y_si.get() * y_si.get())}).handle();
vel.at({{1u}}) = 0.0f;
}
diff --git a/examples/throat_clog_2d/init.hpp b/examples/throat_clog_2d/init.hpp
index fab51b3..7683942 100644
--- a/examples/throat_clog_2d/init.hpp
+++ b/examples/throat_clog_2d/init.hpp
@@ -157,47 +157,23 @@ kel::lbm::error_or<void> init(
);
{
+ // A radius is a lattice length now.
kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radius_p;
radius_p.at({}).set(conv.meter_si_to_lbm({0.05}).handle().get());
std::cout<<"RADIUS: "<<radius_p.at({}).get()<<std::endl;
kel::lbm::data<sch::Scalar<T>> dense_p;
dense_p.at({}).set(1);
- particles = create_spheroid_particle_group<T,Desc::D,particle_amount>(radius_p, dense_p, {{64u}});
+ particles = create_spheroid_particle_group<T,Desc::D,particle_amount>(radius_p, dense_p, {64u});
auto& parts = particles.template get<"particles">();
- /**
- * Seed the particles upstream of the throat on a staggered grid.
- *
- * Spacing is 2.4 radii, so they start clear of one another -- any
- * initial overlap would be resolved as a contact on the first step and
- * fire them apart.
- */
- const auto radius = radius_p.at({}).get();
- const auto pitch = radius * 2.4;
-
- const auto x0 = conv.meter_si_to_lbm({0.10}).handle().get();
- const auto y_mid = conv.meter_si_to_lbm({0.25}).handle().get();
-
- constexpr uint64_t per_column = 4ul;
-
- for(uint64_t i = 0u; i < particle_amount; ++i){
- auto col = i / per_column;
- auto row = i % per_column;
-
- // Offset alternate columns by half a pitch so they interleave.
- auto y_off = (static_cast<double>(row) - (per_column - 1u) * 0.5) * pitch
- + ((col % 2u == 1u) ? pitch * 0.5 : 0.0);
-
- auto& p = parts.at({i});
+ {
+ auto& p = parts.at({0u});
auto& prb = p.template get<"rigid_body">();
auto& p_pos = prb.template get<"position">();
auto& p_pos_old = prb.template get<"position_old">();
+ p_pos.at({{0u}}) = conv.meter_si_to_lbm({0.1}).handle();
+ p_pos.at({{1u}}) = conv.meter_si_to_lbm({0.32}).handle();
- p_pos.at({{0u}}).set(x0 + static_cast<double>(col) * pitch);
- p_pos.at({{1u}}).set(y_mid + y_off);
-
- // Start at rest: position_old defaults to zero, which would read
- // as an enormous velocity.
p_pos_old = p_pos;
}
}
diff --git a/examples/throat_clog_2d/sim.cpp b/examples/throat_clog_2d/sim.cpp
index a25c1a3..04d0092 100644
--- a/examples/throat_clog_2d/sim.cpp
+++ b/examples/throat_clog_2d/sim.cpp
@@ -2,17 +2,31 @@
#include "init.hpp"
#include "step.hpp"
-#include <string_view>
+#include <forstio/codec/args.hpp>
/**
- * The coupling method is the only thing this example takes from the command
- * line, so it is read straight from argv rather than through a codec -- the
- * args codec is forstio's and would need a schema round trip for one string.
+ * For deciding what parameters to use maybe?
*/
+namespace args {
+using namespace kel::lbm::sch;
+
+using LbmArgsStruct = Struct<
+ Member<String, "coupling">
+ //,Member<UInt64, "refinement">
+>;
+
+using LbmArgs = Args<
+ LbmArgsStruct,
+ Tuple<>
+>;
+}
+
template<typename T, typename Desc, typename Coll, uint64_t N>
-kel::lbm::error_or<void> lbm_main(std::string_view coupling){
+kel::lbm::error_or<void> lbm_main(const kel::lbm::data<args::LbmArgs>& args){
using namespace kel::lbm;
+ auto& an = args.template get<"args">();
+
using dfi = df_info<T,Desc>;
auto eo_lbm_dir = output_directory();
@@ -21,7 +35,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
auto& lbm_dir = eo_lbm_dir.get_value();
- auto out_dir = lbm_dir / "throat_clog_2d" / coupling;
+ auto out_dir = lbm_dir / "throat_clog_2d" / an.template get<"coupling">().stl_view();
{
std::error_code ec;
@@ -49,6 +63,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
auto eo_aio = saw::setup_async_io();
if(eo_aio.is_error()){
+ // forstio io reports its own error type; translate at the boundary.
return kel::lbm::make_error<kel::lbm::err::critical>(
std::string{eo_aio.get_error().get_message()});
}
@@ -116,7 +131,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
auto lsdm_view = make_view(lbm_sycl_macro_data);
auto lsdp_view = make_view(lbm_sycl_particle_data);
- kel::lbm::data<sch::UInt64> time_steps{256u*512ul};
+ kel::lbm::data<sch::UInt64> time_steps{1024ul};
auto& info_f = lsd_view.template get<"info">();
@@ -130,7 +145,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
sycl_q.wait();
- if(i.get() % 256u == 0u){
+ if(i.get() % 1u == 0u){
{
auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
if(eov.is_error()){
@@ -138,7 +153,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
}
{
- auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},i.get(), *lbm_macro_data_ptr);
+ auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+an.template get<"coupling">().stl_string(),i.get(), *lbm_macro_data_ptr);
if(eov.is_error()){
return eov;
}
@@ -178,7 +193,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
}
{
- auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},time_steps.get(), *lbm_macro_data_ptr);
+ auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+an.template get<"coupling">().stl_string(),time_steps.get(), *lbm_macro_data_ptr);
if(eov.is_error()){
return eov;
}
@@ -198,36 +213,37 @@ using DescT = kel::lbm::sch::D2Q9;
kel::lbm::error_or<void> k_main(int argc, char** argv){
using namespace kel::lbm;
-
- // Default to fplbm so the example runs with no arguments at all.
- std::string_view coupling{"fplbm"};
- if(argc > 1){
- coupling = argv[1];
+
+ kel::lbm::data<args::LbmArgs> args;
+ {
+ auto eov = kel::lbm::parse_args(args,argc,argv);
+ if(eov.is_error()){
+ return eov;
+ }
}
+ auto& an = args.template get<"args">();
+ auto& coupling = an.template get<"coupling">();
auto resolution_resolve = [&]<typename Cpl>() -> kel::lbm::error_or<void>{
- return lbm_main<FloatT,DescT,Cpl,1u>(coupling);
+ return lbm_main<FloatT,DescT,Cpl,1u>(args);
};
- if(coupling == "hlbm"){
- return resolution_resolve.template operator()<method::Hlbm>();
- }
- if(coupling == "fplbm"){
- return resolution_resolve.template operator()<method::FpLbm>();
- }
- if(coupling == "psm"){
- return resolution_resolve.template operator()<method::Psm>();
- }
+ auto coupling_resolve = [&]() -> kel::lbm::error_or<void> {
+ if(coupling.stl_view() == "hlbm"){
+ return resolution_resolve.template operator()<method::Hlbm>();
+ } else if(coupling.stl_view() == "fplbm"){
+ return resolution_resolve.template operator()<method::FpLbm>();
+ } else if(coupling.stl_view() == "psm"){
+ return resolution_resolve.template operator()<method::Psm>();
+ }
+ };
- /**
- * Previously the dispatch lambda had no return on the unmatched path, so
- * an unknown coupling fell off the end of a non-void function.
- */
- return kel::lbm::make_error<kel::lbm::err::critical>(
- std::string{"Unknown coupling '"} + std::string{coupling}
- + "', expected one of hlbm, fplbm, psm");
+ return coupling_resolve();
+
+ return kel::lbm::make_error<kel::lbm::err::critical>("Invalid coupling");
}
+
int main(int argc, char** argv){
auto eov = k_main(argc, argv);
if(eov.is_error()){
diff --git a/examples/throat_clog_2d/step.hpp b/examples/throat_clog_2d/step.hpp
index 1605cf0..71df661 100644
--- a/examples/throat_clog_2d/step.hpp
+++ b/examples/throat_clog_2d/step.hpp
@@ -41,7 +41,7 @@ kel::lbm::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- hlbm_one_part.apply(fields,macros,particles,index,t_i,{0u});
+ hlbm_one_part.apply(fields,macros,particles,index,t_i,{1u});
});
}).wait();
@@ -75,7 +75,7 @@ kel::lbm::error_or<void> step(
kel::lbm::data<T> scale;
{
scale.set([&](){
- if(t_i.get() > 1024u){
+ if(t_i.get() >= 0u){// > 1024u
return 1.0f;
}
@@ -84,7 +84,7 @@ kel::lbm::error_or<void> step(
}
{
auto y_si = conv.meter_lbm_to_si(as_unit<sch::LbmMeter<T>>(index.at({{1u}}).template cast_to<T>())).handle();
- vel.at({{0u}}) = conv.velocity_si_to_lbm({static_cast<typename kel::lbm::native_data_type<T>::type>((0.1 / 0.64) * y_si.get() - (0.1 / (0.64*0.64)) * y_si.get() * y_si.get())}).handle() * scale;
+ vel.at({{0u}}) = conv.velocity_si_to_lbm({static_cast<typename kel::lbm::native_data_type<T>::type>((0.01 / 0.64) * y_si.get() - (0.01 / (0.64*0.64)) * y_si.get() * y_si.get())}).handle();
vel.at({{1u}}) = 0.0f;
}
return vel;
@@ -116,24 +116,9 @@ kel::lbm::error_or<void> step(
});
}).wait();
- /**
- * Particle step, split so contact lands between the fluid gather and
- * the integration. With 20 particles in a converging throat they jam
- * against one another, so without a contact pass they would simply
- * pass through each other and through the walls.
- */
q.submit([&](acpp::sycl::handler& h){
- component<T,Desc,cmpt::ParticleForceReset,encode::Sycl<kel::lbm::enc::Native>> p_reset;
- component<T,Desc,cmpt::FpLbmOneParticleGather,encode::Sycl<kel::lbm::enc::Native>> p_gather;
- component<T,Desc,cmpt::ParticleIntegrate,encode::Sycl<kel::lbm::enc::Native>> p_integrate;
-
- /**
- * Stiffness is sized so an impact at the inflow speed stays well
- * under a tenth of a radius of overlap; see dem_stiffness_for.
- */
- dem_params<T> p_dem{2.0e-2, 0.4, 0.0, 0.0};
- kel::lbm::data<sch::FixedArray<sch::UInt64,Desc::D>> p_extent{{dim_x,dim_y}};
- component<T,Desc,cmpt::ParticleContact,encode::Sycl<kel::lbm::enc::Native>> p_contact{p_dem,p_extent};
+ kel::lbm::data<sch::LbmAcceleration<sch::Vector<T,Desc::D>>> grav; // body acceleration
+ component<T,Desc,cmpt::FpLbmOneParticle,encode::Sycl<kel::lbm::enc::Native>> fplbm_one_part{grav};
h.parallel_for(acpp::sycl::range<1u>{particle_amount}, [=](acpp::sycl::id<1u> idx){
kel::lbm::data<sch::FixedArray<sch::UInt64,1u>> index;
@@ -141,10 +126,7 @@ kel::lbm::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- p_reset.apply(particles,index,t_i);
- p_gather.apply(fields,macros,particles,index,t_i,{4u});
- p_contact.apply(particles,index,t_i,{4u});
- p_integrate.apply(particles,index,t_i,{4u});
+ fplbm_one_part.apply(fields,macros,particles,index,t_i,{1u});
});
}).wait();
@@ -220,7 +202,7 @@ kel::lbm::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- fplbm_one_part.apply(fields,macros,particles,index,t_i,{0u});
+ fplbm_one_part.apply(fields,macros,particles,index,t_i,{2u});
});
}).wait();