9#include <nanobind/nanobind.h>
10#include <nanobind/ndarray.h>
11#include <nanobind/stl/array.h>
12#include <nanobind/stl/optional.h>
13#include <nanobind/stl/pair.h>
14#include <nanobind/stl/string.h>
15#include <nanobind/stl/tuple.h>
16#include <nanobind/stl/vector.h>
20#include <Kokkos_Core.hpp>
28#include "peclet/core/common/types.hpp"
29#include "peclet/core/decomp/block_decomposer.hpp"
35#include "peclet/core/python/kokkos_teardown.hpp"
36#include "peclet/core/python/ndarray_interop.hpp"
40namespace nb = nanobind;
46inline void ensure_mpi_init() {
48 MPI_Initialized(&inited);
51 char** argv =
nullptr;
52 MPI_Init(&argc, &argv);
61inline nb::ndarray<nb::numpy, double>
field_out(S& s, std::vector<double>&& v) {
62 const auto nx =
static_cast<std::size_t
>(s.nx());
63 const auto ny =
static_cast<std::size_t
>(s.ny());
64 const auto nz =
static_cast<std::size_t
>(s.nz());
65 return peclet::core::python::vector_to_ndarray(
66 std::move(v), {nx, ny, nz},
67 {1,
static_cast<std::int64_t
>(nx),
static_cast<std::int64_t
>(nx * ny)});
72inline std::vector<double>
grid_in(nb::ndarray<double, nb::f_contig> a) {
73 return peclet::core::python::ndarray_to_vector<double>(nb::ndarray<>(a));
78inline int enum_index(
const std::string& v,
const std::vector<std::string>& names,
const char* who,
80 for (std::size_t i = 0; i < names.size(); ++i)
82 return static_cast<int>(i);
84 for (std::size_t i = 0; i < names.size(); ++i)
85 all += (i ?
" | '" :
"'") + names[i] +
"'";
86 throw std::invalid_argument(std::string(who) +
": " + what +
" must be one of " + all +
89inline const std::vector<std::string>
kFaces{
"-x",
"+x",
"-y",
"+y",
"-z",
"+z"};
90inline int face_index(
const std::string& f,
const char* who) {
93inline const std::vector<std::string>
kAxes{
"x",
"y",
"z"};
94inline const std::vector<std::string>
kBcTypes{
"periodic",
"wall",
"inflow",
"outflow",
"slip"};
95inline const std::vector<std::string>
kScalarBcTypes{
"periodic",
"neumann",
"dirichlet"};
96inline const std::vector<std::string>
kAdvSchemes{
"sou",
"koren"};
98inline const std::vector<std::string>
kScalarWallTypes{
"neumann",
"dirichlet",
"robin"};
99inline const std::vector<std::string>
kFluidOnly{
"off",
"filter",
"star"};
100inline const std::vector<std::string>
kCsfModes{
"face",
"cell"};
101inline const std::vector<std::string>
kPivots{
"volume",
"centroid",
"projected-centroid",
107 "sheet-color-centroid",
109 "sheet-plic-centroid",
111inline const std::vector<std::string>
kBlockAssign{
"round-robin",
"lpt",
"orb"};
121 const auto bs = s.blockShape();
122 const std::array<std::size_t, 3> shape{
static_cast<std::size_t
>(bs[0]),
123 static_cast<std::size_t
>(bs[1]),
124 static_cast<std::size_t
>(bs[2])};
125 const std::array<std::int64_t, 3> strides{1,
static_cast<std::int64_t
>(bs[0]),
126 static_cast<std::int64_t
>(bs[0]) * bs[1]};
127 return peclet::core::python::view_to_ndarray(f, shape, strides);
138 void release() noexcept
override { peclet::core::python::destruct_bound_instance(
this); }
146 peclet::core::python::Releasable {
148 void release() noexcept
override { peclet::core::python::destruct_bound_instance(
this); }
156 std::vector<double> v = s.hydroForceTorque();
157 const std::size_t n = v.size() / 12;
158 return peclet::core::python::vector_to_ndarray(std::move(v), {4, n, 3},
159 {
static_cast<std::int64_t
>(3 * n), 3, 1});
flow — the Anderson accelerator of a steady march: core's AndersonCore wrapped around one Solver<Grid...
AndersonAccelerator(Solver< Grid > &solver, int window=5, double mixing=1.0)
Builds the march state (throws std::runtime_error on a refused configuration, §5.3) and allocates the...
Solver(int nx, int ny, int nz)
Input validation of the peclet.flow Python binding (src/flow_bindings.cpp only).
flow — host-facing Kokkos IBM Navier-Stokes solver (drop-in flow-style API).
const std::vector< std::string > kAreaModes
const std::vector< std::string > kScalarSchemes
int face_index(const std::string &f, const char *who)
int enum_index(const std::string &v, const std::vector< std::string > &names, const char *who, const char *what)
const std::vector< std::string > kBlockAssign
const std::vector< std::string > kScalarWallTypes
const std::vector< std::string > kBcTypes
const std::vector< std::string > kFaces
auto field3d_out(S &s, peclet::flow::CCField f)
const std::vector< std::string > kFluidOnly
const std::vector< std::string > kAdvSchemes
std::vector< double > grid_in(nb::ndarray< double, nb::f_contig > a)
nb::ndarray< nb::numpy, double > field_out(S &s, std::vector< double > &&v)
const std::vector< std::string > kScalarBcTypes
const std::vector< std::string > kCsfModes
const std::vector< std::string > kAxes
const std::vector< std::string > kPivots
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 retur...
Kokkos::View< double *, CCMem > CCField
void release() noexcept override
void release() noexcept override
The developer tier: a view onto one Solver<Grid> (no state of its own).