diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/throat_clog_2d/common.hpp | 9 | ||||
| -rw-r--r-- | examples/throat_clog_2d/init.hpp | 35 | ||||
| -rw-r--r-- | examples/throat_clog_2d/sim.cpp | 74 | ||||
| -rw-r--r-- | examples/throat_clog_2d/step.hpp | 24 |
4 files changed, 88 insertions, 54 deletions
diff --git a/examples/throat_clog_2d/common.hpp b/examples/throat_clog_2d/common.hpp index d74b2f9..84baeb3 100644 --- a/examples/throat_clog_2d/common.hpp +++ b/examples/throat_clog_2d/common.hpp @@ -22,10 +22,15 @@ namespace lbm { */ // Base resolution. -constexpr uint64_t dim_y = 64ul; +// +// Kept small on purpose: the SYCL JIT has to compile the whole kernel set +// before the first step runs, and on a modest machine a large domain plus a +// large particle set will exhaust memory during that compile rather than +// during the simulation itself. +constexpr uint64_t dim_y = 32ul; constexpr uint64_t dim_x = dim_y * 4ul; -constexpr uint64_t particle_amount = 1ul; +constexpr uint64_t particle_amount = 20ul; namespace sch { diff --git a/examples/throat_clog_2d/init.hpp b/examples/throat_clog_2d/init.hpp index f76cd67..e03bd5e 100644 --- a/examples/throat_clog_2d/init.hpp +++ b/examples/throat_clog_2d/init.hpp @@ -162,17 +162,42 @@ kel::lbm::error_or<void> init( 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,1u>(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">(); - { - auto& p = parts.at({0u}); + /** + * 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& 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.16}}).handle(); - p_pos.at({{1u}}) = conv.meter_si_to_lbm({{0.25}}).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 118e1b1..89741ca 100644 --- a/examples/throat_clog_2d/sim.cpp +++ b/examples/throat_clog_2d/sim.cpp @@ -2,30 +2,17 @@ #include "init.hpp" #include "step.hpp" -#include <forstio/codec/args.hpp> +#include <string_view> /** - * For deciding what parameters to use maybe? + * 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. */ -namespace args { - -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(const kel::lbm::data<args::LbmArgs>& args){ +kel::lbm::error_or<void> lbm_main(std::string_view coupling){ using namespace kel::lbm; - auto& an = args.template get<"args">(); - using dfi = df_info<T,Desc>; auto eo_lbm_dir = output_directory(); @@ -34,7 +21,7 @@ kel::lbm::error_or<void> lbm_main(const kel::lbm::data<args::LbmArgs>& args){ } auto& lbm_dir = eo_lbm_dir.get_value(); - auto out_dir = lbm_dir / "throat_clog_2d" / an.template get<"coupling">().stl_view(); + auto out_dir = lbm_dir / "throat_clog_2d" / coupling; { std::error_code ec; @@ -151,7 +138,7 @@ kel::lbm::error_or<void> lbm_main(const kel::lbm::data<args::LbmArgs>& args){ } } { - auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+an.template get<"coupling">().stl_string(),i.get(), *lbm_macro_data_ptr); + auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},i.get(), *lbm_macro_data_ptr); if(eov.is_error()){ return eov; } @@ -191,7 +178,7 @@ kel::lbm::error_or<void> lbm_main(const kel::lbm::data<args::LbmArgs>& args){ } } { - 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); + auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},time_steps.get(), *lbm_macro_data_ptr); if(eov.is_error()){ return eov; } @@ -211,37 +198,36 @@ using DescT = kel::lbm::sch::D2Q9; kel::lbm::error_or<void> k_main(int argc, char** argv){ using namespace kel::lbm; - - kel::lbm::data<args::LbmArgs> args; - { - auto eov = saw::parse_args(args,argc,argv); - if(eov.is_error()){ - return eov; - } + + // Default to fplbm so the example runs with no arguments at all. + std::string_view coupling{"fplbm"}; + if(argc > 1){ + coupling = argv[1]; } - 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>(args); - }; - - 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>(); - } + return lbm_main<FloatT,DescT,Cpl,1u>(coupling); }; - return coupling_resolve(); + 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>(); + } - return kel::lbm::make_error<kel::lbm::err::critical>("Invalid coupling"); + /** + * 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"); } - 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 840f8ba..5bb889e 100644 --- a/examples/throat_clog_2d/step.hpp +++ b/examples/throat_clog_2d/step.hpp @@ -116,9 +116,24 @@ 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){ - kel::lbm::data<sch::Vector<T,Desc::D>> grav; - component<T,Desc,cmpt::FpLbmOneParticle,encode::Sycl<kel::lbm::enc::Native>> fplbm_one_part{grav}; + 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}; h.parallel_for(acpp::sycl::range<1u>{particle_amount}, [=](acpp::sycl::id<1u> idx){ kel::lbm::data<sch::FixedArray<sch::UInt64,1u>> index; @@ -126,7 +141,10 @@ kel::lbm::error_or<void> step( index.at({{i}}).set(idx[i]); } - fplbm_one_part.apply(fields,macros,particles,index,t_i,{4u}); + 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}); }); }).wait(); |
