summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp2
-rw-r--r--lib/core/c++/math/n_linear.hpp29
-rw-r--r--lib/core/c++/particle/blur.hpp37
-rw-r--r--util/podman/norce_prefetch_build_and_run.sh104
4 files changed, 171 insertions, 1 deletions
diff --git a/examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp b/examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp
index e4c6de6..7ac663f 100644
--- a/examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp
+++ b/examples/poiseulle_particles_channel_2d/poiseulle_particles_channel_2d.cpp
@@ -603,7 +603,7 @@ void lbm_step(
}
/**
- * 2-Way coupling through trinlinearity
+ * 2-Way coupling through bilinearity (n-linearity)
* o -- o
* | |
* | |
diff --git a/lib/core/c++/math/n_linear.hpp b/lib/core/c++/math/n_linear.hpp
new file mode 100644
index 0000000..62906cd
--- /dev/null
+++ b/lib/core/c++/math/n_linear.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+#include "../common.hpp"
+
+namespace kel {
+namespace lbm {
+
+template<typename FieldSchema, typename T, uint64_t D>
+void n_linear_interpolate(const saw::data<FieldSchema>& field, const saw::data<sch::FixedArray<T,D>>& pos){
+
+ auto pos_bound = pos;
+ auto meta = field.dims();
+ saw::data<sch::UInt64> ind;
+ for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{D}; ++i){
+ pos_bound.at(i).set(
+ std::max(
+ std::min(
+ meta.at(i).template cast_to<T>().get(),
+ pos.at(i).get() + 1.5
+ ),
+ 1,
+ )
+ -1
+ );
+ ind.at(i) = pos_bound.at(i).template cast_to<sch::UInt64>();
+ }
+}
+}
+}
diff --git a/lib/core/c++/particle/blur.hpp b/lib/core/c++/particle/blur.hpp
new file mode 100644
index 0000000..a304e8d
--- /dev/null
+++ b/lib/core/c++/particle/blur.hpp
@@ -0,0 +1,37 @@
+#pragma once
+
+namespace kel {
+namespace lbm {
+template<typename T, uint64_t D>
+void blur_mask(saw::data<sch::Array<T,D>>& p_mask){
+
+ saw::data<T> mid{2.0/3.0};
+ saw::data<T> edge{1.0/6.0};
+
+ // saw::data<sch::FixedArray<sch::UInt64>,2u> blur_weights{{2.0/3.0},{1.0/6.0}};
+
+ auto meta = p_mask.dims();
+ saw::data<sch::Array<T,D>> blurred_mask{meta};
+
+ for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{D}; ++i){
+ iterator<D>::apply([&](const auto& index){
+ blurred_mask.at(index) = p_mask.at(index) * mid;
+
+ if(index.at({i}).get() > 0u){
+ auto l_ind = index;
+ l_ind.at({i}) = ind.at({i}) - 1u;
+ blurred_mask.at(index) = blurred_mask.at(index) + p_mask.at(l_ind) * edge;
+ }
+ if((index.at({i}).get() + 1u) < meta.at({i})){
+ auto r_ind = index;
+ r_ind.at({i}) = ind.at({i}) + 1u;
+ blurred_mask.at(index) = blurred_mask.at(index) + p_mask.at(r_ind) * edge;
+ }
+ },{},meta);
+
+ p_mask = blurred_mask;
+ }
+
+}
+}
+}
diff --git a/util/podman/norce_prefetch_build_and_run.sh b/util/podman/norce_prefetch_build_and_run.sh
new file mode 100644
index 0000000..318ec4a
--- /dev/null
+++ b/util/podman/norce_prefetch_build_and_run.sh
@@ -0,0 +1,104 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# --- Usage ---
+# ./build.sh <url> <sha256>
+if [[ $# -ne 2 ]]; then
+ echo "Usage: $0 <url> <sha256>"
+ exit 1
+fi
+
+SRC_URL="$1"
+SRC_HASH="$2"
+
+NIX_STORE_VOL="nix-store"
+NIX_STATE_VOL="nix-state"
+
+# --- Ensure Podman volumes exist ---
+ensure_volume() {
+ local vol="$1"
+ if ! podman volume inspect "$vol" >/dev/null 2>&1; then
+ echo "📦 Creating Podman volume: $vol"
+ podman volume create "$vol" >/dev/null
+ fi
+}
+
+ensure_volume "$NIX_STORE_VOL"
+ensure_volume "$NIX_STATE_VOL"
+
+# --- Detect host CA bundle ---
+HOST_CA_BUNDLE=""
+if [[ -f /etc/ssl/certs/ca-certificates.crt ]]; then
+ HOST_CA_BUNDLE="/etc/ssl/certs/ca-certificates.crt"
+elif [[ -f /etc/pki/tls/certs/ca-bundle.crt ]]; then
+ HOST_CA_BUNDLE="/etc/pki/tls/certs/ca-bundle.crt"
+fi
+
+# --- Run inside Nix container ---
+podman run --rm -it \
+ -v "$NIX_STORE_VOL":/nix/store \
+ -v "$NIX_STATE_VOL":/nix/var \
+ -v /etc/ssl/certs:/etc/ssl/certs:ro \
+ -v /etc/pki:/etc/pki:ro \
+ ${HOST_CA_BUNDLE:+-v "$HOST_CA_BUNDLE:$HOST_CA_BUNDLE:ro"} \
+ -e SRC_URL="$SRC_URL" \
+ -e SRC_HASH="$SRC_HASH" \
+ -e SSL_CERT_FILE="$HOST_CA_BUNDLE" \
+ -e NIX_SSL_CERT_FILE="$HOST_CA_BUNDLE" \
+ docker.io/nixos/nix:latest \
+ nix-shell -p bash nix-prefetch-url --run "
+ set -euo pipefail
+
+ echo \"⬇ Fetching into nix store...\"
+
+ STORE_PATH=\$(nix-prefetch-url --unpack --type sha256 \"\$SRC_URL\" \"\$SRC_HASH\")
+
+ echo \"📦 Source stored at: \$STORE_PATH\"
+
+ if [[ ! -d \"\$STORE_PATH\" ]]; then
+ echo \"❌ Expected unpacked directory in nix store\"
+ exit 1
+ fi
+
+ cd \"\$STORE_PATH\"
+
+ echo \"📂 Entered: \$(pwd)\"
+
+ if [[ ! -f default.nix ]]; then
+ echo \"❌ No default.nix found in source\"
+ exit 1
+ fi
+
+ echo \"🔨 Running nix-build...\"
+ nix-build default.nix --out-link result
+
+ BIN_DIR=./result/bin
+ if [[ ! -d \"\$BIN_DIR\" ]]; then
+ echo \"ℹ No binaries produced.\"
+ exit 0
+ fi
+
+ mapfile -t BINARIES < <(ls -1 \"\$BIN_DIR\")
+ if (( \${#BINARIES[@]} == 0 )); then
+ echo \"ℹ No binaries found in result/bin\"
+ exit 0
+ fi
+
+ echo \"Available binaries:\"
+ select CHOSEN_BIN in \"\${BINARIES[@]}\" \"Quit\"; do
+ if [[ \"\$CHOSEN_BIN\" == \"Quit\" ]]; then
+ echo \"Exiting.\"
+ break
+ elif [[ -n \"\$CHOSEN_BIN\" ]]; then
+ echo \"▶ Running \$CHOSEN_BIN...\"
+ \"\$BIN_DIR/\$CHOSEN_BIN\"
+ break
+ else
+ echo \"Invalid selection, try again.\"
+ fi
+ done
+ "
+
+echo "✅ Done!"
+echo " • Persistent Nix store: $NIX_STORE_VOL"
+echo " • Persistent Nix state: $NIX_STATE_VOL"