diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-11-13 14:12:49 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-11-13 14:12:49 +0100 |
| commit | e821d617802ebbfff756844e4d9720342fc78a4e (patch) | |
| tree | 1dcf33b84698b5074218e44ea491b77a9c23ee66 /examples/poiseulle_3d | |
| parent | 0c0087ef9482634273ec1a23d3a915754f94926d (diff) | |
| download | libs-lbm-e821d617802ebbfff756844e4d9720342fc78a4e.tar.gz | |
Swarm POCdev
Diffstat (limited to 'examples/poiseulle_3d')
| -rw-r--r-- | examples/poiseulle_3d/.nix/derivation.nix | 4 | ||||
| -rw-r--r-- | examples/poiseulle_3d/SConstruct | 2 | ||||
| -rw-r--r-- | examples/poiseulle_3d/poiseulle_3d.cpp | 695 |
3 files changed, 354 insertions, 347 deletions
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; } |
