Algorithmadvanced
Generalized-alpha method
Also called Chung-Hulbert method.
A second order implicit method for structural dynamics with set damping of high frequencies and little damping of low ones; it contains HHT-alpha.
- Time
- Θ(n b^2 + m n b) worst
- Space
- Θ(n b) extra
- Where
- b = the half bandwidth of the effective matrix; m = the number of time steps; n = the number of unknowns
- Model
- Real RAM
- Properties
- deterministicimplicitone stepunconditionally stable linear
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Jintai Chung, Gregory M. Hulbert, 1993
The generalized-alpha method is an implicit one-step integrator for the equations of structural dynamics . It keeps the displacement and velocity updates of the Newmark-beta method, but it enforces the equation of motion at two shifted points inside the step, one for the inertia term and one for the internal and external forces. One parameter sets the spectral radius of the step as . So the user picks how strongly the unresolved high modes of the mesh are damped, while the method stays second order and unconditionally stable for linear problems and damps the well resolved low modes very little. Newmark can damp the high modes only with , which drops it to first order.
In plain words
When a computer follows a vibrating structure in time, the mesh has many fast vibrations that are not real physics. They come only from the size of the elements. A good time stepper should remove these fast wiggles and leave the slow motion, which is the answer the engineer wants, almost untouched. The Newmark method can either keep everything, or remove the wiggles at the cost of a larger error on the slow motion. The generalized-alpha method moves the points inside the step where the forces are balanced. With one dial the user picks how much of a fast wiggle is left after each step, from all of it to none, and the slow motion keeps full accuracy.
The problem
Input. Matrices (symmetric positive definite), and of size , a load , initial values and , a time step , a number of steps and . On finite element pages is the mesh size and is the time step.
Output. Approximations and for , , and an auxiliary acceleration , such that the Newmark updates
hold, together with the balance at the shifted points
The parameters come from :
The algorithm
GENERALIZED-ALPHA(M, C, K, F, d_0, v_0, dt, m, alpha_m, alpha_f, beta, gamma)- 1
a_0 <- solve M a = F(0) - C v_0 - K d_0 - 2
for k <- 0 to m - 1 do - 3
dp <- d_k + dt v_k + (dt^2 / 2)(1 - 2 beta) a_k - 4
vp <- v_k + (1 - gamma) dt a_k - 5
r <- F(t_k + (1 - alpha_f) dt) - alpha_m M a_k - C((1 - alpha_f) vp + alpha_f v_k) - K((1 - alpha_f) dp + alpha_f d_k) - 6
a_{k+1} <- solve ((1 - alpha_m) M + (1 - alpha_f)(gamma dt C + beta dt^2 K)) a = r - 7
d_{k+1} <- dp + beta dt^2 a_{k+1} - 8
v_{k+1} <- vp + gamma dt a_{k+1} - 9
return (d_k, v_k, a_k) for k = 0 .. m
Lines L3, L4, L7 and L8 are the Newmark predictor and corrector. Lines L5 and L6 are the balance at the shifted points, written as one linear system for after the Newmark updates are put in. The effective matrix of line L6 is the same for all steps when is fixed, so a code factors it once. For a nonlinear internal force, line L6 becomes a Newton iteration with the effective tangent .
Members.
| method | when | ||
|---|---|---|---|
| Newmark-beta | no shift | ||
| HHT-alpha (Hilber, Hughes and Taylor 1977) | shift of the force terms only, | ||
| WBZ-alpha (Wood, Bossak and Zienkiewicz 1980) | shift of the inertia term only | ||
| Chung-Hulbert | as above | as above | both shifts, best ratio of high to low frequency damping |
In each case and . The original HHT paper writes the parameter with the opposite sign, .
Example
One step by hand. Take , , , and . Then , , and . Line L1 gives . Line L3 gives and line L4 gives . Line L6 solves , that is , so . Then and . The exact values are and . Note that is not zero: the auxiliary does not satisfy the equation of motion at . It approximates the acceleration at the earlier time .
Damping at the same . Fix for all four methods: Newmark with and , HHT with , WBZ, and Chung-Hulbert. The table gives the algorithmic damping ratio of the principal eigenvalue of one step, for an undamped oscillator. The values are measurements from the reference code.
| method | at | at | at | period error at | order |
|---|---|---|---|---|---|
| Newmark, | 0.77 % | 1 | |||
| WBZ-alpha | 0.97 % | 2 | |||
| HHT-alpha | 0.93 % | 2 | |||
| Chung-Hulbert | 0.78 % | 2 |
All four remove the same fraction of a very high mode per step. At , a mode resolved with about 60 steps per period, Newmark damps 10 000 times more than Chung-Hulbert. For the second order methods falls like .
Correctness
The full arguments are in the correctness proof.
- Second order (theorem). The auxiliary acceleration approximates with . With this shift the exact solution satisfies the balance of lines L5 and L6 up to and the displacement update up to . The velocity update has the defect , so the step has a local error of exactly when .
- High frequency limit (theorem). As the step matrix of a mode converges to a matrix with eigenvalues and a pair with sum and product . With the Chung-Hulbert parameters all three are equal to , so the spectral radius tends to .
- Stability (theorem, cited). For a linear problem with , the method is unconditionally stable when and (Chung and Hulbert 1993). The Chung-Hulbert parameters satisfy both conditions for every .
- The case (theorem). Then , and , and for a load that is zero or linear in the steps are those of the trapezoidal rule, which conserves the energy of a linear undamped system.
Proof: Second order, high frequency limit and the trapezoidal case of the generalized-alpha methodpartial
Setting. is symmetric positive definite, , , , and is invertible. Lines L3 to L8 give, for every ,
Indeed lines L7 and L8 give and , which are (U1) and (U2). Put them into (B): the terms in are and the other terms are those of the right side of line L5, so (B) is the system of line L6. Write . The status is partial because the unconditional stability (Theorem 4) and the global convergence are cited, not proved.
Theorem 1 (consistency and the second order condition). Let be a smooth solution of , with and . Insert the shifted exact values , , into (U1), (U2) and (B). Then the defect of (U1) is , the defect of (B) is , and the defect of (U2) is
Proof. Write , for the values at . Then and .
(U1): , and .
(U2): , and . The difference is .
(B): put . A weighted mean of a smooth equals . So , because . In the same way the and terms equal and . The exact equation at gives a defect .
Why this is the order condition. Subtract the scheme from the shifted exact values. In one step from exact data, the defect of (B) changes by , and stays bounded as because . Through (U1) and (U2) this changes by and by . The defect of (U1) changes by . So the local error of one step in is , that is per unit time, exactly when . For other the velocity has the local error and the method is first order. With the uniform stability of Theorem 4, a local error gives a global error on a fixed interval (Chung and Hulbert 1993). The shifted value differs from the of line L1 by . This start error enters through and through , so it adds to the global error.
The same computation shows the role of the load time: if the load is taken at in place of , the defect of (B) becomes , which changes by per step, and the method is first order. The reference test test_load_at_the_shifted_time measures orders 2 and 1 for the two choices.
Theorem 2 (high frequency limit). For the mode put and , so that . As , converges to a matrix with the eigenvalues
Proof. Write for the three components of and for those of . Multiply (B) by and use for the stiffness term:
Put the second relation into the first and divide by . As the coefficients converge, and the limit is . The coefficient of before the limit is , which stays away from 0, so the entries of converge. In the limit, . So the first row of is , is an eigenvalue, and the other two are those of the block for . From and this block is
with trace and determinant .
Corollary 3 (the Chung-Hulbert parameters). Let and . Then . With and , all three eigenvalues of equal , so the spectral radius of tends to .
Proof. The trace is and the determinant is . A pair with sum and product , , is the double root . Now , so , and . The eigenvalues of a matrix depend continuously on its entries, so the spectral radius of converges to that of .
The parameter of the corollary is the one that makes the two roots of equal. For a larger the pair is complex with modulus , which is larger than , so a larger damps the highest modes less.
Theorem 4 (unconditional stability, cited). For a linear undamped problem the method is unconditionally stable when and (Chung and Hulbert 1993). The Chung-Hulbert parameters satisfy these conditions: , , and . The reference test test_unconditional_stability measures a spectral radius at most for and from to .
Theorem 5 (the case ). For , , and . If the load is affine in (for example zero), the method produces the same as the average acceleration Newmark method, and for every .
Proof. By induction on . For the equation holds by line L1. If it holds at , then (B) with says that the mean of at and equals , which is the mean of and because is affine. So the equation holds at . Then (U1), (U2) and the equation at are the defining equations of the Newmark step with , , which has a unique solution.
So for and a linear undamped problem the energy is conserved exactly, by the energy theorem of the Newmark-beta method. The reference test test_rho_one_is_the_trapezoidal_rule checks both facts in exact rational arithmetic.
Complexity
The cost is that of the Newmark-beta method: in the real-RAM model a linear problem with banded matrices of half bandwidth and fixed needs one factorization, , and then per step, so in total and memory. The shifted balance adds two vectors of storage and a few vector operations per step. A nonlinear problem costs one tangent assembly and one factorization per Newton iteration. The reference code uses dense Gaussian elimination and is meant only for small systems.
Properties
- One parameter for all the damping. gives no damping (the trapezoidal rule), gives asymptotic annihilation: a mode with is removed in one step, as with an L-stable method.
- Second order for every , and unconditionally stable for linear problems.
- Small low frequency damping. Among the second order three-stage schemes of this form, the Chung-Hulbert choice minimizes the low frequency damping for a given (Chung and Hulbert 1993). The measured ratios are in the example.
- The auxiliary acceleration is not the physical one. is a time-shifted value, so a code that reports accelerations, for example floor response spectra, must say so or recompute them from the equation of motion.
Variants and improvements
- HHT-alpha () and WBZ-alpha (): the two one-shift members. HHT-alpha is the usual implicit dynamics option of several commercial finite element codes.
- First order systems (Jansen, Whiting and Hulbert 2000). The same idea for , with , and in their convention. It is used for stabilized finite element and variational multiscale flow solvers and in isogeometric fluid codes.
- Nonlinear and constrained systems. For multibody dynamics with constraints, Arnold and Bruls (2007) analyzed the method as an index-3 DAE integrator.
- Energy-momentum and energy-decaying schemes. For strongly nonlinear elastodynamics, generalized-alpha can still let the energy grow. Schemes based on discrete gradients bound the energy by construction.
When to use it
Use it as the default implicit integrator for linear and nonlinear structural dynamics with a mesh that has unresolved high modes, for example after a sudden load or with contact, where the trapezoidal rule leaves high frequency noise in the stresses. A value between and is common. Use the trapezoidal rule () when you need exact energy for a linear problem. Use the explicit central difference method for short wave and impact problems where the step is small anyway.
Pitfalls
- Wrong sign conventions. Papers and codes use , , for the same shift. A wrong sign gives a method that is first order or unstable. Check with the second order test and with the spectral radius at a large .
- Inconsistent initial acceleration. Line L1 computes from the equation of motion, but strictly should approximate . The difference is and is damped by the method, so it costs little in practice, but it shows up in the first steps of an error plot.
- Load at the wrong time. The load must be evaluated at (or averaged as ). Using makes the method first order for a time-dependent load.
- Low frequency damping is not zero. For a long simulation of a resolved mode still loses some amplitude, about in relative terms. For very long runs, use close to 1.
- Nonlinear energy growth. The linear stability proof does not cover nonlinear problems. Strongly nonlinear problems with large steps can still blow up.
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/generalized-alpha-method/. The authors are listed in prov/1NTWAK.jsonl.
"""Generalized-alpha time stepping (Chung and Hulbert 1993) for M a + C v + K d = F(t).
Matrices are lists of rows and vectors are lists, as in scimat. The step is dt.
The equation of motion is enforced at shifted points inside the step:
M a_(n+1-am) + C v_(n+1-af) + K d_(n+1-af) = F(t_(n+1-af)),
with x_(n+1-alpha) = (1 - alpha) x_(n+1) + alpha x_n, and the Newmark updates
for d and v. With Fraction data and parameters the steps are exact.
"""
import cmath
import math
import scimat
def chung_hulbert(rho_inf):
"""Return (alpha_m, alpha_f, beta, gamma) for the high frequency limit rho_inf in [0, 1]."""
if not 0 <= rho_inf <= 1:
raise ValueError("rho_inf must be in [0, 1]")
am = (2 * rho_inf - 1) / (rho_inf + 1)
af = rho_inf / (rho_inf + 1)
gamma = (1 - 2 * am + 2 * af) / 2
beta = (1 - am + af) ** 2 / 4
return am, af, beta, gamma
def hht(alpha):
"""Return the parameters of the HHT-alpha method; alpha in [0, 1/3] (am = 0, af = alpha)."""
if not 0 <= alpha <= 1 / 3:
raise ValueError("alpha must be in [0, 1/3]")
return 0 * alpha, alpha, (1 + alpha) ** 2 / 4, (1 + 2 * alpha) / 2
def wbz(rho_inf):
"""Return the parameters of the WBZ-alpha method (af = 0) for rho_inf in [0, 1]."""
am = (rho_inf - 1) / (rho_inf + 1)
return am, 0 * am, (1 - am) ** 2 / 4, (1 - 2 * am) / 2
def step(M, C, K, F, t, d, v, a, dt, am, af, beta, gamma):
"""Advance (d, v, a) at time t by one generalized-alpha step and return the new triple."""
n = len(d)
lhs = [[(1 - am) * M[i][j] + (1 - af) * (gamma * dt * C[i][j] + beta * dt * dt * K[i][j]) for j in range(n)] for i in range(n)]
dp = [d[i] + dt * v[i] + dt * dt / 2 * (1 - 2 * beta) * a[i] for i in range(n)] # @line L3
vp = [v[i] + (1 - gamma) * dt * a[i] for i in range(n)] # @line L4
dm = [(1 - af) * dp[i] + af * d[i] for i in range(n)]
vm = [(1 - af) * vp[i] + af * v[i] for i in range(n)]
rhs = scimat.sub(F(t + (1 - af) * dt), scimat.add(scimat.scale(am, scimat.matvec(M, a)), scimat.add(scimat.matvec(C, vm), scimat.matvec(K, dm)))) # @line L5
a1 = scimat.solve(lhs, rhs) # @line L6
d1 = [dp[i] + beta * dt * dt * a1[i] for i in range(n)] # @line L7
v1 = [vp[i] + gamma * dt * a1[i] for i in range(n)] # @line L8
return d1, v1, a1
def generalized_alpha(M, C, K, F, d0, v0, dt, nsteps, rho_inf=None, params=None):
"""Integrate M a + C v + K d = F(t) from (d0, v0) with nsteps steps of size dt.
Give either rho_inf (Chung-Hulbert parameters) or params = (am, af, beta, gamma).
Return the lists of displacements, velocities and accelerations.
"""
if params is None:
params = chung_hulbert(rho_inf)
am, af, beta, gamma = params
d, v = list(d0), list(v0)
a = scimat.solve(M, scimat.sub(scimat.sub(F(0 * dt), scimat.matvec(C, v)), scimat.matvec(K, d))) # @line L1
ds, vs, accs = [d], [v], [a]
for k in range(nsteps): # @line L2
d, v, a = step(M, C, K, F, k * dt, d, v, a, dt, am, af, beta, gamma)
ds.append(d)
vs.append(v)
accs.append(a)
return ds, vs, accs # @line L9
def amplification_matrix(omega_dt, params, xi=0.0):
"""Return the 3 by 3 matrix A with (d, dt v, dt^2 a)_(n+1) = A (d, dt v, dt^2 a)_n.
It is for a + 2 xi omega v + omega^2 d = 0 with dt = 1 and omega = omega_dt.
"""
am, af, beta, gamma = params
m, c, k = [[1.0]], [[2 * xi * omega_dt]], [[omega_dt * omega_dt]]
cols = []
for x in ((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)):
d1, v1, a1 = step(m, c, k, lambda t: [0.0], 0.0, [x[0]], [x[1]], [x[2]], 1.0, am, af, beta, gamma)
cols.append((d1[0], v1[0], a1[0]))
return [[cols[j][i] for j in range(3)] for i in range(3)]
def eigenvalues_3x3(a):
"""Return the three complex eigenvalues of a real 3 by 3 matrix (Durand-Kerner on its cubic)."""
tr = a[0][0] + a[1][1] + a[2][2]
minors = (a[0][0] * a[1][1] - a[0][1] * a[1][0]) + (a[0][0] * a[2][2] - a[0][2] * a[2][0]) + (a[1][1] * a[2][2] - a[1][2] * a[2][1])
det = scimat.det(a)
# characteristic polynomial: z^3 - tr z^2 + minors z - det
def p(z):
return ((z - tr) * z + minors) * z - det
scale = 1 + abs(tr) + abs(minors) + abs(det)
roots = [scale * (0.4 + 0.9j) ** k for k in range(3)]
for _ in range(500):
new = []
for i, z in enumerate(roots):
den = 1
for j, w in enumerate(roots):
if j != i:
den *= z - w
new.append(z - p(z) / den if den != 0 else z + 1e-12)
done = max(abs(x - y) for x, y in zip(new, roots)) < 1e-15 * scale
roots = new
if done:
break
return roots
def spectral_radius(omega_dt, params, xi=0.0):
"""Return the spectral radius of the step matrix at omega dt."""
return max(abs(z) for z in eigenvalues_3x3(amplification_matrix(omega_dt, params, xi)))
def principal_root(omega_dt, params):
"""Return the eigenvalue near exp(i omega dt) (positive imaginary part) of the undamped step.
Return None if the principal roots are real (no oscillation per step).
"""
roots = eigenvalues_3x3(amplification_matrix(omega_dt, params))
best = max(roots, key=lambda z: z.imag)
if best.imag <= 1e-14:
return None
return best
def damping_ratio_and_period_error(omega_dt, params):
"""Return (algorithmic damping ratio, relative period error) at omega dt.
The principal root is exp(omega_dt (-xi_bar + i) * wbar / omega) in polar form;
xi_bar = -ln|z| / arg z and the period error is omega_dt / arg z - 1.
"""
z = principal_root(omega_dt, params)
ang = cmath.phase(z)
return -math.log(abs(z)) / ang, omega_dt / ang - 1
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_generalized_alpha_method.py 153 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/generalized-alpha-method/. The authors are listed in prov/1NTWAK.jsonl.
import math
from fractions import Fraction as Fr
import scimat
from generalized_alpha_method import (
amplification_matrix,
chung_hulbert,
damping_ratio_and_period_error,
eigenvalues_3x3,
generalized_alpha,
hht,
spectral_radius,
wbz,
)
def free_sdof(omega, T, ns, params):
return generalized_alpha([[1.0]], [[0.0]], [[omega * omega]], lambda t: [0.0], [1.0], [0.0], T / ns, ns, params=params)
def errors_free(params, steps, T=2.0):
out = []
for ns in steps:
ds, vs, _ = free_sdof(1.0, T, ns, params)
out.append(math.hypot(ds[-1][0] - math.cos(T), vs[-1][0] + math.sin(T)))
return out
def test_parameters_from_rho_inf():
am, af, beta, gamma = chung_hulbert(Fr(1, 2))
assert (am, af, beta, gamma) == (Fr(0), Fr(1, 3), Fr(4, 9), Fr(5, 6))
am, af, beta, gamma = chung_hulbert(Fr(1))
assert (am, af, beta, gamma) == (Fr(1, 2), Fr(1, 2), Fr(1, 4), Fr(1, 2))
def test_rho_one_is_the_trapezoidal_rule():
# With rho_inf = 1 the step equals the average acceleration Newmark step, exactly.
M = [[Fr(2), Fr(0)], [Fr(0), Fr(1)]]
K = [[Fr(6), Fr(-2)], [Fr(-2), Fr(4)]]
C = [[Fr(0)] * 2 for _ in range(2)]
ds, vs, accs = generalized_alpha(M, C, K, lambda t: [Fr(0), Fr(0)], [Fr(1), Fr(0)], [Fr(0), Fr(1)], Fr(1, 2), 6, rho_inf=Fr(1))
e0 = (scimat.dot(vs[0], scimat.matvec(M, vs[0])) + scimat.dot(ds[0], scimat.matvec(K, ds[0]))) / 2
for d, v, a in zip(ds, vs, accs):
# the equation of motion holds at every step and the energy is exact
assert scimat.add(scimat.matvec(M, a), scimat.matvec(K, d)) == [0, 0]
assert (scimat.dot(v, scimat.matvec(M, v)) + scimat.dot(d, scimat.matvec(K, d))) / 2 == e0
def test_high_frequency_limit_is_rho_inf():
for r in (0.0, 0.3, 0.5, 0.8, 0.95):
p = chung_hulbert(r)
rho = spectral_radius(1e6, p)
assert abs(rho - r) < 2e-3, (r, rho)
# the three roots meet at -rho_inf
for z in eigenvalues_3x3(amplification_matrix(1e6, p)):
assert abs(z + r) < 5e-3
def test_unconditional_stability():
for r in (0.0, 0.3, 0.6, 0.9, 1.0):
p = chung_hulbert(r)
for k in range(-8, 13):
w = 10 ** (k / 4)
# near omega dt = infinity and rho_inf = 1 the roots form a near Jordan block, so allow rounding
assert spectral_radius(w, p) <= 1 + 1e-6, (r, w)
def test_second_order_for_all_rho():
for r in (0.0, 0.5, 0.9):
p = scimat.observed_order(errors_free(chung_hulbert(r), [40, 80, 160, 320]))
assert all(abs(q - 2) < 0.2 for q in p), (r, p)
def test_hht_and_wbz_second_order_and_limit():
for params, r in ((hht(0.1), 9 / 11), (hht(1 / 3), 0.5), (wbz(0.5), 0.5)):
p = scimat.observed_order(errors_free(params, [40, 80, 160, 320]))
assert all(abs(q - 2) < 0.2 for q in p), p
assert abs(spectral_radius(1e7, params) - r) < 1e-3
def test_less_low_frequency_damping_than_newmark():
# Same rho_inf = 9/11: Newmark with gamma = 0.6 damps the resolved modes far more.
newmark = (0.0, 0.0, 1.1 ** 2 / 4, 0.6)
ch = chung_hulbert(9 / 11)
for w in (0.1, 0.3, 1.0):
xn, _ = damping_ratio_and_period_error(w, newmark)
xc, _ = damping_ratio_and_period_error(w, ch)
xh, _ = damping_ratio_and_period_error(w, hht(0.1))
assert 0 <= xc < xh < xn
p = scimat.observed_order(errors_free(newmark, [80, 160, 320, 640]))
assert all(abs(q - 1) < 0.2 for q in p)
def test_damping_ratio_is_third_order_in_omega_dt():
p = chung_hulbert(0.5)
x = [damping_ratio_and_period_error(w, p)[0] for w in (0.2, 0.1, 0.05)]
orders = scimat.observed_order(x)
assert all(abs(q - 3) < 0.3 for q in orders), orders
def test_forced_damped_two_dof():
# M = I, C = 0.1 K, K = [[2, -1], [-1, 2]], F = (sin t, 0), against a fine reference run.
K = [[2.0, -1.0], [-1.0, 2.0]]
C = scimat.scale(0.1, K)
I2 = scimat.eye(2)
def F(t):
return [math.sin(t), 0.0]
T = 3.0
ref, _, _ = generalized_alpha(I2, C, K, F, [0.0, 0.0], [0.0, 0.0], T / 5120, 5120, rho_inf=0.6)
errs = []
for ns in (40, 80, 160):
ds, _, _ = generalized_alpha(I2, C, K, F, [0.0, 0.0], [0.0, 0.0], T / ns, ns, rho_inf=0.6)
errs.append(max(abs(x - y) for x, y in zip(ds[-1], ref[-1])))
p = scimat.observed_order(errs)
assert all(abs(q - 2) < 0.25 for q in p), p
def test_load_at_the_shifted_time():
# a + 0.2 v + d = cos t from rest. The load at t_(n+1-af) gives order 2; the load at t_(n+1) only order 1.
xi, T = 0.1, 4.0
wd = math.sqrt(1 - xi * xi)
def exact(t):
return 5 * math.sin(t) - 5 / wd * math.exp(-xi * t) * math.sin(wd * t)
params = chung_hulbert(0.5)
af = params[1]
for late, order in ((False, 2), (True, 1)):
errs = []
for ns in (50, 100, 200, 400):
dt = T / ns
F = (lambda t, dt=dt: [math.cos(t + af * dt)]) if late else (lambda t: [math.cos(t)])
ds, _, _ = generalized_alpha([[1.0]], [[0.2]], [[1.0]], F, [0.0], [0.0], dt, ns, params=params)
errs.append(abs(ds[-1][0] - exact(T)))
p = scimat.observed_order(errs)
assert abs(p[-1] - order) < 0.1, (late, p)
def test_stiff_mode_is_damped():
# A stiff spring (omega = 1000) next to a soft one; after 20 large steps the stiff mode is gone.
M = scimat.eye(2)
K = [[1.0, 0.0], [0.0, 1e6]]
Z = scimat.zeros(2)
ds, _, _ = generalized_alpha(M, Z, K, lambda t: [0.0, 0.0], [1.0, 1.0], [0.0, 0.0], 0.1, 20, rho_inf=0.0)
assert abs(ds[-1][1]) < 1e-12
assert abs(ds[-1][0] - math.cos(2.0)) < 1e-2
ds, _, _ = generalized_alpha(M, Z, K, lambda t: [0.0, 0.0], [1.0, 1.0], [0.0, 0.0], 0.1, 20, rho_inf=1.0)
assert abs(ds[-1][1]) > 0.5
History
Hilber, Hughes and Taylor in 1977 shifted the stiffness and load terms of the Newmark balance and obtained second order with controllable high frequency damping. Wood, Bossak and Zienkiewicz in 1980 shifted the inertia term instead. Chung and Hulbert in 1993 used both shifts, related all parameters to the single high frequency spectral radius , and showed that this choice gives the least low frequency damping for a given high frequency damping. Jansen, Whiting and Hulbert extended the method to first order systems in 2000, which made it a standard time integrator for stabilized flow solvers.
References
- J. Chung and G. M. Hulbert, A time integration algorithm for structural dynamics with improved numerical dissipation. The generalized-alpha method, Journal of Applied Mechanics 60(2) (1993) 371-375, the method, the parameter choice by rho_inf, the second order condition and the stability analysis
- H. M. Hilber, T. J. R. Hughes and R. L. Taylor, Improved numerical dissipation for time integration algorithms in structural dynamics, Earthquake Engineering and Structural Dynamics 5(3) (1977) 283-292, the HHT-alpha method
- W. L. Wood, M. Bossak and O. C. Zienkiewicz, An alpha modification of Newmark's method, International Journal for Numerical Methods in Engineering 15(10) (1980) 1562-1566, the WBZ-alpha method
- K. E. Jansen, C. H. Whiting and G. M. Hulbert, A generalized-alpha method for integrating the filtered Navier-Stokes equations with a stabilized finite element method, Computer Methods in Applied Mechanics and Engineering 190(3-4) (2000) 305-319, the generalized-alpha method for first order systems
- Thomas J. R. Hughes, The Finite Element Method, Linear Static and Dynamic Finite Element Analysis, Dover, 2000, Chapter 9 (Newmark and HHT-alpha methods, spectral radius, algorithmic damping and period error)
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 1NTWAK Edit this page History Report an error Markdown