Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Phase Field Methods + FEniCS/Firedrake

Phase Field Methods + FEniCS/Firedrake


Daniel Wheeler

July 21, 2022

More Decks by Daniel Wheeler

Other Decks in Science


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

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

    Time-dependent problems: firedrake-ts, Irksome ◦ Phase field specific example • PFHub benchmarks • Future developments (GPU, AMR) • Embedding into optimization and machine learning packages • Conclusions
  3. FEniCS / Firedrake Introduction firedrakeproject.org fenicsproject.org

  4. FEniCS / Firedrake Unified Form Language (UFL) is a domain

    specific language for specifying and manipulating variational (weak) forms, used in FEniCS, Firedrake, and Dune-Fem. Having a PDE problem specified using UFL, an efficient 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:
  6. “Hello world!” / Stokes equation

  7. UFL language for finite 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 Differential 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/ufl/ufl-user-manual/ufl-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.firedrakeproject.org/solving-interface.html#preconditioning-mixed-finite-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/firedrakeproject/Irksome
  12. Solving time-dependent problems | firedrake-ts The firedrake-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/firedrake-ts
  13. Solving time-dependent problems | firedrake-ts Plans: IMEX methods, interface to

    Julia’s DifferentialEquations.jl https://github.com/IvanYashchuk/firedrake-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 workflow: •

    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
  15. Simple Allen-Cahn variationally derived

  16. Simple Allen-Cahn variationally derived

  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 field 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 finite elements are available for C¹ discretizations Robert C. Kirby, Lawrence Mitchell “Code generation for generally mapped finite elements”, https://arxiv.org/abs/1808.05513
  20. Benchmark Problem 1: Spinodal Decomposition The free energy of the

  21. Benchmark Problem 1: Spinodal Decomposition Chemical free energy density:

  22. Benchmark Problem 1: Spinodal Decomposition Governing equation:

  23. Benchmark Problem 1: Spinodal Decomposition Note: Argyris and Bell finite

    elements are available for C¹ discretizations Robert C. Kirby, Lawrence Mitchell “Code generation for generally mapped finite elements”, https://arxiv.org/abs/1808.05513
  24. Benchmark Problem 1: Spinodal Decomposition (case “d”)

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

    The free energy of the system:
  26. Benchmark Problem 2: Ostwald Ripening The chemical free energy density:

  27. Benchmark Problem 2: Ostwald Ripening Cahn-Hilliard equation: Allen-Cahn equations:

  28. Benchmark Problem 3: Dendritic Growth Allen-Cahn + Heat equations https://github.com/IvanYashchuk/pf-hub-benchmark3

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

    Precipitate Cahn-Hilliard + Linear Elasticity FEniCS demo for Hyperelasticity: https://fenicsproject.org/olddocs/dolfin/latest/python/demos/hyperelasticity/demo_hyperelasticity.py.html • Benchmark Problem 5: Stokes Flow FEniCS demo for Stokes equations: https://fenicsproject.org/olddocs/dolfin/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
  31. Future developments | AMR with FEniCS • Automatic AMR using

    adjoint/dual estimators • There is no coarsening 😔 • Adaptive meshing is removed in the new version FEniCS-X Melting of octadecane (Navier-Stokes+Advection-Diffusion)
  32. Future developments | AMR with Firedrake • There is no

    official support for AMR • There is some effort 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 specification 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 official 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
  36. https://ivanyashchuk.github.io/fenics_pymccon2020/ PyMC3

  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 field solver possibly mixed with different 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 firedrake-ts ivan.yashchuk@aalto.fi