summaryrefslogtreecommitdiff
path: root/examples/throat_clog_2d
diff options
context:
space:
mode:
Diffstat (limited to 'examples/throat_clog_2d')
-rw-r--r--examples/throat_clog_2d/init.hpp36
-rw-r--r--examples/throat_clog_2d/sim.cpp80
-rw-r--r--examples/throat_clog_2d/step.hpp32
3 files changed, 61 insertions, 87 deletions
diff --git a/examples/throat_clog_2d/init.hpp b/examples/throat_clog_2d/init.hpp
index fab51b3..7683942 100644
--- a/examples/throat_clog_2d/init.hpp
+++ b/examples/throat_clog_2d/init.hpp
@@ -157,47 +157,23 @@ kel::lbm::error_or<void> init(
);
{
+ // A radius is a lattice length now.
kel::lbm::data<sch::LbmMeter<sch::Scalar<T>>> radius_p;
radius_p.at({}).set(conv.meter_si_to_lbm({0.05}).handle().get());
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,particle_amount>(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">();
- /**
- * 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& p = parts.at({0u});
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.1}).handle();
+ p_pos.at({{1u}}) = conv.meter_si_to_lbm({0.32}).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 a25c1a3..04d0092 100644
--- a/examples/throat_clog_2d/sim.cpp
+++ b/examples/throat_clog_2d/sim.cpp
@@ -2,17 +2,31 @@
#include "init.hpp"
#include "step.hpp"
-#include <string_view>
+#include <forstio/codec/args.hpp>
/**
- * 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.
+ * For deciding what parameters to use maybe?
*/
+namespace args {
+using namespace kel::lbm::sch;
+
+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(std::string_view coupling){
+kel::lbm::error_or<void> lbm_main(const kel::lbm::data<args::LbmArgs>& args){
using namespace kel::lbm;
+ auto& an = args.template get<"args">();
+
using dfi = df_info<T,Desc>;
auto eo_lbm_dir = output_directory();
@@ -21,7 +35,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
auto& lbm_dir = eo_lbm_dir.get_value();
- auto out_dir = lbm_dir / "throat_clog_2d" / coupling;
+ auto out_dir = lbm_dir / "throat_clog_2d" / an.template get<"coupling">().stl_view();
{
std::error_code ec;
@@ -49,6 +63,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
auto eo_aio = saw::setup_async_io();
if(eo_aio.is_error()){
+ // forstio io reports its own error type; translate at the boundary.
return kel::lbm::make_error<kel::lbm::err::critical>(
std::string{eo_aio.get_error().get_message()});
}
@@ -116,7 +131,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
auto lsdm_view = make_view(lbm_sycl_macro_data);
auto lsdp_view = make_view(lbm_sycl_particle_data);
- kel::lbm::data<sch::UInt64> time_steps{256u*512ul};
+ kel::lbm::data<sch::UInt64> time_steps{1024ul};
auto& info_f = lsd_view.template get<"info">();
@@ -130,7 +145,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
sycl_q.wait();
- if(i.get() % 256u == 0u){
+ if(i.get() % 1u == 0u){
{
auto eov = dev.copy_to_host(lbm_sycl_macro_data,*lbm_macro_data_ptr);
if(eov.is_error()){
@@ -138,7 +153,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
}
{
- auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},i.get(), *lbm_macro_data_ptr);
+ auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+an.template get<"coupling">().stl_string(),i.get(), *lbm_macro_data_ptr);
if(eov.is_error()){
return eov;
}
@@ -178,7 +193,7 @@ kel::lbm::error_or<void> lbm_main(std::string_view coupling){
}
}
{
- auto eov = write_vtk_file(out_dir,std::string{"throat_clog_2d_"}+std::string{coupling},time_steps.get(), *lbm_macro_data_ptr);
+ 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);
if(eov.is_error()){
return eov;
}
@@ -198,36 +213,37 @@ using DescT = kel::lbm::sch::D2Q9;
kel::lbm::error_or<void> k_main(int argc, char** argv){
using namespace kel::lbm;
-
- // Default to fplbm so the example runs with no arguments at all.
- std::string_view coupling{"fplbm"};
- if(argc > 1){
- coupling = argv[1];
+
+ kel::lbm::data<args::LbmArgs> args;
+ {
+ auto eov = kel::lbm::parse_args(args,argc,argv);
+ if(eov.is_error()){
+ return eov;
+ }
}
+ 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>(coupling);
+ return lbm_main<FloatT,DescT,Cpl,1u>(args);
};
- 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>();
- }
+ 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>();
+ }
+ };
- /**
- * 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");
+ return coupling_resolve();
+
+ return kel::lbm::make_error<kel::lbm::err::critical>("Invalid coupling");
}
+
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 1605cf0..71df661 100644
--- a/examples/throat_clog_2d/step.hpp
+++ b/examples/throat_clog_2d/step.hpp
@@ -41,7 +41,7 @@ kel::lbm::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- hlbm_one_part.apply(fields,macros,particles,index,t_i,{0u});
+ hlbm_one_part.apply(fields,macros,particles,index,t_i,{1u});
});
}).wait();
@@ -75,7 +75,7 @@ kel::lbm::error_or<void> step(
kel::lbm::data<T> scale;
{
scale.set([&](){
- if(t_i.get() > 1024u){
+ if(t_i.get() >= 0u){// > 1024u
return 1.0f;
}
@@ -84,7 +84,7 @@ kel::lbm::error_or<void> step(
}
{
auto y_si = conv.meter_lbm_to_si(as_unit<sch::LbmMeter<T>>(index.at({{1u}}).template cast_to<T>())).handle();
- vel.at({{0u}}) = conv.velocity_si_to_lbm({static_cast<typename kel::lbm::native_data_type<T>::type>((0.1 / 0.64) * y_si.get() - (0.1 / (0.64*0.64)) * y_si.get() * y_si.get())}).handle() * scale;
+ vel.at({{0u}}) = conv.velocity_si_to_lbm({static_cast<typename kel::lbm::native_data_type<T>::type>((0.01 / 0.64) * y_si.get() - (0.01 / (0.64*0.64)) * y_si.get() * y_si.get())}).handle();
vel.at({{1u}}) = 0.0f;
}
return vel;
@@ -116,24 +116,9 @@ 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){
- 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};
+ kel::lbm::data<sch::LbmAcceleration<sch::Vector<T,Desc::D>>> grav; // body acceleration
+ component<T,Desc,cmpt::FpLbmOneParticle,encode::Sycl<kel::lbm::enc::Native>> fplbm_one_part{grav};
h.parallel_for(acpp::sycl::range<1u>{particle_amount}, [=](acpp::sycl::id<1u> idx){
kel::lbm::data<sch::FixedArray<sch::UInt64,1u>> index;
@@ -141,10 +126,7 @@ kel::lbm::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- 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});
+ fplbm_one_part.apply(fields,macros,particles,index,t_i,{1u});
});
}).wait();
@@ -220,7 +202,7 @@ kel::lbm::error_or<void> step(
index.at({{i}}).set(idx[i]);
}
- fplbm_one_part.apply(fields,macros,particles,index,t_i,{0u});
+ fplbm_one_part.apply(fields,macros,particles,index,t_i,{2u});
});
}).wait();