morphogen.homogenization.gpu

The FFT solvers of voxel images on the GPU (CuPy; see morphogen.gpu).

The conjugate gradients of the linear solver (morphogen.homogenization.fft) and the iterations of the loading paths (morphogen.homogenization.fft_nonlinear) run on the GPU, in double precision:

  • the stiffness operators of the voxels are applied matrix-free by CUDA kernels, ports of the Numba kernels of morphogen.homogenization.kernels (one thread per node, so no atomics; the point stresses one thread per voxel), with the element matrices of the materials or the tangents of the points;

  • the Fourier preconditioner is cuFFT transforms and a kernel multiplying the blocks of its inverse symbol, computed on the GPU;

  • the dot products are reductions of CuPy, without cuBLAS; GMRES, for the full tangents that are not symmetric, keeps its basis on the GPU (the dot products of a Gram-Schmidt pass in one reduction over its rows, the vectors of its deflated restarts combined in place) and its small Hessenberg matrix and harmonic Ritz vectors on the CPU, as the space it recycles from a solve to the next along a path (GCRO-DR).

Along loading paths (VoxelPaths) the arrays of the integration points stay on the GPU: their measures of strain, the integration of their behaviours (the CUDA kernels of behaviours.cu, ports of the Numba kernels of von Mises plasticity, crystal plasticity and the logarithmic strain space, one thread per point), the stresses conjugate to B-bar and F-bar, the nodal forces and the tangent operator. The Newton iterations, on the CPU, exchange with the GPU the nodal unknowns, the residuals and the integrals of the stresses; the outputs of each step take the stresses, the measures and the cumulated plastic strain of the points back.

morphogen.homogenization.gpu.dot(a, b) → float[source]

Dot product of two vectors on the GPU (a CuPy reduction, without cuBLAS).

morphogen.homogenization.gpu.conjugate_gradient(apply, precondition, rhs, tol, maxiter)[source]

Preconditioned conjugate gradient from x = 0 on the GPU, the algorithm of morphogen.homogenization.solvers.conjugate_gradient() (minres() after a direction of negative curvature).

morphogen.homogenization.gpu.gmres(apply, precondition, rhs, tol, maxiter, restart: int = 50, deflate: int = 20, recycle: Recycling | None = None, stagnation: int = 0)[source]

GMRES with deflated restarts, preconditioned on the right on the GPU, the algorithm of morphogen.homogenization.solvers.gmres(): the basis on the GPU (the dot products of a Gram-Schmidt pass in one reduction over its rows, the vectors kept at a deflated restart combined in place), the Hessenberg matrix, its factors and the harmonic Ritz vectors on the CPU; recycle and stagnation as there, the recycled vectors on the GPU.

morphogen.homogenization.gpu.minres(apply, precondition, rhs, tol, maxiter)[source]

Preconditioned MINRES on the GPU, the algorithm of morphogen.homogenization.solvers.minres().

class morphogen.homogenization.gpu.FourierPreconditioner(shape, k_ref, nd: int)[source]

Bases: object

The Fourier preconditioner of morphogen.homogenization.fft. FourierPreconditioner on the GPU, for the element matrix k_ref of the reference medium: its inverse symbol computed on the GPU, the fields component by component, cuFFT transforms of the grid.

class morphogen.homogenization.gpu.LinearOperator(problem)[source]

Bases: object

The stiffness operator of the voxels of a linear FFT problem on the GPU (the element matrices of its materials).

morphogen.homogenization.gpu.solve_linear(problem, rhs, tol: float, maxiter: int)[source]

Solution of the linear system of an FFT problem on the GPU: (x, iterations, relative residual), x on the CPU. The operator and the preconditioner are kept by the problem.

class morphogen.homogenization.gpu.VoxelPaths(problem: NonlinearFFTProblem)[source]

Bases: _VoxelPaths

The discretization of the loading paths on the voxels (_VoxelPaths) on the GPU: the arrays of the points (measures of strain, stresses, tangents, internal variables) stay in its memory, where the measures, the behaviours, the stresses conjugate to B-bar and F-bar, the nodal forces and the products by the tangent operator are computed. The weights of the points stay on the CPU (they are uniform).

arrays(n_pts: int, nc: int, width: int) → tuple[source]

Measures of strain, weights, stresses, tangents and two sets of internal variables of n_pts points (measures and stresses of nc components, width internal variables).

host(*arrays) → tuple[source]

The arrays in the memory of the CPU (for the outputs).

measures(q, e, grads, wts) → None[source]
integrate(grads, dtemp, dt, old, new, stress, tangent, guess, ratio) → int[source]

The behaviours of the points on the GPU (behaviours.cu), in launches of chunk points that follow their durations, their tangents symmetrized as the problem says.

stress_scale(sigma, wts) → float[source]

Integral of the norm of the stresses of the points: the scale of the residuals of the macroscopic unknowns.

forces(sigma, wts)[source]

With B-bar (F-bar), the stresses of the points are first replaced by their conjugates: the outputs report them.

linearize(tangent, wts, first: bool, symmetric: bool | None = None)[source]
asymmetry(tangent, wts) → float[source]

The largest asymmetry of the tangents of the points of the phases (morphogen.homogenization.nonlinear.asymmetry()), their norms on the GPU.

symmetrize(tangent) → None[source]

The tangents of the points replaced by their symmetric parts on the GPU, in place (to the bit those of the kernels that symmetrize them).

macro_response(tangent, wts, v) → ndarray[source]

K_Ew v: the integral of the stress increments (conjugate ones with B-bar and F-bar) of the points for the nodal fluctuation v.

coupling(tangent, wts, unknown)[source]
class morphogen.homogenization.gpu.KrylovSolver(operator: VoxelPaths, tol: float, maxiter: int, symmetric: bool = True, recycle: Recycling | None = None)[source]

Bases: object

Conjugate gradients of the tangent operator of VoxelPaths on the GPU (GMRES if it is not symmetric, recycling the space of recycle and stopped where it stagnates), with the interface of morphogen.homogenization.fft_nonlinear._KrylovSolver (vectors on the CPU).

solve(rhs, x0=None, tol=None) → tuple[ndarray, SolveInfo][source]

Solution of K x = rhs to the relative residual tol, from x0 if given; the mean of rhs (round-off) is removed.