Algorithmadvanced
Direct linearization method
Also called DLM tolerance analysis.
Chase and coauthors' tolerance analysis that linearizes the vector loops of an assembly to get sensitivities, then worst case or statistical variation.
- Time
- O(k (V m + m^3) + V (m + n) + m^3 + n m^2) worst
- Space
- O(m (m + n)) extra
- Where
- V = number of vectors in the loops; k = number of Newton steps; m = number of kinematic variables, two per 2D loop; n = number of manufactured variables
- Model
- Real RAM
- Properties
- deterministicnot exactiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Kenneth W. Chase, Jinsong Gao, Spencer P. Magleby, 1995
The direct linearization method (DLM) is a tolerance analysis for assemblies whose parts adjust to each other when they are put together, such as a roller that rolls until it touches two surfaces. Chase, Gao and Magleby published it in 1995. The assembly is written as closed vector loops, , where are the part dimensions that have tolerances and are the kinematic variables that the assembly finds by itself. DLM solves the loops once at the nominal dimensions, takes the partial derivatives and , and gets the sensitivity of every output to every dimension from , with no explicit formula for the output. The worst-case and RSS formulas of tolerance stack-up then give the variation. Its model of variation is a first-order (small change) Taylor expansion of the assembly function at the nominal point; this page proves it and bounds its error. Monte Carlo analysis solves the loops exactly for each sample instead, at a higher cost.
In plain words
In many assemblies a gap or an angle is not a sum of part dimensions. It comes out of how the parts settle against each other. You can still write the geometry as chains of arrows that must close into loops. Solve these loops once for the nominal parts. Then ask a linear question: if one dimension changes a little, how much must the free quantities change for the loops to stay closed? That answer is one small linear system, and it gives the sensitivity of the output to each dimension. With the sensitivities, the usual stack-up rules give the worst case and the statistical spread. The method is fast and exact for small changes. For large tolerances it misses the curvature of the true assembly function, and it cannot tell that some parts no longer fit together at all.
The problem
Input: closed vector loops with manufactured variables (lengths and angles of parts, each with a nominal value and a symmetric tolerance ), kinematic variables (two per loop in the plane, six per loop in space), a starting guess for , and an output, one kinematic variable such as a gap or a contact angle.
Output: the nominal output , the sensitivities , the worst-case half-width , and the RSS half-width .
The model of variation is that each deviates from its nominal by : in the worst-case form any , and in the statistical form independent with mean and standard deviation . The output is replaced by its first-order expansion .
The algorithm
DLM(h, x0, u_guess, T, k) ▷ loops h, nominal x0, tolerances T, output u_k- 1
u0 ← NEWTON(h, x0, u_guess) ▷ assemble the nominal parts - 2
A ← ∂h/∂x at (x0, u0); B ← ∂h/∂u at (x0, u0) - 3
for j ← 1 to n do - 4
solve B s_j = −A_j ▷ error if B is singular - 5
S_j ← component k of s_j ▷ ∂u_k / ∂x_j - 6
W ← Σ_j |S_j| T_j ▷ worst case - 7
R ← sqrt(Σ_j S_j² T_j²) ▷ RSS, 3 sigma - 8
return u0_k, S, W, R NEWTON(h, x, u)- 9
repeat - 10
r ← h(x, u) - 11
solve B(x, u) δ = −r; u ← u + δ - 12
until |δ| is below a tolerance and |h(x, u)| is small - 13
return u
The derivatives. A vector of the loop is , with sign , length (a constant or a variable) and absolute angle , an affine function of angle variables. Its derivative with respect to is , and with respect to it is . Line L2 sums these over the vectors; no finite differences are needed. The rows of and are the and sums of each loop.
Why . If changes by and by , the loops stay closed to first order when , so . Lines L3 to L5 compute column of and keep row . When the output is not a kinematic variable but a function , the same columns give .
Example
The one-way clutch. This is Chase's standard 2D example. A hub has a flat at distance from the centre of a ring of inner radius , and a roller of radius wedges between them. The kinematic variables are the position of the roller contact along the flat and the pressure angle between the two contact normals, which decides whether the clutch locks. The loop goes from the ring centre along the flat ( at ), up to the flat ( at ), up to the roller centre ( at ), and back to the ring centre along the line through the roller contact ( at ). It closes when and .
Take , , mm, each with tolerance mm. Newton's method gives mm and . DLM gives:
| dimension | (rad per mm) | (rad) |
|---|---|---|
These agree with the derivatives of the closed form, and so on. The worst case is rad, so , and the RSS value is rad, so at 3 sigma. At the eight corners of the tolerance box the exact ranges from to around the nominal: the linear range is off by at each end, the second-order error that the correctness proof bounds. With mm on each dimension DLM says , but the corners give to , a clearly skewed range. With mm the corner , , has , so the roller does not fit at all; DLM still returns a number.
A linear stack. The housing gap of the stack-up page, with and of , written as one loop, gives sensitivities , nominal , and , the stack-up results.
Correctness
The proof is in the correctness proof. In short:
- The partial derivatives of line L2 are exact, by the chain rule on each vector.
- If is nonsingular at the nominal assembly, the implicit function theorem gives a smooth solution near with derivative . So the sensitivities of line L5 are the exact first derivatives of the output.
- By Taylor's theorem, with , where bounds the Hessian of .
- The worst-case value of line L6 is the exact range of the linear part over the tolerance box, and the true range is within .
- If the deviations are independent with standard deviations , the linear part has standard deviation exactly . If they are also normal, it lies in with probability . Independence is needed for the variance and normality for the probability.
- If every angle is a constant, the loops are linear and DLM is exact for any change.
Proof: The DLM sensitivities are the exact first derivatives, and the worst-case and RSS results follow with a second-order errorfull
Setting. The loops give equations , with the manufactured variables and the kinematic variables. Each component of is a sum of terms or , where is a constant or a variable and is an affine function of the variables, so is infinitely differentiable. Let , and let and at . The output is one kinematic variable .
Claim.
- The partial derivatives that lines L2 and L4 use are exact.
- If is nonsingular, then near there is a unique smooth solution with , and the vector of line L5 is the gradient of at .
- For a change of , with , where bounds the norm of the Hessian of on the segment from to .
- If for all , the linear part ranges exactly over with (line L6). So the true output lies in .
- If the are independent with mean and standard deviations , the linear part has standard deviation exactly , one third of line L7. If the are also normal, the linear part is normal and lies within the RSS value with probability .
- If every angle is a constant, and every variable is a length, then is affine and : DLM is exact for any size of change.
Proof of 1. A term with has the partial derivative with respect to when is a variable, and with respect to , by the chain rule. The function loop_jacobian adds exactly these terms, and a variable that occurs in several terms gets the sum of their derivatives.
Proof of 2. This is the implicit function theorem (Rudin, Principles of Mathematical Analysis, Theorem 9.28): is continuously differentiable, and is invertible, so there are neighborhoods of and of and a unique continuously differentiable with . Here is smooth, so is smooth too. Differentiate at : , so . Line L4 solves for each column of , so is column of , and line L5 takes its component , which is .
Proof of 3. Let for , assuming the segment lies in . Taylor's theorem with the Lagrange remainder gives for some . Here and , with the Hessian of , so .
Proof of 4. The linear function is separable, so its maximum over the box is , at . Its minimum is by symmetry, and every value between is taken because the box is connected. Adding the bound of part 3, with , gives the range of the true output.
This is the worst-case formula of tolerance stack-up applied to the sensitivities. It is exact for the linear part only. The true range can be larger or smaller than by up to , and it need not be symmetric.
Proof of 5. By linearity of expectation , and by independence the variances add: . A linear combination of independent normal variables is normal, and a normal variable lies within 3 standard deviations of its mean with probability .
This is the RSS formula of tolerance stack-up. Independence is needed for the variance, and normality only for the probability. The remainder adds a bias: for smooth and symmetric , which shifts the mean of the output away from . DLM does not see this shift.
Proof of 6. With constant angles, for constant matrices and and a constant vector , and then and at every point. If is invertible, , which is affine, so its Hessian is zero and in part 3.
Line L1 and the Newton loop. Lines L9 to L12 are Newton's method for . The implementation returns only when the last step is below the tolerance and the residual is below , and otherwise raises an error, so every returned satisfies the loops to that accuracy. Newton's method converges quadratically from a start close enough to a solution with nonsingular ; from a poor start it can fail or reach another assembly branch, such as the crossed form of a four-bar. That is why the caller supplies the starting guess.
Complexity
Each Newton step of lines L9 to L12 builds the matrix in time and solves with it in , so the nominal assembly costs for steps. Line L2 builds and in . Factor once in , and each of the solves of line L4 costs , so the sensitivities cost . The code of this page eliminates afresh for each column, , which is fine for the few loops of a real assembly. Lines L6 and L7 take . The extra space is for and . Unlike Monte Carlo, the cost does not grow with the number of samples: one linear solve replaces all of them.
Properties
- Local. The sensitivities are exact derivatives at the nominal point, and the variation is exact only for the linear part.
- Symmetric. Its worst-case and RSS ranges are symmetric about the nominal output, even when the true range is not.
- Distribution-free variance. The RSS variance of the linear part needs independence but no distribution shape.
- Exact for linear loops. With fixed angles, the output is affine in the dimensions and the method has no error.
- Deterministic. The same input gives the same output; no sampling.
Variants and improvements
- 3D loops. Gao, Chase and Magleby replace the 2D vectors by 3D vectors and rotations, with six equations per loop.
- Geometric feature variations. Form, orientation and position variations of features can be modeled as extra small vectors or rotations at the contacts, which keeps the method linear. The small displacement torsor and Jacobian-torsor models build the same kind of linear map from 3D feature frames.
- Mean shift and second order. The proof shows the bias of the output mean. Adding second derivatives estimates it. The estimated mean shift model of the stack-up page adds a worst-case part for process drift.
- Allocation. The sensitivities are the input of tolerance allocation, which chooses the at least cost.
- Simulation. When the assembly is far from linear or a fit can fail, Monte Carlo analysis solves the loops for each sample.
When to use it
Use DLM for an assembly with small kinematic adjustments where the tolerances are small against the dimensions, as in most machined parts. It gives sensitivities, which show where tightening a tolerance helps most, and it costs one linear solve. Check the result with Monte Carlo when the tolerances are large relative to the curvature of the assembly function, when the output is near a limit of assembly (such as the clutch at large tolerances), or when the distributions are far from normal.
Pitfalls
- Singular B. Near a toggle position of a linkage, or when two kinematic vectors are parallel, is singular or close to it, and the sensitivities blow up. The method then says nothing useful.
- The wrong branch. A loop can close in several ways, such as the open and crossed forms of a four-bar linkage. Newton's method finds the one near its starting guess; start from the drawing.
- Parts that do not fit. DLM never checks that each sample assembles. A worst-case corner can be impossible, as in the clutch example.
- Units. Angles are in radians in the derivatives. A tolerance in degrees must be converted.
- Correlated dimensions. RSS assumes independent dimensions. Two dimensions from one setup are not.
- Mean shift. A curved assembly function moves the mean of the output away from its nominal value even for centred inputs; DLM reports the nominal value as the mean.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/direct-linearization-method/. The authors are listed in prov/3NRTQF.jsonl.
"""Direct linearization method (DLM) for 2D vector loops.
An assembly is a list of closed vector loops in the plane. Each vector is a
triple (sign, length, angle):
- sign is +1 or -1;
- length is a number or the name of a variable;
- angle is a pair (const, coefs): the absolute angle in radians is
const + sum(coef * value[name] for name, coef in coefs.items()).
The variables are split into manufactured ones x (part dimensions with
tolerances) and kinematic ones u (the adjustments of the assembly, such as a
gap, a contact position or a joint angle). Loop closure is h(x, u) = 0, two
equations per loop. DLM solves the loops at the nominal x, forms the partial
derivatives A = dh/dx and B = dh/du, and takes the sensitivities of a
kinematic output u_k as the k-th row of -B^-1 A. The worst-case and RSS
variations then follow from the stack-up formulas.
"""
import math
def vector_angle(angle, values):
"""Absolute angle of a vector from its (const, coefs) description."""
const, coefs = angle
return const + sum(c * values[name] for name, c in coefs.items())
def vector_length(length, values):
return values[length] if isinstance(length, str) else float(length)
def loop_residual(loops, values):
"""h(x, u): the x and y sums of each loop, 2 numbers per loop."""
out = []
for loop in loops:
sx = sy = 0.0
for sign, length, angle in loop:
L = vector_length(length, values)
th = vector_angle(angle, values)
sx += sign * L * math.cos(th)
sy += sign * L * math.sin(th)
out += [sx, sy]
return out
def loop_jacobian(loops, values, names):
"""Partial derivatives of h with respect to the variables in names.
d/d(length L) of sign * L * (cos t, sin t) is sign * (cos t, sin t), and
d/d(angle variable with coefficient c) is sign * L * c * (-sin t, cos t).
"""
col = {n: j for j, n in enumerate(names)}
rows = [[0.0] * len(names) for _ in range(2 * len(loops))]
for i, loop in enumerate(loops):
for sign, length, angle in loop:
L = vector_length(length, values)
th = vector_angle(angle, values)
ct, st = math.cos(th), math.sin(th)
if isinstance(length, str) and length in col:
j = col[length]
rows[2 * i][j] += sign * ct
rows[2 * i + 1][j] += sign * st
for name, c in angle[1].items():
if name in col:
j = col[name]
rows[2 * i][j] += -sign * L * c * st
rows[2 * i + 1][j] += sign * L * c * ct
return rows
def solve_linear(M, rhs):
"""Solve M y = rhs by Gaussian elimination with partial pivoting.
Raises ValueError if M is singular to working precision.
"""
n = len(M)
if any(len(r) != n for r in M) or len(rhs) != n:
raise ValueError("the system is not square")
a = [list(map(float, r)) + [float(b)] for r, b in zip(M, rhs)]
scale = max((abs(v) for r in M for v in r), default=0.0) or 1.0
for k in range(n):
p = max(range(k, n), key=lambda i: abs(a[i][k]))
if abs(a[p][k]) <= 1e-12 * scale:
raise ValueError("B is singular: the loops do not fix the kinematic variables")
a[k], a[p] = a[p], a[k]
for i in range(k + 1, n):
f = a[i][k] / a[k][k]
if f:
for j in range(k, n + 1):
a[i][j] -= f * a[k][j]
y = [0.0] * n
for k in range(n - 1, -1, -1):
s = a[k][n] - sum(a[k][j] * y[j] for j in range(k + 1, n))
y[k] = s / a[k][k]
return y
def solve_assembly(loops, x, u_guess, kin_names, tol=1e-13, max_iter=60):
"""Newton's method for h(x, u) = 0 in the kinematic variables u.
x and u_guess are dicts. Returns the dict of all values at the solution.
Raises ValueError if Newton does not converge.
"""
values = dict(x)
values.update(u_guess)
for _ in range(max_iter): # @line L9
r = loop_residual(loops, values) # @line L10
B = loop_jacobian(loops, values, kin_names)
step = solve_linear(B, [-v for v in r]) # @line L11
for name, d in zip(kin_names, step):
values[name] += d
if max(abs(d) for d in step) <= tol * (1.0 + max(abs(values[n]) for n in kin_names)): # @line L12
if max(abs(v) for v in loop_residual(loops, values)) <= 1e-9:
return values # @line L13
raise ValueError("Newton's method did not converge")
def dlm(loops, x0, u_guess, man_names, kin_names, tolerances, output):
"""Direct linearization of a kinematic output.
loops: the vector loops; x0: nominal manufactured values (dict);
u_guess: a starting guess for the kinematic values (dict);
man_names, kin_names: the variable names in order;
tolerances: dict name -> symmetric tolerance T_j;
output: the name of the kinematic variable that is the assembly output.
Returns a dict with the nominal output, the sensitivities, the worst-case
half-width sum |S_j| T_j and the RSS half-width sqrt(sum S_j^2 T_j^2).
"""
if 2 * len(loops) != len(kin_names):
raise ValueError("need exactly two kinematic variables per loop")
values = solve_assembly(loops, x0, u_guess, kin_names) # @line L1
A = loop_jacobian(loops, values, man_names) # @line L2
B = loop_jacobian(loops, values, kin_names)
k = kin_names.index(output)
sens = {}
for j, name in enumerate(man_names): # @line L3
col = solve_linear(B, [-A[i][j] for i in range(len(A))]) # @line L4
sens[name] = col[k] # @line L5
worst = sum(abs(sens[n]) * tolerances[n] for n in man_names) # @line L6
rss = math.sqrt(sum((sens[n] * tolerances[n]) ** 2 for n in man_names)) # @line L7
return {"nominal": values[output], "values": values, "sens": sens, "worst": worst, "rss": rss} # @line L8
# Example assemblies used on the page and in the tests.
def clutch_loops():
"""One-way clutch: hub flat at distance a, roller radius c, ring radius e.
Kinematic variables: b (contact point along the flat) and phi (the
pressure angle between the two contact normals). The loop goes from the
ring centre along the flat (b), up to the flat (a), up to the roller
centre (c), and back to the ring centre along the line of radius e - c,
whose angle is 90 degrees minus phi.
"""
half_pi = math.pi / 2
back = (half_pi, {"phi": -1.0})
return [[
(1, "b", (0.0, {})),
(1, "a", (half_pi, {})),
(1, "c", (half_pi, {})),
(1, "c", back),
(-1, "e", back),
]]
def fourbar_loops():
"""Four-bar linkage with fixed input angle th2 (a constant of the model).
Manufactured: crank a, coupler b, rocker c, ground d.
Kinematic: coupler angle th3 and rocker angle th4.
"""
return [[
(1, "a", (0.0, {"th2": 1.0})),
(1, "b", (0.0, {"th3": 1.0})),
(-1, "c", (0.0, {"th4": 1.0})),
(-1, "d", (0.0, {})),
]]
def linear_stack_loops():
"""End gap of a 1D stack: G = A - B - C - D, written as a vector loop.
The vertical vectors (kinematic h, constant 1) only make B square.
"""
return [[
(1, "A", (0.0, {})),
(-1, "B", (0.0, {})),
(-1, "C", (0.0, {})),
(-1, "D", (0.0, {})),
(-1, "G", (0.0, {})),
(1, "h", (math.pi / 2, {})),
(-1, 1.0, (math.pi / 2, {})),
]]
test_direct_linearization_method.py 183 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/direct-linearization-method/. The authors are listed in prov/3NRTQF.jsonl.
import itertools
import math
import random
import pytest
from direct_linearization_method import (
clutch_loops,
dlm,
fourbar_loops,
linear_stack_loops,
loop_residual,
solve_assembly,
)
CLUTCH_X = {"a": 27.645, "c": 11.43, "e": 50.8}
CLUTCH_MAN = ["a", "c", "e"]
CLUTCH_KIN = ["b", "phi"]
CLUTCH_GUESS = {"b": 4.0, "phi": 0.1}
def clutch_exact(x):
"""Closed form of the clutch: cos(phi) = (a + c) / (e - c)."""
a, c, e = x["a"], x["c"], x["e"]
q = (a + c) / (e - c)
return math.acos(q), math.sqrt((e - c) ** 2 - (a + c) ** 2)
def clutch_phi(x):
return solve_assembly(clutch_loops(), x, CLUTCH_GUESS, CLUTCH_KIN)["phi"]
def test_clutch_solution_matches_closed_form():
v = solve_assembly(clutch_loops(), CLUTCH_X, CLUTCH_GUESS, CLUTCH_KIN)
phi, b = clutch_exact(CLUTCH_X)
assert v["phi"] == pytest.approx(phi, abs=1e-12)
assert v["b"] == pytest.approx(b, abs=1e-10)
assert math.degrees(v["phi"]) == pytest.approx(7.0, abs=0.05)
assert max(abs(r) for r in loop_residual(clutch_loops(), v)) < 1e-10
def test_clutch_sensitivities_analytic_and_finite_differences():
T = {"a": 0.01, "c": 0.0025, "e": 0.0125}
res = dlm(clutch_loops(), CLUTCH_X, CLUTCH_GUESS, CLUTCH_MAN, CLUTCH_KIN, T, "phi")
a, c, e = CLUTCH_X["a"], CLUTCH_X["c"], CLUTCH_X["e"]
s = math.sin(res["nominal"])
analytic = {
"a": -1 / (e - c) / s,
"c": -(e + a) / (e - c) ** 2 / s,
"e": (a + c) / (e - c) ** 2 / s,
}
for name in CLUTCH_MAN:
assert res["sens"][name] == pytest.approx(analytic[name], rel=1e-9)
h = 1e-6
xp, xm = dict(CLUTCH_X), dict(CLUTCH_X)
xp[name] += h
xm[name] -= h
fd = (clutch_phi(xp) - clutch_phi(xm)) / (2 * h)
assert res["sens"][name] == pytest.approx(fd, rel=1e-6)
wc = sum(abs(analytic[n]) * T[n] for n in CLUTCH_MAN)
rss = math.sqrt(sum((analytic[n] * T[n]) ** 2 for n in CLUTCH_MAN))
assert res["worst"] == pytest.approx(wc, rel=1e-9)
assert res["rss"] == pytest.approx(rss, rel=1e-9)
assert res["rss"] <= res["worst"] <= math.sqrt(3) * res["rss"] + 1e-15
def corner_range(x0, T, names, f):
vals = []
for signs in itertools.product((-1, 1), repeat=len(names)):
x = dict(x0)
for s, n in zip(signs, names):
x[n] += s * T[n]
vals.append(f(x))
return min(vals), max(vals)
def test_clutch_linearization_error_is_second_order():
"""The gap between the DLM worst case and the corner range shrinks like T^2."""
errs = []
phi0 = clutch_exact(CLUTCH_X)[0]
for k in (0.02, 0.002):
T = {n: k for n in CLUTCH_MAN}
res = dlm(clutch_loops(), CLUTCH_X, CLUTCH_GUESS, CLUTCH_MAN, CLUTCH_KIN, T, "phi")
lo, hi = corner_range(CLUTCH_X, T, CLUTCH_MAN, lambda x: clutch_exact(x)[0])
err = max(abs((hi - phi0) - res["worst"]), abs((phi0 - lo) - res["worst"]))
errs.append((err, res["worst"]))
assert errs[0][0] > 0
assert errs[1][0] / errs[0][0] < 0.02
assert errs[0][0] < 0.2 * errs[0][1]
FOUR_X = {"a": 40.0, "b": 120.0, "c": 80.0, "d": 100.0, "th2": math.radians(40)}
FOUR_MAN = ["a", "b", "c", "d"]
FOUR_KIN = ["th3", "th4"]
def freudenstein_theta4(x, branch):
"""Closed form for the rocker angle (open branch -1, crossed branch +1)."""
a, b, c, d, t2 = x["a"], x["b"], x["c"], x["d"], x["th2"]
k1, k2, k3 = d / a, d / c, (a * a - b * b + c * c + d * d) / (2 * a * c)
A = math.cos(t2) - k1 - k2 * math.cos(t2) + k3
B = -2 * math.sin(t2)
C = k1 - (k2 + 1) * math.cos(t2) + k3
return 2 * math.atan2(-B + branch * math.sqrt(B * B - 4 * A * C), 2 * A)
def angle_diff(p, q):
return math.remainder(p - q, 2 * math.pi)
def fourbar_guess(x):
t4 = freudenstein_theta4(x, -1)
px = x["c"] * math.cos(t4) + x["d"] - x["a"] * math.cos(x["th2"])
py = x["c"] * math.sin(t4) - x["a"] * math.sin(x["th2"])
return {"th3": math.atan2(py, px) + 0.05, "th4": t4 - 0.05}
def test_fourbar_matches_freudenstein():
rng = random.Random(7)
for _ in range(40):
x = dict(FOUR_X)
x["th2"] = rng.uniform(0, 2 * math.pi)
v = solve_assembly(fourbar_loops(), x, fourbar_guess(x), FOUR_KIN)
assert abs(angle_diff(v["th4"], freudenstein_theta4(x, -1))) < 1e-10
def test_fourbar_sensitivities_against_finite_differences():
T = {"a": 0.05, "b": 0.1, "c": 0.08, "d": 0.1}
rng = random.Random(11)
for _ in range(10):
x0 = dict(FOUR_X)
x0["th2"] = rng.uniform(0.2, 2 * math.pi - 0.2)
res = dlm(fourbar_loops(), x0, fourbar_guess(x0), FOUR_MAN, FOUR_KIN, T, "th4")
for name in FOUR_MAN:
h = 1e-5
xp, xm = dict(x0), dict(x0)
xp[name] += h
xm[name] -= h
fd = angle_diff(freudenstein_theta4(xp, -1), freudenstein_theta4(xm, -1)) / (2 * h)
assert res["sens"][name] == pytest.approx(fd, rel=1e-6, abs=1e-9)
def test_linear_stack_gives_stack_up_formulas():
x0 = {"A": 50.0, "B": 20.0, "C": 15.0, "D": 14.8}
T = {"A": 0.10, "B": 0.05, "C": 0.05, "D": 0.05}
res = dlm(linear_stack_loops(), x0, {"G": 0.0, "h": 0.0}, list(x0), ["G", "h"], T, "G")
assert res["nominal"] == pytest.approx(0.20, abs=1e-12)
assert res["sens"] == pytest.approx({"A": 1.0, "B": -1.0, "C": -1.0, "D": -1.0}, abs=1e-12)
assert res["worst"] == pytest.approx(0.25, abs=1e-12)
assert res["rss"] == pytest.approx(math.sqrt(0.0175), abs=1e-12)
def random_linear_loop(rng, n):
"""A loop with n manufactured lengths and two kinematic lengths, all at fixed angles."""
names = ["x%d" % i for i in range(n)]
loop = [(rng.choice((-1, 1)), nm, (rng.uniform(0, 2 * math.pi), {})) for nm in names]
t = rng.uniform(0, 2 * math.pi)
loop.append((1, "p", (t, {})))
loop.append((1, "q", (t + rng.uniform(0.5, 2.6), {})))
x0 = {nm: rng.uniform(5, 20) for nm in names}
return [loop], x0, names
def test_linear_loops_are_exact_for_large_changes():
rng = random.Random(2026)
for _ in range(50):
n = rng.randint(1, 6)
loops, x0, names = random_linear_loop(rng, n)
T = {nm: 1.0 for nm in names}
res = dlm(loops, x0, {"p": 0.0, "q": 0.0}, names, ["p", "q"], T, "q")
x1 = {nm: v + rng.uniform(-3, 3) for nm, v in x0.items()}
q1 = solve_assembly(loops, x1, {"p": 0.0, "q": 0.0}, ["p", "q"])["q"]
pred = res["nominal"] + sum(res["sens"][nm] * (x1[nm] - x0[nm]) for nm in names)
assert q1 == pytest.approx(pred, abs=1e-8)
def test_singular_b_is_reported():
loops = [[(1, "x", (0.0, {})), (-1, "p", (0.0, {})), (-1, "q", (0.0, {}))]]
with pytest.raises(ValueError):
dlm(loops, {"x": 3.0}, {"p": 1.0, "q": 1.0}, ["x"], ["p", "q"], {"x": 0.1}, "p")
History
Chase and his group at Brigham Young University developed tolerance analysis with vector loops in the 1980s and 1990s. Chase, Gao and Magleby published the general 2D method with small kinematic adjustments in the Journal of Design and Manufacturing in 1995, and Gao, Chase and Magleby the 3D method in IIE Transactions in 1998. Chase's chapters in the Dimensioning and Tolerancing Handbook of 1999 present the method with worked examples, the one-way clutch among them. Chen, Jin, Li and Lai compare DLM with the other 3D tolerance analysis methods in a survey of 2014.
References
- Kenneth W. Chase, Jinsong Gao and Spencer P. Magleby, General 2-D tolerance analysis of mechanical assemblies with small kinematic adjustments, Journal of Design and Manufacturing 5(4), 263 to 274, 1995, the whole paper (vector loop models with manufactured and kinematic variables, the matrices A and B of partial derivatives, the sensitivities from B^-1 A, and the worst-case and RSS results)
- Jinsong Gao, Kenneth W. Chase and Spencer P. Magleby, Generalized 3-D tolerance analysis of mechanical assemblies with small kinematic adjustments, IIE Transactions 30, 367 to 377, 1998, the whole paper (the extension of the method to 3D vector loops)
- Paul J. Drake, Jr. (editor), Dimensioning and Tolerancing Handbook, McGraw-Hill, 1999, the chapters by Kenneth W. Chase on multi-dimensional tolerance analysis with vector loops and on minimum-cost tolerance allocation, which uses the one-way clutch as its 2D example
- Walter Rudin, Principles of Mathematical Analysis, 3rd edition, McGraw-Hill, 1976, Theorem 9.28, the implicit function theorem, and Theorem 5.15, Taylor's theorem
- Hua Chen, Sun Jin, Zhimin Li and Xinmin Lai, A comprehensive study of three dimensional tolerance analysis methods, Computer-Aided Design 53, 1 to 13, 2014, the part on the direct linearization method and its comparison with the other 3D methods
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 3NRTQF Edit this page History Report an error Markdown