summaryrefslogtreecommitdiff
path: root/examples/throat_clog_2d/sim.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/throat_clog_2d/sim.cpp')
-rw-r--r--examples/throat_clog_2d/sim.cpp80
1 files changed, 48 insertions, 32 deletions
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()){