29inline std::string
num(
double v) {
31 std::snprintf(b,
sizeof b,
"%g", v);
34inline void require(
bool ok,
const char* who,
const std::string& name,
const std::string& rule,
37 throw std::invalid_argument(std::string(who) +
": " + name +
" must be " + rule +
", got " +
41inline std::string
component(
const char* name, std::size_t i) {
42 return std::string(name) +
"[" + std::to_string(i) +
"]";
46inline void triple(
const char* who,
const char* name, std::size_t size) {
48 throw std::invalid_argument(std::string(who) +
": " + name +
49 " must be 3 values (z, y, x), got " + std::to_string(size));
53inline void finiteEach(
const char* who,
const char* name,
const std::vector<double>& a,
55 for (std::size_t i = 0; i < a.size(); ++i) {
57 std::string(
"finite as float32 (") + dim +
")", a[i]);
61inline void positiveEach(
const char* who,
const char* name,
const std::vector<double>& a,
63 for (std::size_t i = 0; i < a.size(); ++i) {
64 const float f =
static_cast<float>(a[i]);
66 std::string(
"finite and > 0 as float32 (") + dim +
")", a[i]);
70inline void countEach(
const char* who,
const char* name,
const std::vector<int>& a,
int lo) {
71 for (std::size_t i = 0; i < a.size(); ++i) {
73 "an integer >= " + std::to_string(lo) +
" (voxels)", a[i]);
80inline void spacingZyx(
const char* who,
const std::vector<double>& spacing) {
81 triple(who,
"spacing_zyx", spacing.size());
82 positiveEach(who,
"spacing_zyx", spacing,
"length units");
85inline void grid(
const char* who,
const std::vector<double>& origin,
86 const std::vector<double>& spacing) {
87 triple(who,
"origin_zyx", origin.size());
88 finiteEach(who,
"origin_zyx", origin,
"length units");
93inline void globalShapeZyx(
const char* who,
const std::vector<int>& shape,
bool sized) {
95 triple(who,
"global_shape_zyx", shape.size());
97 countEach(who,
"global_shape_zyx", shape, 1);
103 if (!shape || shape->size() != 3) {
106 countEach(
"extract_topology",
"shape_zyx", *shape, 0);
108 for (
int s : *shape) {
109 require(!__builtin_mul_overflow(n,
static_cast<std::size_t
>(s), &n),
"extract_topology",
110 "shape_zyx",
"a grid whose voxel count fits in 64 bits",
static_cast<double>(s));
115inline void initPore(
Pore* p,
float x,
float y,
float z,
float radius) {
116 require(std::isfinite(x),
"Pore",
"x",
"finite (length units)", x);
117 require(std::isfinite(y),
"Pore",
"y",
"finite (length units)", y);
118 require(std::isfinite(z),
"Pore",
"z",
"finite (length units)", z);
119 require(std::isfinite(radius) && radius >= 0.0f,
"Pore",
"radius",
120 "finite and >= 0 (length units)", radius);
121 new (p)
Pore{x, y, z, radius};
void finiteEach(const char *who, const char *name, const std::vector< double > &a, const char *dim)
Each component finite once narrowed to float32 (a coordinate: any sign).
std::string num(double v)
std::string component(const char *name, std::size_t i)
void grid(const char *who, const std::vector< double > &origin, const std::vector< double > &spacing)
origin_zyx + spacing_zyx of extract_pores / extract_pore_network(_mpi).
void topologyShape(const std::optional< std::vector< int > > &shape)
extract_topology's shape_zyx, when given as three values: voxel counts >= 0 whose product fits in std...
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::vector< double > &a, const char *dim)
Each component finite and > 0 once narrowed to float32 (a cell size).
void spacingZyx(const char *who, const std::vector< double > &spacing)
spacing_zyx: the grid's cell size per axis, three values > 0 (length units).
void globalShapeZyx(const char *who, const std::vector< int > &shape, bool sized)
The global grid of the ORB decomposition: at least one voxel per axis.
void countEach(const char *who, const char *name, const std::vector< int > &a, int lo)
Each component an integer >= lo (a voxel count).
void triple(const char *who, const char *name, std::size_t size)
A z-y-x triple: exactly three values.
void initPore(Pore *p, float x, float y, float z, float radius)
Pore(x, y, z, radius): a finite centre and a finite radius >= 0 (Pore() is all zeros).
peclet.pnm — the ONE set of stage kernels shared by the single-rank (pore_extraction....