diff options
| -rw-r--r-- | examples/poiseulle_particles_2d_gpu/common.hpp | 2 | ||||
| -rw-r--r-- | examples/poiseulle_particles_2d_gpu/init.hpp | 7 | ||||
| -rw-r--r-- | examples/poiseulle_particles_2d_gpu/sim.cpp | 35 | ||||
| -rw-r--r-- | examples/poiseulle_particles_2d_gpu/step.hpp | 7 | ||||
| -rw-r--r-- | lib/core/c++/hlbm.hpp | 11 | ||||
| -rw-r--r-- | lib/core/c++/particle/aabb.hpp | 30 | ||||
| -rw-r--r-- | lib/core/c++/particle/common.hpp | 3 | ||||
| -rw-r--r-- | lib/core/c++/particle/particle.hpp | 68 | ||||
| -rw-r--r-- | lib/core/c++/particle/schema.hpp | 67 | ||||
| -rw-r--r-- | lib/core/c++/schema.hpp | 10 |
10 files changed, 145 insertions, 95 deletions
diff --git a/examples/poiseulle_particles_2d_gpu/common.hpp b/examples/poiseulle_particles_2d_gpu/common.hpp index a69a2cf..6c05b64 100644 --- a/examples/poiseulle_particles_2d_gpu/common.hpp +++ b/examples/poiseulle_particles_2d_gpu/common.hpp @@ -55,7 +55,7 @@ using MacroStruct = Struct< >; template<typename T, typename Desc> -using ParticleSpheroidGroup = ParticleGroup<T,Desc::D,ParticleCollisionSpheroid<T,2.0f>>; +using ParticleSpheroidGroup = ParticleGroup<T,Desc::D,coll::Spheroid<T>>; } } diff --git a/examples/poiseulle_particles_2d_gpu/init.hpp b/examples/poiseulle_particles_2d_gpu/init.hpp index 70d59fc..617b296 100644 --- a/examples/poiseulle_particles_2d_gpu/init.hpp +++ b/examples/poiseulle_particles_2d_gpu/init.hpp @@ -7,10 +7,13 @@ namespace lbm { template<typename T, typename Desc> saw::error_or<void> setup_initial_conditions( + const converter<T>& conv, saw::data<sch::ChunkStruct<T,Desc>>& fields, saw::data<sch::MacroStruct<T,Desc>>& macros, saw::data<sch::ParticleSpheroidGroup<T,Desc>>& particles ){ + (void) conv; + auto& info_f = fields.template get<"info">(); auto& porous_f = macros.template get<"porosity">(); // Set everything as walls @@ -110,9 +113,11 @@ saw::error_or<void> setup_initial_conditions( ); { + saw::data<sch::Scalar<T>> radius_p; + radius_p.at({}).set(2); saw::data<sch::Scalar<T>> dense_p; dense_p.at({}).set(1); - particles = create_spheroid_particle_group<T,Desc::D,2.0f>(dense_p, {{16u}}); + particles = create_spheroid_particle_group<T,Desc::D>(radius_p, dense_p, {{16u}}); } return saw::make_void(); diff --git a/examples/poiseulle_particles_2d_gpu/sim.cpp b/examples/poiseulle_particles_2d_gpu/sim.cpp index 42710f1..47c5daa 100644 --- a/examples/poiseulle_particles_2d_gpu/sim.cpp +++ b/examples/poiseulle_particles_2d_gpu/sim.cpp @@ -7,11 +7,16 @@ /** * For deciding what parameters to use maybe? */ -namespace sch { +namespace args { using namespace saw::schema; +using LbmArgsStruct = Struct< + Member<UInt8,"use_slip">, + Member<String, "coupling"> +>; + using LbmArgs = Args< - Struct<>, + LbmArgsStruct, Tuple<> >; } @@ -22,6 +27,13 @@ saw::error_or<void> lbm_main(int argc, char** argv){ using dfi = df_info<T,Desc>; + auto eo_args = saw::parse_args<args::LbmArgs>(argc,argv); + if(eo_args.is_error()){ + return std::move(eo_args.get_error()); + } + auto& args = eo_args.get_value(); + (void)args; + auto eo_lbm_dir = output_directory(); if(eo_lbm_dir.is_error()){ return std::move(eo_lbm_dir.get_error()); @@ -51,7 +63,7 @@ saw::error_or<void> lbm_main(int argc, char** argv){ auto lbm_data_ptr = saw::heap<saw::data<sch::ChunkStruct<T,Desc>>>(); auto lbm_macro_data_ptr = saw::heap<saw::data<sch::MacroStruct<T,Desc>>>(); auto lbm_particle_data_ptr = saw::heap<saw::data<sch::ParticleSpheroidGroup<T,Desc>>>(); - + std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc>,sch::MacroStruct<T,Desc>>().get()<<std::endl; auto eo_aio = saw::setup_async_io(); @@ -76,7 +88,7 @@ saw::error_or<void> lbm_main(int argc, char** argv){ sycl_q.wait(); { - auto eov = setup_initial_conditions<T,Desc>(*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_data_ptr); + 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; } @@ -106,21 +118,24 @@ saw::error_or<void> lbm_main(int argc, char** argv){ } } sycl_q.wait(); + auto lsd_view = make_view(lbm_sycl_data); auto lsdm_view = make_view(lbm_sycl_macro_data); auto lsdp_view = make_view(lbm_sycl_particle_data); saw::data<sch::UInt64> time_steps{16u*4096ul}; + auto& info_f = lsd_view.template get<"info">(); for(saw::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){ // BC + Collision { - auto eov = step<T,Desc>(lsd_view,lsdm_view,lsdp_view,i,dev); + auto eov = step<T,Desc>(conv,lsd_view,lsdm_view,lsdp_view,i,dev); if(eov.is_error()){ return eov; } } + sycl_q.wait(); if(i.get() % 32u == 0u){ { @@ -145,22 +160,22 @@ saw::error_or<void> lbm_main(int argc, char** argv){ 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){ + + auto info = info_f.at(index).get(); + + if(info > 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(); { diff --git a/examples/poiseulle_particles_2d_gpu/step.hpp b/examples/poiseulle_particles_2d_gpu/step.hpp index a4e44b4..52e8c59 100644 --- a/examples/poiseulle_particles_2d_gpu/step.hpp +++ b/examples/poiseulle_particles_2d_gpu/step.hpp @@ -7,6 +7,7 @@ namespace lbm { template<typename T, typename Desc> saw::error_or<void> step( + const converter<T>& conv, saw::data<sch::Ptr<sch::ChunkStruct<T,Desc>>,encode::Sycl<saw::encode::Native>>& fields, saw::data<sch::Ptr<sch::MacroStruct<T,Desc>>,encode::Sycl<saw::encode::Native>>& macros, saw::data<sch::Ptr<sch::ParticleSpheroidGroup<T,Desc>>,encode::Sycl<saw::encode::Native>>& particles, @@ -19,7 +20,8 @@ saw::error_or<void> step( // auto coll_ev = q.submit([&](acpp::sycl::handler& h){ - component<T,Desc,cmpt::Hlbm,encode::Sycl<saw::encode::Native>> collision{0.65}; + component<T,Desc,cmpt::Hlbm,encode::Sycl<saw::encode::Native>> collision{0.8}; + component<T,Desc,cmpt::HlbmParticle,encode::Sycl<saw::encode::Native>> particle; component<T,Desc,cmpt::BounceBack,encode::Sycl<saw::encode::Native>> bb; component<T,Desc,cmpt::AntiBounceBack<0u>,encode::Sycl<saw::encode::Native>> abb; @@ -32,7 +34,7 @@ saw::error_or<void> step( component<T,Desc,cmpt::ZouHeHorizontal<true>,encode::Sycl<saw::encode::Native>> flow_in{ [&](){ - uint64_t target_t_i = 64u; + uint64_t target_t_i = 16u; if(t_i.get() < target_t_i){ return 1.0 + (0.0002 / target_t_i) * t_i.get(); } @@ -41,7 +43,6 @@ saw::error_or<void> step( }; component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<saw::encode::Native>> flow_out{1.0}; - h.parallel_for(acpp::sycl::range<Desc::D>{dim_x,dim_y}, [=](acpp::sycl::id<Desc::D> idx){ saw::data<sch::FixedArray<sch::UInt64,Desc::D>> index; for(uint64_t i = 0u; i < Desc::D; ++i){ diff --git a/lib/core/c++/hlbm.hpp b/lib/core/c++/hlbm.hpp index 6ae7d80..85e5357 100644 --- a/lib/core/c++/hlbm.hpp +++ b/lib/core/c++/hlbm.hpp @@ -4,6 +4,8 @@ #include "component.hpp" #include "equilibrium.hpp" +#include "particle/particle.hpp" + namespace kel { namespace lbm { namespace cmpt { @@ -114,14 +116,15 @@ public: */ template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema> - void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_groups, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const { + void apply(const saw::data<CellFieldSchema, Encode>& field, const saw::data<MacroFieldSchema,Encode>& macros, const saw::data<ParticleSchema,Encode>& part_group, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const { /// Figure out how to access the particle list // auto& p = particles.at(i); /// Iterate over the grid bounds // auto& grid = p.template get<"grid">(); - auto& part_spheroid_group = part_groups.template get<0>(); + auto& part_spheroid_group = part_group; + auto& mvel = macros.template get<"velocity">(); { auto& parts = part_spheroid_group.template get<"particles">(); auto parts_size = parts.size(); @@ -133,10 +136,8 @@ public: saw::data<sch::FixedArray<sch::UInt64,Desc::D>> start; saw::data<sch::FixedArray<sch::UInt64,Desc::D>> stop; + auto aabb = particle_aabb<ParticleSchema>::calculate(part_spheroid_group,index,mvel.meta()); /// Ok, I iterate over the space which covers our particle? So lower bounds to upper bounds - for(uint64_t i{0u}; i < Desc::D; ++i){ - - } iterator<Desc::D>::apply([&](const auto& index){ // ask for the d_k value here. diff --git a/lib/core/c++/particle/aabb.hpp b/lib/core/c++/particle/aabb.hpp index aec95ca..8579695 100644 --- a/lib/core/c++/particle/aabb.hpp +++ b/lib/core/c++/particle/aabb.hpp @@ -1,36 +1,39 @@ #pragma once -#include "particle.hpp" +#include "common.hpp" +#include "schema.hpp" namespace kel { namespace lbm { -template<typename T, uint64_t D, typename PColl> +template<typename PGroup> class particle_aabb final { }; -template<typename T, uint64_t D, typename saw::native_data_type<T>::type radius> -class particle_aabb<ParticleGroup<T,D,sch::ParticleCollisionSpheroid<T,radius> > > final { +template<typename T, uint64_t D> +class particle_aabb< + sch::ParticleGroup<T,D,coll::Spheroid<T>> +> final { public: - using Schema = sch::ParticleGroup<T,D,sch::ParticleCollisionSpheroid<T,radius>>; + using Schema = sch::ParticleGroup<T,D,coll::Spheroid<T>>; - using AABB = Struct< - Member<sch::FixedArray<sch::UInt64,D>"a">, - Member<sch::FixedArray<sch::UInt64,D>"b"> + using AABB = sch::Struct< + sch::Member<sch::FixedArray<sch::UInt64,D>,"a">, + sch::Member<sch::FixedArray<sch::UInt64,D>,"b"> >; public: - static constexpr saw::data<AABB> get(const saw::data<Schema>& p_grp, const saw::data<sch::FixedArray<sch::UInt64,1u>>& i, const saw::data<sch::FixedArray<sch::UInt64,D>>& meta){ + static constexpr saw::data<AABB> calculate(const saw::data<Schema>& p_grp, const saw::data<sch::FixedArray<sch::UInt64,1u>>& i, const saw::data<sch::FixedArray<sch::UInt64,D>>& meta){ + + saw::data<AABB> aabb; auto& parts = p_grp.template get<"particles">(); auto& pi = parts.at(i); auto& pirb = pi.template get<"rigid_body">(); auto& pirb_pos = pirb.template get<"position">(); - saw::data<AABB> aabb; auto& a = aabb.template get<"a">(); auto& b = aabb.template get<"b">(); - saw::data<sch::Scalar<T>> rad_d; - rad_d.at({}).set(radius); + const saw::data<sch::Scalar<T>>& rad_d = p_grp.template get<"collision">().template get<"radius">().at({0u}); saw::data<sch::Vector<T,D>> lower; saw::data<sch::Vector<T,D>> upper; @@ -39,10 +42,11 @@ public: lower.at({{i}}) = pirb_pos.at({{i}}) >= rad_d.at({}) ? (pirb_pos.at({{i}}) - rad_d.at({})) : saw::data<T>{0}; a.at({i}) = lower.at({{i}}).template cast_to<sch::UInt64>(); upper.at({{i}}) = pirb_pos.at({{i}}) + rad_d.at({}); - b.at({i}) = (upper.at({{i}})+saw::data<T>{1}).template cast_to<sch::UInt64>() + b.at({i}) = (upper.at({{i}})+saw::data<T>{1}).template cast_to<sch::UInt64>(); } return aabb; + } }; } diff --git a/lib/core/c++/particle/common.hpp b/lib/core/c++/particle/common.hpp new file mode 100644 index 0000000..9e673c2 --- /dev/null +++ b/lib/core/c++/particle/common.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include "../common.hpp" diff --git a/lib/core/c++/particle/particle.hpp b/lib/core/c++/particle/particle.hpp index 1a99dcd..13ed37b 100644 --- a/lib/core/c++/particle/particle.hpp +++ b/lib/core/c++/particle/particle.hpp @@ -6,68 +6,22 @@ #include "../iterator.hpp" +#include "schema.hpp" +#include "aabb.hpp" + namespace kel { namespace lbm { -namespace coll { -struct Spheroid{}; -} -namespace sch { -using namespace saw::schema; - -namespace impl { -template<typename T,uint64_t D> -struct rotation_type_helper; - -template<typename T> -struct rotation_type_helper<T,2u> { - using Schema = Scalar<T>; -}; - -template<typename T> -struct rotation_type_helper<T,3u> { - using Schema = Vector<T,3u>; -}; -} - -template<typename T, uint64_t D> -using ParticleRigidBody = Struct< - Member<Vector<T,D>, "position">, - Member<Vector<T,D>, "position_old">, - Member<typename impl::rotation_type_helper<T,D>::Schema, "rotation">, - Member<typename impl::rotation_type_helper<T,D>::Schema, "rotation_old">, - - Member<Vector<T,D>, "acceleration">, - Member<typename impl::rotation_type_helper<T,D>::Schema, "angular_acceleration"> ->; - -template<typename T, typename saw::native_data_type<T>::type radius = 1.0f> -using ParticleCollisionSpheroid = Struct< ->; template<typename T, uint64_t D> -using Particle = Struct< - Member<ParticleRigidBody<T,D>, "rigid_body"> - // Problem is that dynamic data would two layered - // Member<Array<Float64,D>, "mask">, ->; - -template<typename T, uint64_t D, typename CollisionType = ParticleCollisionSpheroid<T>> -using ParticleGroup = Struct< - Member<Array<T,D>, "mask">, - Member<FixedArray<Scalar<T>,1u>, "mask_step">, - Member<FixedArray<Scalar<T>,1u>, "density">, - Member<FixedArray<Vector<T,D>,1u>, "center_of_mass">, - Member<FixedArray<Scalar<T>,1u>, "total_mass">, - Member<Array<Particle<T,D>,1u>, "particles"> ->; -} - -template<typename T, uint64_t D, typename saw::native_data_type<T>::type radius> -saw::data<sch::ParticleGroup<T,D, sch::ParticleCollisionSpheroid<T,radius>>> create_spheroid_particle_group( +saw::data<sch::ParticleGroup<T,D, coll::Spheroid<T>>> create_spheroid_particle_group( + saw::data<sch::Scalar<T>> radius_p, saw::data<sch::Scalar<T>> density_p, const saw::data<sch::UInt64>& mask_resolution ){ - saw::data<sch::ParticleGroup<T,D,sch::ParticleCollisionSpheroid<T,radius>>> part; + saw::data<sch::ParticleGroup<T,D,coll::Spheroid<T>>> part; + + auto& rad_s = part.template get<"collision">().at({0u}).template get<"radius">(); + rad_s = radius_p; auto& mask = part.template get<"mask">(); auto& density = part.template get<"density">().at({{0u}}); @@ -83,7 +37,7 @@ saw::data<sch::ParticleGroup<T,D, sch::ParticleCollisionSpheroid<T,radius>>> cre for(uint64_t i = 0u; i < D; ++i){ mask_dims.at({i}) = mask_resolution; } - saw::data<T> rad_d{radius}; + saw::data<T> rad_d = radius_p.at({}); saw::data<T> dia_d = rad_d * 2; mask = {mask_dims}; @@ -104,7 +58,7 @@ saw::data<sch::ParticleGroup<T,D, sch::ParticleCollisionSpheroid<T,radius>>> cre saw::data<sch::Vector<T,D>> center; for(uint64_t i = 0u; i < D; ++i){ - center.at({{i}}).set(radius); + center.at({{i}}) = rad_d; } iterator<D>::apply([&](const auto& index){ diff --git a/lib/core/c++/particle/schema.hpp b/lib/core/c++/particle/schema.hpp new file mode 100644 index 0000000..18a697a --- /dev/null +++ b/lib/core/c++/particle/schema.hpp @@ -0,0 +1,67 @@ +#pragma once + +#include "common.hpp" + +namespace kel { +namespace lbm { + +namespace coll { +template<typename T> +struct Spheroid { + using ValueSchema = T; + using Schema = sch::Struct< + sch::Member<sch::Scalar<ValueSchema>,"radius"> + >; +}; +} + +namespace sch { +using namespace saw::schema; + +namespace impl { +template<typename T,uint64_t D> +struct rotation_type_helper; + +template<typename T> +struct rotation_type_helper<T,2u> { + using Schema = Scalar<T>; +}; + +template<typename T> +struct rotation_type_helper<T,3u> { + using Schema = Vector<T,3u>; +}; +} + +template<typename T, uint64_t D> +using ParticleRigidBody = Struct< + Member<Vector<T,D>, "position">, + Member<Vector<T,D>, "position_old">, + Member<typename impl::rotation_type_helper<T,D>::Schema, "rotation">, + Member<typename impl::rotation_type_helper<T,D>::Schema, "rotation_old">, + + Member<Vector<T,D>, "acceleration">, + Member<typename impl::rotation_type_helper<T,D>::Schema, "angular_acceleration"> +>; + + +template<typename T, uint64_t D> +using Particle = Struct< + Member<ParticleRigidBody<T,D>, "rigid_body"> + // Problem is that dynamic data would two layered + // Member<Array<Float64,D>, "mask">, +>; + +template<typename T, uint64_t D, typename CollisionType = coll::Spheroid<T>> +using ParticleGroup = Struct< + Member<Array<T,D>, "mask">, + Member<FixedArray<typename CollisionType::Schema,1u>, "collision">, + Member<FixedArray<Scalar<T>,1u>, "mask_step">, + Member<FixedArray<Scalar<T>,1u>, "density">, + Member<FixedArray<Vector<T,D>,1u>, "center_of_mass">, + Member<FixedArray<Scalar<T>,1u>, "total_mass">, + Member<Array<Particle<T,D>,1u>, "particles"> +>; +} +} +} diff --git a/lib/core/c++/schema.hpp b/lib/core/c++/schema.hpp index 0c92ae6..7712f99 100644 --- a/lib/core/c++/schema.hpp +++ b/lib/core/c++/schema.hpp @@ -3,9 +3,9 @@ #include <forstio/codec/schema.hpp> namespace kel { - namespace lbm { - namespace sch { - using namespace saw::schema; - } - } +namespace lbm { +namespace sch { +using namespace saw::schema; +} +} } |
