26using F3Arg = std::array<float, 3>;
28inline std::string
num(
double v) {
30 std::snprintf(b,
sizeof b,
"%g", v);
33inline void require(
bool ok,
const char* who,
const std::string& name,
const std::string& rule,
36 throw std::invalid_argument(std::string(who) +
": " + name +
" must be " + rule +
", got " +
40inline void finite(
const char* who,
const std::string& name,
double v,
const char* dim) {
41 require(std::isfinite(v), who, name, std::string(
"finite (") + dim +
")", v);
43inline void positive(
const char* who,
const std::string& name,
double v,
const char* dim) {
44 require(std::isfinite(v) && v > 0.0, who, name, std::string(
"finite and > 0 (") + dim +
")", v);
46inline void nonneg(
const char* who,
const std::string& name,
double v,
const char* dim) {
47 require(std::isfinite(v) && v >= 0.0, who, name, std::string(
"finite and >= 0 (") + dim +
")", v);
51 require(std::isfinite(v) && v >= 0.0 && v <= 1.0, who, name,
52 "finite and in [0, 1] (dimensionless)", v);
55inline void poissonRatio(
const char* who,
const char* name,
double v) {
56 require(std::isfinite(v) && v > -1.0 && v <= 0.5, who, name,
57 "finite and in (-1, 0.5] (dimensionless)", v);
60inline std::string
component(
const char* name, std::size_t i) {
61 return std::string(name) +
"[" + std::to_string(i) +
"]";
63template <
class T, std::
size_t N>
64inline void finiteEach(
const char* who,
const char* name,
const std::array<T, N>& a,
66 for (std::size_t i = 0; i <
N; ++i) {
70template <
class T, std::
size_t N>
71inline void positiveEach(
const char* who,
const char* name,
const std::array<T, N>& a,
73 for (std::size_t i = 0; i <
N; ++i) {
77template <
class T, std::
size_t N>
78inline void nonnegEach(
const char* who,
const char* name,
const std::array<T, N>& a,
80 for (std::size_t i = 0; i <
N; ++i) {
85inline void count(
const char* who,
const std::string& name, std::int64_t v, std::int64_t lo) {
86 require(v >= lo, who, name,
"an integer >= " + std::to_string(lo),
static_cast<double>(v));
91 count(who,
"resolution[0]", rx, 1);
92 count(who,
"resolution[1]", ry, 1);
93 count(who,
"resolution[2]", rz, 1);
97 const F3Arg& inv_inertia,
float bounding_radius) {
100 nonnegEach(who,
"inv_inertia", inv_inertia,
"1/length^2");
101 positive(who,
"bounding_radius", bounding_radius,
"length");
105 finiteEach(
"set_domain",
"min", mn,
"length");
106 finiteEach(
"set_domain",
"max", mx,
"length");
107 for (std::size_t i = 0; i < 3; ++i) {
109 "> min[" + std::to_string(i) +
"] = " +
num(mn[i]) +
" (length)", mx[i]);
114 finiteEach(
"add_plane",
"point", p,
"length");
115 finiteEach(
"add_plane",
"normal", n,
"dimensionless");
116 require(n[0] != 0.0f || n[1] != 0.0f || n[2] != 0.0f,
"add_plane",
"normal",
"a non-zero vector",
120inline void mpiBox(
const std::tuple<double, double, double>& origin,
121 const std::tuple<double, double, double>& extent,
122 const std::tuple<long, long, long>& cells) {
123 const auto [ox, oy, oz] = origin;
124 const auto [ex, ey, ez] = extent;
125 const auto [cx, cy, cz] = cells;
126 finiteEach(
"init_mpi",
"origin", std::array<double, 3>{ox, oy, oz},
"length");
127 positiveEach(
"init_mpi",
"extent", std::array<double, 3>{ex, ey, ez},
"length");
128 const std::array<std::int64_t, 3> c{cx, cy, cz};
129 for (std::size_t i = 0; i < 3; ++i) {
136 for (std::size_t i = 0; i < ids.size(); ++i) {
138 "an integer in [0, " + std::to_string(
kMaxMaterialId) +
"]", ids[i]);
void mpiBox(const std::tuple< double, double, double > &origin, const std::tuple< double, double, double > &extent, const std::tuple< long, long, long > &cells)
init_mpi's global box: finite origin, positive extent, at least one ORB cell per axis.
void materialIds(const std::vector< int > &ids)
void nonnegEach(const char *who, const char *name, const std::array< T, N > &a, const char *dim)
std::string component(const char *name, std::size_t i)
Per-component forms for a triple (or a quaternion): the parameter is named name[i].
void sampleCounts(const char *who, int rx, int ry, int rz)
A reconstruction grid's samples per axis (get_sdf_grid / export_sdf): each >= 1.
void finiteEach(const char *who, const char *name, const std::array< T, N > &a, const char *dim)
void restitutionCoef(const char *who, const char *name, double v)
A restitution coefficient: [0, 1], dimensionless.
void positive(const char *who, const std::string &name, double v, const char *dim)
std::string num(double v)
void require(bool ok, const char *who, const std::string &name, const std::string &rule, double v)
void positiveEach(const char *who, const char *name, const std::array< T, N > &a, const char *dim)
void poissonRatio(const char *who, const char *name, double v)
An isotropic solid's Poisson ratio: (-1, 0.5], dimensionless.
void finite(const char *who, const std::string &name, double v, const char *dim)
void nonneg(const char *who, const std::string &name, double v, const char *dim)
std::array< float, 3 > F3Arg
A triple: any sequence of three floats (tuple, list, (3,) array).
void domainCorners(const F3Arg &mn, const F3Arg &mx)
set_domain(min, max): finite corners, max > min on every axis.
void plane(const F3Arg &p, const F3Arg &n)
add_plane: a finite point and a finite, non-zero normal.
constexpr int kMaxMaterialId
Material ids index the 8-entry pair tables (narrowphase.hpp kMaxMaterials).
void count(const char *who, const std::string &name, std::int64_t v, std::int64_t lo)
A count (capacity, iterations, samples per axis): an integer >= lo.
void sdfShapeArgs(const char *who, const F3Arg &origin, const F3Arg &spacing, const F3Arg &inv_inertia, float bounding_radius)
The shared arguments of set_sdf_shape / add_sdf_shape.
constexpr int kMaxMaterials
Pair-material lookup: flat [K*K*2] table, entry ((a*K + b)*2) = restitution, +1 = friction.
dem — portable (Kokkos) narrow-phase: SDF point-shell collision + boundary planes.