ETDRK Backbone¤
Core classes 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)+1whereNis 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
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 | |
__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)+1whereNis 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.
BaseNonlinearFun handles this automatically via its fft and
ifft methods which apply pre- and post-dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_1.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 | |
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
78 79 80 81 82 | |
exponax.etdrk.ETDRK2
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_2.py
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 | |
__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.
Adapted 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)+1whereNis 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.
BaseNonlinearFun handles this automatically via its fft and
ifft methods which apply pre- and post-dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_2.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 81 82 83 84 85 86 87 88 89 | |
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
91 92 93 94 95 96 97 98 99 100 101 102 | |
exponax.etdrk.ETDRK3
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_3.py
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
__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)+1whereNis 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.
BaseNonlinearFun handles this automatically via its fft and
ifft methods which apply pre- and post-dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_3.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 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
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
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
exponax.etdrk.ETDRK4
¤
Bases: BaseETDRK
Source code in exponax/etdrk/_etdrk_4.py
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
__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)+1whereNis 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.
BaseNonlinearFun handles this automatically via its fft and
ifft methods which apply pre- and post-dealiasing.
Note
The numerically stable evaluation of the coefficients follows Kassam and Trefethen (2005).
Source code in exponax/etdrk/_etdrk_4.py
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
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
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
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)+1whereNis 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.dttime 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 | |