summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2025-04-22 13:35:38 +0200
committerClaudius "keldu" Holeksa <mail@keldu.de>2025-04-22 13:35:38 +0200
commitd7b6dee2db415fc5d0052dca47a45c44b9aaba6d (patch)
treec21c80c117a1ba3830d668122cc5d47692605c47
parent60fb118680cf773dd5db44a4930bab4b4c119deb (diff)
Broken float decoder in forstio
-rw-r--r--.nix/derivation.nix11
-rw-r--r--c++/config.hpp53
-rw-r--r--c++/lbm.hpp1
-rw-r--r--c++/particle/particle.hpp1
-rw-r--r--examples/config.json5
-rw-r--r--examples/meta_2d.cpp19
6 files changed, 84 insertions, 6 deletions
diff --git a/.nix/derivation.nix b/.nix/derivation.nix
index 7ce23e2..6a50475 100644
--- a/.nix/derivation.nix
+++ b/.nix/derivation.nix
@@ -20,13 +20,14 @@ stdenv.mkDerivation {
forstio.async
forstio.codec
forstio.codec-unit
- ];
+ forstio.codec-json
+ ];
- doCheck = true;
- checkPhase = ''
+ doCheck = true;
+ checkPhase = ''
scons test
- ./bin/tests
- '';
+ ./bin/tests
+ '';
outputs = [ "out" "dev" ];
}
diff --git a/c++/config.hpp b/c++/config.hpp
new file mode 100644
index 0000000..64f7a0f
--- /dev/null
+++ b/c++/config.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <forstio/codec/data.hpp>
+#include <forstio/codec/json/json.hpp>
+
+#include <fstream>
+#include <sstream>
+#include <string_view>
+#include <string>
+
+namespace kel {
+namespace lbm {
+namespace sch {
+using namespace saw::schema;
+template<typename T, typename Desc>
+using LbmConfig = Struct<
+ Member<T, "delta_x">,
+ Member<T, "kinematic_viscosity">,
+ Member<T, "delta_t">
+>;
+}
+
+template<typename T, typename Desc>
+saw::error_or<saw::data<sch::LbmConfig<T,Desc>>> load_lbm_config(std::string_view file_name){
+ std::ifstream file{std::string{file_name}};
+
+ if(!file.is_open()){
+ return saw::make_error<saw::err::not_found>("Couldn't open file");
+ }
+
+ saw::data<sch::LbmConfig<T,Desc>, saw::encode::Json> lbm_json_conf{saw::heap<saw::array_buffer>(1u)};
+
+ uint8_t ele{};
+ while(file.readsome(reinterpret_cast<char*>(&ele), 1u) > 0u){
+ auto err = lbm_json_conf.get_buffer().push(ele,1u);
+ if(err.failed()){
+ return err;
+ }
+ }
+
+ saw::data<sch::LbmConfig<T,Desc>> lbm_conf;
+ saw::codec<sch::LbmConfig<T,Desc>, saw::encode::Json> json_codec;
+ {
+ auto eov = json_codec.decode(lbm_json_conf, lbm_conf);
+ if(eov.is_error()){
+ return std::move(eov.get_error());
+ }
+ }
+
+ return lbm_conf;
+}
+}
+}
diff --git a/c++/lbm.hpp b/c++/lbm.hpp
index 9cd7296..1baaa0e 100644
--- a/c++/lbm.hpp
+++ b/c++/lbm.hpp
@@ -2,6 +2,7 @@
#include "descriptor.hpp"
#include "converter.hpp"
+#include "config.hpp"
#include <forstio/codec/unit/unit_print.hpp>
#include <iostream>
diff --git a/c++/particle/particle.hpp b/c++/particle/particle.hpp
index 58c028c..aeda17f 100644
--- a/c++/particle/particle.hpp
+++ b/c++/particle/particle.hpp
@@ -35,6 +35,7 @@ public:
void step(T time_step){
for(auto& iter : particles_){
+
}
}
};
diff --git a/examples/config.json b/examples/config.json
new file mode 100644
index 0000000..dcd7f91
--- /dev/null
+++ b/examples/config.json
@@ -0,0 +1,5 @@
+{
+ "delta_x" : 0.1,
+ "delta_t" : 0.1,
+ "kinematic_viscosity" : 1e-3
+}
diff --git a/examples/meta_2d.cpp b/examples/meta_2d.cpp
index 5aa39f4..a66f0e9 100644
--- a/examples/meta_2d.cpp
+++ b/examples/meta_2d.cpp
@@ -1,14 +1,31 @@
#include "../c++/lbm.hpp"
+#include <iostream>
+
int main(int argc, char** argv){
using namespace kel::lbm;
+
+ auto eo_conf = load_lbm_config<sch::Float64,sch::Descriptor<2,9>>("config.json");
+ if(eo_conf.is_error()){
+ auto& err = eo_conf.get_error();
+ std::cerr<<"[Error]: "<<err.get_category();
+ auto err_msg = err.get_message();
+ if(!err_msg.empty()){
+ std::cerr<<" - "<<err_msg;
+ }
+ std::cerr<<std::endl;
+
+ return err.get_id();
+ }
+
+ auto& conf = eo_conf.get_value();
converter<sch::Float64> conv{
{0.1},
{0.1}
};
- print_lbm_meta<sch::Float64,sch::Descriptor<2,9>>(conv, {1e-5});
+ print_lbm_meta<sch::Float64,sch::Descriptor<2,9>>(conv, {conf.template get<"kinematic_viscosity">()});
return 0;
}