22
Model Order Reduction with pyMOR and NGSolve Stephan Rave NGSolve User Meeting Vienna June 15, 2017 living knowledge WWU Münster Westfälische Wilhelms-Universität Münster

Model Order Reduction with pyMOR and NGSolve

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Model Order Reduction with pyMOR and NGSolve

Model Order Reduction with pyMOR and NGSolveStephan Rave

NGSolve User MeetingVienna

June 15, 2017living knowledgeWWU Münster

WestfälischeWilhelms-UniversitätMünster

Page 2: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 2 /19

Outline

I Model Order Reduction.

I Model Order Reduction with pyMOR.

I Model Order Reduction with pyMOR and NGSolve.

pyMOR main developers

Rene Milk Petar Mlinaric Stephan Rave Felix Schindler

,,

Stephan Rave ([email protected])

Page 3: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 3 /19

Model Order Reduction

,,

Stephan Rave ([email protected])

Page 4: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 4 /19

Parametric Model Order ReductionConsider parametric problems

Φ : P → V , s : V → RS

whereI P ⊂ RP compact set (parameter domain).

I V Hilbert space (solution state space, dimV 0, possibly dimV =∞).

I Φ maps parameters to solutions of parametric PDE (hard to compute).

I s maps state vectors to quantities of interest.

Objective

Computes Φ : RP → V → RS

for many µ ∈ P or quickly for unknown single µ ∈ P .

,,

Stephan Rave ([email protected])

Page 5: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 5 /19

The Reduced Basis Method in a Nutshell

Objective

Quickly computes Φ

N

: RP → V

N

→ RS .

I When Φ, s are sufficiently smooth, a quickly computable low-dimensionalapproximation of s Φ should exist.

I Idea 1: State space reduction:I Define approximation ΦN : P → VN via Galerkin projection, dimVN =: N dimV .

I Approximate s Φ ≈ s ΦN .

I Idea 2: VN ⊆ spanΦ(µ1), . . . ,Φ(µk ).

I Idea 3: Construct VN iteratively via greedy search of P using quickly computablesurrogate ηN(ΦN(µ), µ) ≥ ‖Φ(µ)− ΦN(µ)‖.

,,

Stephan Rave ([email protected])

Page 6: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 5 /19

The Reduced Basis Method in a Nutshell

Objective

Quickly computes ΦN : RP → VN → RS .

I When Φ, s are sufficiently smooth, a quickly computable low-dimensionalapproximation of s Φ should exist.

I Idea 1: State space reduction:I Define approximation ΦN : P → VN via Galerkin projection, dimVN =: N dimV .

I Approximate s Φ ≈ s ΦN .

I Idea 2: VN ⊆ spanΦ(µ1), . . . ,Φ(µk ).

I Idea 3: Construct VN iteratively via greedy search of P using quickly computablesurrogate ηN(ΦN(µ), µ) ≥ ‖Φ(µ)− ΦN(µ)‖.

,,

Stephan Rave ([email protected])

Page 7: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 5 /19

The Reduced Basis Method in a Nutshell

Objective

Quickly computes ΦN : RP → VN → RS .

I When Φ, s are sufficiently smooth, a quickly computable low-dimensionalapproximation of s Φ should exist.

I Idea 1: State space reduction:I Define approximation ΦN : P → VN via Galerkin projection, dimVN =: N dimV .

I Approximate s Φ ≈ s ΦN .

I Idea 2: VN ⊆ spanΦ(µ1), . . . ,Φ(µk ).

I Idea 3: Construct VN iteratively via greedy search of P using quickly computablesurrogate ηN(ΦN(µ), µ) ≥ ‖Φ(µ)− ΦN(µ)‖.

,,

Stephan Rave ([email protected])

Page 8: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 5 /19

The Reduced Basis Method in a Nutshell

Objective

Quickly computes ΦN : RP → VN → RS .

I When Φ, s are sufficiently smooth, a quickly computable low-dimensionalapproximation of s Φ should exist.

I Idea 1: State space reduction:I Define approximation ΦN : P → VN via Galerkin projection, dimVN =: N dimV .

I Approximate s Φ ≈ s ΦN .

I Idea 2: VN ⊆ spanΦ(µ1), . . . ,Φ(µk ).

I Idea 3: Construct VN iteratively via greedy search of P using quickly computablesurrogate ηN(ΦN(µ), µ) ≥ ‖Φ(µ)− ΦN(µ)‖.

,,

Stephan Rave ([email protected])

Page 9: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 6 /19

An ExampleExperimental Data

MathematicalModeling

MultiscaleNumerics

ModelReduction

IntegrationValidation

MULTIBAT: Gain understandingof degradation processes inrechargeable Li-Ion Batteriesthrough mathematical modelingand simulation.

I Focus: Li-Plating.

I Li-plating initiated atinterface between activeparticles and electrolyte.

I Need microscale modelswhich resolve activeparticle geometry.

I Huge nonlinear discretemodels.

,,

Stephan Rave ([email protected])

Page 10: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 7 /19

An Example – MOR Results

I 2.920.000 DOFs

I Snapshots: 3

I dimVN = 98 + 47

I M = 710 + 774

I Rel. err.: < 1.5 · 10−3

I Full model: ≈ 13h

I Reduction: ≈ 9h

I Red. model: ≈ 5m

I Speedup: 154

0 0.2 0.4 0.6

0.09

0.10

0.11

0.12

0.13

transferred charge / nAhce

llvo

ltage

/V

0 0.2 0.4 0.6

19.60

19.70

19.80

avg.

Lico

ncen

tr./

kmol

/m3

5.74 nA 11.64 nA 18.09 nA 23.66 nA

36.73 nA full model red. model

0 0.2 0.4 0.6

0.09

0.10

0.11

0.12

0.13

transferred charge / nAh

cell

volta

ge/

V

0 0.2 0.4 0.6

19.60

19.70

19.80

avg.

Lico

ncen

tr./

kmol

/m3

5.74 nA 11.64 nA 18.09 nA 23.66 nA

36.73 nA full model red. model

0 0.2 0.4 0.6

0.09

0.10

0.11

0.12

0.13

transferred charge / nAh

cell

volta

ge/

V

0 0.2 0.4 0.6

19.60

19.70

19.80

avg.

Lico

ncen

tr./

kmol

/m3

5.74 nA 11.64 nA 18.09 nA 23.66 nA

36.73 nA full model red. model

,,

Stephan Rave ([email protected])

Page 11: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 8 /19

Model Order Reduction with pyMOR

,,

Stephan Rave ([email protected])

Page 12: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 9 /19

pyMOR – Model Order Reduction with Python

GoalOne tool for algorithm development and large-scale applications.

I Started late 2012, 20k lines of Python code, 3k single commits.

I BSD-licensed, fork us on Github!

I Quick prototyping with Python 2/3.

I Comes with small NumPy/SciPy-based discretization toolkit for getting started quickly.

I Seamless integration with high-performance PDE solvers.

,,

Stephan Rave ([email protected])

Page 13: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 10 /19

Generic Algorithms and Interfaces for MOR

Discretization

Operator

product

operator, rhs

LincombOperator

Operator

Operator

. . .

VectorArray

Reductor

apply inverse

apply2

apply2

Gram-Schmidt

apply2

axpy

scal

Greedyreductor(d, basis)

gram schmidt basis extension(basis, U, prod)

U = d.solve(mu)

Generic algorithms . . .

pyMOR

PDE solver deal.II FEniCS DUNE . . .

dune-pymordolfinpymor-deal.II

dealii model()

fenics model()

dune model()

example.py

User Code

U = d.solve(mu)

d.visualize(U)

greedy(d, ...)

d, prod = ...

I VectorArray, Operator, Discretization classes represent objects in solver’smemory.

I No communication of high-dimensional data.I Tight, low-level integration with external solver.I No MOR-specific code in solver.

,,

Stephan Rave ([email protected])

Page 14: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 11 /19

Implemented Algorithms

I Gram-Schmidt, POD.

I Greedy basis generation with different extension algorithms.

I Automatic (Petrov-)Galerkin projection of arbitrarily nested affine combinations ofoperators.

I Interpolation of arbitrary (nonlinear) operators, EI-Greedy, DEIM.

I A posteriori error estimation.

I Iterative linear solvers, Newton algorithm, time-stepping algorithms.

I New! System theory Methods: balanced truncation, IRKA, . . . (sys-mor branch)

,,

Stephan Rave ([email protected])

Page 15: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 12 /19

FEniCS Support Included

I Directly interfaces FEniCSLA backend, no copies needed.

I Use same MOR code with both backends!

I Only 150 SLOC for bindings.

I Thermal block demo:30 SLOC FEniCS +15 SLOC wrapping for pyMOR.

I Easily increase FEM order, etc.Figure: 3x3 thermal block problemtop: red. solution, bottom: red. errorleft: pyMOR solver, right: FEniCS solver

,,

Stephan Rave ([email protected])

Page 16: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 13 /19

deal.II Support

I pymor-deall.II support modulehttps://github.com/pymor/pymor-deal.II

I Python bindings forI dealii::Vector,

I dealii::SparseMatrix.

I pyMOR wrapper classes.

I MOR demo for linear elasticity examplefrom tutorial.

0 5 1010−12

10−7

10−2

maximum red. error

0 5 10

0.4

0.6

0.8

1

estimator effectivity

Figure: top: Solutions for (µ, λ) = (1, 1) and(µ, λ) = (1, 10), bottom: red. errs. and max./min.estimator effectivities vs. dimVN .

,,

Stephan Rave ([email protected])

Page 17: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 14 /19

Tools for interfacing MPI parallel solvers

I Automatically make sequentialbindings MPI aware.

I Reduce HPC-Cluster modelswithout thinking about MPI atall.

I Interactively debug MPI parallelsolvers.

Figure: FV solution of 3D Burgers-type equation (27.6 · 106 DOFs,

600 time steps) using Dune .

Table: Time (s) needed for solution using DUNE / DUNE with pyMOR timestepping.

MPI ranks 1 2 3 6 12 24 48 96 192

DUNE 17076 8519 5727 2969 1525 775 395 202 107pyMOR 17742 8904 6014 3139 1606 816 418 213 120

overhead 3.9% 4.5% 5.0% 5.7% 5.3% 5.3% 6.0% 5.4% 11.8%

,,

Stephan Rave ([email protected])

Page 18: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 15 /19

Model Order Reduction with pyMOR andNGSolve

,,

Stephan Rave ([email protected])

Page 19: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 16 /19

NGSolve Support

I Based on NGSolve - Python.

I See ngs-user-meeting17 branch ofpyMOR repo.

I pyMOR wrappers for GridFunction andBaseMatrix classes.

I 3d thermal block demo included.

I Joint work withChristoph Lehrenfeld.

Figure: 3d thermal block problemtop: full/red. sol., bottom: err. for worst approx. µand max. red. error vs. dimVN .

,,

Stephan Rave ([email protected])

Page 20: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 17 /19

import live_demo

,,

Stephan Rave ([email protected])

Page 21: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 18 /19

Matrix DEIM with NGSolve

osmosis

Osmotic cell swelling problem

∂tu − α∆u = 0 in Ω(t)

Vnu + α∂nu = 0 on ∂Ω(t)

−βκ+ γ(u − u0) = Vn on ∂Ω(t)

Transformed concentration equation on reference domain∫ΩJn+1un+1v dx + ∆t

∫ΩJn+1V · (F n+1−T · ∇x v)un+1dx

+ ∆t

∫ΩαJn+1(F n+1−T∇xu) · (F n+1−T∇x v) dx =

∫ΩJnun v dx

I Nonlinear in transformation Ψ, F := ∂xΨ, J := | det(F )|, V := ∂tΨ.I Use Matrix-DEIM w.r.t. Ψ.

,,

Stephan Rave ([email protected])

Page 22: Model Order Reduction with pyMOR and NGSolve

WestfälischeWilhelms-UniversitätMünster Model Order Reduction with pyMOR and NGSolve 19 /19

Thank you for your attention!

My homepagehttp://stephanrave.de/

Jupyter notebookhttp://stephanrave.de/talks/pymor_ngsolve.ipynb

pyMOR – Generic Algorithms and Interfaces for Model Order ReductionSIAM J. Sci. Comput., 38(5), pp. S194–S216http://www.pymor.org/

MULTIBAT: Unified Workflow for fast electrochemical 3D simulations of lithium-ion cellscombining virtual stochastic microstructures, electrochemical degradation models andmodel order reduction (submitted)https://arxiv.org/abs/1704.04139

,,

Stephan Rave ([email protected])