Uncertain Geometry#
Geometry is often known only up to a tolerance: a surveyed boundary carries position errors, a cast part wanders around its nominal surfaces, a mapped flood extent has uncertain vertices. The functions of this page carry Gaussian vertex uncertainty into the quantities computed from the vertices, the area and moment integrals of a polygon and the volume of a body. Where the quantity is a polynomial in the vertices the answer is exact, and every result states how it was computed.
Left: an icosahedral body with uncertain vertices. The shaded faces are the mean body, the orange lines are fourteen bodies drawn at the vertex covariance and the green ellipsoids are the two sigma clouds of the vertices facing the viewer. Right: the volumes of 20 000 such draws, each evaluated exactly, against the exact mean and one sigma band of the analytical mode, which carry no sampling error. The exact mean sits above the volume of the mean body, because the shared part of the tolerance breathes the whole body.
from prophys.structures.geometry_uncertainty import solid_volume_moments
report = solid_volume_moments(mean_vertices, faces, vertex_covariance)
report.mean, report.variance # exact, from the closed form
report.mode, report.exact # "analytical_gaussian", True
Which quantity, which method#
Quantity |
Function |
Method and result |
|---|---|---|
Signed area of a ring |
Analytical, exact mean and variance |
|
The six moment integrals of a ring |
Analytical, exact means, no variances claimed |
|
Volume of a triangulated body |
Analytical, exact mean and variance |
|
Area centroid of a ring |
First order delta method, approximate |
|
Any of the above, or a non Gaussian tolerance |
Reparameterized Monte Carlo, with a standard error |
The covariance is always the covariance of the flattened vertex coordinates,
(2v, 2v) for a ring of v vertices and (3v, 3v) for a body, so
coupling between vertices is part of it.
The shapes and their exact moments#
The propagation builds on deterministic moment integrals of the structures, exact closed forms with exact gradients in the vertices:
moments()returns the six signed moment integrals of a ring,[A, Sx, Sy, Sxx, Syy, Sxy].area_centroid(),second_moments()andinertia()derive the centroid and the moments of inertia from them.VertexPolyhedronis a convex body given by its vertices and an outward oriented triangulated surface. Itsvolume(),first_moments(),second_moments()andinertia()are divergence theorem closed forms, andsigned_distance()andcontains()answer point queries.
The vertices may be a Param, a draw or any
expression, so a body can be optimized or made uncertain directly.
The analytical mode#
The shoelace area of a ring is quadratic in its vertices, and the divergence theorem volume of a body is trilinear in them. Both are polynomials of the Gaussian vertex vector, so their mean and variance are finite sums over the pairings of the vertex covariance (Isserlis 1918). The native kernels compute these sums, with exact gradients in the mean vertices and in the covariance.
from prophys.structures.geometry_uncertainty import polygon_area_moments
area = polygon_area_moments(mean_vertices, vertex_covariance) # exact for any ring
area.mean, area.variance
Left: an octagonal ring (bold) with nine draws at the vertex covariance and the one sigma ellipse of every survey point. Right: the areas of 40 000 draws against the exact mean and the exact one sigma band.
A tolerance usually has two parts: every vertex wanders on its own, and some shared cause, such as die wear in a casting, moves all vertices together. The shared part is a low rank block of the covariance, and only it can move the mean volume, because each vertex enters the volume linearly in its own coordinates.
The exact mean (left) and standard deviation (right) of the volume of the icosahedral body over the two parts of its tolerance, one exact call per grid point. The mean does not change along the independent wander and rises with the square of the shared breathing. The standard deviation is dominated by the shared part, which moves every vertex in the same direction.
The Monte Carlo mode and the delta method#
Quantities without a claimed closed form are propagated by reparameterized Monte Carlo through the same kernels: each draw is the mean plus the Cholesky factor times standard normal draws, each draw is evaluated exactly, and the mean carries its standard error.
from prophys.structures.geometry_uncertainty import montecarlo_solid_volume
check = montecarlo_solid_volume(mean_vertices, faces, vertex_covariance, n_samples=8192)
check.mean, check.std_error, check.mode # "montecarlo"
A degenerate draw, a ring with zero area or an inverted surface, raises
GEO101 instead of being dropped, so the estimate never averages over
silently filtered geometry.
The area centroid is a ratio of moment integrals, not a polynomial. It is
propagated by the first order delta method through its exact Jacobian,
J Cov J^T, and reported as such:
from prophys.structures.geometry_uncertainty import polygon_centroid_moments
centroid = polygon_centroid_moments(mean_vertices, vertex_covariance)
centroid.mode, centroid.exact # "delta_first_order", False
centroid.components # {"cx": ..., "cy": ...}
centroid.covariance # the 2 by 2 delta method covariance
Every result says how it was computed#
Every function returns a GeometryMoments
record. mode is one of PROPAGATION_MODES,
exact is True only for the analytical mode, std_error and
n_samples hold the Monte Carlo error when there is one, and
diagnostics holds the findings of the propagation. A quantity with
several parts, the six moment integrals of a ring or the two coordinates of
a centroid, also lists every part by name in components and, where the
method yields one, their covariance in covariance. The same findings
reach the console with the stable codes GEO101 to GEO204, listed on
the Diagnostics page.
The precise scope of the exactness claim
A quantity is computed analytically only when its closed form is a polynomial in the vertices and the vertex distribution is Gaussian with the given mean and covariance. The mean and variance are then finite sums of Isserlis pairings, evaluated without truncating any series, and they are exact for the stated quantity and distribution.
polygon_moment_means()
returns exact means of all six moment integrals and deliberately no
variances: the cubic and quartic integrals would need pairings of order
six and eight. Moments follow the winding of the vertices, so a ring with
the opposite orientation reports negated moments.
Every other quantity, a centroid, a containment probability or anything under a non Gaussian tolerance, carries Monte Carlo or delta method error and says so in its record.
An uncertain body inside a model#
Because the vertices may be an expression, an uncertain body can sit inside a compiled model: its volume and inertia become quantities whose distribution follows from the tolerance, the covariance can be calibrated to measurements, and a mass or centre of gravity constraint can enter a design optimization with exact gradients. In Example: Stator Whine of an Inverter Driven Motor the exact volume moments of a cast bracket give the distribution of its mass, cross checked by Monte Carlo.
Reference#
- class prophys.structures.VertexPolyhedron(vertices, faces, frame, registry=None)[source]#
A convex 3D polyhedron given by its vertices and a triangulated closed surface.
vertices has shape
(v, 3)and may be any expression (a Param, a RandomVariable draw, a gradient carrying array), so the body’s position and shape can be optimized or made uncertain. faces has shape(t, 3)vertex indices and is fixed connectivity, with outward orientation (the volume is positive exactly when the faces wind outward). Convexity is required for the containment test, while the volume and the moment integrals are exact for any closed oriented surface.Every operation runs in a native kernel with an exact analytic gradient with respect to the vertices. There is deliberately no smoothed variant:
SMOOTH_GEOMETRYisFalse, and atauargument that requests one raisesGEO102instead of quietly returning hard geometry from anmode="opt"compile.- Parameters:
vertices (Any) –
(v, 3)body vertices, an array or an expression.faces (Any) –
(t, 3)vertex indices of each outward oriented triangle.frame (Frame) – Coordinate frame (
ndim=3).registry – Frame registry used to align query points.
Example:
box = prp.VertexPolyhedron(cube_vertices, cube_faces, frame=site3d) vol = box.volume() # exact divergence theorem volume, differentiable
- VERTEX_EXACT_GRADIENTS = frozenset({'contains', 'first_moments', 'inertia', 'second_moments', 'signed_distance', 'volume'})#
Names of this structure’s operations with an exact analytic gradient with respect to the vertices. The signed distance and containment select the winning face, so their vertex gradient follows that one face and is exact except on the set of points with two winning faces.
- SMOOTH_GEOMETRY = False#
This structure has no smoothed (
mode="opt") geometry variant. Its containment and distance are always the exact hard forms, which a gradient based compile must not discover silently.
- volume()[source]#
Return the enclosed volume, shape
().The divergence theorem form
V = sum_f det(a_f, b_f, c_f) / 6over the faces, trilinear in the vertices with an exact analytic gradient. A flat, non closed or inconsistently oriented surface encloses zero volume and an inward winding one a negative volume, and both raiseGEO101.- Return type:
- second_moments()[source]#
Return the second moments about the origin
(Sxx, Syy, Szz, Sxy, Sxz, Syz), shape(6,).Sxx = int(x^2 dV)andSxy = int(x y dV)over the body, divergence theorem closed forms that are exact polynomials in the vertices, with exact analytic vertex gradients.- Return type:
- first_moments()[source]#
Return the first moments about the origin
(Sx, Sy, Sz), shape(3,).Sx = int(x dV)over the body, a divergence theorem closed form that is an exact polynomial in the vertices, with an exact analytic vertex gradient.- Return type:
- inertia()[source]#
Return the mass moments of inertia about the centroid as the
(3, 3)tensor, for unit density.The tensor with
Ixx = int((y - cy)^2 + (z - cz)^2) dVabout the body’s centroid, built from the exact first and second moment integrals by the parallel axis theorem, so it is invariant under translation of the body. Differentiable in the vertices. Multiply by a density for the mass moments of a homogeneous body.- Return type:
- signed_distance(points)[source]#
Return the signed distance of each point to the body, negative inside, shape
(n,).The largest normalized face slack
max_f n_f . (x - a_f), which is exact inside and underestimates the distance outside near edges and corners, likePolyhedron.signed_distance(). The gradient is exact in the query point (the winning face’s normal) and in the three vertices of the winning face. A flat face raisesGEO101.
- contains(points, tau=None)[source]#
Return a hard containment indicator for each point, 0 or 1, shape
(n,).Always the exact hard form: this structure has no smoothed variant (
SMOOTH_GEOMETRYisFalse). Passing a positive tau requests one and raisesGEO102rather than quietly returning hard geometry.
- class prophys.structures.GeometryMoments(name, mean, variance, mode, exact, std_error=None, n_samples=None, note='', diagnostics=(), components=None, covariance=None)[source]#
Mean and variance of one geometry quantity under vertex uncertainty.
Returned by the propagation functions of this module. mode is one of
PROPAGATION_MODESand states how the numbers were computed, and exact is True only for the analytical mode, where mean and variance are 100 percent accurate for the stated functional and distribution. Monte Carlo results carry std_error, the standard error of the mean from the draws used. diagnostics holds the findings the propagation emitted (the mode statement and any straddle warning), so the mode is part of the returned record and not only of the console stream.A quantity with several components (the six moment integrals of a ring, the two coordinates of a centroid) reports its leading component in mean and variance and every component by name in components, with their covariance matrix, in the same order, in covariance when the propagation provides one.
- prophys.structures.geometry_uncertainty.polygon_area_moments(mean_vertices, covariance, *, where='polygon area')[source]#
Exact mean and variance of the signed area of a Gaussian ring.
mean_vertices is the ring’s mean vertex array
(v, 2)and covariance the symmetric covariance of its flattened coordinates(2v, 2v). The signed area is quadratic in the vertices, so both moments are exact Isserlis pairings of the covariance (Isserlis 1918), computed by a native kernel with exact gradients in the mean vertices and the covariance. The moments follow the winding: report them for the orientation of mean_vertices.- Returns:
A
GeometryMomentswith mode"analytical_gaussian", exact, plus an info diagnostic (GEO201) stating the mode.- Parameters:
- Return type:
- prophys.structures.geometry_uncertainty.polygon_moment_means(mean_vertices, covariance, *, where='polygon moments')[source]#
Exact Gaussian means of the six moment integrals of a ring.
The area is quadratic and the first and second moments are cubic and quartic polynomials of the vertices, and the mean of a polynomial of a Gaussian is its exact Isserlis form, so every mean here is exact. The variances are deliberately not claimed: the cubic and quartic integrals would need pairings of order six and eight, so use
montecarlo_polygon_moments()for those.- Returns:
A
GeometryMomentswith mean set to the exact mean area, the six exact means by name in components (seeMOMENT_ORDER) and variance None, mode"analytical_gaussian"(GEO201).- Parameters:
- Return type:
- prophys.structures.geometry_uncertainty.polygon_centroid_moments(mean_vertices, covariance, *, where='polygon area centroid')[source]#
First order delta method mean and covariance of the area centroid.
The area centroid is a ratio of moment integrals, not a polynomial, so no exact closed form of its distribution is claimed here. The mean is the centroid of the mean vertices and the covariance is the delta method
J Cov J^Tthrough the exact analytic JacobianJof the centroid with respect to the vertices. This is a first order approximation whose quality falls with the curvature of the centroid over the vertex uncertainty: the mode is reported as such (GEO204), never passed off as analytical exact.- Returns:
A
GeometryMomentswith mean and variance ofcx, both coordinates in components and their delta method covariance in covariance, mode"delta_first_order".- Parameters:
- Return type:
- prophys.structures.geometry_uncertainty.solid_volume_moments(mean_vertices, faces, covariance, *, where='solid volume')[source]#
Exact mean and variance of the volume of a Gaussian triangulated body.
mean_vertices is the body’s mean vertex array
(v, 3), faces its(t, 3)outward oriented triangulation and covariance the symmetric covariance of the flattened coordinates(3v, 3v). The divergence theorem volume is trilinear in the vertices, so the mean needs pairings of order two and the variance pairings up to order six, both exact Isserlis forms computed by a native kernel with exact gradients in the mean vertices and the covariance.- Returns:
A
GeometryMomentswith mode"analytical_gaussian", exact, plus an info diagnostic (GEO201) stating the mode.- Parameters:
- Return type:
- prophys.structures.geometry_uncertainty.montecarlo_polygon_moments(mean_vertices, covariance, n_samples=8192, seed=0, *, where='polygon moments')[source]#
Monte Carlo mean and variance of the signed area of a Gaussian ring.
Draws n_samples reparameterized vertex vectors from the given mean and covariance and evaluates the native moment kernel on each, so the estimate covers every moment integral, the winding sign included, with its standard error reported. The mean ring must itself be non degenerate (
GEO101before any draw) and a degenerate draw (a ring with zero signed area) raisesGEO101instead of being skipped, so the estimate never averages over a quietly accepted or silently dropped ring. Use this for the quantities whose exact closed form is not claimed (the variances of the cubic and quartic moments) or under a transformed vertex distribution.- Returns:
mean and variance of the signed area with the standard error of the mean and n_samples, the sample means of all six integrals by name in components and their sample covariance in covariance.
- Return type:
A
GeometryMomentswith mode"montecarlo"(GEO202)- Parameters:
- prophys.structures.geometry_uncertainty.montecarlo_solid_volume(mean_vertices, faces, covariance, n_samples=8192, seed=0, *, where='solid volume')[source]#
Monte Carlo mean and variance of the volume of a Gaussian body.
The reparameterized Monte Carlo counterpart of
solid_volume_moments(), for cross checking the closed form or for vertex distributions the analytical kernel does not claim. The mean body must itself be valid (GEO101before any draw) and a draw whose surface is flat, non closed or inverted raisesGEO101instead of being skipped, so the estimate never averages over a quietly accepted or silently dropped body.- Returns:
A
GeometryMomentswith mode"montecarlo"(GEO202).- Parameters:
- Return type:
- prophys.structures.geometry_uncertainty.PROPAGATION_MODES#
Propagation modes and when each one is exact. A quantity is propagated analytically only when its closed form is a polynomial in the vertices and the vertex distribution is Gaussian with the given mean and covariance, in which case the mean needs pairings up to the polynomial’s degree and the variance pairings up to twice it, all exact. Everything else is Monte Carlo (or the delta method where stated), and its result carries Monte Carlo error.