|
pnm 1.0.3
peclet.pnm — pore-network extraction from SDF geometry (Kokkos)
|
nanobind module pnm — Kokkos pore-network extraction from SDF geometry.
More...
#include <nanobind/nanobind.h>#include <nanobind/ndarray.h>#include <nanobind/stl/optional.h>#include <nanobind/stl/string.h>#include <nanobind/stl/vector.h>#include <array>#include <cstddef>#include <cstdint>#include <cstdio>#include <cstdlib>#include <Kokkos_Core.hpp>#include <optional>#include <type_traits>#include <utility>#include <vector>#include "peclet/core/python/kokkos_teardown.hpp"#include "peclet/core/python/ndarray_interop.hpp"#include "pore_extraction.hpp"#include "sdf_reader.h"Go to the source code of this file.
Functions | |
| static std::vector< float > | to_sdf (nb::ndarray< float, nb::c_contig > a, std::array< int, 3 > &res) |
| static std::vector< double > | to_field (nb::ndarray< double, nb::c_contig > a, const std::array< int, 3 > &res, const char *name) |
| static nb::ndarray< nb::numpy, int > | labels_to_ndarray (std::vector< int > &&seg, const std::array< int, 3 > &res) |
| static nb::ndarray< nb::numpy, int > | pairs_to_ndarray (std::vector< std::pair< int, int > > &&v) |
| static nb::ndarray< nb::numpy, double > | doubles_to_ndarray (std::vector< double > &&v) |
| static nb::dict | network_flow_dict (pnm::NetworkFlow &&net) |
| NB_MODULE (_pnm, m) | |
Variables | |
| static constexpr const char * | kNetworkFlowDictDoc |
nanobind module pnm — Kokkos pore-network extraction from SDF geometry.
Matches the numpy convention: SDF is (Nz,Ny,Nx) C-order, and every triple that describes it (origin_zyx, spacing_zyx, shape_zyx, grad_p_zyx) is stated in that order and carries the _zyx suffix (NAMING.md §1.7). VTI reading (SDFReader) is pure C++ (sdf_reader.cpp, backend-free); the pore / segmentation / topology / network-flow compute is Kokkos (any backend). Exposes SDFReader, Pore, extract_pores, segment_volume, extract_topology, extract_pore_network, extract_network_flow (+ mpi_block and the *_mpi collectives when built with PECLET_PNM_MPI). A C-order (Nz,Ny,Nx) buffer is contiguous x-fastest, so it maps onto the flat layout directly via the shared bridge (peclet::core::python, core).
Arrays in, arrays out: a segmentation is returned as an int32 (Nz,Ny,Nx) C-order ndarray (the flat x-fastest label vector re-shaped in place — no copy, no reshape on the caller's side), a connection / throat list as an (M,2) int32 ndarray, and the network-flow scalars as float64 ndarrays; the host vectors are moved into the capsule that backs the array (vector_to_ndarray). extract_topology takes that segmentation back without a copy. Only the pores stay a Python list of Pore objects (small, and each carries four named scalars).
Precision policy: the SDF is float32 (the VTI's storage type; the kernels compute in float), origin_zyx / spacing_zyx are taken as Python floats (double) and NARROWED to float32 before the kernels, so pore centres and radii are float32 in the input unit system; the MAC fields of the network-flow extraction (u, v, w, p, openness) are float64 and the flow sums are double.
Kokkos teardown follows the suite-wide pattern of peclet/core/python/kokkos_teardown.hpp: Kokkos is initialized at import and the module's single atexit hook (also pnm.finalize()) releases every registered View owner and THEN calls Kokkos::finalize. pnm keeps no Kokkos state between calls (its registry stays empty), but the finalize is still REQUIRED on CUDA (else cudaErrorCudartUnloading at exit).
Definition in file pnm_bindings.cpp.
|
static |
Definition at line 83 of file pnm_bindings.cpp.
Referenced by NB_MODULE().
|
static |
Definition at line 91 of file pnm_bindings.cpp.
Referenced by NB_MODULE().
|
static |
Definition at line 103 of file pnm_bindings.cpp.
Referenced by NB_MODULE().
|
static |
Definition at line 113 of file pnm_bindings.cpp.
Referenced by NB_MODULE(), and network_flow_dict().
|
static |
Definition at line 125 of file pnm_bindings.cpp.
Referenced by network_flow_dict().
|
static |
Definition at line 131 of file pnm_bindings.cpp.
References doubles_to_ndarray(), and pairs_to_ndarray().
Referenced by NB_MODULE().
| NB_MODULE | ( | _pnm | , |
| m | |||
| ) |
Definition at line 155 of file pnm_bindings.cpp.
References pnm::extract_network_flow_k(), pnm::extract_network_flow_mpi(), pnm::extract_pore_network_k(), pnm::extract_pore_network_mpi(), pnm::extract_pores_k(), pnm::extract_topology_k(), kNetworkFlowDictDoc, labels_to_ndarray(), pnm::mpi_block_of(), network_flow_dict(), pairs_to_ndarray(), pnm::Pore::radius, SDFReader::read_vti(), pnm::segment_volume_k(), to_field(), to_sdf(), pnm::Pore::x, pnm::Pore::y, and pnm::Pore::z.
|
staticconstexpr |
Definition at line 145 of file pnm_bindings.cpp.
Referenced by NB_MODULE().