morphogen.homogenization.solvers¶
Linear solvers for the symmetric positive definite systems of the FE problems.
direct: sparse LU factorization (SuperLU, from SciPy), reused for every right-hand side. Exact and fast for small systems; its memory grows quickly in 3D.amg: conjugate gradient preconditioned by smoothed-aggregation algebraic multigrid (morphogen.homogenization.amg), with the rigid-body modes (or constants) as near-null space. For 10-node tetrahedra, the preconditioner has two levels: a Gauss-Seidel sweep on the quadratic system, and an AMG cycle on the linear system of the corner nodes (Galerkin projection). The hierarchy is reused for every right-hand side.cg: conjugate gradient with a Jacobi preconditioner (slow on large or high-contrast problems; for checks).auto:directup toDIRECT_LIMITunknowns,amgabove.
The tangents of the nonlinear problems whose behaviours have nonsymmetric consistent
tangents (symmetric=False: crystal and porous plasticity, the Armstrong-Frederick
hardening, learned laws that are not potentials, MFront behaviours without a symmetric
tangent) are solved by sparse LU (direct) or by GMRES with deflated restarts
(gmres()) with the preconditioner of their symmetric part (amg, cg); along
the loading paths of the voxels GMRES recycles its space from a solve to the next once
one restarts (GCRO-DR, Recycling) and stops where it stagnates
(GMRES_STAGNATION).
- morphogen.homogenization.solvers.WORN = 1.3¶
A multigrid preconditioner kept from a step of a loading path to the next is built again when the iterations that a solve takes for a decade of its residual have grown by this factor since it was built (
LinearSolver.worn()): building it costs as much as the iterations that a third more would add to a step
- morphogen.homogenization.solvers.GMRES_RESTART = 50¶
The dimension of the Krylov spaces of
gmres()before it restarts (the vectors of its basis kept in memory)
- morphogen.homogenization.solvers.GMRES_DEFLATE = 20¶
the harmonic Ritz vectors of the harmonic Ritz values of least modulus (deflated restarting; 0: the plain restarts)
- Type:
The approximate eigenvectors that
gmres()keeps at its restarts
- morphogen.homogenization.solvers.GMRES_STAGNATION = 8¶
The cycles over which the residual of a solve of
gmres()along a loading path must at least halve (stagnation): 240 iterations of restarted cycles. Measured on the softening composites of 16^3 voxels (Rousselier and GTN at high triaxialities), it stops all the solves that would end at theirmaxiterabove their tolerance (35 of them, after about 300 iterations instead of 1,320) and none of the 95 that converge after restarts (up to 528 iterations, after slow cycles); six cycles would stop three of these, three cycles eight
- morphogen.homogenization.solvers.SOLVERS = ('auto', 'direct', 'amg', 'cg', 'fenicsx')¶
morphoGen’s linear solvers, or FEniCSx (
morphogen.homogenization.fenicsx).- Type:
Solvers of finite element problems
- morphogen.homogenization.solvers.NEGLIGIBLE = 1e-12¶
Right-hand sides smaller than this fraction of their scale (the norm they would have without cancellation between elements) are round-off: the affine field solves the problem (homogeneous medium, laminate loaded along its layers…).
- morphogen.homogenization.solvers.dot(a: ndarray, b: ndarray) float[source]¶
Dot product of two vectors in a single thread. BLAS (
a @ b) splits long vectors over its own threads, which compete with those of the compiled kernels and slow the solvers down several times — during the product and for a tenth of a second after it, while its idle threads wait for the next one (OpenBLAS); this sum is also the same for any number of threads.
- morphogen.homogenization.solvers.norm(a: ndarray) float[source]¶
Euclidean norm of a vector (see
dot()).
- morphogen.homogenization.solvers.times(a: ndarray, b: ndarray) ndarray[source]¶
a @ bfor arrays of one or two dimensions, in a single thread: the products of long arrays between two compiled kernels (seedot()).
- morphogen.homogenization.solvers.choose_method(method: str, n: int) str[source]¶
Concrete solver for
nunknowns (resolvesauto).
- class morphogen.homogenization.solvers.SolveInfo(method: 'str', n_dofs: 'int', iterations: 'int', residual: 'float', setup_s: 'float', solve_s: 'float')[source]¶
Bases:
object
- morphogen.homogenization.solvers.conjugate_gradient(apply, precondition, rhs, tol, maxiter)[source]¶
Preconditioned conjugate gradient from
x = 0.apply(v)andprecondition(r)return new arrays. Stops when the residual is belowtoltimes the norm ofrhs; returns (x, iterations, relative residual). A direction of negative curvature (an indefinite operator: the tangent of softening points) hands the system tominres(), from the current iterate or from zero, whichever leaves the smaller residual. Each iteration is a checkpoint ofmorphogen.stopping.
- morphogen.homogenization.solvers.minres(apply, precondition, rhs, tol, maxiter)[source]¶
Preconditioned MINRES (Paige & Saunders 1975) from
x = 0, for a symmetric operator that may be indefinite (the tangent of softening points) and a symmetric positive definite preconditioner.Each cycle stops when the residual in the norm of the preconditioner falls below the target; the residual is then computed in the Euclidean norm, and another cycle starts from it while it is above
toltimes the norm ofrhs. Returns (x, iterations, relative residual), asconjugate_gradient().
- morphogen.homogenization.solvers.gmres(apply, precondition, rhs, tol, maxiter, restart: int = 50, deflate: int = 20, recycle: Recycling | None = None, stagnation: int = 0)[source]¶
GMRES (Saad & Schultz 1986) from
x = 0, preconditioned on the right, with deflated restarts (Morgan 2002): the solver of the tangent operators that are not symmetric (the full consistent tangents of the points), with the preconditioner ofconjugate_gradient()(apply(v)andprecondition(r)return new arrays).Each cycle builds an orthonormal basis of the Krylov space of
apply(precondition(.))by classical Gram-Schmidt (each pass sweeps the basis once for all its dot products, summed by blocks that do not depend on the threads), passed again where it cancels most of the vector (twice is enough: orthogonal to round-off), and minimizes the residual over it by the Givens rotations of its Hessenberg matrix. Preconditioned on the right, the residual minimized is that of the system,rhs - apply(x): the cycle stops when it falls belowtoltimes the norm ofrhs, the test of the conjugate gradients. Afterrestartiterations (the vectors kept)xis updated, and the next cycle starts from the harmonic Ritz vectors of thedeflateharmonic Ritz values of least modulus and from the residual (_deflation(); their combinations replace the first vectors of the basis): the approximate eigenvectors of the eigenvalues nearest zero, which a plain restart loses and the next cycle must find again (restarted GMRES stalls on them: the indefinite tangents of softening points), stay in the space, and the cycle minimizes the residual over them and the Krylov vectors of the residual. The Hessenberg matrix of such a cycle has a full first block, factorized by Householder reflections, its next columns by rotations. A cycle that does not decrease the residual ends the solve; after deflated restarts the residual that reaches the tolerance is computed again (a product) and, if it is above it, the next cycle starts from it alone, as withdeflate=0(the plain restarted GMRES: each cycle from the residual computed again) or a singular Hessenberg matrix. A solve that does not restart is that of the plain GMRES. Returns (x, iterations, relative residual); each iteration takes a product by the operator and one by the preconditioner, each cycle one more by the preconditioner, each residual computed again one more by the operator. Each iteration is a checkpoint ofmorphogen.stopping.recycle(aRecyclingshared by a sequence of solves): a solve that restarts leaves it the vectors of its last deflated restart, and the next solves of the sequence start from them by GCRO-DR (_gcro_dr()); the solves before the first restart are those without it, to the bit.stagnation: a solve whose residual has not been halved over its laststagnationcycles stops there (0: never), an inexact correction of Newton’s method that more cycles would improve only slowly.
- class morphogen.homogenization.solvers.Recycling[source]¶
Bases:
objectThe space that
gmres()recycles from a solve to the next of a sequence of systems whose operators change little, those of the Newton iterations of a loading path: GCRO-DR (Parks, de Sturler, Mackey, Johnson & Maiti 2006), the recycled vectors approximate eigenvectors of the eigenvalues nearest zero of the preconditioned operator, which restarted GMRES must otherwise find again in each solve. Empty until a solve of the sequence restarts, so that the solves before are those of GMRES with deflated restarts to the bit and cost nothing more: that solve leaves it the harmonic Ritz vectors of its last deflated restart, and each later solve minimizes its residual over them and the Krylov vectors of the operator projected out of their images, and keeps the harmonic Ritz vectors of that space at each of its own restarts. The solves of the same operator reuse the images of the recycled vectors; a new operator (renew(): the tangent of the next Newton iteration) has them computed again by its first solve,kproducts (products), if the last solve filled a cycle (needed), and drops the space otherwise. The vectors live where those of the solves do (on the GPU formorphogen.homogenization.gpu.gmres()).- u¶
The recycled vectors (rows), in the variable of the preconditioned operator (the corrections are their images by the preconditioner), or None
- c¶
Their images by the preconditioned operator, orthonormal
- needed¶
Whether the last solve filled a cycle (it restarted, or would have without the recycled vectors): otherwise a new operator drops them (
renew())
- products¶
The products by the operators spent on the images of the recycled vectors, and the solves started from them
- class morphogen.homogenization.solvers.TwoLevelPreconditioner(matrix, prolongation, near_null=None, dofs=None, coarse_dofs=None, blocks=None)[source]¶
Bases:
objectSymmetric two-level preconditioner of
Awith a coarse spaceP.A forward Gauss-Seidel sweep on
A, a correction by one AMG V-cycle on the Galerkin matrixP^T A P, then a backward sweep (so the preconditioner is symmetric). WithPthe interpolation of the linear (4-node) elements into the quadratic (10-node) ones, the coarse matrix is the stiffness of the linear elements, on which smoothed aggregation is efficient.dofs,coarse_dofs: the degree of freedom3 node + componentof each unknown of the matrix and of the coarse space, where they are components of the nodes of a mesh (the sweeps then work by nodes, seeSmoother);blocks: the blocks of the matrix, where they have been made already (NodeBlocks).- refresh(blocks: NodeBlocks) bool[source]¶
The sweeps for the values that the blocks of the matrix have now (see
refresh()); the coarse space and its multigrid cycle are kept. The preconditioner stays symmetric positive definite: the coarse correction adds a positive term to the symmetric sweeps of the matrix as it is.
- class morphogen.homogenization.solvers.LinearSolver(matrix, *, method='auto', tol=1e-08, maxiter=None, near_null=None, coarse=None, symmetric: bool = True, dofs=None)[source]¶
Bases:
objectSolver of A x = b for a fixed matrix A and several right-hand sides.
near_null: low-energy modes (columns) of A, used by algebraic multigrid.coarse:(P, near_null_coarse), a coarse space for the two-levelamgpreconditioner (seeTwoLevelPreconditioner).symmetric: false for a matrix that is not symmetric (the tangent of nonsymmetric consistent tangents), which the iterative methods solve bygmres()with the preconditioner of its symmetric part (LU factorizes it as it is).dofs: the degree of freedom3 node + componentof each unknown, where the unknowns are components of the displacements of the nodes of a mesh (the sweeps of the multigrid preconditioners then work by nodes, seeSmoother;coarsemay carry those of its coarse space as a third item). The products of the iterative methods then read the matrix by the 3 x 3 blocks of its nodes (blocks:NodeBlocks, the same products to the bit).- blocks¶
The matrix by blocks of nodes, for the products of the iterative methods
- updated(matrix, symmetric: bool | None = None) LinearSolver[source]¶
Solver of another matrix of the same size (a new tangent operator): direct methods factorize it, iterative ones keep this preconditioner (
symmetric: whether the matrix is, by default as this one). This solver is not to be used afterwards: the blocks of its matrix take the values of the new one, and with them the sweeps of a multigrid preconditioner that work by nodes (for a symmetric matrix of the same pattern) — the interpolations and the coarse levels are kept, and the preconditioner stays symmetric positive definite.
- worn() bool[source]¶
Whether the preconditioner is to be built again, asked at the start of a step of a loading path, before the solver is
updated(): true for a factorization or a diagonal (built with the solver); for a multigrid preconditioner, when the solves of the last step tookWORNtimes the iterations per decade of their residual that those of the step for which it was built took (the tangent has moved away from the one whose coarse levels it holds).