ETDRK Backbone¤
Core clases that implement the Exponential Time Differencing Runge-Kutta (ETDRK) method for solving semi-linear PDEs in form of timesteppers. Require supplying the time step size \(\Delta t\), the linear operator in Fourier space \(\hat{\mathcal{L}}_h\), and the non-linear operator in Fourier space \(\hat{\mathcal{N}}_h\).
exponax.etdrk.ETDRK0
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_0.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
__init__
¤
__init__(
dt: float,
linear_operator: Complex[Array, "E ... (N//2)+1"],
)
Exactly solve a linear PDE in Fourier space.
Arguments:
dt
: The time step size.linear_operator
: The linear operator of the PDE. Must have a leading channel axis, followed by one, two or three spatial axes whereas the last axis must be of size(N//2)+1
whereN
is the number of dimensions in the former spatial axes.
Source code in exponax/etdrk/_etdrk_0.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
step_fourier
¤
step_fourier(
u_hat: Complex[Array, "C ... (N//2)+1"]
) -> Complex[Array, "C ... (N//2)+1"]
Source code in exponax/etdrk/_etdrk_0.py
30 31 32 33 34 |
|
exponax.etdrk.ETDRK1
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_1.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
__init__
¤
__init__(
dt: float,
linear_operator: Complex[Array, "E ... (N//2)+1"],
nonlinear_fun: BaseNonlinearFun,
*,
num_circle_points: int = 16,
circle_radius: float = 1.0
)
Solve a semi-linear PDE using Exponential Time Differencing Runge-Kutta with a first order approximation.
Adapted from Eq. (4) of Cox and Matthews (2002):
where \(\hat{\mathcal{N}}_h\) is the Fourier pseudo-spectral treatment of the nonlinear differential operator.
Arguments:
dt
: The time step size.linear_operator
: The linear operator of the PDE. Must have a leading channel axis, followed by one, two or three spatial axes whereas the last axis must be of size(N//2)+1
whereN
is the number of dimensions in the former spatial axes.nonlinear_fun
: The Fourier pseudo-spectral treatment of the nonlinear differential operator.num_circle_points
: The number of points on the unit circle used to approximate the numerically challenging coefficients.circle_radius
: The radius of the circle used to approximate the numerically challenging coefficients.
Warning
The nonlinear function must take care of proper dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_1.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
step_fourier
¤
step_fourier(
u_hat: Complex[Array, "C ... (N//2)+1"]
) -> Complex[Array, "C ... (N//2)+1"]
Source code in exponax/etdrk/_etdrk_1.py
70 71 72 73 74 |
|
exponax.etdrk.ETDRK2
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_2.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
__init__
¤
__init__(
dt: float,
linear_operator: Complex[Array, "E ... (N//2)+1"],
nonlinear_fun: BaseNonlinearFun,
*,
num_circle_points: int = 16,
circle_radius: float = 1.0
)
Solve a semi-linear PDE using Exponential Time Differencing Runge-Kutta with a second order approximation.
Adopted from Eq. (22) of Cox and Matthews (2002):
where \(\hat{\mathcal{N}}_h\) is the Fourier pseudo-spectral treatment of the nonlinear differential operator.
Arguments:
dt
: The time step size.linear_operator
: The linear operator of the PDE. Must have a leading channel axis, followed by one, two or three spatial axes whereas the last axis must be of size(N//2)+1
whereN
is the number of dimensions in the former spatial axes.nonlinear_fun
: The Fourier pseudo-spectral treatment of the nonlinear differential operator. ! The operator must take care of proper dealiasing.num_circle_points
: The number of points on the unit circle used to approximate the numerically challenging coefficients.circle_radius
: The radius of the circle used to approximate the numerically challenging coefficients.
Warning
The nonlinear function must take care of proper dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_2.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
step_fourier
¤
step_fourier(
u_hat: Complex[Array, "C ... (N//2)+1"]
) -> Complex[Array, "C ... (N//2)+1"]
Source code in exponax/etdrk/_etdrk_2.py
81 82 83 84 85 86 87 88 89 90 91 92 |
|
exponax.etdrk.ETDRK3
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_3.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
__init__
¤
__init__(
dt: float,
linear_operator: Complex[Array, "E ... (N//2)+1"],
nonlinear_fun: BaseNonlinearFun,
*,
num_circle_points: int = 16,
circle_radius: float = 1.0
)
Solve a semi-linear PDE using Exponential Time Differencing Runge-Kutta with a third order approximation.
Adapted from Eq. (23-25) of Cox and Matthews (2002):
where \(\hat{\mathcal{N}}_h\) is the Fourier pseudo-spectral treatment of the nonlinear differential operator.
Arguments:
dt
: The time step size.linear_operator
: The linear operator of the PDE. Must have a leading channel axis, followed by one, two or three spatial axes whereas the last axis must be of size(N//2)+1
whereN
is the number of dimensions in the former spatial axes.nonlinear_fun
: The Fourier pseudo-spectral treatment of the nonlinear differential operator. ! The operator must take care of proper dealiasing.num_circle_points
: The number of points on the unit circle used to approximate the numerically challenging coefficients.circle_radius
: The radius of the circle used to approximate the numerically challenging coefficients.
Warning
The nonlinear function must take care of proper dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_3.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
step_fourier
¤
step_fourier(
u_hat: Complex[Array, "E ... (N//2)+1"]
) -> Complex[Array, "E ... (N//2)+1"]
Source code in exponax/etdrk/_etdrk_3.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
exponax.etdrk.ETDRK4
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_4.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
__init__
¤
__init__(
dt: float,
linear_operator: Complex[Array, "E ... (N//2)+1"],
nonlinear_fun: BaseNonlinearFun,
*,
num_circle_points: int = 16,
circle_radius: float = 1.0
)
Solve a semi-linear PDE using Exponential Time Differencing Runge-Kutta with a fourth order approximation.
Adapted from Eq. (26-29) of Cox and Matthews (2002):
where \(\hat{\mathcal{N}}_h\) is the Fourier pseudo-spectral treatment of the nonlinear differential operator.
Arguments:
dt
: The time step size.linear_operator
: The linear operator of the PDE. Must have a leading channel axis, followed by one, two or three spatial axes whereas the last axis must be of size(N//2)+1
whereN
is the number of dimensions in the former spatial axes.nonlinear_fun
: The Fourier pseudo-spectral treatment of the nonlinear differential operator. ! The operator must take care of proper dealiasing.num_circle_points
: The number of points on the unit circle used to approximate the numerically challenging coefficients.circle_radius
: The radius of the circle used to approximate the numerically challenging coefficients.
Warning
The nonlinear function must take care of proper dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_4.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
step_fourier
¤
step_fourier(
u_hat: Complex[Array, "C ... (N//2)+1"]
) -> Complex[Array, "C ... (N//2)+1"]
Source code in exponax/etdrk/_etdrk_4.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
exponax.etdrk.BaseETDRK
¤
Bases: Module
, ABC
Source code in exponax/etdrk/_base_etdrk.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
__init__
¤
__init__(
dt: float,
linear_operator: Complex[Array, "E ... (N//2)+1"],
)
Base class for exponential time differencing Runge-Kutta methods.
Arguments:
dt
: The time step size.linear_operator
: The linear operator of the PDE. Must have a leading channel axis, followed by one, two or three spatial axes whereas the last axis must be of size(N//2)+1
whereN
is the number of dimensions in the former spatial axes.
Example
Below is an example how to get the linear operator for the heat equation.
import jax.numpy as jnp
import exponax as ex
# Define the linear operator
N = 256
L = 5.0 # The domain size
D = 1 # Being in 1D
derivative_operator = 1j * ex.spectral.build_derivative_operator(
D,
L,
N,
)
print(derivative_operator.shape) # (1, (N//2)+1)
nu = 0.01 # The diffusion coefficient
linear_operator = nu * derivative_operator**2
Source code in exponax/etdrk/_base_etdrk.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
step_fourier
abstractmethod
¤
step_fourier(
u_hat: Complex[Array, "C ... (N//2)+1"]
) -> Complex[Array, "C ... (N//2)+1"]
Advance the state in Fourier space.
Arguments:
u_hat
: The previous state in Fourier space.
Returns:
- The next state in Fourier space, i.e.,
self.dt
time units later.
Source code in exponax/etdrk/_base_etdrk.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
exponax.etdrk.roots_of_unity
¤
roots_of_unity(M: int) -> Complex[Array, M]
Return (complex-valued) array with M roots of unity. Useful to perform contour integrals in the complex plane.
Arguments:
M
: The number of roots of unity.
Returns:
roots
: The M roots of unity in an array of shape(M,)
.
Source code in exponax/etdrk/_utils.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|