One plate stands for millions
A real crystal holds millions of these plates. I cannot compute them all.
So take one box with one of me, and repeat it. Every copy sees the same neighbors.
We write the physics, then its Fourier discretisation, then the code that implements it. Every stress, strain and acoustic-tensor entry is written out as an explicit polynomial in the components, as in my Fortran solver. We keep the worked code blocks visible here, so we can follow the implementation step by step. The complete notebook is available on request.
Code use: teaching, learning and demonstration only. Any other use requires my written permission.
We keep the code examples visible below. For the complete notebook, email me and clearly state which code you want, why you need it and how you intend to use it. Request details .
Take a soft plate that wants to stretch along \(x\) and contract along \(y\), tilted at 30° inside a stiffer matrix. The matrix holds it back. Which regions end up in compression, and which in tension? This picture is the answer we compute on this page: the plate is compressed, and just above and below its long faces the matrix is pulled into tension.

Because the stiffness changes from place to place, we cannot write this field down in one step. So we start from a displacement, solve an easier problem with one uniform stiffness, put what that problem leaves out on the right-hand side, and repeat until the displacement stops changing.
This page explains the first of the two inhomogeneous elasticity solvers. The complete NumPy, pyFFTW and Matplotlib notebook is available on request. It is based on my older Fortran codes, adapted to a single elliptical inclusion in two dimensions: the same iteration, the same homogeneous-strain treatment and the same expanded component form.
A coherent precipitate would like to undergo a transformation strain \(\epsilon^0(\mathbf x)\), but the surrounding solid constrains it. The precipitate and matrix have different stiffnesses, so \(C(\mathbf x)\) varies in space. We need the displacement \(\mathbf u\) that puts the solid in mechanical equilibrium:
The total strain has two parts: a periodic part from the displacement, and the homogeneous strain \(\bar E\), its spatial average. How \(\bar E\) is chosen sets the macroscopic boundary condition (Step 9). The cell is a periodic unit square in two dimensions.
In Voigt notation stress and strain are written as six-component lists and the stiffness as a symmetric \(6\times6\) matrix with 21 independent constants. A cubic crystal needs only three, \(C_{11}, C_{12}, C_{44}\), and in two dimensions only the in-plane block is used. The strain list carries the engineering shear \(\gamma_{12}=2\epsilon_{12}\); this is what makes the matrix product and the energy come out right:
where \(e=\epsilon-\epsilon^0\) is the elastic strain. Multiplying out gives the polynomials the code uses directly:
Each field is a separate two-dimensional array, so every line of the code is a short vectorised expression. This is several times faster than contracting full fourth-order tensors.
| Function | Inputs | Returns |
|---|---|---|
wavevectors(n) | grid size n (64, 128, 256, …) | wavevector arrays kx, ky |
plate_fields(n, contrast, angle, misfit_ratio, matrix) | grid size, stiffness ratio, plate angle in degrees, tetragonality, matrix constants | stiffness fields, eigenstrain fields, reference stiffness and the indicator h |
solve_direct_voigt(stiffness, eigenstrain, reference, control, mean_strain, applied_stress, tolerance, max_iterations) | the fields from plate_fields; control is 'strain' or 'stress'; the prescribed \(\bar E\) or applied \(\sigma^a\); tolerance on the relative displacement change (default \(10^{-8}\)); iteration limit | a dictionary with displacement, strain, stress, mean strain, energy, equilibrium residual and the convergence history |
We sample the unit square on an \(N\times N\) grid, \(x_n=n/N\), and represent each field by its discrete Fourier series with wavevector components \(k_m=2\pi m\), we use grids of \(N=2^n\) points (64, 128, 256), and number the modes as in my older Fortran codes: \(m=0,1,\dots,N/2,-N/2+1,\dots,-1\). The mode \(m=N/2\) is the Nyquist mode. We set \(k=0\) for that mode and transform with pyFFTW; here is why.
def wavevectors(n):
"""Fourier wavevector components on an n x n grid (n = 64, 128, 256, ...), x along axis 0.
k = 2 pi m with m = 0, 1, ..., n/2, -n/2+1, ..., -1, as in my Fortran codes, except that k = 0 at m = n/2:
every derivative here is a first derivative, whose Nyquist term vanishes (Johnson 2011, Algorithm 1)."""
if n < 4 or n & (n - 1):
raise ValueError('Choose a power of two for the grid size, at least 4: 64, 128 or 256.')
m = np.arange(n)
m = np.where(m > n//2, m - n, m)
k = 2*np.pi*m
k[n//2] = 0.0
return np.meshgrid(k, k, indexing='ij')
n\(N\)Grid points along each side: 64, 128 or 256.
mThe mode numbers 0, 1, …, N/2, −N/2+1, …, −1.
k\(k_m=2\pi m\)The wavenumbers, with k=0 at the Nyquist mode.
kx, ky\(k_1,\ k_2\)The two wavevector components at every Fourier point.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
n | \(N\) | Number of grid points along each side; an FFT-friendly size such as 64, 128 or 256. |
m | Integer mode numbers 0, 1, …, N/2, −N/2+1, …, −1, as in my older codes. | |
k | \(k_m=2\pi m\) | One-dimensional list of wavenumbers. |
kx, ky | \(k_1,\ k_2\) | Arrays of the two wavevector components at every Fourier point; x is array axis 0. |
Units and the matrix. One grid cell is 1 nm, so an \(N\times N\) grid is a box \(N\) nm across. Stiffness, stress and energy density are in eV/nm³: 1 eV/nm³ is 160.2 MPa, so 1 GPa is 6.2415 eV/nm³. The matrix is a superalloy at high temperature, described as in the Elastic Stress Effects Laboratory by its average shear modulus \(\mu=80\) GPa, effective Poisson parameter \(\nu=1/3\) and Zener ratio \(A_Z=1\), and converted to cubic constants by the Schmidt–Gross formulas:
which at \(A_Z=1\) and \(\nu=1/3\) give \(C_{11}=4\mu\), \(C_{12}=2\mu\), \(C_{44}=\mu\): 1997.3, 998.6 and 499.3 eV/nm³, that is 320, 160 and 80 GPa. The code keeps these in cubic and MATRIX, and converts stresses to MPa with MPA when it prints or plots them.
A smooth indicator \(h(\mathbf x)\) is 1 inside an elliptical plate and 0 in the matrix, with a tanh interface of fixed physical width. Each stiffness constant and eigenstrain component interpolates separately:
as in my PhD thesis (Eq. 3.2): \(\epsilon_\eta\) is the characteristic misfit strain and \(t=\epsilon^0_{22}/\epsilon^0_{11}\) is the tetragonality, between \(-1\) (pure shear) and \(+1\) (dilatation). The default \(t=-0.5\) (Case D of the thesis) means \(\epsilon^0_{11}=0.003\), \(\epsilon^0_{22}=-0.0015\). The plate's stiffness is the matrix stiffness times the stiffness ratio. The reference stiffness is the mean of matrix and precipitate, as in my Fortran code. Rotating the plate rotates only its shape; crystal axes, stiffness and eigenstrain stay fixed.
# Units: one grid cell is 1 nm, so lengths are in nm; stiffness, stress and energy density are in eV/nm^3.
EV_NM3 = 1.602176634e-19/1e-27 # one eV/nm^3 in pascal: 1.602e8 Pa = 160.2 MPa
GPA, MPA = 1e9/EV_NM3, 1e6/EV_NM3 # one GPa and one MPa in eV/nm^3: 6.2415 and 0.0062415
def cubic(mu, nu=1/3, az=1.0):
"""Cubic constants C11, C12, C44 from the Schmidt-Gross parameters: the average shear modulus mu,
the effective Poisson parameter nu and the Zener ratio az (Schmidt and Gross 1997; our Elastic Lab).
az = 1 is isotropic: C44 = mu, C12 = 2 mu nu/(1 - 2 nu), C11 = 2 mu (1 - nu)/(1 - 2 nu)."""
p = (1 - 4*nu)/(1 - 2*nu)
return mu*(2*(2 + az)/(1 + az) - p), mu*(2*az/(1 + az) - p), mu*2*az/(1 + az)
MATRIX = cubic(80*GPA) # a superalloy matrix at high temperature: mu = 80 GPa = 499.3 eV/nm^3, nu = 1/3, isotropic
MISFIT = 0.003 # the characteristic misfit strain: a few tenths of a percent, as between gamma and gamma'
def plate_fields(n=64, contrast=0.5, angle=30.0, misfit_ratio=-0.5, matrix=MATRIX):
"""Smooth plate: stiffness fields c11, c12, c44 and eigenstrain (e011, e022, g012)."""
x, y = np.meshgrid(np.arange(n)/n - .5, np.arange(n)/n - .5, indexing='ij')
t = np.deg2rad(angle)
along = x*np.cos(t) + y*np.sin(t)
across = -x*np.sin(t) + y*np.cos(t)
h = .5*(1 - np.tanh(((along/.23)**2 + (across/.075)**2 - 1)/.35))
m11, m12, m44 = matrix
p11, p12, p44 = (contrast*m11, contrast*m12, contrast*m44)
c11 = m11 + h*(p11 - m11)
c12 = m12 + h*(p12 - m12)
c44 = m44 + h*(p44 - m44)
e011 = MISFIT*h
e022 = MISFIT*misfit_ratio*h
g012 = np.zeros_like(h)
reference = (.5*(m11 + p11), .5*(m12 + p12), .5*(m44 + p44))
return (c11, c12, c44), (e011, e022, g012), reference, h
matrix\(C^m_{11}, C^m_{12}, C^m_{44}\)The matrix stiffness constants.
contrast\(C^{p}/C^{m}\)Precipitate stiffness as a fraction of the matrix: 0.5 soft, 2 hard.
angle\(\theta\)The plate angle from x, in degrees.
m11, m12, m44\(C^m_{ij}\)The matrix constants unpacked.
p11, p12, p44\(C^p_{ij}\)The precipitate constants: contrast times the matrix.
t\(\theta\)The angle in radians.
reference\(C^{\mathrm{ref}}\)The reference stiffness: the mean of matrix and precipitate.
c11, c12, c44\(C_{ij}(\mathbf x)\)The stiffness fields, interpolated with h.
along, acrossCoordinates along and across the rotated plate.
misfit_ratio\(t\)The tetragonality \(\epsilon^0_{22}/\epsilon^0_{11}\).
e011, e022, g012\(\epsilon^0_{ij}\)The eigenstrain fields in Voigt form; g012 is zero here.
h\(h(\mathbf x)\)The smooth indicator: 1 in the plate, 0 in the matrix.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
contrast | \(C^{p}/C^{m}\) | Precipitate stiffness as a fraction of the matrix stiffness (0.5 = soft plate, 2 = hard plate). |
angle | \(\theta\) | Angle of the plate's long axis from x, in degrees. |
misfit_ratio | \(t\) | Tetragonality \(t=\epsilon^0_{22}/\epsilon^0_{11}\). |
matrix | \(C^m_{11}, C^m_{12}, C^m_{44}\) | Matrix stiffness constants. |
x, y | \(x,\ y\) | Grid coordinates, centered on the plate. |
t | \(\theta\) | The plate angle converted to radians. |
along, across | Coordinates along and across the rotated plate. | |
h | \(h(\mathbf x)\) | Smooth precipitate indicator: 1 inside the plate, 0 in the matrix. |
m11, m12, m44 | \(C^m_{ij}\) | Matrix constants unpacked from matrix. |
p11, p12, p44 | \(C^p_{ij}\) | Precipitate stiffness constants. |
c11, c12, c44 | \(C_{11}(\mathbf x)\), … | Stiffness fields interpolated with \(h\). |
e011, e022, g012 | \(\epsilon^0_{11},\ \epsilon^0_{22},\ \gamma^0_{12}\) | Eigenstrain fields in Voigt form; g012 is the engineering shear (zero here). |
reference | \(C^{\mathrm{ref}}\) | Reference stiffness: the mean of matrix and precipitate constants. |
The unknown is the displacement. In Fourier space a derivative is a multiplication, \(\partial_j\to\mathrm i k_j\), so the periodic strain components follow directly from \(\widetilde u\):
We start from zero displacement, as in my older codes.
# Start from zero displacement, as in my older codes.
u1_hat = np.zeros((n, n), complex)
u2_hat = np.zeros((n, n), complex)
# Periodic strain from the current displacement: eps_ij = (u_i,j + u_j,i)/2, g12 = u1,2 + u2,1.
de11 = ifft(1j*kx*u1_hat)
de22 = ifft(1j*ky*u2_hat)
dg12 = ifft(1j*(ky*u1_hat + kx*u2_hat))
u1_hat, u2_hat\(\widetilde u_1,\ \widetilde u_2\)The Fourier displacement; the iteration updates these.
fft, ifftThe forward and inverse FFT; ifft keeps the real part.
E11, E22, G12\(\bar E_{ij}\)The homogeneous strain; G12 is its engineering shear.
de11, de22, dg12\(\delta\epsilon_{ij}\)The periodic strain from the displacement.
e11, e22, g12\(\epsilon_{ij}\)The total strain: homogeneous plus periodic.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
u1_hat, u2_hat | \(\widetilde u_1,\ \widetilde u_2\) | Fourier transforms of the two displacement components; the iteration updates these. |
fft, ifft | Two-dimensional forward and inverse FFT; ifft keeps the real part. | |
de11, de22, dg12 | \(\delta\epsilon_{11},\ \delta\epsilon_{22},\ \delta\gamma_{12}\) | Periodic strain from the displacement; dg12 is the engineering shear \(u_{1,2}+u_{2,1}\). |
E11, E22, G12 | \(\bar E_{11},\ \bar E_{22},\ \bar\Gamma_{12}\) | Homogeneous (average) strain; G12 is its engineering shear. |
e11, e22, g12 | \(\epsilon_{11},\ \epsilon_{22},\ \gamma_{12}\) | Total strain = homogeneous + periodic. |
Before the code of Step 6, here is the idea it serves, told by the matrix, the plate and the strain. The numbers are from the default plate of Step 12: a 64 × 64 box, stiffness ratio 0.5, \(\epsilon^0_{11}=0.003\), \(\epsilon^0_{22}=-0.0015\), plate at 30°, matrix \(\mu=80\) GPa (\(C_{11}=1997\), \(C_{12}=999\), \(C_{44}=499\) eV/nm³), one grid cell 1 nm, so the box is 64 nm across; stresses are in MPa.
A real crystal holds millions of these plates. I cannot compute them all.
So take one box with one of me, and repeat it. Every copy sees the same neighbors.
Periodic copies have no outer surface, so no edge effects. And every derivative becomes a multiplication in Fourier space.
The price: I feel my own images one box away. A box much bigger than me keeps that small.
Stretch the whole box by Ē and every copy follows. The mean stress I answer with is the box’s own law: ⟨σ⟩ = C_eff : Ē.
With no misfit, Ē = (0.001, 0, 0) gives ⟨σₓₓ⟩ = 308 MPa. The box with its soft plate has C₁₁ = 308 GPa, not the matrix’s 320. That is what homogenization computes.
Clamp me: Ē = 0. The plate wants to stretch along x, I do not let it, and I answer with a mean stress of −29 MPa along x.
Any fixed Ē works the same way: with Ē = (0.001, 0, 0) and the misfit, the mean stress is 279 MPa along x. This is control = 'strain'.
Now let go: ⟨σ⟩ = 0. Each iteration finds the Ē that makes the mean stress vanish, so I change the box’s shape: Ē = (0.000127, −0.000063, −0.000020).
And the energy falls from 1.00 × 10⁻⁴ to 0.88 × 10⁻⁴ eV/nm³, as it must when a constraint is released. This is control = 'stress' with σᵃ = 0.
With σᵃ ≠ 0 we pull on a box that has no surface to pull. The same Ē update does it.
How that works, how to hold a void or a rigid inclusion, and which solver to use: How do we pull on a periodic box?
| Case | What is held | \(\bar E\) | \(\langle\sigma\rangle\) | Energy \(F/V\) (eV/nm³) |
|---|---|---|---|---|
| No misfit, pulled | \(\bar E\) | (0.001, 0, 0) | (308, 153, 0.7) MPa | |
| Clamped | \(\bar E\) | (0, 0, 0) | (−29.4, −0.02, 1.5) MPa | \(1.001\times10^{-4}\) |
| Pulled, with misfit | \(\bar E\) | (0.001, 0, 0) | (279, 153, 2.2) MPa | \(8.786\times10^{-4}\) |
| Stress-free | \(\langle\sigma\rangle\) | (0.000127, −0.000063, −0.000020) | (0, 0, 0) to \(10^{-8}\) MPa | \(8.837\times10^{-5}\) |
The first row is homogenization in one line: the box answers a pure stretch with a mean stress, and the ratio, 1924 eV/nm³ or 308 GPa, is the effective \(C_{11}\) of the box with its soft plate, against 320 GPa for the matrix alone. Each run converged in 15 iterations. The strain triples carry the engineering shear \(\gamma_{12}\), as everywhere on this page. Prescribing a mean stress other than zero, and the exact void and rigid limits that this solver cannot reach, are the subject of How do we pull on a periodic box?
The Fourier solve fixes only the periodic part of the strain. The average part, \(\bar E\), is set by the macroscopic boundary condition:
control='strain'): \(\bar E\) is prescribed. \(\bar E=0\) clamps the cell.control='stress'): the body is free to change shape, and \(\bar E\) is chosen so that the average stress equals the applied stress \(\sigma^{a}\) (zero for a stress-free body):Because \(\delta\epsilon\) changes with the displacement, \(\bar E\) is recomputed at every iteration, exactly as in my older codes.
Write the total strain as its average plus the periodic part from the displacement, \(\epsilon(\mathbf x)=\bar E+\delta\epsilon(\mathbf x)\). The periodic part has zero average, \(\langle\delta\epsilon\rangle=0\), because it is a gradient of a periodic displacement. Hooke's law gives
Average over the cell. \(\bar E\) is uniform, so it comes out of the average, but \(\delta\epsilon\) does not: \(C\) varies in space, so \(\langle C:\delta\epsilon\rangle\ne0\) even though \(\langle\delta\epsilon\rangle=0\):
The macroscopic boundary condition sets this average equal to the applied stress, \(\langle\sigma\rangle=\sigma^{a}\). Solving for \(\bar E\),
For the in-plane cubic block, \(\langle C\rangle\) has the same form as \(C\), and its inverse in Voigt form (engineering shear) is written out:
In my older Fortran code this is hom_strain_v = SS_v · (sigappl_v + avgeigstress_v − avgperstress_v), with SS_v the inverse of the averaged stiffness from FindInv.
# Averages used by the stress-controlled homogeneous strain.
a11, a12, a44 = c11.mean(), c12.mean(), c44.mean()
t011 = (c11*e011 + c12*e022).mean()
t022 = (c12*e011 + c11*e022).mean()
t012 = (c44*g012).mean()
sa11, sa22, sa12 = applied_stress
E11, E22, G12 = mean_strain
if control == 'stress':
# <sigma> = <C>:E + <C:delta_eps> - <C:eps0> = sigma_applied, solved for E.
b11 = sa11 + t011 - (c11*de11 + c12*de22).mean()
b22 = sa22 + t022 - (c12*de11 + c11*de22).mean()
b12 = sa12 + t012 - (c44*dg12).mean()
E11 = (a11*b11 - a12*b22)/(a11**2 - a12**2)
E22 = (a11*b22 - a12*b11)/(a11**2 - a12**2)
G12 = b12/a44
sa11, sa22, sa12\(\sigma^{a}_{ij}\)The applied stress; zero for a stress-free body.
t011, t022, t012\(\langle C:\epsilon^0\rangle\)The average eigenstress, computed once before the loop.
control'strain' fixes the homogeneous strain; 'stress' makes the average stress equal the applied stress.
b11, b22, b12\(b\)The right-hand side \(\sigma^a+\langle C:\epsilon^0 angle-\langle C:\delta\epsilon angle\), recomputed every iteration.
E11, E22, G12\(\bar E\)The homogeneous strain, \(\langle C angle^{-1}b\) under stress control.
a11, a12, a44\(\langle C_{ij}\rangle\)The spatial averages of the stiffness constants.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
control | 'strain' fixes the homogeneous strain; 'stress' makes the average stress equal the applied stress. | |
a11, a12, a44 | \(\langle C_{11}\rangle,\ \langle C_{12}\rangle,\ \langle C_{44}\rangle\) | Spatial averages of the stiffness constants. |
t011, t022, t012 | \(\langle C:\epsilon^0\rangle\) | Average eigenstress, computed once before the loop. |
sa11, sa22, sa12 | \(\sigma^{a}_{11},\ \sigma^{a}_{22},\ \sigma^{a}_{12}\) | Applied stress (zero for a stress-free body). |
b11, b22, b12 | \(b=\sigma^a+\langle C:\epsilon^0\rangle-\langle C:\delta\epsilon\rangle\) | Right-hand side for the homogeneous strain, recomputed every iteration. |
Stress-free here, loaded on the next page. Every stress-controlled run on this page is stress-free, \(\sigma^{a}=0\): the homogeneous strain is evaluated so that the mean stress vanishes, and the plate relaxes the box. Pulling on the box with a prescribed mean stress, such as the 160 MPa of a turbine blade, uses the same \(\bar E\) update and is the subject of the homogenization page, which explains the two ways to hold the load and why the mean strain is moved with \(\langle C\rangle^{-1}\). The equivalent-eigenstrain method evaluates the same homogeneous strain from its virtual strain, \(\bar\epsilon=\langle q\rangle+S^0:\sigma^{\mathrm{appl}}\): stress-free for the same plate, and under the 160 MPa load for its hole.
This is the central idea. We split the stiffness into a homogeneous part and the remainder, \(C=C^{\mathrm{hom}}+\Delta C\), and write the stress with the total strain \(\epsilon=\bar E+\delta\epsilon\):
Equilibrium, \(\partial_j\sigma_{ij}=0\), then reads \(\partial_j\big(C^{\mathrm{hom}}_{ijkl}\,\delta\epsilon_{kl}\big)=\partial_j\, ts_{ij}\): a problem for a homogeneous solid, with every heterogeneous term moved into \(ts\). In components,
# Inhomogeneous part of the stiffness, as Cinhom in my older codes.
d11, d12, d44 = c11 - r11, c12 - r12, c44 - r44
# Right-hand side as in my older codes: ts = C:(eps0 - E) - Cinhom:delta_eps.
ts11 = c11*(e011 - E11) + c12*(e022 - E22) - (d11*de11 + d12*de22)
ts22 = c12*(e011 - E11) + c11*(e022 - E22) - (d12*de11 + d11*de22)
ts12 = c44*(g012 - G12) - d44*dg12
r11, r12, r44\(C^{\mathrm{hom}}_{ij}\)The homogeneous stiffness: the mean of matrix and precipitate.
d11, d12, d44\(\Delta C_{ij}\)The inhomogeneous part \(C-C^{\mathrm{hom}}\) at every point.
ts11, ts22, ts12\(ts_{ij}\)The right-hand side \(C:(\epsilon^0-\bar E)-\Delta C:\delta\epsilon\).
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
r11, r12, r44 | \(C^{\mathrm{hom}}_{ij}\) | Homogeneous (reference) stiffness constants: the mean of matrix and precipitate, Chom in my older codes. |
d11, d12, d44 | \(\Delta C_{ij}\) | Inhomogeneous part \(C-C^{\mathrm{hom}}\) at every grid point, Cinhom in my older codes. |
ts11, ts22, ts12 | \(ts_{11},\ ts_{22},\ ts_{12}\) | Right-hand side \(C:(\epsilon^0-\bar E)-\Delta C:\delta\epsilon\), the array ts in my older codes. |
Substituting \(\partial_j\to\mathrm i k_j\) turns the homogeneous equilibrium equation into a \(2\times2\) linear system for \(\widetilde u\) at every wavevector, with the acoustic tensor \(Q\) and its inverse \(\Omega=Q^{-1}\):
# Acoustic tensor of the homogeneous solid, Q_ik = Chom_ijkl k_j k_l, and its inverse Omega.
q11 = r11*kx**2 + r44*ky**2
q22 = r44*kx**2 + r11*ky**2
q12 = (r12 + r44)*kx*ky
det = q11*q22 - q12**2
zero_k = (kx == 0) & (ky == 0) # no displacement for a k = 0 mode
det[zero_k] = 1.0
o11, o22, o12 = q22/det, q11/det, -q12/det
q11, q22, q12\(Q_{ij}\)The acoustic tensor of the homogeneous solid at every wavevector.
det\(Q_{11}Q_{22}-Q_{12}^2\)Its determinant, set to 1 at k=0 only to avoid dividing by zero.
o11, o22, o12\(\Omega_{ij}=Q^{-1}_{ij}\)The inverse, written out explicitly.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
q11, q22, q12 | \(Q_{11},\ Q_{22},\ Q_{12}\) | Acoustic tensor of the homogeneous solid at every wavevector. |
det | \(Q_{11}Q_{22}-Q_{12}^2\) | Its determinant; set to 1 at \(\mathbf k=\mathbf 0\) only to avoid dividing by zero. |
o11, o22, o12 | \(\Omega_{11},\ \Omega_{22},\ \Omega_{12}\) | Components of \(\Omega=Q^{-1}\), written out explicitly (omega in my older codes). |
The new displacement is then
The \(\mathbf k=\mathbf 0\) mode only translates the body, so we set it to zero; the average strain is carried by \(\bar E\).
# Solve the homogeneous problem for the new displacement: u_new = -i Omega . (k . ts).
ts11_hat, ts22_hat, ts12_hat = fft(ts11), fft(ts22), fft(ts12)
f1 = kx*ts11_hat + ky*ts12_hat
f2 = kx*ts12_hat + ky*ts22_hat
u1_new = -1j*(o11*f1 + o12*f2)
u2_new = -1j*(o12*f1 + o22*f2)
u1_new[zero_k] = u2_new[zero_k] = 0
ts11_hat, ts22_hat, ts12_hat\(\widetilde{ts}_{ij}\)The Fourier transforms of the right-hand side.
f1, f2\(f_i=k_j\widetilde{ts}_{ij}\)The force term.
u1_new, u2_new\(-\mathrm i\,\Omega\cdot\mathbf f\)The new displacement, with the k=0 mode set to 0.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
ts11_hat, ts22_hat, ts12_hat | \(\widetilde{ts}_{ij}\) | Fourier transforms of the right-hand side. |
f1, f2 | \(f_1,\ f_2\) | Force term \(k_j\widetilde{ts}_{ij}\) (fk1, fk2 in my older codes). |
u1_new, u2_new | \(\widetilde u_1,\ \widetilde u_2\) | New displacement \(-\mathrm i\,\Omega\cdot\mathbf f\); the \(\mathbf k=\mathbf 0\) mode is set to 0 (unewkx, unewky). |
\(ts\) depends on the strain, and so on the displacement being solved for. We therefore repeat Steps 5–8, replacing the displacement by the new one each time, and stop when the relative change is below the tolerance:
My older codes test the absolute change (disperror); here we divide by the size of the displacement so that the same tolerance works for any misfit.
# Convergence: how much did the displacement change? (disperror in my older codes)
change = np.sqrt(np.sum(np.abs(u1_new - u1_hat)**2 + np.abs(u2_new - u2_hat)**2))
size = max(np.sqrt(np.sum(np.abs(u1_new)**2 + np.abs(u2_new)**2)), 1e-300)
u1_hat, u2_hat = u1_new, u2_new
history.append((iteration, change/size))
if change/size < tolerance:
break
if not np.isfinite(change) or change/size > 1e12:
raise RuntimeError('Displacement iteration diverged; choose a reference stiffness closer to the phases.')
changeThe size of the change in displacement since the previous iteration.
sizeThe size of the new displacement.
toleranceThe stopping value, \(10^{-8}\) by default.
historyOne row per iteration: its number and the relative change, for the convergence plot.
change/size < toleranceStop when the relative change falls below the tolerance.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
change | Size of the change in displacement since the previous iteration (disperror in my older codes). | |
size | Size of the new displacement; the test uses the relative change change/size. | |
history | One row per iteration: iteration number and relative displacement change. Used for the convergence plot. | |
tolerance | Stop when the relative change falls below this value (default \(10^{-8}\)). |
With the converged displacement, we build the strain, the elastic strain and the stress with the expanded Hooke's law of Step 2:
e11, e22, g12 = E11 + de11, E22 + de22, G12 + dg12
# Elastic strain and stress, written out in components.
el11, el22, elg = e11 - e011, e22 - e022, g12 - g012
s11 = c11*el11 + c12*el22
s22 = c12*el11 + c11*el22
s12 = c44*elg
el11, el22, elg\(e_{ij}\)The elastic strain: total strain minus eigenstrain.
s11, s22, s12\(\sigma_{ij}\)The stress from the expanded Hooke's law.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
el11, el22, elg | \(e_{11},\ e_{22},\ \gamma^{\mathrm{el}}_{12}\) | Elastic strain: total strain minus eigenstrain. |
s11, s22, s12 | \(\sigma_{11},\ \sigma_{22},\ \sigma_{12}\) | Stress components from the expanded Hooke's law. |
As an independent test, the divergence of the stress must vanish, \(\widetilde{(\nabla\cdot\sigma)}_i=\mathrm i\,k_j\widetilde\sigma_{ij}=0\). We use the same first-derivative wavevectors as for the strain, so the Nyquist term drops out here too.
# Check equilibrium: div(sigma)_i = i k_j sigma_ij should vanish.
s11_hat, s22_hat, s12_hat = fft(s11), fft(s22), fft(s12)
div1_hat = 1j*(kx*s11_hat + ky*s12_hat)
div2_hat = 1j*(kx*s12_hat + ky*s22_hat)
div1, div2 = ifft(div1_hat), ifft(div2_hat)
stress_size = max(2*np.pi*np.sqrt(np.mean(s11**2 + s22**2 + 2*s12**2)), 1e-300)
residual = np.sqrt(np.mean(div1**2 + div2**2))/stress_size
s11_hat, s22_hat, s12_hat\(\widetilde\sigma_{ij}\)The Fourier transforms of the stresses.
div1_hat, div2_hat, div1, div2\((\nabla\cdot\sigma)_i\)The two components of the stress divergence; zero at equilibrium.
stress_sizeA typical stress size, to make the residual dimensionless.
residual\(r\)The root-mean-square divergence over stress_size: an independent check after convergence.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
s11_hat, s22_hat, s12_hat | \(\widetilde\sigma_{ij}\) | Fourier transforms of the stresses. |
div1_hat, div2_hat, div1, div2 | \((\nabla\cdot\sigma)_1,\ (\nabla\cdot\sigma)_2\) | The two components of the stress divergence; zero at equilibrium. |
stress_size | A typical stress size, used to make the residual dimensionless. | |
residual | \(r\) | Root-mean-square divergence divided by stress_size: an independent check, reported after convergence. |
# Elastic energy density; under stress control subtract the work of the applied load.
energy = 0.5*np.mean(el11*s11 + el22*s22 + elg*s12)
if control == 'stress':
energy -= sa11*E11 + sa22*E22 + sa12*G12
| In the code | Symbol | Meaning |
|---|---|---|
energy | \(F/V\) | Average elastic energy density; under stress control the work term \(\sigma^a:\bar E\) is subtracted. |
Putting Steps 5–10 together: start from zero displacement; compute the strain; update \(\bar E\) under stress control; form \(ts\); solve for the new displacement; repeat until it stops changing; then compute the stress, check equilibrium and evaluate the energy.
def solve_direct_voigt(stiffness, eigenstrain, reference, control='strain',
mean_strain=(0.0, 0.0, 0.0), applied_stress=(0.0, 0.0, 0.0),
tolerance=1e-8, max_iterations=4000):
c11, c12, c44 = stiffness
e011, e022, g012 = eigenstrain
r11, r12, r44 = reference
if min(r44, r11 - r12, r11 + r12) <= 0:
raise ValueError('The reference stiffness must be stable.')
if control not in ('strain', 'stress'):
raise ValueError("control must be 'strain' or 'stress'.")
n = c11.shape[0]
kx, ky = wavevectors(n)
fft, ifft = fftw.fft2, lambda a: fftw.ifft2(a).real
# Inhomogeneous part of the stiffness, as Cinhom in my older codes.
d11, d12, d44 = c11 - r11, c12 - r12, c44 - r44
# Acoustic tensor of the homogeneous solid, Q_ik = Chom_ijkl k_j k_l, and its inverse Omega.
q11 = r11*kx**2 + r44*ky**2
q22 = r44*kx**2 + r11*ky**2
q12 = (r12 + r44)*kx*ky
det = q11*q22 - q12**2
zero_k = (kx == 0) & (ky == 0) # no displacement for a k = 0 mode
det[zero_k] = 1.0
o11, o22, o12 = q22/det, q11/det, -q12/det
# Averages used by the stress-controlled homogeneous strain.
a11, a12, a44 = c11.mean(), c12.mean(), c44.mean()
t011 = (c11*e011 + c12*e022).mean()
t022 = (c12*e011 + c11*e022).mean()
t012 = (c44*g012).mean()
sa11, sa22, sa12 = applied_stress
E11, E22, G12 = mean_strain
# Start from zero displacement, as in my older codes.
u1_hat = np.zeros((n, n), complex)
u2_hat = np.zeros((n, n), complex)
history = []
for iteration in range(1, max_iterations + 1):
# Periodic strain from the current displacement: eps_ij = (u_i,j + u_j,i)/2, g12 = u1,2 + u2,1.
de11 = ifft(1j*kx*u1_hat)
de22 = ifft(1j*ky*u2_hat)
dg12 = ifft(1j*(ky*u1_hat + kx*u2_hat))
if control == 'stress':
# <sigma> = <C>:E + <C:delta_eps> - <C:eps0> = sigma_applied, solved for E.
b11 = sa11 + t011 - (c11*de11 + c12*de22).mean()
b22 = sa22 + t022 - (c12*de11 + c11*de22).mean()
b12 = sa12 + t012 - (c44*dg12).mean()
E11 = (a11*b11 - a12*b22)/(a11**2 - a12**2)
E22 = (a11*b22 - a12*b11)/(a11**2 - a12**2)
G12 = b12/a44
# Right-hand side as in my older codes: ts = C:(eps0 - E) - Cinhom:delta_eps.
ts11 = c11*(e011 - E11) + c12*(e022 - E22) - (d11*de11 + d12*de22)
ts22 = c12*(e011 - E11) + c11*(e022 - E22) - (d12*de11 + d11*de22)
ts12 = c44*(g012 - G12) - d44*dg12
# Solve the homogeneous problem for the new displacement: u_new = -i Omega . (k . ts).
ts11_hat, ts22_hat, ts12_hat = fft(ts11), fft(ts22), fft(ts12)
f1 = kx*ts11_hat + ky*ts12_hat
f2 = kx*ts12_hat + ky*ts22_hat
u1_new = -1j*(o11*f1 + o12*f2)
u2_new = -1j*(o12*f1 + o22*f2)
u1_new[zero_k] = u2_new[zero_k] = 0
# Convergence: how much did the displacement change? (disperror in my older codes)
change = np.sqrt(np.sum(np.abs(u1_new - u1_hat)**2 + np.abs(u2_new - u2_hat)**2))
size = max(np.sqrt(np.sum(np.abs(u1_new)**2 + np.abs(u2_new)**2)), 1e-300)
u1_hat, u2_hat = u1_new, u2_new
history.append((iteration, change/size))
if change/size < tolerance:
break
if not np.isfinite(change) or change/size > 1e12:
raise RuntimeError('Displacement iteration diverged; choose a reference stiffness closer to the phases.')
else:
raise RuntimeError(f'Displacement did not converge in {max_iterations} iterations.')
# Fields at the converged displacement.
de11 = ifft(1j*kx*u1_hat)
de22 = ifft(1j*ky*u2_hat)
dg12 = ifft(1j*(ky*u1_hat + kx*u2_hat))
e11, e22, g12 = E11 + de11, E22 + de22, G12 + dg12
# Elastic strain and stress, written out in components.
el11, el22, elg = e11 - e011, e22 - e022, g12 - g012
s11 = c11*el11 + c12*el22
s22 = c12*el11 + c11*el22
s12 = c44*elg
# Check equilibrium: div(sigma)_i = i k_j sigma_ij should vanish.
s11_hat, s22_hat, s12_hat = fft(s11), fft(s22), fft(s12)
div1_hat = 1j*(kx*s11_hat + ky*s12_hat)
div2_hat = 1j*(kx*s12_hat + ky*s22_hat)
div1, div2 = ifft(div1_hat), ifft(div2_hat)
stress_size = max(2*np.pi*np.sqrt(np.mean(s11**2 + s22**2 + 2*s12**2)), 1e-300)
residual = np.sqrt(np.mean(div1**2 + div2**2))/stress_size
# Elastic energy density; under stress control subtract the work of the applied load.
energy = 0.5*np.mean(el11*s11 + el22*s22 + elg*s12)
if control == 'stress':
energy -= sa11*E11 + sa22*E22 + sa12*G12
return dict(displacement=(ifft(u1_hat), ifft(u2_hat)), strain=(e11, e22, g12),
stress=(s11, s22, s12), mean_strain=(E11, E22, G12), energy=energy,
residual=residual, history=np.array(history))n = 64
contrast = 0.5
angle = 30.0
misfit_ratio = -0.5
stiffness, eigenstrain, reference, h = plate_fields(n, contrast, angle, misfit_ratio)
clamped = solve_direct_voigt(stiffness, eigenstrain, reference)
free = solve_direct_voigt(stiffness, eigenstrain, reference, control='stress')
print(f"Clamped (E = 0): energy = {clamped['energy']:.9g} eV/nm^3, iterations = {len(clamped['history'])}, equilibrium residual = {clamped['residual']:.1e}")
print(f"Stress-free (<s>=0): energy = {free['energy']:.9g} eV/nm^3, E = {tuple(round(float(x), 7) for x in free['mean_strain'])}")
print('Average stress, stress-free cell (MPa):', [f'{s.mean()/MPA:.1e}' for s in free['stress']])
print('Peak stress in the plate (MPa):', f"{clamped['stress'][0].min()/MPA:.1f} clamped, {free['stress'][0].min()/MPA:.1f} stress-free")
stiffness, eigenstrain, reference, hThe four results of plate_fields.
clamped\(\bar E=0\)The result under strain control.
free\(\langle\sigma\rangle=0\)The result under stress control with no applied load.
result['strain'], result['stress']Three strain and three stress fields: 11, 22 and 12, in each result.
result['mean_strain'], result['energy']\(\bar E,\ F/V\)The homogeneous strain and the energy density at convergence.
result['displacement']\(u_1,\ u_2\)The converged displacement: the quantity the solver iterates on.
result['residual'], result['history']The equilibrium check and the record of displacement changes.
Arrows show what feeds what. Dashed blue boxes are what we give the code, green boxes are what it returns, and the orange box is the stopping rule. Every name, including the ones left out of the chart, is in the table.
| In the code | Symbol | Meaning |
|---|---|---|
stiffness, eigenstrain, reference, h | The four results of plate_fields. | |
clamped | Result with \(\bar E=0\) (strain control). | |
free | Result with \(\langle\sigma\rangle=0\) (stress control, no applied load). | |
result['strain'] | Three strain fields: 11, 22 and the engineering shear 12. | |
result['stress'] | Three stress fields: 11, 22 and 12. | |
result['mean_strain'] | \(\bar E\) | Homogeneous strain at convergence. |
result['energy'] | \(F/V\) | Final elastic energy density. |
result['displacement'] | \(u_1,\ u_2\) | The converged displacement field: the quantity the solver iterates on. |
result['residual'], result['history'] | Equilibrium check, and the record of displacement changes. |
With the default plate (64 × 64 grid, stiffness ratio 0.5, \(\epsilon^0_{11}=0.003\) and \(\epsilon^0_{22}=-0.0015\), i.e. tetragonality \(t=-0.5\), plate at 30°):
Reference: Saswata Bhattacharyya, Tae Wook Heo, Kunok Chang and Long-Qing Chen, A Spectral Iterative Method for the Computation of Effective Properties of Elastically Inhomogeneous Polycrystals, Communications in Computational Physics 11 (2012), 726–738. The iterative perturbation method was implemented in our group by Tushar Jogi.
← Back to the two inhomogeneous elasticity solvers · Elastic Stress Effects Laboratory