summaryrefslogtreecommitdiff
path: root/lib/core/c++
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2026-02-17 18:29:22 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2026-02-17 18:29:22 +0100
commitdcee24278ed28d21cd3addffeeb8e5f9f7248602 (patch)
treed590ede2996f04f69e2c4521019ae5b1bedd05df /lib/core/c++
parentbb90083ca62483a1cf0e1b72dfb96e05701035ef (diff)
downloadlibs-lbm-master.tar.gz
End of dayHEADmasterdev
Diffstat (limited to 'lib/core/c++')
-rw-r--r--lib/core/c++/descriptor.hpp10
-rw-r--r--lib/core/c++/environment.hpp1
-rw-r--r--lib/core/c++/equilibrium.hpp3
-rw-r--r--lib/core/c++/lbm.hpp1
-rw-r--r--lib/core/c++/memory.hpp62
-rw-r--r--lib/core/c++/write_vtk.hpp22
6 files changed, 93 insertions, 6 deletions
diff --git a/lib/core/c++/descriptor.hpp b/lib/core/c++/descriptor.hpp
index 9cc2591..e38daee 100644
--- a/lib/core/c++/descriptor.hpp
+++ b/lib/core/c++/descriptor.hpp
@@ -180,6 +180,7 @@ public:
static constexpr std::array<std::array<int32_t, D>, Q> directions = {{
{ 0, 0, 0}, // 0
+ // Into 1D
{-1, 0, 0}, // 1
{ 1, 0, 0}, // 2
// Expand into 2D
@@ -212,14 +213,17 @@ public:
static constexpr std::array<typename saw::native_data_type<T>::type,Q> weights = {
8./27.,
- 1./9.,
- 1./9.,
- 1./9.,
+ // 1D
+ 2./27.,
+ 2./27.,
+ // 2D
+ 2./27.,
1./9.,
1./36.,
1./36.,
1./36.,
1./36.,
+ // 3D
8./27.,
1./9.,
1./9.,
diff --git a/lib/core/c++/environment.hpp b/lib/core/c++/environment.hpp
index 4915e3a..9e587d0 100644
--- a/lib/core/c++/environment.hpp
+++ b/lib/core/c++/environment.hpp
@@ -20,5 +20,6 @@ saw::error_or<std::filesystem::path> output_directory(){
return std::filesystem::path{home_dir} / ".lbm";
}
+
}
}
diff --git a/lib/core/c++/equilibrium.hpp b/lib/core/c++/equilibrium.hpp
index 7d1324e..eb2b043 100644
--- a/lib/core/c++/equilibrium.hpp
+++ b/lib/core/c++/equilibrium.hpp
@@ -9,6 +9,7 @@ saw::data<sch::FixedArray<T, Descriptor::Q>> equilibrium(saw::data<sch::Scalar<T
using dfi = df_info<T, Descriptor>;
saw::data<sch::FixedArray<T,Descriptor::Q>> eq;
+ // Brain broken, here's an owl
// ^
// 0.0
// / \
@@ -23,7 +24,7 @@ saw::data<sch::FixedArray<T, Descriptor::Q>> equilibrium(saw::data<sch::Scalar<T
/**
* Calculate equilibrium
*/
- for(uint64_t i = 0u; i < eq.template get_dim_size<0u>(); ++i){
+ for(uint64_t i = 0u; i < Descriptor::Q; ++i){
saw::data<T> vel_c{};
for(uint64_t j = 0u; j < Descriptor::D; ++j){
// <vel,c_i>_2
diff --git a/lib/core/c++/lbm.hpp b/lib/core/c++/lbm.hpp
index 24f93f1..df89a69 100644
--- a/lib/core/c++/lbm.hpp
+++ b/lib/core/c++/lbm.hpp
@@ -14,6 +14,7 @@
#include "iterator.hpp"
#include "hlbm.hpp"
#include "macroscopic.hpp"
+#include "memory.hpp"
#include "stream.hpp"
#include "write_vtk.hpp"
#include "util.hpp"
diff --git a/lib/core/c++/memory.hpp b/lib/core/c++/memory.hpp
new file mode 100644
index 0000000..b6a089e
--- /dev/null
+++ b/lib/core/c++/memory.hpp
@@ -0,0 +1,62 @@
+#pragma once
+
+#include "common.hpp"
+#include "chunk.hpp"
+
+namespace kel {
+namespace lbm {
+
+namespace impl {
+
+template<typename Sch>
+struct memory_size_helper;
+
+template<typename Sch, uint64_t N>
+struct memory_size_helper<sch::Primitive<Sch,N>> {
+ static constexpr uint64_t bytes = N;
+};
+
+template<typename Sch, uint64_t... N>
+struct memory_size_helper<sch::FixedArray<Sch,N...>> {
+ static constexpr uint64_t bytes = saw::ct_multiply<uint64_t,N...>::value * memory_size_helper<Sch>::bytes;
+};
+
+template<typename Sch, uint64_t Ghost, uint64_t... N>
+struct memory_size_helper<sch::Chunk<Sch,Ghost,N...>> {
+ static constexpr uint64_t bytes = memory_size_helper<typename sch::Chunk<Sch,Ghost,N...>::InnerSchema>::bytes;
+};
+
+template<typename... T>
+class memory_estimate_helper final {
+private:
+
+ template<uint64_t i>
+ static void apply_i(saw::data<sch::UInt64>& bytes){
+
+ if constexpr ( i < sizeof...(T)){
+ using T_I = typename saw::parameter_pack_type<i,T...>::type;
+
+ bytes.set(bytes.get() + memory_size_helper<T_I>::bytes);
+
+ apply_i<i+1u>(bytes);
+ }
+ }
+
+public:
+
+ static void apply(saw::data<sch::UInt64>& bytes){
+ apply_i<0u>(bytes);
+ }
+};
+}
+
+template<typename... T>
+saw::data<sch::UInt64> memory_estimate(){
+ saw::data<sch::UInt64> bytes;
+
+ impl::memory_estimate_helper<T...>::apply(bytes);
+
+ return bytes;
+}
+}
+}
diff --git a/lib/core/c++/write_vtk.hpp b/lib/core/c++/write_vtk.hpp
index f7b8f8f..f925361 100644
--- a/lib/core/c++/write_vtk.hpp
+++ b/lib/core/c++/write_vtk.hpp
@@ -222,9 +222,27 @@ struct lbm_vtk_writer<sch::Struct<sch::Member<sch::Chunk<MemberT,Ghost,Dims...>,
}
template<typename Sch>
-saw::error_or<void> write_vtk_file(const std::filesystem::path& file_name, const saw::data<Sch>& field){
+saw::error_or<void> write_vtk_file(const std::filesystem::path& out_dir, const std::string_view& file_name, uint64_t d_t, const saw::data<Sch>& field){
+
+ auto vtk_dir = out_dir / "vtk";
+ {
+ std::error_code ec;
+ std::filesystem::create_directories(vtk_dir,ec);
+ if(ec != std::errc{}){
+ return saw::make_error<saw::err::critical>("Could not create directory for write_vtk_file function");
+ }
+ }
+ std::string ft_name{file_name};
+
+ std::stringstream sstr;
+ sstr
+ <<file_name
+ <<"_"
+ <<d_t
+ <<".vtk"
+ ;
- std::ofstream vtk_file{file_name};
+ std::ofstream vtk_file{vtk_dir / sstr.str() };
if( not vtk_file.is_open() ){
return saw::make_error<saw::err::critical>("Could not open file.");