diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-16 17:23:34 +0200 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-07-16 17:23:34 +0200 |
| commit | 879188f7c55b4f8383002b6bf09ef32dd592ab90 (patch) | |
| tree | 32e8e1c4816337fa6457f30c51ddf996e888aeb0 | |
| parent | 91f75c895fb2c344805ddcb91439b93bba0293c4 (diff) | |
| parent | bd9f266756849a7381d7a4ff575d5f1ccc6e28bb (diff) | |
| download | libs-lbm-879188f7c55b4f8383002b6bf09ef32dd592ab90.tar.gz | |
Merge branch 'dev'
| -rw-r--r-- | examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp | 10 | ||||
| -rw-r--r-- | modules/core/c++/abstract/alloc.hpp | 9 | ||||
| -rw-r--r-- | modules/core/c++/abstract/data.hpp | 53 | ||||
| -rw-r--r-- | modules/core/c++/abstract/encode.hpp | 9 | ||||
| -rw-r--r-- | modules/core/c++/abstract/schema.hpp | 60 | ||||
| -rw-r--r-- | modules/core/c++/abstract/string_literal.hpp | 61 | ||||
| -rw-r--r-- | modules/core/c++/abstract/stringify_schema.hpp | 51 | ||||
| -rw-r--r-- | modules/core/c++/hlbm.hpp | 20 | ||||
| -rw-r--r-- | modules/sycl/c++/data.hpp | 4 |
9 files changed, 224 insertions, 53 deletions
diff --git a/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp b/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp index 75dd666..749c951 100644 --- a/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp +++ b/examples/moving_poiseulle_particles_2d_hlbm_gpu/sim.cpp @@ -150,6 +150,14 @@ saw::error_or<void> setup_initial_conditions( saw::data<sch::Scalar<T>> dense; dense.at({}) = 1.0f; particles = create_spheroid_particle_group<T,Desc::D,1u>(rad,dense,{16u}); + { + auto& rb = particles.template get<"particles">().at({0u}).template get<"rigid_body">(); + auto& rbp = rb.template get<"position">(); + rbp.at({0u}) = 0.25 * dim_x; + rbp.at({1u}) = 0.5 * dim_y; + auto& rbp_old = rbp; + + } return saw::make_void(); } @@ -177,8 +185,6 @@ saw::error_or<void> step( hlbm_one_part.apply(fields,macros,particles,index,t_i); - // auto aabb = particle_aabb<>::cacl(); - }); }).wait(); diff --git a/modules/core/c++/abstract/alloc.hpp b/modules/core/c++/abstract/alloc.hpp new file mode 100644 index 0000000..b15e737 --- /dev/null +++ b/modules/core/c++/abstract/alloc.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace kel { +namespace lbm { +namespace all { +struct Native {}; +} +} +} diff --git a/modules/core/c++/abstract/data.hpp b/modules/core/c++/abstract/data.hpp index ed23268..f1ae5a7 100644 --- a/modules/core/c++/abstract/data.hpp +++ b/modules/core/c++/abstract/data.hpp @@ -1,52 +1,19 @@ #pragma once -#include "templates.hpp" +#include "schema.hpp" +#include "encode.hpp" namespace kel { -namespace sch { -struct Void {}; - -struct UnsignedInteger {}; -struct SignedInteger {}; -struct FloatingPoint {}; - -template<typename StorageT, typename InterfaceT> -struct MixedPrecision { - using Meta = Void; - using StorageType = StorageT; - using InterfaceType = InterfaceT; -}; - -template<typename PrimType, uint64_t N> -struct Primitive { - using Meta = Void; - using Type = PrimType; - static constexpr uint64_t Bytes = N; -}; - -template<typename T, uint64_t... Dims> -struct FixedArray { - using Meta = Void; - using Inner = T; - static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims...}; +namespace lbm { +template<typename Schema, typename Encode = enc::Native> +class data final {}; + +template<typename T, uint64_t N> +class data<sch::Primitive<T,N>,Encode> final { +private: +public: }; -template<typename T, uint64_t Dims> -struct Array { - using Meta = FixedArray<UInt64,Dims>; - using Inner = T; - static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims}; -}; - -template<typename... T> -struct Tuple { -}; } - -template<typename Sch> -struct schema { - using Type = Sch; -}; - } diff --git a/modules/core/c++/abstract/encode.hpp b/modules/core/c++/abstract/encode.hpp new file mode 100644 index 0000000..64aef4a --- /dev/null +++ b/modules/core/c++/abstract/encode.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace kel { +namespace lbm { +namespace enc { +struct Native {}; +} +} +} diff --git a/modules/core/c++/abstract/schema.hpp b/modules/core/c++/abstract/schema.hpp new file mode 100644 index 0000000..8305005 --- /dev/null +++ b/modules/core/c++/abstract/schema.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include "string_literal.hpp" +#include "templates.hpp" + +namespace kel { +namespace sch { +struct Void {}; + +struct UnsignedInteger {}; +struct SignedInteger {}; +struct FloatingPoint {}; + +template<typename StorageT, typename InterfaceT> +struct MixedPrecision { + using Meta = Void; + using StorageType = StorageT; + using InterfaceType = InterfaceT; +}; + +template<typename PrimType, uint64_t N> +struct Primitive { + using Meta = Void; + using StorageType = PrimType; + using InterfaceType = PrimType; + static constexpr uint64_t Bytes = N; +}; + +template<typename T, uint64_t... Dims> +struct FixedArray { + using Meta = Void; + using Inner = T; + static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims...}; +}; + +template<typename T, uint64_t Dims> +struct Array { + using Meta = FixedArray<UInt64,Dims>; + using Inner = T; + static constexpr std::array<uint64_t,sizeof...(Dims)> Dimensions{Dims}; +}; + +template<typename... T> +struct Tuple { +}; + +template<typename Value, string_literal Key> +struct Member {}; + +template<typename... SL> +struct Struct {}; + +} + +template<typename Sch> +struct schema { + using Type = Sch; +}; + +} diff --git a/modules/core/c++/abstract/string_literal.hpp b/modules/core/c++/abstract/string_literal.hpp new file mode 100644 index 0000000..51e58c8 --- /dev/null +++ b/modules/core/c++/abstract/string_literal.hpp @@ -0,0 +1,61 @@ +#pragma once + +#include <array> +#include <string_view> + +namespace kel { +namespace lbm { +/** + * Helper object which creates a templated string from the provided string + * literal. It guarantees compile time uniqueness and thus allows using strings + * in template parameters. + */ +template <class CharT, size_t N> class string_literal { +public: + static_assert(N > 0, "string_literal needs a null terminator"); + + constexpr string_literal(const CharT (&input)[N]) noexcept { + for (size_t i = 0; i < N; ++i) { + data[i] = input[i]; + } + } + + std::array<CharT, N> data{}; + + constexpr std::string_view view() const noexcept { + return std::string_view{data.data()}; + } + + constexpr bool + operator==(const string_literal<CharT, N> &) const noexcept = default; + + template <class CharTR, size_t NR> + constexpr bool + operator==(const string_literal<CharTR, NR> &) const noexcept { + return false; + } + + template<size_t NR> + constexpr string_literal<CharT, N+NR-1> operator+(const string_literal<CharT, NR>& rhs) const noexcept { + CharT sum[N+NR-1]; + + // The weird i+1 happens due to needing to skip the '\0' terminator + for(size_t i = 0; (i+1) < N; ++i){ + sum[i] = data[i]; + } + for(size_t i = 0; i < NR; ++i){ + sum[i+N-1] = rhs.data[i]; + } + + return string_literal<CharT, N+NR-1>{sum}; + } + + +}; + +template <typename T, T... Chars> +constexpr string_literal<T, sizeof...(Chars) + 1u> operator""_sl() { + return string_literal<T, sizeof...(Chars) + 1u>{{Chars..., '\0'}}; +} +} +} diff --git a/modules/core/c++/abstract/stringify_schema.hpp b/modules/core/c++/abstract/stringify_schema.hpp new file mode 100644 index 0000000..866bc7e --- /dev/null +++ b/modules/core/c++/abstract/stringify_schema.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "schema.hpp" + +namespace kel { +namespace lbm { +namespace impl { +template<class T> +struct schema_to_string_helper { + static_assert(always_false<T>, "schema_to_string_helper specialization not handled."); + + static constexpr string_literal apply(){ + return {}; + } +}; + +template<> +struct schema_to_string_helper<sch::SignedInteger> final { + static constexpr string_literal apply(){ + return "SignedInteger"; + } +}; + +template<> +struct schema_to_string_helper<sch::UnsignedInteger> final { + static constexpr string_literal apply(){ + return "UnsignedInteger"; + } +}; + +template<> +struct schema_to_string_helper<sch::FloatingPoint> final { + static constexpr string_literal apply(){ + return "FloatingPoint"; + } +}; + +template<typename T, uint64_t N> +struct schema_to_string_helper<sch::Primitive<T,N>> final { + static constexpr string_literal apply(){ + return "Primitive<"+schema_to_string_helper<T>::apply()+","+N+">"; + } +}; +} + +template<class T> +struct schema_to_string{ + static constexpr std::string_view value = impl::schema_to_string_helper<T>::apply().view(); +}; +} +} diff --git a/modules/core/c++/hlbm.hpp b/modules/core/c++/hlbm.hpp index eccc2cd..1c625bb 100644 --- a/modules/core/c++/hlbm.hpp +++ b/modules/core/c++/hlbm.hpp @@ -103,16 +103,13 @@ public: template<typename T, typename Desc, typename Encode> class component<T, Desc, cmpt::HlbmParticle, Encode> final { private: +/* template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema, uint64_t i> void apply_i(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 { // if constexpr ( i < ) - } + } +*/ public: - /* - template<typename CellFieldSchema, typename MacroFieldSchema, typename ParticleSchema, uint64_t i> - void apply_i() - */ - 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_group, saw::data<sch::FixedArray<sch::UInt64,1u>> index, saw::data<sch::UInt64> time_step) const { /// Figure out how to access the particle list @@ -125,7 +122,7 @@ public: auto& mvel = macros.template get<"velocity">(); { auto& parts = part_spheroid_group.template get<"particles">(); - auto parts_size = parts.dims().at({0u}); + auto parts_size = parts.meta().at({0u}); auto& pi = parts.at(index); auto& pirb = pi.template get<"rigid_body">(); @@ -134,7 +131,14 @@ 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()); + auto eo_aabb = particle_aabb<typename ParticleSchema::ValueType>::calculate(part_spheroid_group,index,mvel.meta()); + if(eo_aabb.is_error()){ + std::cerr<<"Prepping error"<<std::endl; + std::cerr<<eo_aabb.get_error().get_category()<<std::endl; + return; + } + auto& aabb = eo_aabb.get_value(); + /// Ok, I iterate over the space which covers our particle? So lower bounds to upper bounds start = aabb.template get<"a">(); stop = aabb.template get<"b">(); diff --git a/modules/sycl/c++/data.hpp b/modules/sycl/c++/data.hpp index 9f43848..ec0fccf 100644 --- a/modules/sycl/c++/data.hpp +++ b/modules/sycl/c++/data.hpp @@ -103,6 +103,10 @@ public: return saw::data<schema::FixedArray<schema::UInt64, sizeof...(Dims)>>{{Dims...}}; } + static constexpr data<schema::FixedArray<schema::UInt64, sizeof...(Dims)>> meta() { + return saw::data<schema::FixedArray<schema::UInt64, sizeof...(Dims)>>{{Dims...}}; + } + constexpr data<Sch,Encode>& at(const data<schema::FixedArray<schema::UInt64,sizeof...(Dims)>>& index){ return values_[kel::lbm::flatten_index<schema::UInt64,sizeof...(Dims)>::apply(index,get_dims()).get()]; } |
