flow 1.3.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
flow_bindings.cpp File Reference

nanobind module flow — the Kokkos cut-cell IBM Navier-Stokes solver (peclet.flow.Solver). More...

#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/array.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/pair.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/vector.h>
#include <array>
#include <cstdint>
#include <limits>
#include <Kokkos_Core.hpp>
#include <string>
#include <vector>
#include <nanobind/stl/tuple.h>
#include "anderson_accelerator.hpp"
#include "flow_ibm.hpp"
#include "peclet/core/python/kokkos_teardown.hpp"
#include "peclet/core/python/ndarray_interop.hpp"

Go to the source code of this file.

Classes

struct  BoundSolver< Grid >
 
struct  BoundAccelerator< Grid >
 
struct  Diagnostics< Grid >
 The developer tier: a view onto one Solver<Grid> (no state of its own). More...
 

Functions

template<class S >
static nb::ndarray< nb::numpy, double > field_out (S &s, std::vector< double > &&v)
 
template<class S >
static nb::ndarray< nb::numpy, double > vofBlockColourArray (S &s, long id)
 
template<class S >
static nb::ndarray< nb::numpy, double > vofBlockKappaArray (S &s, long id)
 
static std::vector< double > grid_in (nb::ndarray< double, nb::f_contig > a)
 
static int enum_index (const std::string &v, const std::vector< std::string > &names, const char *who, const char *what)
 
static int face_index (const std::string &f, const char *who)
 
template<class S >
static auto field3d_out (S &s, peclet::flow::CCField f)
 
template<class Grid >
static void bind_accelerator (nb::module_ &m, const char *name)
 
template<class Grid >
static auto traction_force_torque_array (peclet::flow::Solver< Grid > &s)
 The reconstructed-traction loads as the (4, n_instances, 3) array that both of its Python names return: diagnostics.hydro_force_torque_traction() (canonical) and the deprecated hydro_force_torque().
 
template<class Grid >
static void bind_diagnostics (nb::module_ &m, const char *name)
 
template<class Grid >
static void bind_solver (nb::module_ &m, const char *name, const char *diag_name)
 
 NB_MODULE (_flow, m)
 

Variables

static const std::vector< std::string > kFaces {"-x", "+x", "-y", "+y", "-z", "+z"}
 
static const std::vector< std::string > kAxes {"x", "y", "z"}
 
static const std::vector< std::string > kBcTypes {"periodic", "wall", "inflow", "outflow", "slip"}
 
static const std::vector< std::string > kScalarBcTypes {"periodic", "neumann", "dirichlet"}
 
static const std::vector< std::string > kAdvSchemes {"sou", "koren"}
 
static const std::vector< std::string > kScalarSchemes {"fou", "koren", "sou"}
 
static const std::vector< std::string > kScalarWallTypes {"neumann", "dirichlet", "robin"}
 
static const std::vector< std::string > kFluidOnly {"off", "filter", "star"}
 
static const std::vector< std::string > kCsfModes {"face", "cell"}
 
static const std::vector< std::string > kPivots
 
static const std::vector< std::string > kAreaModes
 
static const std::vector< std::string > kBlockAssign {"round-robin", "lpt", "orb"}
 

Detailed Description

nanobind module flow — the Kokkos cut-cell IBM Navier-Stokes solver (peclet.flow.Solver).

Exposes peclet::flow::IbmSolver to Python: set rho/mu/dt, a body force, an SDF solid (cut-cell IBM no-slip

  • optional cut-cell pressure projection), step, read back the velocity/pressure, and query the cut-cell flux divergence. Exercised by verify_poiseuille_sdflow (IBM channel) and verify_periodic_spheres_sdflow (cut-cell Stokes through a sphere packing). rank()/bcast_from_root() are single-rank stubs (the multi-rank path lives in tests/kokkos_mpi).

Kokkos teardown follows the suite-wide pattern of peclet/core/python/kokkos_teardown.hpp: Kokkos is initialized at import; every bound Solver is a Releasable (registered on construction) and every zero-copy array (field_view) is a Releasable capsule; the module's single atexit hook (also flow.finalize()) releases all of them and THEN calls Kokkos::finalize, so a Solver or array still referenced at interpreter exit (script globals, a Jupyter/Quarto kernel) can no longer be destroyed after finalize – which is a Kokkos::abort (SIGABRT / exit 134, on OpenMP as on CUDA), not a warning. Nothing needs to be deleted before exit any more.

Arrays cross the boundary through the shared zero-copy bridge (peclet::core::python, in core): fields come back as Fortran-order (nx,ny,nz) float64 NumPy arrays referencing the field buffer, and inputs are read as flat x-fastest buffers. See peclet/core/python/ndarray_interop.hpp.

Definition in file flow_bindings.cpp.

Function Documentation

◆ field_out()

template<class S >
static nb::ndarray< nb::numpy, double > field_out ( S &  s,
std::vector< double > &&  v 
)
static

Definition at line 70 of file flow_bindings.cpp.

Referenced by bind_diagnostics(), and bind_solver().

◆ vofBlockColourArray()

template<class S >
static nb::ndarray< nb::numpy, double > vofBlockColourArray ( S &  s,
long  id 
)
static

Definition at line 82 of file flow_bindings.cpp.

◆ vofBlockKappaArray()

template<class S >
static nb::ndarray< nb::numpy, double > vofBlockKappaArray ( S &  s,
long  id 
)
static

Definition at line 101 of file flow_bindings.cpp.

Referenced by bind_diagnostics().

◆ grid_in()

static std::vector< double > grid_in ( nb::ndarray< double, nb::f_contig >  a)
static

Definition at line 120 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ enum_index()

static int enum_index ( const std::string &  v,
const std::vector< std::string > &  names,
const char *  who,
const char *  what 
)
static

Definition at line 126 of file flow_bindings.cpp.

Referenced by bind_diagnostics(), bind_solver(), and face_index().

◆ face_index()

static int face_index ( const std::string &  f,
const char *  who 
)
static

Definition at line 138 of file flow_bindings.cpp.

References enum_index(), and kFaces.

Referenced by bind_solver().

◆ field3d_out()

template<class S >
static auto field3d_out ( S &  s,
peclet::flow::CCField  f 
)
static

Definition at line 163 of file flow_bindings.cpp.

Referenced by bind_diagnostics().

◆ bind_accelerator()

template<class Grid >
static void bind_accelerator ( nb::module_ &  m,
const char *  name 
)
static

Definition at line 198 of file flow_bindings.cpp.

◆ traction_force_torque_array()

template<class Grid >
static auto traction_force_torque_array ( peclet::flow::Solver< Grid > &  s)
static

The reconstructed-traction loads as the (4, n_instances, 3) array that both of its Python names return: diagnostics.hydro_force_torque_traction() (canonical) and the deprecated hydro_force_torque().

One helper, so the two stay bit-identical.

Definition at line 241 of file flow_bindings.cpp.

◆ bind_diagnostics()

template<class Grid >
static void bind_diagnostics ( nb::module_ &  m,
const char *  name 
)
static

◆ bind_solver()

template<class Grid >
static void bind_solver ( nb::module_ &  m,
const char *  name,
const char *  diag_name 
)
static

◆ NB_MODULE()

NB_MODULE ( _flow  ,
m   
)

Definition at line 3708 of file flow_bindings.cpp.

References weights().

Variable Documentation

◆ kFaces

const std::vector<std::string> kFaces {"-x", "+x", "-y", "+y", "-z", "+z"}
static

Definition at line 137 of file flow_bindings.cpp.

Referenced by face_index().

◆ kAxes

const std::vector<std::string> kAxes {"x", "y", "z"}
static

Definition at line 141 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ kBcTypes

const std::vector<std::string> kBcTypes {"periodic", "wall", "inflow", "outflow", "slip"}
static

Definition at line 142 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ kScalarBcTypes

const std::vector<std::string> kScalarBcTypes {"periodic", "neumann", "dirichlet"}
static

Definition at line 143 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ kAdvSchemes

const std::vector<std::string> kAdvSchemes {"sou", "koren"}
static

Definition at line 144 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ kScalarSchemes

const std::vector<std::string> kScalarSchemes {"fou", "koren", "sou"}
static

Definition at line 145 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ kScalarWallTypes

const std::vector<std::string> kScalarWallTypes {"neumann", "dirichlet", "robin"}
static

Definition at line 146 of file flow_bindings.cpp.

Referenced by bind_solver().

◆ kFluidOnly

const std::vector<std::string> kFluidOnly {"off", "filter", "star"}
static

Definition at line 147 of file flow_bindings.cpp.

Referenced by bind_diagnostics().

◆ kCsfModes

const std::vector<std::string> kCsfModes {"face", "cell"}
static

Definition at line 148 of file flow_bindings.cpp.

Referenced by bind_diagnostics().

◆ kPivots

const std::vector<std::string> kPivots
static
Initial value:
{"volume", "centroid", "projected-centroid",
"contact-line"}

Definition at line 149 of file flow_bindings.cpp.

Referenced by bind_diagnostics().

◆ kAreaModes

const std::vector<std::string> kAreaModes
static
Initial value:
{
"plic", "cascade-metric", "cascade-normal", "cascade-footprint",
"sheet-color-centroid", "sheet-color-split", "sheet-plic-centroid", "sheet-plic-split"}

Definition at line 151 of file flow_bindings.cpp.

Referenced by bind_diagnostics().

◆ kBlockAssign

const std::vector<std::string> kBlockAssign {"round-robin", "lpt", "orb"}
static

Definition at line 154 of file flow_bindings.cpp.

Referenced by bind_solver().