Daniel Wheeler
July 21, 2022
380

# Phase Field Methods + FEniCS/Firedrake

July 21, 2022

## Transcript

1. ### Ivan Yashchuk Aalto University | Quansight Labs Phase Field Methods

+ FEniCS/Firedrake CHiMaD Phase Field Methods Workshop XI ivan.yashchuk@aalto.ﬁ
2. ### Content • FEniCS/Firedrake introduction ◦ Composable solvers & preconditioning ◦

Time-dependent problems: ﬁredrake-ts, Irksome ◦ Phase ﬁeld speciﬁc example • PFHub benchmarks • Future developments (GPU, AMR) • Embedding into optimization and machine learning packages • Conclusions

4. ### FEniCS / Firedrake Uniﬁed Form Language (UFL) is a domain

speciﬁc language for specifying and manipulating variational (weak) forms, used in FEniCS, Firedrake, and Dune-Fem. Having a PDE problem speciﬁed using UFL, an eﬃcient low-level code is generated from a higher-level description. FEniCS is implemented in C++ and has C++ and Python user interface. Firedrake is implemented in Python (with bits of Cython) and is tightly integrated with PETSc library.
5. ### Strong and weak formulations for a Poisson problem ✗ Strong

form: where Ω is the spatial domain and ∂ Ω is the boundary of Ω . ✓ Variational or weak form:

7. ### UFL language for ﬁnite element forms Weak formulation is easy

to work with for deriving adjoint Jacobian, matrix actions, etc. Source: FEniCS Book The adjoint a* of a bilinear form a is the form obtained by interchanging the two arguments The linear form Aa is the action of the bilinear form a
8. ### Some useful UFL operators Tensor algebra operators: transpose, tr, dor,

inner, outer, cross, det, dev, sym, skew Diﬀerential operators: Spatial derivatives, gradient, divergence, curl, rot, variable derivatives, functional derivatives Discontinuous Galerkin operators: jump, avg, restriction UFL User Manual: https://fenicsproject.org/pub/documents/uﬂ/uﬂ-user-manual/uﬂ-user-manual.pdf
9. ### “Physics-based” preconditioners & solver composition in Firedrake Firedrake relies on

PETSc KSP and PETSc SNES for solving linear and nonlinear problems. All the power of “command-line programming” of PETSc options is available separating the model and solver implementation. The code remains the same. ✓ matrix-free methods ✓ geometric multigrid ✓ Schur complements ✓ block Jacobi, block Gauss-Seidel Robert C. Kirby, Lawrence Mitchell “Solver composition across the PDE/linear algebra barrier”, https://arxiv.org/abs/1706.01346
10. ### Example | Runtime solver composition in Firedrake 〈 p, q

〉 − 〈 q, div u 〉 + λ 〈 v, u 〉 + 〈 div v, p 〉 = 〈 f, q 〉   ∀ v ∈ V ₁ , q ∈ V ₂ https://www.ﬁredrakeproject.org/solving-interface.html#preconditioning-mixed-ﬁnite-element-systems S=D−CA ⁻ ¹B “diag” “lower” “upper” “FULL”
11. ### Solving time-dependent problems | Irksome The Irksome library provides Implicit

Runge Kutta methods for Firedrake. https://github.com/ﬁredrakeproject/Irksome
12. ### Solving time-dependent problems | ﬁredrake-ts The ﬁredrake-ts library provides an

interface to PETSc TS for the scalable solution of DAEs arising from the discretization of time-dependent PDEs. https://github.com/IvanYashchuk/ﬁredrake-ts
13. ### Solving time-dependent problems | ﬁredrake-ts Plans: IMEX methods, interface to

Julia’s DiﬀerentialEquations.jl https://github.com/IvanYashchuk/ﬁredrake-ts The current PETSc TS interface for solving time dependent problems assumes the problem is written in the form F(t, u, u ̇ ) = 0, u(t ₀ ) = u ₀ . The Jacobian required by PETSc TS is automatically derived with UFL
14. ### Parallel support Parallelism is implemented using MPI. Usual workﬂow: •

initial solver implementation on a desktop/laptop for small scale problem • run the same code on a supercomputer using many parallel processes mpirun -np 128 python script.py

17. ### Simple Allen-Cahn variationally derived | Code example R( ϕ̇ ,

ϕ , t) = τ ( ϕ ) 〈ϕ̇ , v 〉 + 〈 δ F/ δϕ , v 〉 ∀ v ∈ V In code: R_AC = tau(phi) * inner(dphi_dt, v) * dx + derivative(F, phi, v) * dx Then just problem = firedrake_ts.DAEProblem(R_AC,phi,dphi_dt,(0.0, 1.0),bcs=bc) solver = firedrake_ts.DAESolver(problem) solver.solve()
18. ### PFHub benchmarks Great way to get started with implementing own

phase ﬁeld solver and share knowledge! https://pages.nist.gov/pfhub/
19. ### Benchmark Problem 1: Spinodal Decomposition The free energy of the

system: Chemical free energy density: Note: Argyris and Bell ﬁnite elements are available for C¹ discretizations Robert C. Kirby, Lawrence Mitchell “Code generation for generally mapped ﬁnite elements”, https://arxiv.org/abs/1808.05513

system:

23. ### Benchmark Problem 1: Spinodal Decomposition Note: Argyris and Bell ﬁnite

elements are available for C¹ discretizations Robert C. Kirby, Lawrence Mitchell “Code generation for generally mapped ﬁnite elements”, https://arxiv.org/abs/1808.05513

25. ### Benchmark Problem 2: Ostwald Ripening Vector Allen-Cahn + Cahn-Hilliard equations.

The free energy of the system:

29. ### Similar code for other benchmarks! • Benchmark Problem 4: Elastic

Precipitate Cahn-Hilliard + Linear Elasticity FEniCS demo for Hyperelasticity: https://fenicsproject.org/olddocs/dolﬁn/latest/python/demos/hyperelasticity/demo_hyperelasticity.py.html • Benchmark Problem 5: Stokes Flow FEniCS demo for Stokes equations: https://fenicsproject.org/olddocs/dolﬁn/latest/python/demos/stokes-iterative/demo_stokes-iterative.py.html • Benchmark Problem 6: Electrostatics Cahn-Hilliard + Poisson Equation
30. ### Example: Navier-Stokes+Cahn-Hilliard+Heat Tatu Pinomaa, Ivan Yashchuk, Matti Lindroos, Tom Andersson,

Nikolas Provatas, Anssi Laukkanen “Process-Structure-Properties-Performance Modeling for Selective Laser Melting”, 2019, https://doi.org/10.3390/met9111138

32. ### Future developments | AMR with Firedrake • There is no

oﬃcial support for AMR • There is some eﬀort and on some branch this functionality exists Nicolas Barral, et al. Anisotropic mesh adaptation in Firedrake with PETSc DMPlex, https://arxiv.org/abs/1610.09874, 2016 April 2021 update:
33. ### Future developments | AMR with DUNE Did not try personally

but looks promising! Same model speciﬁcation using UFL. Peter Bastian, Markus Blatt, Andreas Dedner, Nils-Arne Dreier, Christian Engwer, René Fritze, Carsten Gräser, Christoph Grüninger, Dominic Kempf, Robert Klöfkorn, Mario Ohlberger, Oliver Sander “The DUNE Framework: Basic Concepts and Recent Developments”, https://arxiv.org/abs/1909.13672
34. ### Future developments | GPU support for Firedrake ✓ PETSc supports

GPUs ✗ Firedrake doesn’t have an oﬃcial support of assembling matrices and vectors on GPUs There is an ongoing work by Kaushik Kulkarni and Andreas Kloeckner (UIUC) SIAM CSE21 poster: https://ssl.tiker.net/nextcloud/s/rsSa6KsYEsA3xqk
35. ### Automatic Differentiation libraries + FEniCS/Firedrake FEniCS’21 presentation: https://fenics2021.com/talks/yashchuk.html Embedding of

PDE solvers into optimization and machine learning packages

37. ### https://github.com/IvanYashchuk/PyFenicsAD.jl Julia | Turing.jl Summary Statistics parameters mean std naive_se

mcse ess rhat Symbol Float64 Float64 Float64 Float64 Float64 Float64 kappa0 1.2497 0.3789 0.0120 0.0357 130.3485 1.0001 kappa1 0.5443 0.1711 0.0054 0.0155 139.7087 1.0001 σ 0.0143 0.0019 0.0001 0.0001 178.8158 1.0043 Quantiles parameters 2.5% 25.0% 50.0% 75.0% 97.5% Symbol Float64 Float64 Float64 Float64 Float64 kappa0 0.5183 0.9850 1.2590 1.5483 1.9140 kappa1 0.2295 0.4291 0.5424 0.6698 0.8579 σ 0.0111 0.0130 0.0142 0.0154 0.0188
38. ### Conclusions Firedrake and FEniCS are powerful libraries with many useful

tools for developing a phase ﬁeld solver possibly mixed with diﬀerent kind of physics. • Keep the models and solvers separate • Rely on UFL to do derivatives and other weak form transformations • Mostly same code runs on supercomputers How to get started? 1. Start with FEniCS tutorial “Solving PDEs in Python - The FEniCS Tutorial Volume I” by Hans Petter Langtangen, Anders Logg 2. Join the FEniCS Discourse forum to ask questions on UFL or other aspects 3. Continue with implementing PFHub benchmark problems 4. Try using Firedrake and ﬁredrake-ts ivan.yashchuk@aalto.ﬁ