Algorithm Search⌘K

Algorithmresearch

Generalized interpolation material point method

Also called GIMP.

Gives each material point a finite domain and averages the grid shape functions over it, which reduces the cell crossing noise of the original MPM.

Time
Θ(N + M) worst
Space
Θ(M) extra
Where
M = the number of grid nodes; N = the number of material points
Properties
conservativedeterministic
Origin
Scott G. Bardenhagen, Edward M. Kober, 2004

The generalized interpolation material point method (GIMP) is a version of the material point method in which each material point is not a point but a small region of the body, its domain. The weight that connects a point to a grid node is the average of the node's shape function over the domain, and the force uses the gradient of that average. With the linear hats of the original method, the force on a node jumps each time a point crosses a cell boundary; with GIMP the weights and their gradients change continuously, so the jumps go away and the stress noise is much smaller. The cost per step is the same order as MPM.

In plain words

In the plain material point method each bead of material talks only to the two grid points around its centre. When a bead moves across a grid point, its pull on that grid point changes all at once, and the forces in the material jump. In GIMP each bead is a short piece of material with a width. Its pull on a grid point is the average pull over its whole width. When the piece slides over a grid point, part of it is on each side for a while, so the pull changes smoothly. If the pieces fit together with no gaps, a material under even tension feels no false forces inside at all, only at its two ends.

The problem

The input is the same as for MPM: NN material points with mass mpm_p, initial volume Vp0V_p^0, position xpx_p, velocity vpv_p, deformation gradient FpF_p and stress σp\sigma_p; the stress rule (here 1D linear elasticity, σ˙=Eε˙\dot\sigma = E \dot\varepsilon); a grid of nodes xi=iΔxx_i = i \Delta x with the hats Ni(x)=max⁡(0,1−∣x−xi∣/Δx)N_i(x) = \max(0, 1 - |x - x_i| / \Delta x); the supports; and a step hh. In addition each point has a half width lpl_p, here lp=Fplp0l_p = F_p l_p^0, so in 1D the domain Ωp=[xp−lp,xp+lp]\Omega_p = [x_p - l_p, x_p + l_p] stretches with the material (the contiguous particle form, cpGIMP). The GIMP weight and its gradient are

Sip=12lp∫xp−lpxp+lpNi(x) dx,Sip′=∂Sip∂xp=Ni(xp+lp)−Ni(xp−lp)2lp.S_{ip} = \frac{1}{2 l_p} \int_{x_p - l_p}^{x_p + l_p} N_i(x)\, dx, \qquad S_{ip}' = \frac{\partial S_{ip}}{\partial x_p} = \frac{N_i(x_p + l_p) - N_i(x_p - l_p)}{2 l_p}.

With the antiderivative Φ\Phi of the unit hat, Φ(t)=0\Phi(t) = 0 for t≤−1t \le -1, (t+1)2/2(t + 1)^2 / 2 for −1≤t≤0-1 \le t \le 0, 1−(1−t)2/21 - (1 - t)^2 / 2 for 0≤t≤10 \le t \le 1, and 11 for t≥1t \ge 1, the weight is Sip=Δx(Φ((xp+lp−xi)/Δx)−Φ((xp−lp−xi)/Δx))/(2lp)S_{ip} = \Delta x \bigl(\Phi((x_p + l_p - x_i)/\Delta x) - \Phi((x_p - l_p - x_i)/\Delta x)\bigr) / (2 l_p). The rest of the step is the update stress last MPM step with SipS_{ip} and Sip′S_{ip}' in place of Ni(xp)N_i(x_p) and Ni′(xp)N_i'(x_p).

The algorithm

  1. GIMP-STEP(points, grid, E, h)
  2. 1for each material point p do ▷ points to grid
  3. 2l_p ← F_p l_p^0; for each node i whose hat meets [x_p - l_p, x_p + l_p] do
  4. 3S_ip ← (1 / (2 l_p)) ∫ N_i over [x_p - l_p, x_p + l_p]
  5. 4S′_ip ← (N_i(x_p + l_p) - N_i(x_p - l_p)) / (2 l_p)
  6. 5m_i += S_ip m_p; (mv)_i += S_ip m_p v_p
  7. 6f_i ← -Σ_p V_p σ_p S′_ip for every node i ▷ internal force, V_p = F_p V_p^0
  8. 7v_i ← (mv)_i / m_i; v_i^new ← v_i + h f_i / m_i; v_i^new ← 0 at fixed nodes; a_i ← (v_i^new - v_i) / h
  9. 8for each material point p do ▷ grid to points
  10. 9v_p ← v_p + h Σ_i S_ip a_i; x_p ← x_p + h Σ_i S_ip v_i^new
  11. 10ε̇_p ← Σ_i S′_ip v_i^new; F_p ← (1 + h ε̇_p) F_p; σ_p ← σ_p + E h ε̇_p
  12. 11return the points; clear the grid

Lines L2 to L4 are the only change from MPM. With lp≤Δxl_p \le \Delta x, a domain meets at most 3 hats in 1D, so line L2 visits at most 3 nodes, against 2 for MPM. Line L7 is the lumped explicit grid update with the supports, and lines L9 and L10 are the FLIP update and the stress update at the points, as in MPM.

Example

Take the cell crossing example of the MPM page: Δx=1\Delta x = 1, 8 points at x=0.3,0.9,…,4.5x = 0.3, 0.9, \ldots, 4.5, each with Vp=0.6V_p = 0.6 and σ=1\sigma = 1. Give each point the half width lp=0.3l_p = 0.3, so the domains [0,0.6],[0.6,1.2],…,[4.2,4.8][0, 0.6], [0.6, 1.2], \ldots, [4.2, 4.8] fill the body [0,4.8][0, 4.8] with no gaps.

The point at 0.90.9 has the domain [0.6,1.2][0.6, 1.2]. On it, N0N_0 has the mean 0.08/0.6=2/150.08 / 0.6 = 2/15, N1N_1 has the mean 0.5/0.6=5/60.5 / 0.6 = 5/6 and N2N_2 has the mean 0.02/0.6=1/300.02 / 0.6 = 1/30; the three add up to 1. The gradients are S0′=(0−0.4)/0.6=−2/3S_0' = (0 - 0.4) / 0.6 = -2/3, S1′=(0.8−0.6)/0.6=1/3S_1' = (0.8 - 0.6)/0.6 = 1/3 and S2′=(0.2−0)/0.6=1/3S_2' = (0.2 - 0)/0.6 = 1/3.

Line L6 then gives the nodal forces f=(1,0,0,0,−0.2,−0.8,0)f = (1, 0, 0, 0, -0.2, -0.8, 0) at nodes 0 to 6. The interior nodes 1, 2 and 3 get no force, where MPM gave −0.6,0.6,0-0.6, 0.6, 0 at nodes 1 to 3. The only forces are the traction of the stress at the two ends of the body: +1+1 at the left end x=0x = 0, and −1-1 at the right end x=4.8x = 4.8, shared by nodes 4 and 5 in the ratio N4(4.8):N5(4.8)=0.2:0.8N_4(4.8) : N_5(4.8) = 0.2 : 0.8.

A measurement with the code on this page shows the effect on a run. Take the vibrating bar of the MPM page (E=100E = 100, ρ=1\rho = 1, 20 cells, 2 points per cell, h=0.1Δx/ch = 0.1 \Delta x / c, 800 steps, one period), started with v0=1v_0 = 1. The displacement amplitude v0/ω1≈0.064v_0 / \omega_1 \approx 0.064 is larger than Δx=0.05\Delta x = 0.05, so points cross cells. The largest second difference of the stress along the points, divided by Ev0/cE v_0 / c, is 0.044 with GIMP and 2.7 with MPM, and the energy error is 6 percent with GIMP and 26 percent with MPM. At v0=0.1v_0 = 0.1, where no point crosses a cell, the two methods agree.

Correctness

The full proof is in the correctness proof. It proves these facts (theorems, in exact arithmetic):

  • The weights form a partition of unity and reproduce linear functions: ∑iSip=1\sum_i S_{ip} = 1, ∑iSipxi=xp\sum_i S_{ip} x_i = x_p and ∑iSip′=0\sum_i S_{ip}' = 0. So the transfer of mass and momentum is exact, momentum is conserved without supports, and a rigid translation is exact, by the same arguments as for MPM.
  • Sip′S_{ip}' is the derivative of SipS_{ip} with respect to xpx_p, and for lp>0l_p > 0 it is a Lipschitz continuous function of xpx_p with constant 1/(lpΔx)1 / (l_p \Delta x). So no nodal force jumps when a point crosses a node or a cell boundary.
  • If the domains tile an interval [a,b][a, b] and Vp=2lpV_p = 2 l_p (unit cross section), a uniform stress σ\sigma gives fi=σ(Ni(a)−Ni(b))f_i = \sigma (N_i(a) - N_i(b)): zero at every node whose hat does not reach an end of the body.

The last fact holds for any tiling, with points of any sizes and at any positions. For MPM the same force is the stress times the difference of the particle volumes in two cells, which is zero only for special positions.

GIMP does not make the method exact. When the domains do not tile the body, for example after a 2D or 3D deformation that the axis aligned domains of the simple form cannot follow, the quadrature error comes back, usually smaller than in MPM (a heuristic, not a bound); Steffen, Kirby and Berzins (2008) analyse these errors.

Proof: The GIMP weights form a partition of unity, their gradients are continuous in the point position, and tiling domains under a uniform stress give no interior forcefull

We work in 1D with the hats Ni(x)=max⁡(0,1−∣x−xi∣/Δx)N_i(x) = \max(0, 1 - |x - x_i| / \Delta x), xi=iΔxx_i = i \Delta x, and exact arithmetic. A point pp has the domain [ap,bp]=[xp−lp,xp+lp][a_p, b_p] = [x_p - l_p, x_p + l_p] with lp>0l_p > 0, and

Sip=12lp∫apbpNi(x) dx,Sip′=Ni(bp)−Ni(ap)2lp.S_{ip} = \frac{1}{2 l_p} \int_{a_p}^{b_p} N_i(x)\, dx, \qquad S_{ip}' = \frac{N_i(b_p) - N_i(a_p)}{2 l_p}.

Line L2 visits every node whose hat is not zero on an open part of the domain, and the other nodes have Sip=Sip′=0S_{ip} = S_{ip}' = 0, so sums over the visited nodes equal sums over all nodes. We use two facts of the hats: for every xx, ∑iNi(x)=1\sum_i N_i(x) = 1 and ∑iNi(x) xi=x\sum_i N_i(x)\, x_i = x (on the cell [xj,xj+1][x_j, x_{j+1}] only NjN_j and Nj+1N_{j+1} are not zero, and they are 1−w1 - w and ww with x=xj+wΔxx = x_j + w \Delta x).

Claim 1 (partition of unity). ∑iSip=1\sum_i S_{ip} = 1, ∑iSip xi=xp\sum_i S_{ip}\, x_i = x_p and ∑iSip′=0\sum_i S_{ip}' = 0.

Proof. Only finitely many terms are not zero, so the sum and the integral commute: ∑iSip=12lp∫apbp∑iNi(x) dx=12lp(bp−ap)=1\sum_i S_{ip} = \frac{1}{2 l_p} \int_{a_p}^{b_p} \sum_i N_i(x)\, dx = \frac{1}{2 l_p} (b_p - a_p) = 1. In the same way ∑iSipxi=12lp∫apbpx dx=ap+bp2=xp\sum_i S_{ip} x_i = \frac{1}{2 l_p} \int_{a_p}^{b_p} x\, dx = \frac{a_p + b_p}{2} = x_p. Finally ∑iSip′=(∑iNi(bp)−∑iNi(ap))/(2lp)=(1−1)/(2lp)=0\sum_i S_{ip}' = (\sum_i N_i(b_p) - \sum_i N_i(a_p)) / (2 l_p) = (1 - 1)/(2 l_p) = 0. □\square

With Claim 1 in place of the partition of unity of the hats, the proofs of Claims 1, 2 and 3 on the MPM page go through word for word: the transfer in line L5 puts all mass and momentum on the grid, the step conserves momentum when no node is fixed (since ∑ifi=−∑pVpσp∑iSip′=0\sum_i f_i = -\sum_p V_p \sigma_p \sum_i S_{ip}' = 0), and a rigid translation with zero stress is reproduced exactly (each point moves by h∑iSipu=huh \sum_i S_{ip} u = h u and has ε˙p=u∑iSip′=0\dot\varepsilon_p = u \sum_i S_{ip}' = 0). These need the same assumption as there, that every node with Sip≠0S_{ip} \ne 0 or Sip′≠0S_{ip}' \ne 0 for some point has a positive mass.

Claim 2 (the gradient). For fixed lpl_p, SipS_{ip} is a continuously differentiable function of xpx_p with derivative Sip′S_{ip}', and for all xx, yy,

∣Sip′(x)−Sip′(y)∣≤∣x−y∣lpΔx.|S_{ip}'(x) - S_{ip}'(y)| \le \frac{|x - y|}{l_p \Delta x}.

Proof. NiN_i is continuous, so by the fundamental theorem of calculus ddxp∫xp−lpxp+lpNi=Ni(xp+lp)−Ni(xp−lp)\frac{d}{dx_p} \int_{x_p - l_p}^{x_p + l_p} N_i = N_i(x_p + l_p) - N_i(x_p - l_p), and dividing by 2lp2 l_p gives Sip′S_{ip}'. This is continuous in xpx_p because NiN_i is. NiN_i is Lipschitz with constant 1/Δx1/\Delta x, so each of the two terms changes by at most ∣x−y∣/Δx|x - y| / \Delta x, and ∣Sip′(x)−Sip′(y)∣≤2∣x−y∣/(2lpΔx)|S_{ip}'(x) - S_{ip}'(y)| \le 2 |x - y| / (2 l_p \Delta x). □\square

So the internal force fi=−∑pVpσpSip′f_i = -\sum_p V_p \sigma_p S_{ip}' is a continuous function of the positions, and it cannot jump when a point crosses a node or a cell boundary. For the hats themselves (lp→0l_p \to 0), Ni′N_i' jumps by 1/Δx1/\Delta x at each node, which is the cell crossing jump of MPM.

Claim 3 (no interior force for tiling domains). Let the domains of points 1,…,n1, \ldots, n tile [a,b][a, b], that is a1=aa_1 = a, bk=ak+1b_k = a_{k+1} for k<nk < n and bn=bb_n = b; let Vp=bp−ap=2lpV_p = b_p - a_p = 2 l_p, and let every point have the stress σ\sigma. Then for every node ii,

fi=σ(Ni(a)−Ni(b)).f_i = \sigma \bigl(N_i(a) - N_i(b)\bigr).

Proof. VpSip′=Ni(bp)−Ni(ap)V_p S_{ip}' = N_i(b_p) - N_i(a_p), so

fi=−σ∑p=1n(Ni(bp)−Ni(ap))=−σ(Ni(bn)−Ni(a1)),f_i = -\sigma \sum_{p=1}^{n} \bigl(N_i(b_p) - N_i(a_p)\bigr) = -\sigma \bigl(N_i(b_n) - N_i(a_1)\bigr),

since the sum telescopes by bk=ak+1b_k = a_{k+1}. □\square

Ni(a)=0N_i(a) = 0 and Ni(b)=0N_i(b) = 0 for every node with ∣xi−a∣≥Δx|x_i - a| \ge \Delta x and ∣xi−b∣≥Δx|x_i - b| \ge \Delta x, so these nodes get no force, whatever the sizes and positions of the points. The forces at the remaining nodes are the traction +σ+\sigma at the left end and −σ-\sigma at the right end, spread over the nodes by the hats; in the example of the page, a=0a = 0 and b=4.8b = 4.8 give f=(1,0,0,0,−0.2,−0.8,0)f = (1, 0, 0, 0, -0.2, -0.8, 0).

Claim 4 (the MPM limit). If xpx_p is not a node, then Sip→Ni(xp)S_{ip} \to N_i(x_p) and Sip′→Ni′(xp)S_{ip}' \to N_i'(x_p) as lp→0l_p \to 0.

Proof. SipS_{ip} is the mean of a continuous function over an interval that shrinks to xpx_p, so it tends to Ni(xp)N_i(x_p). For lpl_p smaller than the distance from xpx_p to the nearest node, NiN_i is linear on [ap,bp][a_p, b_p], so Sip′=(Ni(bp)−Ni(ap))/(bp−ap)=Ni′(xp)S_{ip}' = (N_i(b_p) - N_i(a_p)) / (b_p - a_p) = N_i'(x_p) exactly. ■\blacksquare

Complexity

In the real-RAM model, with lp≤Δxl_p \le \Delta x each point meets at most 3 hats per axis, so 3d3^d nodes in dd dimensions, against 2d2^d for MPM with linear hats. Each weight costs O(1)O(1) through Φ\Phi. So one step costs Θ(N+M)\Theta(N + M) time and Θ(M)\Theta(M) extra space, a constant factor of about (3/2)d(3/2)^d above MPM for the transfers. The explicit step has the same CFL limit as MPM.

Properties

  • Continuous weights and gradients. SipS_{ip} is continuously differentiable in xpx_p, so the forces change smoothly as points move.
  • Conservation. Mass is exact, and momentum is conserved without supports, as in MPM.
  • No interior force from a uniform stress when the domains tile the body (a theorem in 1D).
  • The MPM limit. As lp→0l_p \to 0, Sip→Ni(xp)S_{ip} \to N_i(x_p) and Sip′→Ni′(xp)S_{ip}' \to N_i'(x_p) away from the nodes, so MPM is the limit of GIMP.
  • Wider stencil. A point reaches nodes up to Δx+lp\Delta x + l_p away, so the grid needs one more layer of nodes at the edges of the body.

Variants and improvements

  • uGIMP. The domain size stays lp0l_p^0 for the whole run. This is cheap and is the form used in many codes, but the domains stop tiling the body under large stretch or compression.
  • cpGIMP. The domain follows the stretch of the material along each axis, as in the code on this page (lp=Fplp0l_p = F_p l_p^0).
  • CPDI. The convected particle domain interpolation of Sadeghirad, Brannon and Burghardt (2011) follows the domain as a parallelogram or a tetrahedron under the full deformation gradient, which also handles shear and rotation.
  • B-spline MPM. Quadratic or cubic B-spline shape functions on the grid have continuous gradients, which removes the jumps without particle domains. Computer graphics codes for snow and sand, for example those built on APIC, usually take this route; they use quadratic B-spline weights and do not use GIMP domains, and they aim at visual plausibility rather than at convergent stresses.

When to use it

Use GIMP when an MPM solid moves more than a cell and the stress matters, for example in impact, soil and other geomechanics problems, or in any MPM run where the stress shows noise from cell crossing. If the deformation is small, so that the points stay in their cells, plain MPM gives the same answer at less cost. If shear and rotation are large in 2D or 3D, prefer CPDI or B-spline shape functions.

Pitfalls

  • Domains that leave the grid. A point near the edge of the body reaches one more node than in MPM; the grid must have that node.
  • The wrong domain size at the start. For the zero interior force result, the domains must tile the body: with ncn_c points per cell in 1D, lp0=Δx/(2nc)l_p^0 = \Delta x / (2 n_c) and the points at the centres of their domains.
  • Mixing uGIMP and the tiling claim. With fixed domain sizes, a stretched body has gaps between domains and a compressed one has overlaps, and the force from a uniform stress is no longer zero.
  • Tiny nodal masses. As in MPM, a node with a very small mass gets a huge acceleration; skip or threshold such nodes.
  • Boundary conditions. A support acts on nodes, and the domain of a point next to a fixed node also overlaps the next node; check that the boundary is where the domains end.

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.

generalized_interpolation_material_point.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/generalized-interpolation-material-point/. The authors are listed in prov/4J3GZH.jsonl.
"""The generalized interpolation material point (GIMP) method in 1D.

Each material point p has a domain [x_p - l_p, x_p + l_p]. The grid uses the
linear hats N_i(x) = max(0, 1 - |x - x_i| / dx), x_i = i dx. The GIMP weight
of node i is the mean of N_i over the domain,

    S_ip = (1 / (2 l_p)) * integral of N_i over [x_p - l_p, x_p + l_p],

and its gradient with respect to x_p is

    dS_ip = (N_i(x_p + l_p) - N_i(x_p - l_p)) / (2 l_p).

In 1D the domain follows the deformation: l_p = F_p l_p^0 (the "contiguous
particle" form, cpGIMP). The rest of the step is the update-stress-last MPM
step with the FLIP velocity update.

Cost per step: Theta(N + n) time for N points and n nodes, if l_p <= dx.
"""

import math
from dataclasses import dataclass, field


def hat(t: float) -> float:
    """N(t) = max(0, 1 - |t|) in units of dx."""
    return max(0.0, 1.0 - abs(t))


def hat_integral(t: float) -> float:
    """Phi(t) = integral of N from -infinity to t, in units of dx."""
    if t <= -1:
        return 0.0
    if t <= 0:
        return (t + 1) ** 2 / 2
    if t <= 1:
        return 1 - (1 - t) ** 2 / 2
    return 1.0


def gimp_weights(x: float, lp: float, dx: float) -> list[tuple[int, float, float]]:
    """(i, S_ip, dS_ip) for every node i whose hat overlaps the domain [x - lp, x + lp]; lp > 0."""
    a, b = x - lp, x + lp
    out = []
    for i in range(math.floor(a / dx) - 1, math.floor(b / dx) + 2):  # @line L2
        s = dx * (hat_integral((b - i * dx) / dx) - hat_integral((a - i * dx) / dx)) / (2 * lp)  # @line L3
        g = (hat((b - i * dx) / dx) - hat((a - i * dx) / dx)) / (2 * lp)  # @line L4
        if s != 0.0 or g != 0.0:
            out.append((i, s, g))
    return out


@dataclass
class Points:
    x: list[float]
    v: list[float]
    m: list[float]
    vol0: list[float]
    l0: list[float]
    F: list[float] = field(default_factory=list)
    stress: list[float] = field(default_factory=list)

    def __post_init__(self):
        if not self.F:
            self.F = [1.0] * len(self.x)
        if not self.stress:
            self.stress = [0.0] * len(self.x)


def grid_force(ps: Points, dx: float, n: int) -> list[float]:
    """f_i = -sum_p V_p sigma_p dS_ip with V_p = F_p V_p^0 and l_p = F_p l_p^0."""
    f = [0.0] * n
    for p in range(len(ps.x)):
        for i, _, g in gimp_weights(ps.x[p], ps.F[p] * ps.l0[p], dx):
            f[i] -= ps.F[p] * ps.vol0[p] * ps.stress[p] * g
    return f


def gimp_step(ps: Points, dx: float, n: int, young: float, h: float, fixed: frozenset = frozenset()) -> Points:
    """One update-stress-last step with GIMP weights, for sigma_dot = E eps_dot."""
    mass, mom = [0.0] * n, [0.0] * n
    weights = []
    for p in range(len(ps.x)):  # @line L1
        ws = gimp_weights(ps.x[p], ps.F[p] * ps.l0[p], dx)
        weights.append(ws)
        for i, s, _ in ws:
            mass[i] += s * ps.m[p]  # @line L5
            mom[i] += s * ps.m[p] * ps.v[p]  # @line L5
    f = grid_force(ps, dx, n)  # @line L6
    v_old = [mom[i] / mass[i] if mass[i] > 0 else 0.0 for i in range(n)]  # @line L7
    v_new = [v_old[i] + h * f[i] / mass[i] if mass[i] > 0 else 0.0 for i in range(n)]  # @line L7
    for i in fixed:  # @line L7
        v_new[i] = 0.0  # @line L7
    acc = [(v_new[i] - v_old[i]) / h for i in range(n)]  # @line L7
    out = Points(list(ps.x), list(ps.v), list(ps.m), list(ps.vol0), list(ps.l0), list(ps.F), list(ps.stress))
    for p, ws in enumerate(weights):  # @line L8
        out.v[p] = ps.v[p] + h * sum(s * acc[i] for i, s, _ in ws)  # @line L9
        out.x[p] = ps.x[p] + h * sum(s * v_new[i] for i, s, _ in ws)  # @line L9
        rate = sum(g * v_new[i] for i, _, g in ws)  # @line L10
        out.F[p] = ps.F[p] * (1 + h * rate)  # @line L10
        out.stress[p] = ps.stress[p] + young * h * rate  # @line L10
    return out  # @line L11


def vibrating_bar(cells: int, ppc: int, length: float, rho: float, v0: float):
    """Points of a bar on [0, length] in its first mode, with domains that tile the bar."""
    dx = length / cells
    xs, vs, ms, vols, ls = [], [], [], [], []
    for c in range(cells):
        for k in range(ppc):
            x = (c + (k + 0.5) / ppc) * dx
            xs.append(x)
            vs.append(v0 * math.sin(math.pi * x / (2 * length)))
            vols.append(dx / ppc)
            ms.append(rho * dx / ppc)
            ls.append(dx / (2 * ppc))
    return Points(xs, vs, ms, vols, ls), dx, cells + 3
test_generalized_interpolation_material_point.py 133 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/generalized-interpolation-material-point/. The authors are listed in prov/4J3GZH.jsonl.
import math
import random

import pytest

from generalized_interpolation_material_point import Points, gimp_step, gimp_weights, grid_force, hat, vibrating_bar


def quadrature_weight(i, x, lp, dx, k=2000):
    # oracle: the midpoint rule for the mean of N_i over [x - lp, x + lp]
    a = x - lp
    return sum(hat((a + (j + 0.5) * 2 * lp / k - i * dx) / dx) for j in range(k)) / k


def test_page_example_has_no_interior_force():
    ps = Points([0.3 + 0.6 * k for k in range(8)], [0.0] * 8, [0.6] * 8, [0.6] * 8, [0.3] * 8, stress=[1.0] * 8)
    f = grid_force(ps, 1.0, 7)
    assert f == pytest.approx([1.0, 0.0, 0.0, 0.0, -0.2, -0.8, 0.0], abs=1e-12)
    ws = gimp_weights(0.9, 0.3, 1.0)
    assert [i for i, _, _ in ws] == [0, 1, 2]
    assert [s for _, s, _ in ws] == pytest.approx([2 / 15, 5 / 6, 1 / 30], abs=1e-12)
    assert [g for _, _, g in ws] == pytest.approx([-2 / 3, 1 / 3, 1 / 3], abs=1e-12)


def test_weights_match_quadrature_and_form_a_partition_of_unity():
    rng = random.Random(1)
    for _ in range(60):
        dx = rng.uniform(0.2, 2)
        lp = rng.uniform(0.01, 1) * dx
        x = rng.uniform(2, 10)
        ws = gimp_weights(x, lp, dx)
        for i, s, _ in ws:
            assert s == pytest.approx(quadrature_weight(i, x, lp, dx), abs=1e-6)
        assert sum(s for _, s, _ in ws) == pytest.approx(1, abs=1e-12)
        assert sum(s * i * dx for i, s, _ in ws) == pytest.approx(x, abs=1e-9)
        assert sum(g for _, _, g in ws) == pytest.approx(0, abs=1e-12)
        assert all(s >= 0 for _, s, _ in ws)


def test_gradient_is_the_derivative_of_the_weight():
    rng = random.Random(2)
    for _ in range(200):
        dx, lp = 1.0, rng.uniform(0.05, 0.5)
        x, d = rng.uniform(2, 6), 1e-6
        up = dict((i, s) for i, s, _ in gimp_weights(x + d, lp, dx))
        dn = dict((i, s) for i, s, _ in gimp_weights(x - d, lp, dx))
        for i, _, g in gimp_weights(x, lp, dx):
            assert (up.get(i, 0.0) - dn.get(i, 0.0)) / (2 * d) == pytest.approx(g, abs=1e-5)


def test_gradient_is_continuous_in_the_position():
    # |dS(x + e) - dS(x)| <= e / (lp dx): no jump when a point crosses a node
    rng = random.Random(3)
    for _ in range(300):
        dx, lp, e = 1.0, rng.uniform(0.05, 0.5), 1e-7
        x = rng.choice([3.0, 3.0 + lp, 3.0 - lp, rng.uniform(2, 6)])
        a = dict((i, g) for i, _, g in gimp_weights(x - e, lp, dx))
        b = dict((i, g) for i, _, g in gimp_weights(x + e, lp, dx))
        for i in set(a) | set(b):
            assert abs(a.get(i, 0.0) - b.get(i, 0.0)) <= 2 * e / (lp * dx) + 1e-12


def test_small_domains_give_the_mpm_hat_weights():
    rng = random.Random(4)
    for _ in range(100):
        dx = rng.uniform(0.5, 2)
        x = (rng.randint(2, 8) + rng.uniform(0.1, 0.9)) * dx
        j, w = math.floor(x / dx), x / dx - math.floor(x / dx)
        ws = dict((i, (s, g)) for i, s, g in gimp_weights(x, 1e-6 * dx, dx))
        assert ws[j][0] == pytest.approx(1 - w, abs=1e-9) and ws[j + 1][0] == pytest.approx(w, abs=1e-9)
        assert ws[j][1] == pytest.approx(-1 / dx, abs=1e-9) and ws[j + 1][1] == pytest.approx(1 / dx, abs=1e-9)


def test_any_tiling_with_uniform_stress_has_zero_interior_force():
    rng = random.Random(5)
    for _ in range(30):
        cuts = sorted(rng.uniform(1.0, 7.0) for _ in range(rng.randint(3, 12)))
        lengths = [b - a for a, b in zip(cuts, cuts[1:])]
        xs = [(a + b) / 2 for a, b in zip(cuts, cuts[1:])]
        s = rng.uniform(-2, 2)
        ps = Points(xs, [0.0] * len(xs), [1.0] * len(xs), lengths, [d / 2 for d in lengths], stress=[s] * len(xs))
        f = grid_force(ps, 1.0, 10)
        for i in range(10):
            # only the two ends of the body carry the traction
            assert f[i] == pytest.approx(s * hat(cuts[0] - i) - s * hat(cuts[-1] - i), abs=1e-12)


def test_momentum_is_conserved_and_rigid_translation_is_exact():
    rng = random.Random(6)
    n, dx = 16, 0.5
    xs = [rng.uniform(2, 5) for _ in range(30)]
    ps = Points(xs, [rng.uniform(-1, 1) for _ in xs], [rng.uniform(0.5, 2) for _ in xs], [0.1] * 30, [0.05] * 30,
                stress=[rng.uniform(-1, 1) for _ in xs])
    p0 = sum(m * v for m, v in zip(ps.m, ps.v))
    for _ in range(50):
        ps = gimp_step(ps, dx, n, 10.0, 1e-3)
    assert sum(m * v for m, v in zip(ps.m, ps.v)) == pytest.approx(p0, abs=1e-10)
    xs = [0.5 + 0.25 * k for k in range(10)]
    ps = Points(xs, [0.3] * 10, [1.0] * 10, [0.25] * 10, [0.125] * 10)
    for _ in range(100):
        ps = gimp_step(ps, 0.5, 12, 50.0, 0.01)
    assert ps.v == pytest.approx([0.3] * 10, abs=1e-12)
    assert ps.x == pytest.approx([x + 0.3 for x in xs], abs=1e-9)
    assert ps.stress == pytest.approx([0.0] * 10, abs=1e-12)


def test_vibrating_bar_first_mode():
    young, rho, length, v0 = 100.0, 1.0, 1.0, 0.1
    ps, dx, n = vibrating_bar(20, 2, length, rho, v0)
    c = math.sqrt(young / rho)
    h = 0.1 * dx / c
    w1 = math.pi * c / (2 * length)
    worst = 0.0
    for s in range(1, int(round(0.4 / h)) + 1):
        ps = gimp_step(ps, dx, n, young, h, frozenset([0]))
        vcm = sum(m * v for m, v in zip(ps.m, ps.v)) / sum(ps.m)
        worst = max(worst, abs(vcm - 2 / math.pi * v0 * math.cos(w1 * s * h)))
    assert worst < 0.02 * (2 / math.pi * v0)


def test_stress_stays_smooth_when_points_cross_cells():
    # displacement amplitude v0 / omega_1 = 0.064 > dx = 0.05, so points cross cell boundaries
    young, rho, length, v0 = 100.0, 1.0, 1.0, 1.0
    ps, dx, n = vibrating_bar(20, 2, length, rho, v0)
    h = 0.1 * dx / math.sqrt(young / rho)
    rough = 0.0
    for _ in range(800):
        ps = gimp_step(ps, dx, n + 8, young, h, frozenset([0]))
        st = ps.stress
        rough = max(rough, max(abs(st[k + 1] - 2 * st[k] + st[k - 1]) for k in range(1, len(st) - 1)))
    assert rough < 0.1 * young * v0 / math.sqrt(young / rho)

History

Bardenhagen and Kober (2004) wrote the weak form of the momentum equation with a characteristic function for the region of each material point. With a Dirac delta as the characteristic function they got the original MPM of Sulsky, Chen and Schreyer (1994), and with the indicator function of a box they got GIMP. They showed that the noise of MPM comes from the jumps of the hat gradients at cell boundaries. Steffen, Kirby and Berzins (2008) analysed the quadrature errors of both methods and their effect on convergence in space. CPDI followed in 2011.

References

  1. Scott G. Bardenhagen and Edward M. Kober, The generalized interpolation material point method, Computer Modeling in Engineering and Sciences 5(6), 2004, 477-495, the weak form with particle characteristic functions, the GIMP weights and the cell crossing noise
  2. Michael Steffen, Robert M. Kirby and Martin Berzins, Analysis and reduction of quadrature errors in the material point method (MPM), International Journal for Numerical Methods in Engineering 76(6), 2008, 922-948, the quadrature errors of MPM and GIMP and their effect on convergence
  3. Deborah Sulsky, Zhen Chen and Howard L. Schreyer, A particle method for history-dependent materials, Computer Methods in Applied Mechanics and Engineering 118(1-2), 1994, 179-196, the original MPM that GIMP changes

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 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