Algorithm Search⌘K

Algorithmadvanced

Arc-length method

Also called Riks method, Crisfield method.

Traces nonlinear equilibrium paths through limit points by constraining the step length in load and displacement space together.

Time
Θ(s j n b^2) worst
Space
Θ(n b) extra
Where
b = the half bandwidth of the tangent stiffness; j = the number of Newton iterations per step; n = the number of unknowns; s = the number of arc-length steps
Properties
deterministiciterativepasses limit pointspasses snap back
Origin
E. Riks, G. A. Wempner, M. A. Crisfield, 1979

The arc-length method follows the equilibrium path of a nonlinear structure, fint(u)=λPf_{\rm int}(u) = \lambda P, as the load factor λ\lambda and the displacements uu change together. Plain load control fixes λ\lambda and solves for uu with Newton's method, so it fails at a limit point, where the load reaches a maximum and the tangent stiffness becomes singular. The arc-length method treats λ\lambda as an unknown and adds one scalar equation: each step must move a fixed distance Δl\Delta l along the path, measured in the combined space of displacement and load. With this constraint the bordered system stays regular at limit points, so the method passes through snap-through, where the load falls after a peak, and snap-back, where the displacement also turns back.

In plain words

Push down on the top of a shallow arch. At first it resists more and more, then at some point it gives way and jumps through to the other side. A computer that raises the push in fixed amounts cannot follow what happens after the peak, because no nearby position can carry a larger push. The arc-length method does not choose the push in advance. It asks for the next state to be a fixed distance away along the curve of all balanced states, where the distance counts both the movement and the change in push. So it can go over the top of the curve, follow it down while the arch gives way, and come back up on the other side.

The problem

Input. An internal force fint:Rn→Rnf_{\rm int} : \mathbb R^n \to \mathbb R^n and its tangent stiffness KT(u)=∂fint/∂uK_T(u) = \partial f_{\rm int} / \partial u, a fixed load pattern P∈RnP \in \mathbb R^n, a start point (u0,λ0)(u_0, \lambda_0) on the path, an arc length Δl>0\Delta l > 0, a scale ψ≥0\psi \ge 0 for the load term, a tolerance and a number of steps ss.

Output. Points (uk,λk)(u_k, \lambda_k), k=0,…,sk = 0, \ldots, s, with ∥fint(uk)−λkP∥≤\|f_{\rm int}(u_k) - \lambda_k P\| \le tol, such that each increment (Δu,Δλ)=(uk+1−uk,λk+1−λk)(\Delta u, \Delta\lambda) = (u_{k+1} - u_k, \lambda_{k+1} - \lambda_k) satisfies

Δu⊤Δu+ψ2Δλ2P⊤P=Δl2,\Delta u^\top \Delta u + \psi^2 \Delta\lambda^2 P^\top P = \Delta l^2,

and the points follow the path forward (no increment turns back against the previous one).

The constraint with ψ>0\psi > 0 is the spherical form. With ψ=0\psi = 0 it is the cylindrical form of Crisfield, which measures only the displacement and is not affected by the units of the load.

The algorithm

  1. ARC-LENGTH(f_int, K_T, P, u_0, lambda_0, dl, psi, s)
  2. 1(u, lambda) <- (u_0, lambda_0)
  3. 2repeat s times
  4. 3solve K_T(u) u_t = P ▷ tangent direction
  5. 4Dlambda <- ± dl / sqrt(u_t . u_t + psi^2 P . P); Du <- Dlambda u_t ▷ sign: same way as the last step
  6. 5loop
  7. 6g <- f_int(u + Du) - (lambda + Dlambda) P; if |g| <= tol then exit loop
  8. 7solve K_T(u + Du) [u_r, u_t] = [-g, P]
  9. 8choose the root d of |Du + u_r + d u_t|^2 + psi^2 (Dlambda + d)^2 P . P = dl^2 that keeps the step direction
  10. 9Du <- Du + u_r + d u_t; Dlambda <- Dlambda + d
  11. 10(u, lambda) <- (u + Du, lambda + Dlambda); record the point
  12. 11return the recorded points

The quadratic of line L8. With w=Δu+urw = \Delta u + u_r the constraint is a d2+b d+c=0a\,d^2 + b\,d + c = 0 with

a=ut⊤ut+ψ2P⊤P,b=2(ut⊤w+ψ2Δλ P⊤P),c=w⊤w+ψ2Δλ2P⊤P−Δl2.a = u_t^\top u_t + \psi^2 P^\top P, \qquad b = 2\big(u_t^\top w + \psi^2 \Delta\lambda\,P^\top P\big), \qquad c = w^\top w + \psi^2 \Delta\lambda^2 P^\top P - \Delta l^2.

Of the two roots, take the one for which the new increment has the larger inner product with the old one (Crisfield 1981). The other root usually sends the step back to the point it came from. If the roots are not real, the step is too long for the local curvature: halve Δl\Delta l and repeat the step. The reference code does this.

Riks variant. In place of the quadratic, use the linear condition that the correction is normal to the predictor, Δu0⊤(ur+d ut)+ψ2Δλ0 d P⊤P=0\Delta u_0^\top(u_r + d\,u_t) + \psi^2 \Delta\lambda_0\,d\,P^\top P = 0. Then each iteration is Newton's method on the bordered system of n+1n + 1 equations, and no root has to be chosen.

Example

The two-bar truss. Two bars of axial stiffness EA=1EA = 1 go from (±1,0)(\pm 1, 0) to the apex (0,12)(0, \tfrac12), with a downward load λ\lambda at the apex. Let ww be the downward displacement of the apex, y=12−wy = \tfrac12 - w, l=1+y2l = \sqrt{1 + y^2} and l0=5/2=1.1180l_0 = \sqrt{5}/2 = 1.1180. The vertical force of the two bars is

fint(w)=2 EA y (1l−1l0),KT(w)=−2 EA(1l3−1l0).f_{\rm int}(w) = 2\,EA\,y\,\Big(\frac1l - \frac1{l_0}\Big), \qquad K_T(w) = -2\,EA\Big(\frac{1}{l^3} - \frac1{l_0}\Big).

At w=0w = 0, KT=0.35777K_T = 0.35777. The load has a maximum where l3=l0l^3 = l_0, at w=0.22212w = 0.22212 with λ=0.038384\lambda = 0.038384. For larger loads there is no equilibrium near the start, so load control fails there. The apex then snaps through: the force is zero again at w=12w = \tfrac12 (both bars horizontal), negative down to λ=−0.038384\lambda = -0.038384 at w=0.77788w = 0.77788, zero at w=1w = 1 (the mirror image of the start), and rising after that.

The first step. With Δl=0.1\Delta l = 0.1 and ψ=1\psi = 1, line L3 gives ut=1/0.35777=2.7951u_t = 1/0.35777 = 2.7951 and line L4 gives Δλ=0.1/2.79512+1=0.033686\Delta\lambda = 0.1/\sqrt{2.7951^2 + 1} = 0.033686 and Δu=0.094155\Delta u = 0.094155. The residual of line L6 is −0.0075738-0.0075738, because the path bends below its tangent. Two corrections bring the residual below 10−1010^{-10}, at w=0.0964w = 0.0964, λ=0.02655\lambda = 0.02655.

The whole path. Twelve steps with Δl=0.1\Delta l = 0.1 give the points below. The reference code records them, and each needs two Newton corrections.

step ww λ\lambda step ww λ\lambda
1 0.0964 0.02655 7 0.6897 -0.03341
2 0.1958 0.03789 8 0.7896 -0.03829
3 0.2957 0.03487 9 0.8892 -0.02918
4 0.3948 0.02106 10 0.9861 -0.00479
5 0.4928 0.00151 11 1.0786 0.03339
6 0.5908 -0.01843 12 1.1657 0.08253

The steps pass the maximum between steps 2 and 3 and the minimum near step 8 with no special treatment. The largest sampled load misses the exact peak by O(Δl2)O(\Delta l^2): the measured gaps are 1.2×10−41.2 \times 10^{-4}, 3.0×10−53.0 \times 10^{-5} and 8.2×10−68.2 \times 10^{-6} for Δl=0.04\Delta l = 0.04, 0.020.02 and 0.010.01.

Snap-back. Put a spring of stiffness k=0.1k = 0.1 between the apex and the loaded point. Then the loaded point moves z=w+λ/kz = w + \lambda/k. The truss softens with a slope down to −0.2111-0.2111 at w=12w = \tfrac12, which is steeper than −k-k, so on part of the path zz decreases while the path goes on. Load control and control by zz both fail there. The arc-length method with two unknowns follows the whole curve (test_snap_back_with_a_soft_spring).

Correctness

The proofs are in the correctness proof.

  • Each recorded point is in equilibrium (theorem). Line L10 is reached only after the test of line L6 succeeds.
  • The constraint holds exactly at every iterate (theorem). The predictor of line L4 satisfies it by its choice of Δλ\Delta\lambda, and line L9 adds a correction whose dd is a root of the constraint quadratic.
  • The bordered system is regular at a limit point (theorem). At a point where KTK_T is singular with a one-dimensional null space spanned by ϕ\phi, and ϕ⊤P≠0\phi^\top P \ne 0 (a limit point, not a bifurcation point), the (n+1)×(n+1)(n + 1) \times (n + 1) matrix of the equilibrium equations and the linearized constraint is nonsingular when the step direction is not orthogonal to the path tangent. So the Riks iteration is Newton's method on a regular system and converges locally quadratically. For Crisfield's quadratic form the local convergence is a standard result (Crisfield 1981) that the proof only sketches.
  • The method cannot be trusted at a bifurcation point. If ϕ⊤P=0\phi^\top P = 0, the bordered matrix is singular at the point for every constraint, and the steps may follow either branch without warning.
Proof: The arc-length steps keep the constraint, and the bordered system is regular at limit pointspartial

Setting. fint:Rn→Rnf_{\rm int} : \mathbb R^n \to \mathbb R^n is twice continuously differentiable with tangent KT(u)K_T(u), P≠0P \ne 0 is fixed, and G(u,λ)=fint(u)−λPG(u, \lambda) = f_{\rm int}(u) - \lambda P. The equilibrium path is the set where G=0G = 0. A point of the path is regular if the n×(n+1)n \times (n + 1) matrix [KT(u),−P][K_T(u), -P] has rank nn. Near a regular point the path is a smooth curve by the implicit function theorem, and its tangent t=(u˙,λ˙)t = (\dot u, \dot\lambda) spans the null space of [KT,−P][K_T, -P]. The status is partial because the local convergence of Crisfield's quadratic form is only sketched (Remark 6).

Lemma 1 (recorded points are in equilibrium). Every point recorded at line L10 satisfies ∥G(u,λ)∥≤\|G(u, \lambda)\| \le tol.

Proof. The loop of line L5 exits only through the test of line L6, which checks this inequality for (u+Δu,λ+Δλ)(u + \Delta u, \lambda + \Delta\lambda), and line L10 records exactly this pair. In the reference code a step whose loop ends in another way is not recorded; it is repeated with half the arc length. □\square

Lemma 2 (the predictor). If KT(u)K_T(u) is nonsingular, line L3 gives the tangent of the path at (u,λ)(u, \lambda), and the increment of line L4 satisfies Δu⊤Δu+ψ2Δλ2P⊤P=Δl2\Delta u^\top \Delta u + \psi^2 \Delta\lambda^2 P^\top P = \Delta l^2.

Proof. KTut=PK_T u_t = P means [KT,−P] (ut,1)=0[K_T, -P]\,(u_t, 1) = 0, so (ut,1)(u_t, 1) spans the null space, which is the tangent direction. With Δu=Δλ ut\Delta u = \Delta\lambda\,u_t the left side of the constraint is Δλ2(ut⊤ut+ψ2P⊤P)\Delta\lambda^2 (u_t^\top u_t + \psi^2 P^\top P), which is Δl2\Delta l^2 for Δλ=±Δl/ut⊤ut+ψ2P⊤P\Delta\lambda = \pm \Delta l / \sqrt{u_t^\top u_t + \psi^2 P^\top P}. □\square

Lemma 3 (the corrector keeps the constraint). Let (Δu,Δλ)(\Delta u, \Delta\lambda) satisfy the constraint or not, and let uru_r, utu_t be the solutions of line L7. For every real root dd of ad2+bd+c=0a d^2 + b d + c = 0 with the coefficients of the page, the new increment (Δu+ur+d ut,Δλ+d)(\Delta u + u_r + d\,u_t, \Delta\lambda + d) satisfies the constraint exactly. It also satisfies the linearized equilibrium equation: G(u+Δu,λ+Δλ)+KT (ur+d ut)−d P=0G(u + \Delta u, \lambda + \Delta\lambda) + K_T\,(u_r + d\,u_t) - d\,P = 0.

Proof. Put w=Δu+urw = \Delta u + u_r. Then ∣w+dut∣2+ψ2(Δλ+d)2P⊤P−Δl2=d2(ut⊤ut+ψ2P⊤P)+2d(ut⊤w+ψ2ΔλP⊤P)+(w⊤w+ψ2Δλ2P⊤P−Δl2)=ad2+bd+c|w + d u_t|^2 + \psi^2(\Delta\lambda + d)^2 P^\top P - \Delta l^2 = d^2(u_t^\top u_t + \psi^2 P^\top P) + 2d(u_t^\top w + \psi^2\Delta\lambda P^\top P) + (w^\top w + \psi^2\Delta\lambda^2 P^\top P - \Delta l^2) = a d^2 + b d + c, which is zero at a root. For the second claim, KTur=−GK_T u_r = -G and KTut=PK_T u_t = P, so G+KTur+d KTut−dP=G−G+dP−dP=0G + K_T u_r + d\,K_T u_t - d P = G - G + dP - dP = 0. □\square

So every iterate, and hence every recorded increment, lies exactly on the sphere (or cylinder for ψ=0\psi = 0) of radius Δl\Delta l around the last converged point. The reference test test_arc_length_constraint_holds_for_each_step checks this to 10−1210^{-12}.

Lemma 4 (the bordered matrix). Let (u,λ)(u, \lambda) be a regular point of the path with tangent t=(u˙,λ˙)t = (\dot u, \dot\lambda), and let r=(ru,rλ)∈Rn+1r = (r_u, r_\lambda) \in \mathbb R^{n+1}. The matrix

J=(KT−Pru⊤rλ)J = \begin{pmatrix} K_T & -P \\ r_u^\top & r_\lambda \end{pmatrix}

is nonsingular exactly when r⊤t=ru⊤u˙+rλλ˙≠0r^\top t = r_u^\top \dot u + r_\lambda \dot\lambda \ne 0.

Proof. Since [KT,−P][K_T, -P] has rank nn, its null space is spanned by tt. If Jz=0J z = 0 for z∈Rn+1z \in \mathbb R^{n+1}, then [KT,−P]z=0[K_T, -P] z = 0, so z=μtz = \mu t, and the last row gives μ r⊤t=0\mu\,r^\top t = 0. If r⊤t≠0r^\top t \ne 0, then μ=0\mu = 0 and z=0z = 0, so JJ is nonsingular. If r⊤t=0r^\top t = 0, then Jt=0J t = 0 and JJ is singular. □\square

Corollary 5 (limit points). Let (u∗,λ∗)(u^*, \lambda^*) be a point where KTK_T has a one-dimensional null space spanned by ϕ\phi and ϕ⊤P≠0\phi^\top P \ne 0 (here KTK_T is symmetric, as for a conservative internal force). Then the point is regular, its tangent is (ϕ,0)(\phi, 0), and the bordered matrix of the Riks iteration, with r=(Δu0,ψ2Δλ0P⊤P)r = (\Delta u_0, \psi^2 \Delta\lambda_0 P^\top P) from the predictor, is nonsingular as long as Δu0⊤ϕ≠0\Delta u_0^\top \phi \ne 0.

Proof. The range of KTK_T is the orthogonal complement of ϕ\phi, and PP is not in it because ϕ⊤P≠0\phi^\top P \ne 0. So the columns of [KT,−P][K_T, -P] span Rn\mathbb R^n, and the point is regular. KTϕ=0K_T \phi = 0 gives [KT,−P](ϕ,0)=0[K_T, -P](\phi, 0) = 0, so the tangent is (ϕ,0)(\phi, 0): at a limit point the load is stationary. Lemma 4 with r⊤t=Δu0⊤ϕr^\top t = \Delta u_0^\top \phi gives the last claim. □\square

The Riks iteration solves G=0G = 0 together with the linear constraint Δu0⊤(Δu−Δu0)+ψ2Δλ0(Δλ−Δλ0)P⊤P=0\Delta u_0^\top(\Delta u - \Delta u_0) + \psi^2\Delta\lambda_0 (\Delta\lambda - \Delta\lambda_0) P^\top P = 0 by Newton's method, and the Jacobian of this system of n+1n + 1 equations is JJ with r=(Δu0,ψ2Δλ0P⊤P)r = (\Delta u_0, \psi^2\Delta\lambda_0 P^\top P). When the predictor is close enough to the path, rr is close to a multiple of tt, so r⊤t≠0r^\top t \ne 0. By Lemma 4, JJ is nonsingular near the solution, and the standard local theorem for Newton's method for systems (for example the Kantorovich theorem) gives local quadratic convergence, at limit points as well as at ordinary points. Load control is the case r=(0,1)r = (0, 1), and r⊤t=λ˙=0r^\top t = \dot\lambda = 0 at a limit point. So by Lemma 4 its bordered matrix is singular there, which is why load control fails.

Bifurcation points. If ϕ⊤P=0\phi^\top P = 0, then [KT,−P][K_T, -P] has rank n−1n - 1 at the point, the point is not regular, and JJ is singular for every rr. Lemma 4 does not apply, and the method gives no guarantee about which branch it follows.

Remark 6 (Crisfield's quadratic form, sketch). Crisfield's iteration replaces the linear constraint by the exact sphere and picks the root dd that keeps the direction of the increment. Near a regular point on the path the two roots are well separated: one is close to the Newton correction of the Riks form, the other moves the increment to the opposite side of the sphere, where its inner product with the old increment is negative. With the rule of line L8, each iteration differs from a Newton step on the bordered system by a term of second order in the correction, so local convergence follows as for Newton's method. Crisfield (1981) gives the method and its use on snap-through problems. We do not give a full proof here.

Lemma 7 (the limit point of the two-bar truss). For fint(w)=2 EA y (1/l−1/l0)f_{\rm int}(w) = 2\,EA\,y\,(1/l - 1/l_0) with y=H−wy = H - w, l=L2+y2l = \sqrt{L^2 + y^2} and l0=L2+H2l_0 = \sqrt{L^2 + H^2}, the load has a stationary point at l3=L2l0l^3 = L^2 l_0 with 0<y<H0 < y < H.

Proof. With dl/dy=y/ldl/dy = y/l, ddy(y/l)=1/l−y2/l3=L2/l3\tfrac{d}{dy}\big(y/l\big) = 1/l - y^2/l^3 = L^2/l^3, so dfintdy=2 EA (L2/l3−1/l0)\tfrac{d f_{\rm int}}{dy} = 2\,EA\,(L^2/l^3 - 1/l_0). This is zero at l3=L2l0l^3 = L^2 l_0. At y=Hy = H it is 2EA(L2/l03−1/l0)=−2EA H2/l03<02EA(L^2/l_0^3 - 1/l_0) = -2EA\,H^2/l_0^3 < 0, and at y=0y = 0 it is 2EA(1/L−1/l0)>02EA(1/L - 1/l_0) > 0. It is monotone in ll, hence in y≥0y \ge 0, so there is exactly one zero in (0,H)(0, H). Since dw=−dydw = -dy, the load rises with ww from w=0w = 0 to this point and falls after it. □\square

For EA=L=1EA = L = 1 and H=12H = \tfrac12 this gives w=0.22212w = 0.22212 and the limit load 0.0383840.038384, which the reference test test_limit_load_against_closed_form compares with the arc-length path.

Complexity

In the real-RAM model, each Newton iteration assembles KTK_T and factors it once. For a banded matrix with half bandwidth bb this costs Θ(nb2)\Theta(n b^2). The two right sides of line L7 share the factor and cost Θ(nb)\Theta(n b), and the quadratic costs Θ(n)\Theta(n). So ss steps with jj iterations each cost Θ(sjnb2)\Theta(s j n b^2), the same as load control with the same number of iterations. The extra memory is one more vector of length nn, so Θ(nb)\Theta(n b) for the factor. The number jj is a measurement, not a bound: it is 2 for the truss and at most 3 for the truss with a spring in the reference tests, with Δl\Delta l between 0.02 and 0.1. The reference code uses dense Gaussian elimination and is meant only for small systems.

Properties

  • One extra scalar unknown. The tangent matrix keeps its sparsity and symmetry, because line L7 solves with KTK_T alone and the bordering is done by the two right sides.
  • Works when KTK_T is singular at isolated points, as at limit points, as long as the iterates do not land exactly on them.
  • The step size is a length, not a load. Near a limit point the load changes little and the displacement a lot, so the method takes small load steps where they are needed without any rule for it.
  • Sign of the predictor. The sign of Δλ\Delta\lambda at line L4 changes when the path passes a limit point. The rule "same direction as the last increment" handles this, while the rule "sign of det⁡KT\det K_T" fails at bifurcation points.

Variants and improvements

  • Riks normal plane and Ramm updated normal plane. Linearize the constraint about the predictor (Riks) or about the current iterate (Ramm). Then no quadratic root has to be chosen, at the price of a slightly different step length.
  • Crisfield cylindrical (ψ=0\psi = 0) and spherical (ψ>0\psi > 0). The cylindrical form is the default in many codes because the load and the displacement have different units.
  • Adaptive arc length. Scale Δl\Delta l by the ratio of a target number of iterations to the actual number, for example Δlnew=Δl jtarget/j\Delta l_{\rm new} = \Delta l\,\sqrt{j_{\rm target}/j}.
  • Local or indirect displacement control. For problems with localized damage, measure the arc length only on a few chosen degrees of freedom, such as a crack mouth opening.
  • Pseudo-arclength continuation in numerical analysis. Keller's method is the same idea for general parameter dependent equations G(x,λ)=0G(x, \lambda) = 0, with the normal plane constraint. See homotopy continuation for path following toward the roots of polynomial systems.

When to use it

Use it for quasi-static nonlinear structural problems where the load reaches a maximum or the response turns back: buckling of shallow shells and arches, snap-through of trusses, post-peak softening in concrete and composites, and contact problems with a load drop. When the load only increases, plain load control with Newton's method is simpler. When the path has a bifurcation, add a check of the sign and the number of negative pivots of KTK_T, and perturb the structure or switch branches on purpose.

Pitfalls

  • Wrong root. Choosing the root of line L8 by the smaller absolute value, or by sign, can send the path back on itself, which looks like a loop of converged points.
  • Steps that are too long. Near a sharp turn of the path the quadratic has no real root, or Newton converges to a far part of the path. Halve the step and retry.
  • Units in the spherical form. With ψ=1\psi = 1 the constraint adds a displacement squared and a load squared. If the load is in newtons and the displacements in metres, the load term dominates and the method behaves like load control. Scale ψ\psi or use the cylindrical form.
  • Bifurcation is not a limit point. At a symmetric bifurcation ϕ⊤P=0\phi^\top P = 0, and the method passes the point on the primary path without noticing the secondary path. Monitor the number of negative pivots of KTK_T.
  • Path dependent materials. For plasticity or damage, the internal force depends on the history. Each step must start from the converged state of the last step, and the iterations within a step must not update the history. See the return mapping algorithm.

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.

arc_length_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/arc-length-method/. The authors are listed in prov/J4J4WD.jsonl.

"""Arc-length continuation (Riks 1979, Crisfield 1981) for f_int(u) = lam P.

The unknowns are the displacements u (a list) and the load factor lam. Each
step moves a distance dl along the equilibrium path, measured by
    |Du|^2 + psi^2 Dlam^2 |P|^2 = dl^2,
and corrects with Newton iterations that keep this constraint (Crisfield's
spherical form; psi = 0 gives the cylindrical form). Matrices are lists of
rows, as in scimat.
"""

import math

import scimat


def arc_length(fint, tangent, P, u0, dl, nsteps, psi=1.0, tol=1e-10, maxit=25, lam0=0.0):
    """Trace the equilibrium path of fint(u) = lam P from (u0, lam0).

    tangent(u) returns d fint / d u. Return a list of (u, lam, iterations), the
    start point included. A step whose quadratic has no real root, or whose
    Newton iteration does not converge, is retried with half the arc length.
    """
    n = len(u0)
    pp = scimat.dot(P, P)
    u, lam = list(u0), lam0  # @line L1
    path = [(list(u), lam, 0)]
    prev = None  # previous increment (Du, Dlam)
    step = 0
    length = dl
    while step < nsteps:  # @line L2
        ut = scimat.solve(tangent(u), P)  # @line L3
        dlam = length / math.sqrt(scimat.dot(ut, ut) + psi * psi * pp)
        if prev is not None and scimat.dot(prev[0], ut) + psi * psi * prev[1] * pp < 0:
            dlam = -dlam  # keep going forward along the path
        du = scimat.scale(dlam, ut)  # @line L4
        ok = False
        for it in range(maxit):  # @line L5
            g = scimat.sub(fint(scimat.add(u, du)), scimat.scale(lam + dlam, P))  # @line L6
            if scimat.norm2(g) <= tol * (1 + abs(lam + dlam) * math.sqrt(pp)):
                ok = True
                break
            kt = tangent(scimat.add(u, du))
            sol = scimat.solve(kt, [[-gi, pi] for gi, pi in zip(g, P)])  # @line L7
            ur = [row[0] for row in sol]
            ut = [row[1] for row in sol]
            root = _constraint_root(du, dlam, ur, ut, pp, psi, length)  # @line L8
            if root is None:
                break
            du = [du[i] + ur[i] + root * ut[i] for i in range(n)]  # @line L9
            dlam += root
        if not ok:
            length /= 2
            if length < dl * 1e-6:
                raise RuntimeError("arc-length step failed")
            continue
        u = scimat.add(u, du)  # @line L10
        lam += dlam
        prev = (du, dlam)
        path.append((list(u), lam, it))
        step += 1
        length = dl
    return path  # @line L11


def _constraint_root(du, dlam, ur, ut, pp, psi, length):
    """Return the correction dmu of the load factor that keeps the arc length.

    The new increment is du + ur + dmu ut. Of the two roots of the quadratic,
    take the one whose new increment makes the smaller angle with du (Crisfield).
    Return None if the roots are not real.
    """
    w = scimat.add(du, ur)
    a = scimat.dot(ut, ut) + psi * psi * pp
    b = 2 * (scimat.dot(ut, w) + psi * psi * dlam * pp)
    c = scimat.dot(w, w) + psi * psi * dlam * dlam * pp - length * length
    disc = b * b - 4 * a * c
    if disc < 0:
        return None
    s = math.sqrt(disc)
    # stable formulas for the two roots
    q = -(b + math.copysign(s, b)) / 2
    roots = [q / a, c / q] if q != 0 else [0.0, 0.0]

    def cosine(mu):
        new = [w[i] + mu * ut[i] for i in range(len(w))]
        return scimat.dot(new, du) + psi * psi * (dlam + mu) * dlam * pp

    return max(roots, key=cosine)


def load_control(fint, tangent, P, u0, lams, tol=1e-10, maxit=50):
    """Newton's method at each prescribed load factor in lams, from the last solution.

    Return a list of (u, lam, iterations). Raise RuntimeError if Newton does not converge.
    """
    u = list(u0)
    out = []
    for lam in lams:
        for it in range(maxit):
            g = scimat.sub(fint(u), scimat.scale(lam, P))
            if scimat.norm2(g) <= tol * (1 + abs(lam) * scimat.norm2(P)):
                break
            u = scimat.sub(u, scimat.solve(tangent(u), g))
        else:
            raise RuntimeError("Newton did not converge at lam = %r" % lam)
        out.append((list(u), lam, it))
    return out


def von_mises_truss(EA=1.0, L=1.0, H=0.5):
    """Return (fint, tangent) of the symmetric two-bar truss with one degree of freedom.

    The bars go from (-L, 0) and (L, 0) to the apex (0, H). u = [w] is the
    downward displacement of the apex, and fint is the upward resisting force
    2 EA y (1/l - 1/l0) with y = H - w, l = sqrt(L^2 + y^2), l0 = sqrt(L^2 + H^2).
    """
    l0 = math.hypot(L, H)

    def fint(u):
        y = H - u[0]
        l = math.hypot(L, y)
        return [2 * EA * y * (1 / l - 1 / l0)]

    def tangent(u):
        y = H - u[0]
        l = math.hypot(L, y)
        return [[-2 * EA * (L * L / l ** 3 - 1 / l0)]]

    return fint, tangent


def von_mises_limit_point(EA=1.0, L=1.0, H=0.5):
    """Return (w, load) at the first limit point of the truss, in closed form.

    d fint / d y = 2 EA (L^2 / l^3 - 1 / l0) is zero at l^3 = L^2 l0.
    """
    l0 = math.hypot(L, H)
    l = (L * L * l0) ** (1 / 3)
    y = math.sqrt(l * l - L * L)
    return H - y, 2 * EA * y * (1 / l - 1 / l0)


def truss_with_spring(k, EA=1.0, L=1.0, H=0.5):
    """Return (fint, tangent) of the truss loaded through a vertical spring of stiffness k.

    u = [w, z]: w is the apex displacement and z the displacement of the loaded
    end of the spring, both downward. The load acts on z, so P = [0, 1].
    The path has a snap-back in z when k is smaller than the largest softening slope.
    """
    f1, t1 = von_mises_truss(EA, L, H)

    def fint(u):
        s = k * (u[1] - u[0])
        return [f1([u[0]])[0] - s, s]

    def tangent(u):
        kt = t1([u[0]])[0][0]
        return [[kt + k, -k], [-k, k]]

    return fint, tangent
scimat.py 227 lines
# SPDX-License-Identifier: MIT
# Shared helper of the scientific-computing pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Small dense linear algebra and error norms for the scientific-computing pages.

A matrix is a list of rows and a vector is a list. Entries may be int,
float or fractions.Fraction. The routines that do not take a square root
(solve, inv, det and the arithmetic) keep Fraction entries exact.
cholesky, cholesky_solve and norm2 take square roots and return floats.

API (fixed; other pages copy this file byte for byte):
    zeros(m, n=None)        m by n zero matrix (n = m if not given)
    eye(n)                  n by n identity
    add(A, B), sub(A, B)    entrywise sum and difference (vectors or matrices)
    scale(c, A)             c times A (vector or matrix)
    matmul(A, B)            matrix product
    matvec(A, x)            matrix times vector
    transpose(A)            transpose
    dot(x, y)               inner product of two vectors
    norm2(x)                Euclidean norm of a vector, as a float
    outer(x, y)             outer product x y^T
    solve(A, b)             Gaussian elimination with partial pivoting;
                            b is a vector or a matrix of right sides
    inv(A)                  inverse of A
    det(A)                  determinant of A
    cholesky(A)             lower triangular L with A = L L^T (floats)
    cholesky_solve(L, b)    solve L L^T x = b for a vector b
    err_l1(e, dx=1)         sum |e_j| dx
    err_l2(e, dx=1)         sqrt(sum e_j^2 dx), as a float
    err_linf(e, dx=1)       max |e_j| (dx is not used)
    observed_order(errors)  [log2(E_i / E_(i+1)) for successive errors]
"""

import math


def zeros(m, n=None):
    """Return an m by n matrix of zeros (n = m if n is None)."""
    if n is None:
        n = m
    return [[0] * n for _ in range(m)]


def eye(n):
    """Return the n by n identity matrix."""
    out = zeros(n, n)
    for i in range(n):
        out[i][i] = 1
    return out


def _is_matrix(a):
    return len(a) > 0 and isinstance(a[0], list)


def add(a, b):
    """Return a + b for two vectors or two matrices of the same shape."""
    if _is_matrix(a):
        return [[x + y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
    return [x + y for x, y in zip(a, b)]


def sub(a, b):
    """Return a - b for two vectors or two matrices of the same shape."""
    if _is_matrix(a):
        return [[x - y for x, y in zip(ra, rb)] for ra, rb in zip(a, b)]
    return [x - y for x, y in zip(a, b)]


def scale(c, a):
    """Return c times a, for a vector or a matrix a."""
    if _is_matrix(a):
        return [[c * x for x in row] for row in a]
    return [c * x for x in a]


def transpose(a):
    """Return the transpose of the matrix a."""
    return [list(col) for col in zip(*a)]


def matmul(a, b):
    """Return the matrix product a b."""
    bt = transpose(b)
    return [[sum(x * y for x, y in zip(row, col)) for col in bt] for row in a]


def matvec(a, x):
    """Return the product of the matrix a and the vector x."""
    return [sum(aij * xj for aij, xj in zip(row, x)) for row in a]


def dot(x, y):
    """Return the inner product of the vectors x and y."""
    return sum(a * b for a, b in zip(x, y))


def norm2(x):
    """Return the Euclidean norm of the vector x, as a float."""
    return math.sqrt(float(dot(x, x)))


def outer(x, y):
    """Return the outer product x y^T as a matrix."""
    return [[a * b for b in y] for a in x]


def _eliminate(a, rhs):
    """Reduce a to upper triangular form with partial pivoting.

    a is a copy of the square matrix, rhs a list of right side rows (one
    row per row of a) that receives the same row operations. Return the
    number of row swaps. Raise ValueError if a pivot is zero.
    """
    n = len(a)
    swaps = 0
    for k in range(n):
        p = max(range(k, n), key=lambda i: abs(a[i][k]))
        if a[p][k] == 0:
            raise ValueError("matrix is singular")
        if p != k:
            a[k], a[p] = a[p], a[k]
            rhs[k], rhs[p] = rhs[p], rhs[k]
            swaps += 1
        for i in range(k + 1, n):
            f = a[i][k] / a[k][k]
            if f == 0:
                continue
            for j in range(k, n):
                a[i][j] -= f * a[k][j]
            for j in range(len(rhs[i])):
                rhs[i][j] -= f * rhs[k][j]
    return swaps


def solve(a, b):
    """Solve a x = b by Gaussian elimination with partial pivoting.

    b is a vector (the result is a vector) or a matrix with one column per
    right side (the result is a matrix). Fraction entries stay exact.
    Raise ValueError if a is singular.
    """
    n = len(a)
    work = [list(row) for row in a]
    vector = not _is_matrix(b)
    rhs = [[v] for v in b] if vector else [list(row) for row in b]
    _eliminate(work, rhs)
    m = len(rhs[0]) if n else 0
    x = [[0] * m for _ in range(n)]
    for i in range(n - 1, -1, -1):
        for j in range(m):
            s = rhs[i][j]
            for k in range(i + 1, n):
                s -= work[i][k] * x[k][j]
            x[i][j] = s / work[i][i]
    if vector:
        return [row[0] for row in x]
    return x


def inv(a):
    """Return the inverse of the square matrix a."""
    return solve(a, eye(len(a)))


def det(a):
    """Return the determinant of the square matrix a (0 if singular)."""
    work = [list(row) for row in a]
    rhs = [[] for _ in a]
    try:
        swaps = _eliminate(work, rhs)
    except ValueError:
        return 0
    d = -1 if swaps % 2 else 1
    for i in range(len(a)):
        d *= work[i][i]
    return d


def cholesky(a):
    """Return the lower triangular L with a = L L^T, in floats.

    Raise ValueError if a is not symmetric positive definite.
    """
    n = len(a)
    low = [[0.0] * n for _ in range(n)]
    for j in range(n):
        s = float(a[j][j]) - sum(low[j][k] ** 2 for k in range(j))
        if s <= 0.0:
            raise ValueError("matrix is not positive definite")
        low[j][j] = math.sqrt(s)
        for i in range(j + 1, n):
            t = float(a[i][j]) - sum(low[i][k] * low[j][k] for k in range(j))
            low[i][j] = t / low[j][j]
    return low


def cholesky_solve(low, b):
    """Solve L L^T x = b, with L from cholesky, for a vector b."""
    n = len(low)
    y = [0.0] * n
    for i in range(n):
        y[i] = (float(b[i]) - sum(low[i][k] * y[k] for k in range(i))) / low[i][i]
    x = [0.0] * n
    for i in range(n - 1, -1, -1):
        x[i] = (y[i] - sum(low[k][i] * x[k] for k in range(i + 1, n))) / low[i][i]
    return x


def err_l1(e, dx=1):
    """Return the discrete L1 norm sum |e_j| dx."""
    return sum(abs(v) for v in e) * dx


def err_l2(e, dx=1):
    """Return the discrete L2 norm sqrt(sum e_j^2 dx), as a float."""
    return math.sqrt(float(sum(v * v for v in e) * dx))


def err_linf(e, dx=1):
    """Return the max norm max |e_j|. dx is accepted for a uniform call and not used."""
    return max(abs(v) for v in e)


def observed_order(errors):
    """Return [log2(E_i / E_(i+1))] for a list of errors on meshes h, h/2, h/4, ..."""
    return [math.log2(float(errors[i]) / float(errors[i + 1])) for i in range(len(errors) - 1)]
test_arc_length_method.py 116 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/arc-length-method/. The authors are listed in prov/J4J4WD.jsonl.

import math

import scimat
from arc_length_method import (
    arc_length,
    load_control,
    truss_with_spring,
    von_mises_limit_point,
    von_mises_truss,
)


def residual(fint, P, u, lam):
    return scimat.norm2(scimat.sub(fint(u), scimat.scale(lam, P)))


def increments(path):
    return [(scimat.sub(b[0], a[0]), b[1] - a[1]) for a, b in zip(path, path[1:])]


def test_linear_problem_is_a_straight_line():
    K = [[4.0, -1.0], [-1.0, 3.0]]
    P = [1.0, 2.0]
    path = arc_length(lambda u: scimat.matvec(K, u), lambda u: K, P, [0.0, 0.0], 0.5, 6, psi=0.5)
    x = scimat.solve(K, P)
    for u, lam, it in path:
        assert it == 0
        assert all(abs(ui - lam * xi) < 1e-12 for ui, xi in zip(u, x))
    for du, dlam in increments(path):
        assert abs(scimat.dot(du, du) + 0.25 * dlam * dlam * scimat.dot(P, P) - 0.25) < 1e-12


def test_truss_path_through_the_limit_points():
    fint, tangent = von_mises_truss()
    path = arc_length(fint, tangent, [1.0], [0.0], 0.02, 70)
    ws = [p[0][0] for p in path]
    lams = [p[1] for p in path]
    for u, lam, _ in path:
        assert residual(fint, [1.0], u, lam) < 1e-9
    # the apex moves down all the time, past the flat position w = H and the inverted one w = 2H
    assert all(b > a for a, b in zip(ws, ws[1:]))
    assert ws[-1] > 1.0
    # the load rises, falls through zero and below, and rises again
    i_max = max(range(len(lams)), key=lambda i: lams[i] if ws[i] < 0.5 else -1)
    i_min = min(range(len(lams)), key=lambda i: lams[i])
    assert 0 < i_max < i_min < len(lams) - 1
    assert lams[i_min] < -0.03
    assert lams[-1] > 0


def test_arc_length_constraint_holds_for_each_step():
    fint, tangent = von_mises_truss()
    for psi in (1.0, 0.0):
        path = arc_length(fint, tangent, [1.0], [0.0], 0.03, 30, psi=psi)
        for du, dlam in increments(path):
            assert abs(scimat.dot(du, du) + psi * psi * dlam * dlam - 0.03 ** 2) < 1e-12


def test_limit_load_against_closed_form():
    fint, tangent = von_mises_truss()
    w_lim, p_lim = von_mises_limit_point()
    # the closed form is a stationary point of fint
    h = 1e-6
    assert abs(fint([w_lim + h])[0] - fint([w_lim - h])[0]) < 1e-12
    errs = []
    for dl in (0.04, 0.02, 0.01):
        path = arc_length(fint, tangent, [1.0], [0.0], dl, int(0.6 / dl))
        best = max(p[1] for p in path if p[0][0] < 0.5)
        assert best <= p_lim + 1e-12
        errs.append(p_lim - best)
    # the largest sampled load misses the peak by O(dl^2)
    assert errs[-1] < 1e-5
    assert all(q > 1.5 for q in scimat.observed_order(errs))


def test_load_control_cannot_pass_the_limit_point():
    fint, tangent = von_mises_truss()
    w_lim, p_lim = von_mises_limit_point()
    below = load_control(fint, tangent, [1.0], [0.0], [p_lim * s for s in (0.25, 0.5, 0.75, 0.95)])
    assert below[-1][0][0] < w_lim
    # just above the limit load there is no equilibrium near the start branch:
    # Newton either fails or jumps through to the far branch beyond w = 2H.
    try:
        out = load_control(fint, tangent, [1.0], below[-1][0], [1.05 * p_lim])
    except RuntimeError:
        return
    assert out[-1][0][0] > 1.0


def test_snap_back_with_a_soft_spring():
    # Load on the free end of a spring of stiffness 0.1 on top of the apex.
    # The truss softens faster than the spring is stiff, so the loaded point moves back.
    k = 0.1
    fint, tangent = truss_with_spring(k)
    P = [0.0, 1.0]
    path = arc_length(fint, tangent, P, [0.0, 0.0], 0.05, 80)
    zs = [p[0][1] for p in path]
    for u, lam, _ in path:
        assert residual(fint, P, u, lam) < 1e-9
        assert abs(k * (u[1] - u[0]) - lam) < 1e-9
    backs = sum(1 for a, b in zip(zs, zs[1:]) if b < a)
    assert backs >= 3
    assert path[-1][0][0] > 1.0
    # successive increments never point backwards along the path
    inc = increments(path)
    for (a, la), (b, lb) in zip(inc, inc[1:]):
        assert scimat.dot(a, b) + la * lb > 0


def test_iterations_are_few():
    fint, tangent = truss_with_spring(0.1)
    path = arc_length(fint, tangent, [0.0, 1.0], [0.0, 0.0], 0.05, 80)
    assert max(p[2] for p in path) <= 6

History

Wempner in 1971 used the arc length of the equilibrium path as a parameter for nonlinear structural problems. Riks in 1979 gave an incremental method that adds the arc-length constraint and solves with Newton corrections normal to the predictor, for snapping and buckling problems. Crisfield in 1981 gave the cylindrical form with a quadratic for the load correction and a rule to choose its root, and showed it on snap-through problems. Ramm in 1981 gave the updated normal plane variant. In numerical analysis Keller developed the same idea as pseudo-arclength continuation in 1977.

References

  1. E. Riks, An incremental approach to the solution of snapping and buckling problems, International Journal of Solids and Structures 15(7) (1979) 529-551, the arc-length constraint on the load and displacement increment, with the linearized (normal plane) correction
  2. M. A. Crisfield, A fast incremental/iterative solution procedure that handles snap-through, Computers and Structures 13(1-3) (1981) 55-62, the cylindrical arc-length constraint, the quadratic for the load correction and the choice of its root
  3. G. A. Wempner, Discrete approximations related to nonlinear theories of solids, International Journal of Solids and Structures 7(11) (1971) 1581-1599, the arc length as a path parameter for nonlinear structural problems
  4. Ted Belytschko, Wing Kam Liu and Brian Moran, Nonlinear Finite Elements for Continua and Structures, Wiley, 2000, Chapter 6 (solution methods for equilibrium problems, load and arc-length continuation)

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.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of correctness
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example