Algorithm Search⌘K

Algorithmadvanced

FE2 method

Also called FE squared method.

Computes the stress at each integration point of a macroscopic finite element model by solving a finite element problem on a representative volume element.

Time
Θ(p q M n) worst
Space
Θ(M + n) extra
Where
M = the number of macro integration points; n = the number of micro cells of the RVE; p = the number of macro Newton steps; q = the number of micro Newton steps per RVE solve
Properties
concurrent couplingconsistent tangentdeterministicnested newton
Origin
Frederic Feyel, Jean Louis Chaboche, 1999

The FE2 method is a nested finite element method for materials whose stress-strain law is not known in closed form, because it comes from a microstructure. A macroscopic finite element model of the part needs the stress at each integration point. FE2 computes it by solving a second finite element problem on a representative volume element (RVE) of the microstructure, loaded by the macroscopic strain at that point, and taking the volume average of the micro stress. The same RVE problem gives the macroscopic tangent by static condensation, so the macro problem can be solved by Newton's method. The method needs no fitted constitutive law, and it follows nonlinear and history-dependent micro behavior at the cost of one RVE solve per integration point per Newton step.

In plain words

An engineer wants to know how a composite part bends under load. The fibers and the matrix each have a known behavior, but how the mix behaves is not known, and it changes as the matrix yields. FE2 runs two simulations, one inside the other. The big one models the part on a coarse mesh. Wherever the big one asks how much stress a given stretch causes, a small simulation stretches a tiny sample of the real fibers and matrix by that amount and reports the average stress back. The small simulations also report how stiff the sample is, so the big one can find its answer quickly by Newton's method. Nothing is fitted in advance, but there are many small simulations.

The problem

Given a macroscopic domain with loads and boundary conditions, a mesh with integration points xKx_K, and an RVE: a cell YY with a fine mesh and the constitutive law σ(y,ε)\sigma(y, \varepsilon) of each phase, find the macroscopic displacement UU such that the macro equilibrium equations hold with the macro stress

Σ(E)=⟨σ(y,E+∇yw)⟩Y,\Sigma(E) = \langle \sigma(y, E + \nabla_y w) \rangle_Y,

where EE is the macro strain at xKx_K and the fluctuation ww solves the micro equilibrium problem on YY with periodic, linear displacement or uniform traction boundary conditions. The macro stress and strain must satisfy the Hill-Mandel condition ⟨σ:ε⟩=Σ:E\langle \sigma : \varepsilon \rangle = \Sigma : E, which holds for these boundary conditions.

The algorithm

  1. FE2(macro mesh, RVE, loads)
  2. 1U ← a start value that satisfies the boundary conditions
  3. 2repeat
  4. 3for each macro integration point K do E_K ← strain of U at x_K
  5. 4solve the RVE problem with mean strain E_K by Newton's method for the fluctuation w
  6. 5Σ_K ← mean micro stress, C_K ← ⟨k⟩ - Bᵀ K⁻¹ B ▷ consistent tangent by condensation
  7. 6assemble the residual r(U) from the Σ_K and the loads, and the Jacobian from the C_K
  8. 7solve J ΔU = -r and set U ← U + ΔU
  9. 8until the norm of r is below the tolerance
  10. 9return U and the macro stresses Σ_K

Lines L3 to L5 are the constitutive routine of an ordinary nonlinear finite element code, replaced by a micro finite element solve. In line L5, kk is the micro tangent stiffness, KK its block on the fluctuation unknowns and BB its coupling to the macro strain; eliminating the fluctuation by static condensation gives the exact derivative dΣ/dEd\Sigma / dE. Lines L6 and L7 are a step of Newton's method for systems. With the exact tangent the outer Newton iteration converges quadratically near the solution. For history-dependent materials, each RVE stores its internal variables, such as plastic strains, between load steps, and line L4 updates them with the micro return mapping.

In 1D, the RVE is a chain of nn cells with a periodic fluctuation ww, w0=wn=0w_0 = w_n = 0. The micro equilibrium is equal stress in all cells, and line L4 is a tridiagonal Newton iteration. The condensed tangent equals the harmonic mean ⟨1/k⟩−1\langle 1/k \rangle^{-1} of the micro tangents.

Example

Take a bar on (0,1)(0, 1) whose period has 10 cells: 5 cells with c=1c = 1 and 5 with c=4c = 4, and the law σ=c e+e3\sigma = c\, e + e^3 in each cell.

  • The RVE at E=0.3E = 0.3. Micro Newton converges in 4 steps. The strain is 0.4610.461 in the soft cells and 0.1390.139 in the stiff cells, both with stress Σ=0.558890\Sigma = 0.558890. The tangent is C=2.333336C = 2.333336, and a central difference of Σ(E)\Sigma(E) gives the same value to 7 digits.
  • The linear case by hand. Without the cubic term, the RVE gives Σ=1.6E\Sigma = 1.6 E, the harmonic mean of 1 and 4. With body force b=1b = 1 and fixed ends, FE2 on 8 elements takes one Newton step and returns Ui=xi(1−xi)/3.2U_i = x_i(1 - x_i)/3.2 at the nodes, the exact solution of the homogenized bar.
  • Against a resolved bar. With the end displacement g=0.1g = 0.1 and no body force, FE2 agrees with the resolved bar at the macro nodes to rounding for M=2,5,10M = 2, 5, 10 elements of one period each. With b=1b = 1 the macro stress varies along the bar; macro Newton takes 4 or 5 steps, and the largest nodal difference from the resolved bar is 7.8×10−47.8 \times 10^{-4}, 3.7×10−43.7 \times 10^{-4} and 1.8×10−41.8 \times 10^{-4} for periods 1/51/5, 1/101/10 and 1/201/20. At x=1/2x = 1/2 with period 1/101/10, FE2 gives 0.1198480.119848 and the resolved bar 0.1195000.119500.

Correctness

The proof shows four facts for the 1D case with convex cell energies. The RVE problem is the minimization of a strictly convex energy over the fluctuation, so it has one solution, the stress is the same in all cells, the mean strain is EE and the Hill-Mandel condition holds. The condensed tangent of line L5 is exactly dΣ/dEd\Sigma / dE, by the implicit function theorem and summation by parts, and it equals ⟨1/k⟩−1\langle 1/k \rangle^{-1}. The macro law Σ\Sigma is the derivative of the convex function W(E)=min⁡wΦE(w)W(E) = \min_w \Phi_E(w), so the macro equations have one solution and line L7 is an exact Newton step for them. Without body force, FE2 reproduces the resolved bar at the nodes when each element holds whole periods.

FE2 is a numerical form of first-order homogenization: it is correct for the macro problem with the homogenized law, and that law describes the real part only when the RVE is small compared with the scale on which the macro strain changes.

Proof: The 1D FE2 method solves the macro problem for the homogenized law and uses its exact tangentfull

We prove the facts behind the 1D implementation, in exact arithmetic. A micro cell jj of the RVE has the energy density ψj(e)=12cje2+14de4\psi_j(e) = \tfrac12 c_j e^2 + \tfrac14 d e^4 with cj>0c_j > 0 and d≥0d \ge 0, so its stress is sj=ψj′(e)=cje+de3s_j = \psi_j'(e) = c_j e + d e^3 and its tangent is kj=ψj′′(e)=cj+3de2≥cj>0k_j = \psi_j''(e) = c_j + 3 d e^2 \ge c_j > 0. The RVE has nn cells of length η=1/n\eta = 1/n, and ⟨⋅⟩\langle \cdot \rangle is the mean over the cells.

Lemma 1 (the RVE problem). For a macro strain EE, let ej=E+(wj+1−wj)/ηe_j = E + (w_{j+1} - w_j)/\eta with w0=wn=0w_0 = w_n = 0, and let

ΦE(w)=∑jη ψj(ej).\Phi_E(w) = \sum_{j} \eta\, \psi_j(e_j).

Then ΦE\Phi_E has exactly one minimizer w∗w^*. It is the only solution of the equilibrium equations rm=sm−1−sm=0r_m = s_{m-1} - s_m = 0 for m=1,…,n−1m = 1, \ldots, n - 1, which line L4 solves, and at w∗w^* all cells carry the same stress ss. Moreover ⟨e⟩=E\langle e \rangle = E, the macro stress is Σ(E)=⟨s⟩=s\Sigma(E) = \langle s \rangle = s, and the Hill-Mandel condition ⟨s e⟩=ΣE\langle s\, e \rangle = \Sigma E holds.

Proof. The map from ww to the differences wj+1−wjw_{j+1} - w_j is linear and one to one under w0=wn=0w_0 = w_n = 0. Each ψj\psi_j is strictly convex with ψj′′≥cj>0\psi_j'' \ge c_j > 0, so ΦE\Phi_E is strictly convex and grows at least quadratically in ww, and it has one minimizer. Its partial derivative is ∂ΦE/∂wm=ψm−1′(em−1)−ψm′(em)=rm\partial \Phi_E / \partial w_m = \psi_{m-1}'(e_{m-1}) - \psi_m'(e_m) = r_m, so the minimizer is the only zero of rr, and there the stresses of neighbor cells agree. The sum of the differences is wn−w0=0w_n - w_0 = 0, so ⟨e⟩=E\langle e \rangle = E. With sj=ss_j = s for all jj, ⟨se⟩=s⟨e⟩=sE=ΣE\langle s e \rangle = s \langle e \rangle = s E = \Sigma E. □\square

Line L4 is Newton's method for r=0r = 0. Its Jacobian JJ is the tridiagonal matrix with (km−1+km)/η(k_{m-1} + k_m)/\eta on the diagonal and −k/η-k/\eta beside it, which is symmetric positive definite, so each step is defined, and near w∗w^* the iteration converges quadratically. The loop stops when the residual is below the tolerance, and the claims below hold for the returned state up to that tolerance.

Lemma 2 (the consistent tangent). Line L5 returns

C=⟨k⟩−1nηβTJ−1β=dΣdE=⟨1k⟩−1,βm=km−1−km.C = \langle k \rangle - \frac{1}{n \eta} \beta^T J^{-1} \beta = \frac{d \Sigma}{d E} = \Big\langle \frac{1}{k} \Big\rangle^{-1}, \qquad \beta_m = k_{m-1} - k_m.

Proof. At equilibrium r(w∗(E),E)=0r(w^*(E), E) = 0. The derivative of rmr_m with respect to EE at fixed ww is km−1−km=βmk_{m-1} - k_m = \beta_m, so the implicit function theorem gives dw∗/dE=−J−1βd w^* / d E = -J^{-1} \beta. Write z=dw∗/dEz = d w^* / d E, with z0=zn=0z_0 = z_n = 0. Then

dΣdE=1n∑jkj(1+zj+1−zjη)=⟨k⟩+1nη∑m=1n−1zm(km−1−km)=⟨k⟩−1nηβTJ−1β,\frac{d \Sigma}{d E} = \frac1n \sum_j k_j \Big( 1 + \frac{z_{j+1} - z_j}{\eta} \Big) = \langle k \rangle + \frac{1}{n \eta} \sum_{m=1}^{n-1} z_m (k_{m-1} - k_m) = \langle k \rangle - \frac{1}{n\eta} \beta^T J^{-1} \beta,

by summation by parts. For the second form, differentiate sj(ej)=Σs_j(e_j) = \Sigma for all jj: kj dej=dΣk_j\, d e_j = d \Sigma, so dej=dΣ/kjd e_j = d \Sigma / k_j. The mean of dejd e_j is dEd E by Lemma 1, so dE=dΣ ⟨1/k⟩d E = d \Sigma\, \langle 1/k \rangle. □\square

The first form is static condensation of the fluctuation unknowns, which is what an FE2 code computes in any dimension. The second form, the harmonic mean of the micro tangents, holds only in 1D, and the tests check that both agree.

Lemma 3 (the macro law is convex). Let W(E)=min⁡wΦE(w)W(E) = \min_w \Phi_E(w). Then W′(E)=Σ(E)W'(E) = \Sigma(E) and W′′(E)=C(E)>0W''(E) = C(E) > 0.

Proof. At the minimizer, ∂ΦE/∂w=0\partial \Phi_E / \partial w = 0, so W′(E)=∂ΦE/∂E=∑jη sj=ΣW'(E) = \partial \Phi_E / \partial E = \sum_j \eta\, s_j = \Sigma. Lemma 2 gives W′′=C=⟨1/k⟩−1>0W'' = C = \langle 1/k \rangle^{-1} > 0. □\square

Theorem (the macro problem). Lines L1 to L8 compute the P1 solution of the bar with the macro law Σ(E)\Sigma(E), one Gauss point per element and U0=0U_0 = 0, UM=gU_M = g:

Σi−1−Σi=bH,i=1,…,M−1,Σe=Σ(Ue+1−UeH).\Sigma_{i-1} - \Sigma_i = b H, \qquad i = 1, \ldots, M - 1, \qquad \Sigma_e = \Sigma\Big( \frac{U_{e+1} - U_e}{H} \Big).

This system has exactly one solution. If b=0b = 0 and each macro element holds a whole number of periods of the resolved bar, then UU equals the resolved solution at the macro nodes.

Proof. The equations are the stationarity conditions of the macro energy ∑eH W((Ue+1−Ue)/H)−∑ibHUi\sum_e H\, W((U_{e+1} - U_e)/H) - \sum_i b H U_i over U1,…,UM−1U_1, \ldots, U_{M-1}, which is strictly convex by Lemma 3, so they have one solution. Line L6 forms their residual and the Jacobian, the tridiagonal matrix with entries Ce/HC_e / H, using the exact tangent of Lemma 2, and line L7 is a Newton step. For b=0b = 0, the equations say that Σe\Sigma_e is the same in all elements; since Σ\Sigma is strictly increasing, all macro strains are equal, and UM=gU_M = g gives Ee=gE_e = g and Ui=g iHU_i = g\, i H. In the resolved bar with b=0b = 0 the stress is one constant ss in all cells, so each cell strain is the unique solution ej(s)e_j(s) of sj(e)=ss_j(e) = s, and the strains of every period are the same. A macro element holding pp whole periods therefore has the mean strain eˉ(s)\bar e(s), and u(1)=gu(1) = g gives eˉ(s)=g\bar e(s) = g. By Lemma 1, the RVE with E=gE = g has cell strains ej(Σ(g))e_j(\Sigma(g)) with mean gg; since eˉ\bar e is strictly increasing, Σ(g)=s\Sigma(g) = s, and the resolved displacement at the node iHiH is iH eˉ(s)=g iH=UiiH\, \bar e(s) = g\, iH = U_i. □\square

With a body force, the stress changes inside each period of the resolved bar, while the RVE sees one constant macro strain, so FE2 and the resolved bar differ by a term that shrinks with the period; the tests measure a factor of about 2 per halving.

Complexity

In the real RAM model, one micro Newton step costs Θ(n)\Theta(n) in 1D with the Thomas algorithm, and the condensed tangent costs one more tridiagonal solve. With qq micro steps per RVE and MM integration points, one macro step costs Θ(qMn)\Theta(q M n), and pp macro steps cost Θ(pqMn)\Theta(p q M n). The extra space is Θ(M+n)\Theta(M + n) for an elastic law, since each RVE can be dropped after line L5; with history variables, all MM RVE states must be kept, which costs Θ(Mn)\Theta(M n).

In 3D, the RVE problem is a sparse nonlinear solve with thousands to millions of unknowns, repeated at every macro integration point in every Newton step and load step. This is the main cost of FE2, and it is the reason for parallel RVE solves and for reduced order models of the RVE.

Properties

  • No closed-form law. The macro law is computed, not fitted, so it follows nonlinear and history-dependent micro behavior.
  • Nested Newton. An outer Newton iteration on the macro unknowns, and an inner Newton iteration in each RVE. The exact tangent keeps the outer convergence quadratic.
  • Embarrassingly parallel. The RVE problems at different integration points do not interact within one macro step.
  • Energy consistent. The Hill-Mandel condition makes the macro work equal to the mean micro work.

Variants and improvements

  • Boundary conditions of the RVE. Periodic conditions are usual for periodic media; linear displacement conditions give a stiffer and uniform traction conditions a softer apparent response.
  • Second-order homogenization. Pass the macro strain gradient to the RVE as well, for problems with localization or strong gradients over the RVE.
  • Reduced order RVE models. Replace the RVE solve by a reduced basis or a proper orthogonal decomposition of its fluctuation fields, or by a model trained on RVE results, to cut the cost of line L4; this is an application of model order reduction.
  • Selective FE2. Run the RVE only at integration points where the macro strain leaves the range in which a cheap fitted or tabulated law is valid.
  • The heterogeneous multiscale method has the same structure for general macro solvers, with micro problems that need not be RVEs.

When to use it

Use FE2 when the macroscopic behavior of a heterogeneous material is nonlinear or history-dependent, is not well described by any closed-form law, and the microstructure is much smaller than the part: fiber composites under damage or plasticity, polycrystals, porous metals, foams. If the material is linear elastic, compute the effective tensor once by periodic homogenization and use it everywhere. If the micro scale is not much smaller than the part, or if strain localizes into bands, a first-order FE2 model is not valid, and the microstructure must be resolved in the critical region.

Pitfalls

  • An approximate tangent. A tangent from the micro phases alone, or a secant, keeps the macro iteration but slows it to linear convergence, or makes it fail at large load steps.
  • Loose micro tolerances. The macro residual can be only as small as the error of the micro solves allows. Inner tolerances must be tighter than the outer one.
  • Softening. When the micro material softens, the RVE response depends on the RVE size, and the macro problem loses ellipticity. The results then depend on the mesh at both scales.
  • The size of the RVE. For random microstructure, a small RVE gives a law that differs from sample to sample, as the definition of the representative volume element explains.
  • Storage. History variables at all micro integration points of all RVEs take a lot of memory in 3D.

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.

fe2_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fe2-method/. The authors are listed in prov/6626AA.jsonl.
"""The FE2 method (Feyel 1999) for a nonlinear 1D bar.

Macro problem: a bar on (0, 1) with -(sigma)' = b, u(0) = 0, u(1) = g, where
the stress-strain law of the bar is not known in closed form. P1 elements
on M macro elements, one Gauss point (the midpoint) per element.

Micro problem (the RVE): one period of the microstructure, n micro cells of
length eta = 1 / n with stiffness c[j] and the law

    sigma_j(e) = c[j] e + d e^3,

which is convex in e for c[j] > 0, d >= 0. For a macro strain E the micro
strain is e_j = E + (w[j+1] - w[j]) / eta with a periodic fluctuation w,
w[0] = w[n] = 0. Equilibrium (equal stress in all cells) is solved by
Newton's method with the Thomas algorithm. The macro stress is the mean
micro stress, and the macro tangent is the consistent tangent
<k> - b^T K^-1 b from static condensation of the fluctuation.

Cost: each macro Newton step solves M RVE problems of n - 1 unknowns.
"""

from scisparse import thomas


def micro_law(c, d, e):
    """Stress and tangent of one micro cell."""
    return c * e + d * e ** 3, c + 3 * d * e ** 2


def solve_rve(c, d, E, tol=1e-13, maxit=50):
    """Solve the RVE problem for the mean strain E.

    Returns (Sigma, C, w, iterations): mean stress, consistent tangent,
    fluctuation at the n + 1 micro nodes and the number of micro Newton steps.
    """
    n = len(c)
    eta = 1.0 / n
    w = [0.0] * (n + 1)
    it = 0
    while True:
        strain = [E + (w[j + 1] - w[j]) / eta for j in range(n)]               # @line L4
        s, k = zip(*(micro_law(c[j], d, strain[j]) for j in range(n)))         # @line L4
        # residual of node m: the stress jump s[m-1] - s[m]
        r = [s[m - 1] - s[m] for m in range(1, n)]                             # @line L4
        if n == 1 or max(abs(v) for v in r) <= tol * max(1.0, max(abs(v) for v in s)) or it >= maxit:  # @line L4
            break
        sub = [0.0] + [-k[m - 1] / eta for m in range(2, n)]                   # @line L4
        diag = [(k[m - 1] + k[m]) / eta for m in range(1, n)]                  # @line L4
        sup = [-k[m] / eta for m in range(1, n - 1)] + [0.0]                   # @line L4
        dw = thomas(sub, diag, sup, r)                                         # @line L4
        for m in range(1, n):                                                  # @line L4
            w[m] -= dw[m - 1]                                                  # @line L4
        it += 1
    sigma = sum(s) / n                                                         # @line L5
    # Consistent tangent by static condensation of the fluctuation unknowns:
    # C = <k> - b^T K^-1 b, with K the micro stiffness and b its coupling to E.
    C = sum(k) / n                                                             # @line L5
    if n > 1:
        sub = [0.0] + [-k[m - 1] / eta for m in range(2, n)]                   # @line L5
        diag = [(k[m - 1] + k[m]) / eta for m in range(1, n)]                  # @line L5
        sup = [-k[m] / eta for m in range(1, n - 1)] + [0.0]                   # @line L5
        bvec = [k[m - 1] - k[m] for m in range(1, n)]                          # @line L5
        y = thomas(sub, diag, sup, bvec)                                       # @line L5
        C -= sum(bvec[i] * y[i] for i in range(n - 1)) / (n * eta)             # @line L5
    return sigma, C, w, it


def fe2_bar(c, d, M, g, b, tol=1e-12, maxit=50):
    """FE2 solve of the macro bar. Returns (U, Sigma, iterations)."""
    H = 1.0 / M
    U = [g * i * H for i in range(M + 1)]                                      # @line L1
    it = 0
    while True:                                                                # @line L2
        sig, tan = [], []
        for e in range(M):                                                     # @line L3
            E = (U[e + 1] - U[e]) / H                                          # @line L3
            s, C, _, _ = solve_rve(c, d, E)                                    # @line L4
            sig.append(s)                                                      # @line L5
            tan.append(C)                                                      # @line L5
        r = [sig[i - 1] - sig[i] - b * H for i in range(1, M)]                 # @line L6
        if M == 1 or max(abs(v) for v in r) <= tol or it >= maxit:             # @line L8
            break
        sub = [0.0] + [-tan[i - 1] / H for i in range(2, M)]                   # @line L6
        diag = [(tan[i - 1] + tan[i]) / H for i in range(1, M)]                # @line L6
        sup = [-tan[i] / H for i in range(1, M - 1)] + [0.0]                   # @line L6
        dU = thomas(sub, diag, sup, r)                                         # @line L7
        for i in range(1, M):                                                  # @line L7
            U[i] -= dU[i - 1]                                                  # @line L7
        it += 1
    return U, sig, it                                                          # @line L9


def fine_bar(c, d, periods, g, b, tol=1e-12, maxit=50):
    """Reference: the bar with the microstructure resolved, `periods` copies of c, by P1 Newton."""
    cells = [cj for _ in range(periods) for cj in c]
    N = len(cells)
    h = 1.0 / N
    u = [g * j * h for j in range(N + 1)]
    for _ in range(maxit):
        s, k = zip(*(micro_law(cells[j], d, (u[j + 1] - u[j]) / h) for j in range(N)))
        r = [s[j - 1] - s[j] - b * h for j in range(1, N)]
        if max(abs(v) for v in r) <= tol:
            break
        sub = [0.0] + [-k[j - 1] / h for j in range(2, N)]
        diag = [(k[j - 1] + k[j]) / h for j in range(1, N)]
        sup = [-k[j] / h for j in range(1, N - 1)] + [0.0]
        du = thomas(sub, diag, sup, r)
        for j in range(1, N):
            u[j] -= du[j - 1]
    return u
scisparse.py 189 lines
# SPDX-License-Identifier: MIT
# Shared helper of the scientific-computing pages of https://algorithm.tamnd.com/. The authors are listed in prov/.

"""Tridiagonal solvers, sparse matrices and simple iterative solvers.

A vector is a list. A sparse matrix is a list of rows, and each row is a
dict that maps a column index to a value. Entries may be int, float or
fractions.Fraction. thomas, thomas_periodic, spmatvec, from_dense and
to_dense keep Fraction entries exact. cg takes square roots and works in
float.

API (fixed; other pages copy this file byte for byte):
    thomas(a, b, c, d)             solve a tridiagonal system. Row i reads
                                   a[i] x[i-1] + b[i] x[i] + c[i] x[i+1] = d[i];
                                   a[0] and c[n-1] are not used.
    thomas_periodic(a, b, c, d)    solve a cyclic tridiagonal system: as
                                   thomas, but a[0] multiplies x[n-1] and
                                   c[n-1] multiplies x[0]. Uses the
                                   Sherman-Morrison formula. n >= 3.
    from_dense(A)                  sparse copy of a dense matrix (drops zeros)
    to_dense(A, ncols=None)        dense copy of a sparse matrix
    spmatvec(A, x)                 A times x
    poisson2d(nx, ny, dx, dy, bc="dirichlet")
                                   the matrix of MINUS the 5-point Laplacian
                                   on nx by ny unknowns, numbered
                                   k = i + nx * j (i along x, j along y).
                                   bc = "dirichlet": unknowns at the interior
                                   nodes ((i + 1) dx, (j + 1) dy) with zero
                                   values outside; the matrix is symmetric
                                   positive definite.
                                   bc = "periodic": the grid wraps around in
                                   both directions; the matrix is symmetric
                                   positive semidefinite, and its null space
                                   is the constant vectors.
                                   bc = "neumann": unknowns at cell centers,
                                   zero normal derivative at the walls (a
                                   missing neighbor drops out of the
                                   stencil); null space as for "periodic".
    cg(A, b, tol=1e-10, maxit=None, x0=None)
                                   conjugate gradient for a symmetric
                                   positive (semi)definite A. Stops when
                                   ||b - A x||_2 <= tol * ||b||_2. Returns
                                   (x, iterations). For a singular A, b must
                                   be in the range of A (for the Poisson
                                   matrices above: sum(b) = 0).
    gauss_seidel(A, b, iters, x0=None)
                                   iters forward Gauss-Seidel sweeps; every
                                   row needs a nonzero diagonal entry.
"""

import math


def thomas(a, b, c, d):
    n = len(d)
    if n == 0:
        return []
    cp = [0] * n
    dp = [0] * n
    cp[0] = c[0] / b[0] if n > 1 else 0
    dp[0] = d[0] / b[0]
    for i in range(1, n):
        m = b[i] - a[i] * cp[i - 1]
        if i < n - 1:
            cp[i] = c[i] / m
        dp[i] = (d[i] - a[i] * dp[i - 1]) / m
    x = [0] * n
    x[n - 1] = dp[n - 1]
    for i in range(n - 2, -1, -1):
        x[i] = dp[i] - cp[i] * x[i + 1]
    return x


def thomas_periodic(a, b, c, d):
    """Cyclic tridiagonal solve. A = T + u v^T with u = (gamma, 0, .., 0, c[n-1])
    and v = (1, 0, .., 0, a[0] / gamma), so T is tridiagonal."""
    n = len(d)
    if n < 3:
        raise ValueError("thomas_periodic needs n >= 3")
    gamma = -b[0]
    bb = list(b)
    bb[0] = b[0] - gamma
    bb[n - 1] = b[n - 1] - c[n - 1] * a[0] / gamma
    y = thomas(a, bb, c, d)
    u = [0] * n
    u[0] = gamma
    u[n - 1] = c[n - 1]
    z = thomas(a, bb, c, u)
    vy = y[0] + a[0] * y[n - 1] / gamma
    vz = z[0] + a[0] * z[n - 1] / gamma
    f = vy / (1 + vz)
    return [y[i] - f * z[i] for i in range(n)]


def from_dense(A):
    return [{j: v for j, v in enumerate(row) if v != 0} for row in A]


def to_dense(A, ncols=None):
    if ncols is None:
        ncols = len(A)
    out = []
    for row in A:
        r = [0] * ncols
        for j, v in row.items():
            r[j] = v
        out.append(r)
    return out


def spmatvec(A, x):
    return [sum(v * x[j] for j, v in row.items()) for row in A]


def poisson2d(nx, ny, dx, dy, bc="dirichlet"):
    if bc not in ("dirichlet", "periodic", "neumann"):
        raise ValueError("bc must be dirichlet, periodic or neumann")
    cx = 1 / (dx * dx)
    cy = 1 / (dy * dy)
    A = []
    for j in range(ny):
        for i in range(nx):
            row = {}
            k = i + nx * j
            for (ii, jj, w) in ((i - 1, j, cx), (i + 1, j, cx), (i, j - 1, cy), (i, j + 1, cy)):
                inside = 0 <= ii < nx and 0 <= jj < ny
                if bc == "periodic":
                    ii %= nx
                    jj %= ny
                    inside = True
                if bc == "neumann" and not inside:
                    continue
                row[k] = row.get(k, 0) + w
                if inside:
                    m = ii + nx * jj
                    row[m] = row.get(m, 0) - w
            A.append({m: v for m, v in row.items() if v != 0})
    return A


def cg(A, b, tol=1e-10, maxit=None, x0=None):
    n = len(b)
    if maxit is None:
        maxit = 10 * n
    x = [0.0] * n if x0 is None else [float(v) for v in x0]
    if x0 is None:
        r = [float(v) for v in b]
    else:
        ax = spmatvec(A, x)
        r = [b[i] - ax[i] for i in range(n)]
    bnorm = math.sqrt(sum(float(v) * float(v) for v in b))
    stop = tol * bnorm
    rr = sum(v * v for v in r)
    if math.sqrt(rr) <= stop:
        return x, 0
    p = list(r)
    for it in range(1, maxit + 1):
        ap = spmatvec(A, p)
        pap = sum(p[i] * ap[i] for i in range(n))
        if pap <= 0:
            return x, it
        alpha = rr / pap
        for i in range(n):
            x[i] += alpha * p[i]
            r[i] -= alpha * ap[i]
        rr_new = sum(v * v for v in r)
        if math.sqrt(rr_new) <= stop:
            return x, it
        beta = rr_new / rr
        rr = rr_new
        p = [r[i] + beta * p[i] for i in range(n)]
    return x, maxit


def gauss_seidel(A, b, iters, x0=None):
    n = len(b)
    x = [0] * n if x0 is None else list(x0)
    for _ in range(iters):
        for i in range(n):
            row = A[i]
            s = b[i]
            diag = 0
            for j, v in row.items():
                if j == i:
                    diag = v
                else:
                    s -= v * x[j]
            x[i] = s / diag
    return x
test_fe2_method.py 63 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/fe2-method/. The authors are listed in prov/6626AA.jsonl.
import random

from fe2_method import fe2_bar, fine_bar, micro_law, solve_rve

TWO_PHASE = [1.0] * 5 + [4.0] * 5


def test_rve_is_in_equilibrium_with_the_given_mean_strain():
    rng = random.Random(2)
    c = [rng.uniform(0.5, 5.0) for _ in range(12)]
    for E in (-0.4, 0.05, 0.7):
        sigma, _, w, it = solve_rve(c, 1.0, E)
        n = len(c)
        strain = [E + (w[j + 1] - w[j]) * n for j in range(n)]
        stress = [micro_law(c[j], 1.0, strain[j])[0] for j in range(n)]
        assert max(stress) - min(stress) < 1e-12
        assert abs(sum(strain) / n - E) < 1e-14
        assert abs(sigma - stress[0]) < 1e-12
        assert it <= 8


def test_consistent_tangent_matches_finite_differences_and_the_harmonic_mean():
    for E in (0.0, 0.3, -0.8):
        sigma, C, w, _ = solve_rve(TWO_PHASE, 1.0, E)
        h = 1e-6
        fd = (solve_rve(TWO_PHASE, 1.0, E + h)[0] - solve_rve(TWO_PHASE, 1.0, E - h)[0]) / (2 * h)
        assert abs(C - fd) < 1e-7 * C
        strain = [E + (w[j + 1] - w[j]) * 10 for j in range(10)]
        k = [micro_law(TWO_PHASE[j], 1.0, strain[j])[1] for j in range(10)]
        assert abs(C - 10 / sum(1 / v for v in k)) < 1e-12
    sigma, C, _, _ = solve_rve(TWO_PHASE, 1.0, 0.3)
    assert abs(sigma - 0.558889792228) < 1e-11


def test_linear_material_gives_the_harmonic_mean_and_the_exact_bar():
    sigma, C, _, _ = solve_rve(TWO_PHASE, 0.0, 0.3)
    assert abs(C - 1.6) < 1e-14 and abs(sigma - 0.48) < 1e-14
    U, _, it = fe2_bar(TWO_PHASE, 0.0, 8, 0.0, 1.0)
    assert it == 1
    for i in range(9):
        x = i / 8
        assert abs(U[i] - x * (1 - x) / 3.2) < 1e-14


def test_without_body_force_fe2_equals_the_resolved_bar():
    for M in (2, 5, 10):
        U, _, _ = fe2_bar(TWO_PHASE, 1.0, M, 0.1, 0.0)
        u = fine_bar(TWO_PHASE, 1.0, M, 0.1, 0.0)
        assert max(abs(U[i] - u[10 * i]) for i in range(M + 1)) < 1e-13


def test_with_body_force_the_difference_decreases_with_the_period():
    diffs = []
    for M in (5, 10, 20):
        U, _, it = fe2_bar(TWO_PHASE, 1.0, M, 0.1, 1.0)
        u = fine_bar(TWO_PHASE, 1.0, M, 0.1, 1.0)
        assert it <= 6
        diffs.append(max(abs(U[i] - u[10 * i]) for i in range(M + 1)))
    assert diffs[0] < 1e-3
    for d1, d2 in zip(diffs, diffs[1:]):
        assert 1.8 < d1 / d2 < 2.4

History

Smit, Brekelmans and Meijer described multi-level finite element modeling of nonlinear heterogeneous materials in 1998, and Miehe, Schroder and Schotte gave a computational homogenization scheme for polycrystals in 1999. Feyel named the method FE2 in 1999, and Feyel and Chaboche applied it to elastoviscoplastic SiC/Ti fiber composites in 2000, with parallel RVE solves. The averaging and energy condition at its core go back to Hill (1963) and Mandel. Later work added second-order homogenization, reduced order models of the RVE and data-driven replacements of the micro solve.

References

  1. Frederic Feyel, Multiscale FE2 elastoviscoplastic analysis of composite structures, Computational Materials Science 16, 1999, 344-354, the nested scheme with a finite element RVE problem at each macro integration point, the periodic boundary conditions of the RVE and the parallel computation
  2. Frederic Feyel and Jean-Louis Chaboche, FE2 multiscale approach for modelling the elastoviscoplastic behaviour of long fibre SiC/Ti composite materials, Computer Methods in Applied Mechanics and Engineering 183(3-4), 2000, 309-330, the FE2 algorithm with history variables stored at the micro integration points, the macro tangent and the structural examples
  3. R. Hill, Elastic properties of reinforced solids, some theoretical principles, Journal of the Mechanics and Physics of Solids 11(5), 1963, 357-372, the averages of stress and strain over a representative volume and the energy identity that links the two scales

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