summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcsv_sum_of_one_minus_a.py18
-rwxr-xr-xcsv_test.py56
-rw-r--r--examples/one_particle_sedimentation_2d/common.hpp2
-rw-r--r--examples/one_particle_sedimentation_2d/init.hpp2
-rw-r--r--examples/one_particle_sedimentation_2d/sim.cpp5
-rw-r--r--examples/one_particle_sedimentation_2d/step.hpp2
-rw-r--r--examples/schaefer_turek_durst_krause_rannbacher/common.hpp46
-rw-r--r--examples/schaefer_turek_durst_krause_rannbacher/init.hpp6
-rw-r--r--examples/schaefer_turek_durst_krause_rannbacher/sim.cpp32
-rw-r--r--examples/schaefer_turek_durst_krause_rannbacher/step.hpp16
-rw-r--r--modules/core/c++/fplbm.hpp143
-rw-r--r--modules/core/c++/hlbm.hpp15
-rw-r--r--modules/core/c++/psm.hpp57
13 files changed, 276 insertions, 124 deletions
diff --git a/csv_sum_of_one_minus_a.py b/csv_sum_of_one_minus_a.py
new file mode 100755
index 0000000..ba6cdf4
--- /dev/null
+++ b/csv_sum_of_one_minus_a.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python3
+
+import argparse
+import numpy as np
+
+
+def main():
+ parser = argparse.ArgumentParser(description="Compute the sum of 1-a")
+ parser.add_argument("one")
+ args = parser.parse_args()
+
+ a = np.loadtxt(args.one, delimiter=",")
+
+ print(np.sum(1 - a, axis=0))
+
+
+if __name__ == "__main__":
+ main()
diff --git a/csv_test.py b/csv_test.py
new file mode 100755
index 0000000..e6077fd
--- /dev/null
+++ b/csv_test.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+import argparse
+import numpy as np
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description="Calculate drag coefficient from LBM CSV data."
+ )
+
+ parser.add_argument("force_csv")
+ parser.add_argument("momentum_csv")
+ parser.add_argument("density_csv")
+
+ parser.add_argument("--U", type=float, default=0.003)
+ parser.add_argument("--D", type=float, default=10.0)
+ parser.add_argument("--rho", type=float, default=1.0)
+
+ args = parser.parse_args()
+
+ # Load CSVs
+ force = np.loadtxt(args.force_csv, delimiter=",")
+ momentum = np.loadtxt(args.momentum_csv, delimiter=",")
+ density = np.loadtxt(args.density_csv, delimiter=",")
+
+ # If each file is just a scalar field:
+ Fx = force
+ px = momentum
+ rho = density
+
+ # Total force
+ F_drag = abs(np.sum(Fx))
+
+ # 2D cylinder, unit depth
+ A_ref = args.D
+
+ # Dynamic pressure
+ q = 0.5 * args.rho * args.U**2
+
+ # Drag coefficient
+ Cd = F_drag / (q * A_ref)
+
+ print(f"Total Fx = {np.sum(Fx):.8e}")
+ print(f"Drag force = {F_drag:.8e}")
+ print(f"Reference area = {A_ref:.8e}")
+ print(f"Cd = {Cd:.8f}")
+
+ print("\nDiagnostics:")
+ print(f"rho: min={rho.min():.6e}, max={rho.max():.6e}, mean={rho.mean():.6e}")
+ print(f"px: min={px.min():.6e}, max={px.max():.6e}, mean={px.mean():.6e}")
+ print(f"Fx: min={Fx.min():.6e}, max={Fx.max():.6e}, mean={Fx.mean():.6e}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/examples/one_particle_sedimentation_2d/common.hpp b/examples/one_particle_sedimentation_2d/common.hpp
index 18d6584..ffb7f40 100644
--- a/examples/one_particle_sedimentation_2d/common.hpp
+++ b/examples/one_particle_sedimentation_2d/common.hpp
@@ -23,8 +23,8 @@ namespace lbm {
* fluid density 0.001g/mm³
*/
-constexpr uint64_t dim_y = 800ul;
constexpr uint64_t dim_x = 200ul;
+constexpr uint64_t dim_y = 800ul;
constexpr uint64_t particle_amount = 1ul;
diff --git a/examples/one_particle_sedimentation_2d/init.hpp b/examples/one_particle_sedimentation_2d/init.hpp
index d9b8a37..8bcc236 100644
--- a/examples/one_particle_sedimentation_2d/init.hpp
+++ b/examples/one_particle_sedimentation_2d/init.hpp
@@ -75,7 +75,7 @@ saw::error_or<void> init(
{
saw::data<sch::Scalar<T>> radius_p;
- radius_p.at({}).set(conv.meter_si_to_lbm({{0.05}}).handle().get());
+ radius_p.at({}).set(conv.meter_si_to_lbm({{0.00125}}).handle().get());
std::cout<<"RADIUS: "<<radius_p.at({}).get()<<std::endl;
saw::data<sch::Scalar<T>> dense_p;
dense_p.at({}).set(1);
diff --git a/examples/one_particle_sedimentation_2d/sim.cpp b/examples/one_particle_sedimentation_2d/sim.cpp
index a722fc3..0cb3ce0 100644
--- a/examples/one_particle_sedimentation_2d/sim.cpp
+++ b/examples/one_particle_sedimentation_2d/sim.cpp
@@ -51,7 +51,8 @@ saw::error_or<void> lbm_main(const saw::data<args::LbmArgs>& args){
{{1.5e-6}}
};
- print_lbm_meta<T,Desc>(conv,{1e-3},{1e-4},{0.02});
+ print_lbm_meta<T,Desc>(conv,{1e-3},{1e-4},{2});
+ std::cout<<"Position: "<<conv.meter_si_to_lbm({{0.01}}).handle().get()<<", "<<conv.meter_si_to_lbm({{0.04}}).handle().get()<<std::endl;
// saw::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
auto lbm_data_ptr = saw::heap<saw::data<sch::ChunkStruct<T,Desc>>>();
@@ -144,7 +145,7 @@ saw::error_or<void> lbm_main(const saw::data<args::LbmArgs>& args){
}
}
{
- auto eov = write_csv_file(out_dir,"ops_2d",i.get(), *lbm_macro_data_ptr);
+ auto eov = write_vtk_file(out_dir,"ops_2d",i.get(), *lbm_macro_data_ptr);
if(eov.is_error()){
return eov;
}
diff --git a/examples/one_particle_sedimentation_2d/step.hpp b/examples/one_particle_sedimentation_2d/step.hpp
index 86064ae..c3a3b8a 100644
--- a/examples/one_particle_sedimentation_2d/step.hpp
+++ b/examples/one_particle_sedimentation_2d/step.hpp
@@ -175,7 +175,7 @@ saw::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- fplbm_one_part.apply(fields,macros,particles,index,t_i,{16u});
+ fplbm_one_part.apply(fields,macros,particles,index,t_i,{32u});
});
}).wait();
diff --git a/examples/schaefer_turek_durst_krause_rannbacher/common.hpp b/examples/schaefer_turek_durst_krause_rannbacher/common.hpp
index a85cd50..59d2f9c 100644
--- a/examples/schaefer_turek_durst_krause_rannbacher/common.hpp
+++ b/examples/schaefer_turek_durst_krause_rannbacher/common.hpp
@@ -19,6 +19,7 @@ namespace lbm {
* viscosity 10^-3
* particle diameter 0.1m
* position at (0.16m,0.2m)
+ * velocity of 0.3 m/s from 1.2/0.41 * x - 1.2/0.41² * x² at x=0.41/2
*/
constexpr uint64_t dim_y = 41u;
@@ -29,38 +30,39 @@ constexpr uint64_t particle_amount = 1ul;
namespace sch {
using namespace saw::schema;
-using InfoChunk = Chunk<UInt8, 0u, dim_x, dim_y>;
+template<uint64_t N>
+using InfoChunk = Chunk<UInt8, 0u, dim_x*N, dim_y*N>;
-template<typename T, typename Desc>
-using DfChunk = Chunk<FixedArray<T,Desc::Q>, 1u, dim_x, dim_y>;
+template<typename T, typename Desc, uint64_t N>
+using DfChunk = Chunk<FixedArray<T,Desc::Q>, 1u, dim_x*N, dim_y*N>;
-template<typename T, typename Desc>
-using ScalarChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
+template<typename T, typename Desc, uint64_t N>
+using ScalarChunk = Chunk<Scalar<T>, 0u, dim_x*N, dim_y*N>;
-template<typename T, typename Desc>
-using VectorChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
+template<typename T, typename Desc, uint64_t N>
+using VectorChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x*N, dim_y*N>;
-template<typename T, typename Desc>
+template<typename T, typename Desc, uint64_t N = 1u>
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">
+ Member<InfoChunk<N>, "info">,
+ Member<DfChunk<T,Desc,N>, "dfs">,
+ Member<DfChunk<T,Desc,N>, "dfs_old">,
+ Member<VectorChunk<T,Desc,N>, "particle_N">,
+ Member<ScalarChunk<T,Desc,N>, "particle_D">
>;
-template<typename T, typename Desc>
-using VelChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x, dim_y>;
+template<typename T, typename Desc, uint64_t N>
+using VelChunk = Chunk<Vector<T,Desc::D>, 0u, dim_x*N, dim_y*N>;
-template<typename T>
-using RhoChunk = Chunk<Scalar<T>, 0u, dim_x, dim_y>;
+template<typename T, uint64_t N>
+using RhoChunk = Chunk<Scalar<T>, 0u, dim_x*N, dim_y*N>;
-template<typename T, typename Desc>
+template<typename T, typename Desc, uint64_t N = 1u>
using MacroStruct = Struct<
- Member<VelChunk<T,Desc>, "momentum">,
- Member<RhoChunk<T>, "density">,
- Member<ScalarChunk<T,Desc>, "porosity">,
- Member<VelChunk<T,Desc>, "force">
+ Member<VelChunk<T,Desc,N>, "momentum">,
+ Member<RhoChunk<T,N>, "density">,
+ Member<ScalarChunk<T,Desc,N>, "porosity">,
+ Member<VelChunk<T,Desc,N>, "force">
>;
template<typename T, typename Desc>
diff --git a/examples/schaefer_turek_durst_krause_rannbacher/init.hpp b/examples/schaefer_turek_durst_krause_rannbacher/init.hpp
index af7eb89..96e2917 100644
--- a/examples/schaefer_turek_durst_krause_rannbacher/init.hpp
+++ b/examples/schaefer_turek_durst_krause_rannbacher/init.hpp
@@ -5,11 +5,11 @@
namespace kel {
namespace lbm {
-template<typename T, typename Desc, typename Coll>
+template<typename T, typename Desc, typename Coll, uint64_t N>
saw::error_or<void> init(
const converter<T>& conv,
- saw::data<sch::ChunkStruct<T,Desc>>& fields,
- saw::data<sch::MacroStruct<T,Desc>>& macros,
+ saw::data<sch::ChunkStruct<T,Desc,N>>& fields,
+ saw::data<sch::MacroStruct<T,Desc,N>>& macros,
saw::data<sch::ParticleSpheroidGroup<T,Desc>>& particles
){
(void) conv;
diff --git a/examples/schaefer_turek_durst_krause_rannbacher/sim.cpp b/examples/schaefer_turek_durst_krause_rannbacher/sim.cpp
index a152789..35c04a4 100644
--- a/examples/schaefer_turek_durst_krause_rannbacher/sim.cpp
+++ b/examples/schaefer_turek_durst_krause_rannbacher/sim.cpp
@@ -46,19 +46,21 @@ saw::error_or<void> lbm_main(const saw::data<args::LbmArgs>& args){
converter<T> conv {
// delta_x
- {{0.41 / dim_y}},
+ {{0.41 / (dim_y*N)}},
// delta_t
- {{1.067e-4}}
+ {{3e-3/(N*N)}}
};
- print_lbm_meta<T,Desc>(conv,{1e-3},{1e-4},{0.5 * dim_y});
+ print_lbm_meta<T,Desc>(conv,{1e-3},{0.3},{0.1});
+
+ std::cout<<"Inflow free flow velocity: "<<conv.velocity_si_to_lbm({0.3}).handle().get()<<std::endl;
// saw::data<sch::FixedArray<sch::UInt64,Desc::D>> meta{{dim_x,dim_y}};
- 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_data_ptr = saw::heap<saw::data<sch::ChunkStruct<T,Desc,N>>>();
+ auto lbm_macro_data_ptr = saw::heap<saw::data<sch::MacroStruct<T,Desc,N>>>();
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;
+ std::cout<<"Estimated Bytes: "<<memory_estimate<sch::ChunkStruct<T,Desc,N>,sch::MacroStruct<T,Desc,N>>().get()<<std::endl;
auto eo_aio = saw::setup_async_io();
if(eo_aio.is_error()){
@@ -82,14 +84,14 @@ saw::error_or<void> lbm_main(const saw::data<args::LbmArgs>& args){
sycl_q.wait();
{
- auto eov = init<T,Desc,Coll>(conv,*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_data_ptr);
+ auto eov = init<T,Desc,Coll,N>(conv,*lbm_data_ptr,*lbm_macro_data_ptr,*lbm_particle_data_ptr);
if(eov.is_error()){
return eov;
}
}
- saw::data<sch::ChunkStruct<T,Desc>, encode::Sycl<saw::encode::Native>> lbm_sycl_data{sycl_q};
- saw::data<sch::MacroStruct<T,Desc>, encode::Sycl<saw::encode::Native>> lbm_sycl_macro_data{sycl_q};
+ saw::data<sch::ChunkStruct<T,Desc,N>, encode::Sycl<saw::encode::Native>> lbm_sycl_data{sycl_q};
+ saw::data<sch::MacroStruct<T,Desc,N>, encode::Sycl<saw::encode::Native>> lbm_sycl_macro_data{sycl_q};
saw::data<sch::ParticleSpheroidGroup<T,Desc>, encode::Sycl<saw::encode::Native>> lbm_sycl_particle_data{sycl_q};
sycl_q.wait();
@@ -123,14 +125,13 @@ saw::error_or<void> lbm_main(const saw::data<args::LbmArgs>& args){
for(saw::data<sch::UInt64> i{0u}; i < time_steps and krun; ++i){
// BC + Collision
{
- auto eov = step<T,Desc,Coll>(conv,lsd_view,lsdm_view,lsdp_view,i,dev);
+ auto eov = step<T,Desc,Coll,N>(conv,lsd_view,lsdm_view,lsdp_view,i,dev);
if(eov.is_error()){
return eov;
}
}
sycl_q.wait();
- /*
if(i.get() % 64u == 0u){
{
auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
@@ -139,13 +140,12 @@ saw::error_or<void> lbm_main(const saw::data<args::LbmArgs>& args){
}
}
{
- auto eov = write_vtk_file(out_dir,std::string{"stdkr_2d_"}+an.template get<"coupling">().stl_string(),i.get(), *lbm_macro_data_ptr);
+ auto eov = write_vtk_file(out_dir,std::string{"ops_2d_"}+an.template get<"coupling">().stl_string(),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<saw::encode::Native>> stream;
@@ -212,11 +212,11 @@ saw::error_or<void> k_main(int argc, char** argv){
auto& coupling = an.template get<"coupling">();
if(coupling.stl_view() == "hlbm"){
- return lbm_main<FloatT,DescT,method::Hlbm,1u>(args);
+ return lbm_main<FloatT,DescT,method::Hlbm,2u>(args);
} else if(coupling.stl_view() == "fplbm"){
- return lbm_main<FloatT,DescT,method::FpLbm,1u>(args);
+ return lbm_main<FloatT,DescT,method::FpLbm,2u>(args);
} else if(coupling.stl_view() == "psm"){
- return lbm_main<FloatT,DescT,method::Psm,1u>(args);
+ return lbm_main<FloatT,DescT,method::Psm,2u>(args);
}
return saw::make_error<saw::err::critical>("Invalid coupling");
diff --git a/examples/schaefer_turek_durst_krause_rannbacher/step.hpp b/examples/schaefer_turek_durst_krause_rannbacher/step.hpp
index 9a75e6f..e88f262 100644
--- a/examples/schaefer_turek_durst_krause_rannbacher/step.hpp
+++ b/examples/schaefer_turek_durst_krause_rannbacher/step.hpp
@@ -5,11 +5,11 @@
namespace kel {
namespace lbm {
-template<typename T, typename Desc, typename Coll>
+template<typename T, typename Desc, typename Coll, uint64_t N>
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::ChunkStruct<T,Desc,N>>,encode::Sycl<saw::encode::Native>>& fields,
+ saw::data<sch::Ptr<sch::MacroStruct<T,Desc,N>>,encode::Sycl<saw::encode::Native>>& macros,
saw::data<sch::Ptr<sch::ParticleSpheroidGroup<T,Desc>>,encode::Sycl<saw::encode::Native>>& particles,
saw::data<sch::UInt64> t_i,
device& dev
@@ -46,7 +46,7 @@ saw::error_or<void> step(
}).wait();
q.submit([&](acpp::sycl::handler& h){
- component<T,Desc,cmpt::Hlbm,encode::Sycl<saw::encode::Native>> collision{1.0};
+ component<T,Desc,cmpt::Hlbm,encode::Sycl<saw::encode::Native>> collision{0.59};
component<T,Desc,cmpt::BounceBack,encode::Sycl<saw::encode::Native>> bb;
component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<saw::encode::Native>> flow_out{1.0};
@@ -121,8 +121,8 @@ saw::error_or<void> step(
// auto coll_ev =
q.submit([&](acpp::sycl::handler& h){
- component<T,Desc,cmpt::BGK,encode::Sycl<saw::encode::Native>> bgk{1.0};
- component<T,Desc,cmpt::FpLbm,encode::Sycl<saw::encode::Native>> collision{1.0};
+ component<T,Desc,cmpt::BGK,encode::Sycl<saw::encode::Native>> bgk{0.59};
+ component<T,Desc,cmpt::FpLbm,encode::Sycl<saw::encode::Native>> collision{0.59};
component<T,Desc,cmpt::BounceBack,encode::Sycl<saw::encode::Native>> bb;
component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<saw::encode::Native>> flow_out{1.0};
@@ -197,8 +197,8 @@ saw::error_or<void> step(
// auto coll_ev =
q.submit([&](acpp::sycl::handler& h){
- component<T,Desc,cmpt::BGK,encode::Sycl<saw::encode::Native>> bgk{1.0};
- component<T,Desc,cmpt::Psm,encode::Sycl<saw::encode::Native>> collision{1.0};
+ component<T,Desc,cmpt::BGK,encode::Sycl<saw::encode::Native>> bgk{0.59};
+ component<T,Desc,cmpt::Psm,encode::Sycl<saw::encode::Native>> collision{0.59};
component<T,Desc,cmpt::BounceBack,encode::Sycl<saw::encode::Native>> bb;
component<T,Desc,cmpt::ZouHeHorizontal<false>,encode::Sycl<saw::encode::Native>> flow_out{1.0};
diff --git a/modules/core/c++/fplbm.hpp b/modules/core/c++/fplbm.hpp
index 5ad692b..0ab7903 100644
--- a/modules/core/c++/fplbm.hpp
+++ b/modules/core/c++/fplbm.hpp
@@ -10,7 +10,7 @@ namespace cmpt {
struct FpLbmReset{};
struct FpLbm {};
struct FpLbmOneParticle {};
-struct FpLbmOneParticleImplicit {};
+struct FpLbmMomentumOneParticle {};
struct FpLbmOneParticleNoVelocity{};
}
namespace method {
@@ -132,6 +132,145 @@ public:
};
template<typename T, typename Descriptor, typename Encode>
+class component<T, Descriptor, cmpt::FpLbmMomentumOneParticle, Encode> final {
+public:
+ using Component = cmpt::FpLbmOneParticle;
+private:
+ saw::data<sch::Vector<T,Descriptor::D>> global_force_;
+public:
+ component():
+ global_force_{}
+ {}
+ component(saw::data<sch::Vector<T,Descriptor::D>> global_force__):
+ global_force_{global_force__}
+ {}
+
+ 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, saw::data<sch::UInt64> sub_steps) 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">();
+ using dfi = df_info<T,Descriptor>;
+ bool is_even = ((time_step.get() % 2) == 0);
+
+ saw::data<sch::Scalar<T>> one;
+ one.at({}) = 1.0;
+
+ auto& dfs_old_f = (is_even) ? field.template get<"dfs_old">() : field.template get<"dfs">();
+
+ auto& part_spheroid_group = part_group;
+ auto& mvel_f = macros.template get<"momentum">();
+ auto& mrho_f = macros.template get<"density">();
+ auto& mpor_f = macros.template get<"porosity">();
+
+ auto& particle_N_f = field.template get<"particle_N">();
+ auto& particle_D_f = field.template get<"particle_D">();
+ {
+ auto parts = part_spheroid_group.template get<"particles">();
+ auto parts_size = parts.meta().at({0u});
+
+ auto& p_coll = part_spheroid_group.template get<"collision">().at({});
+ auto& p_rad = p_coll.template get<"radius">();
+
+ auto& pi = parts.at(index);
+ auto& pirb = pi.template get<"rigid_body">();
+ saw::data<sch::Vector<T,Descriptor::D>>& pirb_pos = pirb.template get<"position">();
+ auto& pirb_pos_old = pirb.template get<"position_old">();
+
+ // TODO !!!! Divide by actual time step - for now it's ok
+ saw::data<sch::Scalar<T>> ts;
+ ts.at({}) = one.at({}) / sub_steps.template cast_to<T>();
+
+ saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> start;
+ saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> stop;
+
+ auto eo_aabb = particle_aabb<typename ParticleSchema::ValueType>::calculate(part_spheroid_group,{{0u}},mvel_f.meta());
+ if(eo_aabb.is_error()){
+ 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">();
+
+ saw::data<sch::Vector<T,Descriptor::D>> force_p;
+ for(uint64_t i{0u}; i < Descriptor::D; ++i){
+ force_p.at({{i}}) = 0.0;
+ }
+ auto vel_p_old = (pirb_pos-pirb_pos_old) / ts;
+
+ iterator<Descriptor::D>::apply([&](const auto& index_f) -> void{
+ auto& dfs = dfs_old_f.at(index_f);
+ saw::data<sch::Vector<T,Descriptor::D>> rel_dist = saw::math::vectorize_data(index_f).template cast_to<T>() - pirb_pos;
+ saw::data<sch::Scalar<T>> eps;
+ eps.at({}) = 1.5f;
+
+ auto& mpor = mpor_f.at(index_f);
+ mpor = particle_porosity<T,Descriptor::D,1u,por::ParticleSpheroid<T>>::calculate(rel_dist,p_rad,eps);
+
+ if(mpor.at({}).get() >= 1.0f){
+ return;
+ }
+
+ saw::data<sch::Vector<T,Descriptor::D>> momentum;
+ for(uint64_t i{0u}; i < Descriptor::D; ++i){
+ momentum.at({{i}}) = 0.0;
+ }
+
+ for(uint64_t i{0u}; i < Descriptor::Q; ++i){
+ saw::data<sch::Vector<T,Descriptor::D>> e_i;
+ saw::data<sch::FixedArray<sch::UInt64,Descriptor::D>> n_ind_i;
+ for(uint64_t k{0u}; k < Descriptor::D; ++k){
+ e_i.at({{k}}) = (dfi::directions[i])[k];
+ n_ind_i.at({k}) = index_f.at({k}) + (dfi::directions[i])[k];
+ }
+
+ uint64_t i_opp = dfi::opposite_index[i];
+
+ auto u_p_e = saw::math::dot(e_i,vel_p_old);
+
+ saw::data<T> dfs_added = dfs.at({i})*(saw::data<T>{1}-u_p_e.at({})) + dfs_old_f.at(n_ind_i).at({i_opp})*(saw::data<T>{1}+u_p_e.at({}));
+ saw::data<sch::Scalar<T>> dfs_added_v;
+ dfs_added_v.at({}) = dfs_added;
+ auto ei_dfs = e_i * dfs_added_v;
+
+ momentum = momentum + ei_dfs;
+ }
+
+ // TODO technically needs to adjust for rotation as well
+
+ auto& rho = mrho_f.at(index_f);
+
+ macros.template get<"force">().at(index_f) = momentum;
+ force_p = force_p + momentum;
+ },start,stop);
+
+ auto& pirb_acc = pirb.template get<"acceleration">();
+ pirb_acc = - force_p / part_spheroid_group.template get<"total_mass">().at({});
+
+ for(saw::data<sch::UInt64> i{0u}; i < sub_steps; ++i){
+ verlet_step_lambda<T,Descriptor::D>(pi,ts);
+ }
+ auto vel_p = (pirb_pos-pirb_pos_old) / ts;
+
+ iterator<Descriptor::D>::apply([&](const auto& index_f){
+ auto& N = particle_N_f.at(index_f);
+ auto& D = particle_D_f.at(index_f);
+ auto& mpor = mpor_f.at(index_f);
+ auto flip_porosity = one - mpor;
+
+ D = D + flip_porosity;
+ N = N + vel_p * flip_porosity;
+ },start,stop);
+ // Check
+ }
+ }
+};
+
+template<typename T, typename Descriptor, typename Encode>
class component<T, Descriptor, cmpt::FpLbmOneParticle, Encode> final {
public:
using Component = cmpt::FpLbmOneParticle;
@@ -213,7 +352,7 @@ public:
// vel_s is technically time the density of the particle?
- force = ( vel_s - mom) * flip_por;
+ force = global_force_ * por + ( vel_s - mom) * two * flip_por;
// force = (vel_s - mom) * flip_por / (flip_por / two + one);
force_p = force_p - force;
diff --git a/modules/core/c++/hlbm.hpp b/modules/core/c++/hlbm.hpp
index e8ea66a..0df5896 100644
--- a/modules/core/c++/hlbm.hpp
+++ b/modules/core/c++/hlbm.hpp
@@ -102,12 +102,6 @@ public:
template<typename T, typename Desc, typename Encode>
class component<T, Desc, cmpt::HlbmOneParticle, 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>
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, saw::data<sch::UInt64> sub_steps) const {
@@ -167,10 +161,6 @@ public:
auto vel_p_old = (pirb_pos-pirb_pos_old) / ts;
iterator<Desc::D>::apply([&](const auto& index_f) -> void{
- // ask for the d_k value here.
- // For every value im iterating over I need sth
- // std::cout<<"Pos: "<<index.at({0u}).get()<<" "<<index.at({1u}).get()<<std::endl;
-
auto& dfs = dfs_old_f.at(index_f);
saw::data<sch::Vector<T,Desc::D>> rel_dist = saw::math::vectorize_data(index_f).template cast_to<T>() - pirb_pos;
saw::data<sch::Scalar<T>> eps;
@@ -207,9 +197,12 @@ public:
momentum = momentum + ei_dfs;
}
- // technically needs to adjust for rotation as well
+
+ // TODO technically needs to adjust for rotation as well
auto& rho = mrho_f.at(index_f);
+
+ macros.template get<"force">().at(index_f) = momentum;
force_p = force_p + momentum;
},start,stop);
diff --git a/modules/core/c++/psm.hpp b/modules/core/c++/psm.hpp
index 1dca64b..f5a8452 100644
--- a/modules/core/c++/psm.hpp
+++ b/modules/core/c++/psm.hpp
@@ -79,22 +79,6 @@ public:
uint64_t i_opp = dfi::opposite_index[i];
dfs.at({i}) = dfs_cpy.at({i}) + frequency_ * (eq.at(i) - dfs_cpy.at({i})) * porous.at({}) + (dfs_cpy.at({i_opp}) - dfs_cpy.at({i}) ) * flip_porous;
}
-
- auto& force_f = macros.template get<"force">();
- auto& force = force_f.at(index);
- for(uint64_t k{0u}; k < Descriptor::D; ++k){
- force.at({{k}}).set(0);
- }
-
- for(uint64_t i{0u}; i < Descriptor::Q; ++i){
- uint64_t i_opp = dfi::opposite_index[i];
- auto dfs_diff = dfs.at({i}) - dfs.at({i_opp});
- for(uint64_t k{0u}; k < Descriptor::D; ++k){
- force.at({{k}}) = force.at({{k}}) + dfs_diff * dfi::directions[i][k];
- }
- }
-
- force = force * porous;
}
};
@@ -314,14 +298,9 @@ void apply(
/*
* ------------------------------------------------
- * D3Q27 / general Q momentum exchange
- *
* We exclude i=0 because the rest population has
* no momentum.
*
- * The original code summed both directions of
- * every opposite pair. Therefore we apply 1/2
- * after the sum.
* ------------------------------------------------
*/
@@ -425,46 +404,10 @@ void apply(
+ e_i * dfs_added_v;
}
-
- /*
- * ------------------------------------------------
- * Since both i and i_opp were included above,
- * compensate for double counting.
- *
- * This is the important change from your original
- * implementation.
- * ------------------------------------------------
- */
-
-
-
- momentum =
- momentum * half;
-
-
- /*
- * ------------------------------------------------
- * PSM solid fraction
- *
- * por = 1 -> fluid
- * por = 0 -> particle
- *
- * Therefore:
- *
- * flip_por = 1 - por
- * ------------------------------------------------
- */
-
auto flip_por =
one - por;
- /*
- * ------------------------------------------------
- * Force transferred TO FLUID
- * ------------------------------------------------
- */
-
auto& force =
force_f.at(index_f);