From 971250070e7b27590d215de54116f3990ab8ff5a Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 2 Mar 2026 21:10:46 +0100 Subject: Adding bluring for masks --- .../poiseulle_particles_channel_2d.cpp | 2 +- lib/core/c++/math/n_linear.hpp | 29 ++++++ lib/core/c++/particle/blur.hpp | 37 ++++++++ util/podman/norce_prefetch_build_and_run.sh | 104 +++++++++++++++++++++ 4 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 lib/core/c++/math/n_linear.hpp create mode 100644 lib/core/c++/particle/blur.hpp create mode 100644 util/podman/norce_prefetch_build_and_run.sh 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 +void n_linear_interpolate(const saw::data& field, const saw::data>& pos){ + + auto pos_bound = pos; + auto meta = field.dims(); + saw::data ind; + for(saw::data i{0u}; i < saw::data{D}; ++i){ + pos_bound.at(i).set( + std::max( + std::min( + meta.at(i).template cast_to().get(), + pos.at(i).get() + 1.5 + ), + 1, + ) + -1 + ); + ind.at(i) = pos_bound.at(i).template cast_to(); + } +} +} +} 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 +void blur_mask(saw::data>& p_mask){ + + saw::data mid{2.0/3.0}; + saw::data edge{1.0/6.0}; + + // saw::data,2u> blur_weights{{2.0/3.0},{1.0/6.0}}; + + auto meta = p_mask.dims(); + saw::data> blurred_mask{meta}; + + for(saw::data i{0u}; i < saw::data{D}; ++i){ + iterator::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 +if [[ $# -ne 2 ]]; then + echo "Usage: $0 " + 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" -- cgit v1.2.3