Skip to content

Commit e4fe160

Browse files
committed
TL: playground update
1 parent aeffa7d commit e4fe160

9 files changed

Lines changed: 87 additions & 16 deletions

File tree

docs/notebooks.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ All tutorials are written in jupyter notebooks, that can be :
77
- read using the [online documentation](https://qmat.readthedocs.io/en/latest/notebooks.html)
88
- downloaded from the [notebook folder](https://github.com/Parallel-in-Time/qmat/tree/main/docs/notebooks) and played with
99

10-
> 📋 _Table of content_ :
10+
📋 **Table of content**
1111

12-
1. **Basic usage** : how to generate and use basic $Q$-coefficients and $Q_\Delta$ approximations, through a step-by-step tutorial going from generic Runge-Kutta methods to SDC for simple problems.
12+
1. **Basic usage tutorials** : how to generate and use basic $Q$-coefficients and $Q_\Delta$ approximations, through a step-by-step tutorial going from generic Runge-Kutta methods to SDC for simple problems.
1313
2. **Advanced tutorials** : additional features or `qmat` to go deeper into time-integration (Node-to-Node formulation, use for non-linear problems, $\phi$-SDC, ...)
1414
3. **Components usage** : how to use the main utility modules, like {py:mod}`qmat.lagrange`, etc ...
1515

qmat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
**Secondary sub-packages** 🍭
1010
1111
- :class:`solvers` : implementations of time-integration solvers that make use of `qmat`-generated coefficients
12-
- :class:`playgrounds`: **non-tested but documented** codes with experiments or small applications with `qmat`
12+
- :class:`playgrounds`: **non-tested** codes with experiments or small applications with `qmat`
1313
1414
**Utility modules** ⚙️
1515

qmat/playgrounds/tibo/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

qmat/playgrounds/tibo/imex.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
First tentative for a dedicated IMEX solver class
3+
"""
14
import numpy as np
25

36
from qmat.solvers.dahlquist import DahlquistIMEX
@@ -9,7 +12,9 @@ class DiffOpIMEX(DiffOp):
912
Base class for an IMEX differential operator
1013
"""
1114

12-
def evalF2(self, u:np.ndarray, t:float, out:np.ndarray):
15+
evalF_IM = DiffOp.evalF
16+
17+
def evalF_EX(self, u:np.ndarray, t:float, out:np.ndarray):
1318
"""
1419
Evaluate f_EX(u,t) and store the result into out
1520
"""
@@ -26,9 +31,11 @@ def __init__(self, diffOp, tEnd=1, nSteps=1, t0=0):
2631
f"DiffOpIMEX object is required for diffOp argument, not {diffOp}"
2732
super().__init__(diffOp, tEnd, nSteps, t0)
2833

34+
def evalF_IM(self, u:np.ndarray, t:float, out:np.ndarray):
35+
self.diffOp.evalF_IM(u, t, out)
2936

30-
def evalF2(self, u:np.ndarray, t:float, out:np.ndarray):
31-
self.diffOp.evalF2(u, t, out)
37+
def evalF_EX(self, u:np.ndarray, t:float, out:np.ndarray):
38+
self.diffOp.evalF_EX(u, t, out)
3239

3340
def solve(self, QI, wI, QE, wE, uNum=None):
3441
nNodes, QI, wI, QE, wE, useWeights = DahlquistIMEX.checkCoeff(QI, wI, QE, wE)
@@ -74,8 +81,8 @@ def solve(self, QI, wI, QE, wE, uNum=None):
7481
np.copyto(uNode, rhs)
7582

7683
# evalF on current stage
77-
self.evalF(u=uNode, t=tNode, out=fEvals[m])
78-
self.evalF2(u=uNode, t=tNode, out=fEvals2[m])
84+
self.evalF_IM(u=uNode, t=tNode, out=fEvals[m])
85+
self.evalF_EX(u=uNode, t=tNode, out=fEvals2[m])
7986

8087
# step update (if not, uNum[i+1] is already the last stage)
8188
if useWeights:

qmat/playgrounds/tibo/imexStabilityAdvDiffSDC.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# -*- coding: utf-8 -*-
33
"""
44
Script investigating IMEX stability for advection-diffusion solved with SDC
5+
6+
.. literalinclude:: /../qmat/playgrounds/tibo/imexStabilityAdvDiffSDC.py
7+
:language: python
8+
:linenos:
9+
:lines: 11-
510
"""
611
import numpy as np
712
import matplotlib.pyplot as plt

qmat/playgrounds/tibo/imexStabilityRK.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# -*- coding: utf-8 -*-
33
"""
44
Script investigating IMEX stability for RK methods
5+
6+
.. literalinclude:: /../qmat/playgrounds/tibo/imexStabilityRK.py
7+
:language: python
8+
:linenos:
9+
:lines: 11-
510
"""
611
import numpy as np
712
import scipy.optimize as sco

qmat/playgrounds/tibo/imexStabilitySDC.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# -*- coding: utf-8 -*-
33
"""
44
Script investigating IMEX stability for SDC methods
5+
6+
.. literalinclude:: /../qmat/playgrounds/tibo/imexStabilitySDC.py
7+
:language: python
8+
:linenos:
9+
:lines: 11-
510
"""
611
import numpy as np
712
import scipy.optimize as sco

qmat/playgrounds/tibo/lorenz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
.. literalinclude:: /../qmat/playgrounds/tibo/lorenz.py
88
:language: python
99
:linenos:
10-
:lines: 11-
10+
:lines: 12-
1111
"""
1212
import numpy as np
1313
import matplotlib.pyplot as plt

qmat/playgrounds/tibo/stability.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Compute accuracy and stability of a monolitic SDC scheme
5+
6+
.. literalinclude:: /../qmat/playgrounds/tibo/stability.py
7+
:language: python
8+
:linenos:
9+
:lines: 11-
10+
"""
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
14+
from qmat.qcoeff.collocation import Collocation
15+
from qmat.qdelta import QDELTA_GENERATORS
16+
17+
from qmat.solvers.dahlquist import Dahlquist
18+
19+
# Script parameters
20+
nNodes = 4
21+
nSweeps = 1
22+
sweepType = "SOE"
23+
24+
# Script execution
25+
re = np.linspace(-4.5, 1, num=200)
26+
im = np.linspace(0, 5.0, num=201)
27+
lam = re[None, :] + 1j*im[:, None]
28+
29+
problem = Dahlquist(lam)
30+
coll = Collocation(nNodes=nNodes, nodeType="LEGENDRE", quadType="RADAU-RIGHT")
31+
approx = QDELTA_GENERATORS[sweepType](qGen=coll)
32+
33+
sweeps = [k+1 for k in range(nSweeps)]
34+
35+
uNum = problem.solveSDC(
36+
coll.Q, None, approx.genCoeffs(k=sweeps), nSweeps=nSweeps)
37+
38+
39+
u1 = uNum[-1]
40+
stab = np.abs(u1)
41+
stab = np.clip(stab, 0, 1.2) # clip to ignore unstable area
42+
error = np.abs(u1 - np.exp(lam))
43+
44+
plt.figure(f"{sweepType}_M{nNodes}_K{nSweeps}")
45+
coords = (re, im)
46+
plt.contourf(*coords, stab, levels = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.2])
47+
plt.colorbar()
48+
plt.contour(*coords, stab, levels=[1], colors="black")
49+
plt.contour(*coords, error, levels=[1], colors="red", linestyles=":")
50+
plt.contour(*coords, error, levels=[1e-1], colors="orange", linestyles="-.")
51+
plt.contour(*coords, error, levels=[1e-2], colors="gray", linestyles="--")
52+
plt.grid(True)
53+
plt.ylabel(r"$Im(\lambda)$")
54+
plt.xlabel(r"$Re(\lambda)$")
55+
plt.gca().set_aspect('equal', 'box')
56+
plt.tight_layout()

0 commit comments

Comments
 (0)