Skip to content

Kuramoto-Sivashinsky (conservative format)¤

Uses the convection nonlinearity similar to Burgers, but only works in 1D:

\[ \frac{\partial u}{\partial t} + \frac{1}{2} \frac{\partial u^2}{\partial x} + \frac{\partial^2 u}{\partial x^2} + \frac{\partial^4 u}{\partial x^4} = 0 \]

exponax.stepper.KuramotoSivashinskyConservative ¤

Bases: BaseStepper

Source code in exponax/stepper/_kuramoto_sivashinsky.py
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
class KuramotoSivashinskyConservative(BaseStepper):
    convection_scale: float
    second_order_scale: float
    fourth_order_scale: float
    single_channel: bool
    conservative: bool
    dealiasing_fraction: float

    def __init__(
        self,
        num_spatial_dims: int,
        domain_extent: float,
        num_points: int,
        dt: float,
        *,
        convection_scale: float = 1.0,
        second_order_scale: float = 1.0,
        fourth_order_scale: float = 1.0,
        single_channel: bool = False,
        conservative: bool = True,
        dealiasing_fraction: float = 2 / 3,
        order: int = 2,
        num_circle_points: int = 16,
        circle_radius: float = 1.0,
    ):
        """
        Using the fluid dynamics form of the KS equation (i.e. similar to the
        Burgers equation).

        In 1d, the KS equation is given by

        ```
            uₜ + b₁ 1/2 (u²)ₓ + ψ₁ uₓₓ + ψ₂ uₓₓₓₓ = 0
        ```

        with `b₁` the convection coefficient, `ψ₁` the second-order scale and
        `ψ₂` the fourth-order. If the latter two terms were on the right-hand
        side, they could be interpreted as diffusivity and hyper-diffusivity,
        respectively. Here, the second-order term acts destabilizing (increases
        the energy of the system) and the fourth-order term acts stabilizing
        (decreases the energy of the system). A common configuration is `b₁ = ψ₁
        = ψ₂ = 1` and the dynamics are only adapted using the `domain_extent`.
        For this, we espect the KS equation to experience spatio-temporal chaos
        roughly once `L > 60`.

        !!! info
            In this fluid dynamics (=conservative) format, the number of
            channels grows with the spatial dimension. However, it seems that
            this format does not generalize well to higher dimensions. For
            higher dimensions, consider using the combustion format
            (`exponax.stepper.KuramotoSivashinsky`) instead.

        **Arguments:**

        - `num_spatial_dims`: The number of spatial dimensions `d`.
        - `domain_extent`: The size of the domain `L`; in higher dimensions
            the domain is assumed to be a scaled hypercube `Ω = (0, L)ᵈ`.
        - `num_points`: The number of points `N` used to discretize the
            domain. This **includes** the left boundary point and **excludes**
            the right boundary point. In higher dimensions; the number of points
            in each dimension is the same. Hence, the total number of degrees of
            freedom is `Nᵈ`.
        - `dt`: The timestep size `Δt` between two consecutive states.
        - `convection_scale`: The convection coefficient `b₁`. Note that the
            convection term is already scaled by 1/2. This factor allows for
            further modification. Default: 1.0.
        - `second_order_scale`: The "diffusivity" `ψ₁` in the KS equation.
        - `fourth_order_diffusivity`: The "hyper-diffusivity" `ψ₂` in the KS
            equation.
        - `single_channel`: Whether to use a single channel for the spatial
            dimension. Default: `False`.
        - `conservative`: Whether to use the conservative format. Default:
            `True`.
        - `dealiasing_fraction`: The fraction of the wavenumbers to keep
            before evaluating the nonlinearity. The default 2/3 corresponds to
            Orszag's 2/3 rule. To fully eliminate aliasing, use 1/2. Default:
            2/3.
        - `order`: The order of the Exponential Time Differencing Runge
            Kutta method. Must be one of {0, 1, 2, 3, 4}. The option `0` only
            solves the linear part of the equation. Use higher values for higher
            accuracy and stability. The default choice of `2` is a good
            compromise for single precision floats.
        - `num_circle_points`: How many points to use in the complex contour
            integral method to compute the coefficients of the exponential time
            differencing Runge Kutta method. Default: 16.
        - `circle_radius`: The radius of the contour used to compute the
            coefficients of the exponential time differencing Runge Kutta
            method. Default: 1.0.
        """
        self.convection_scale = convection_scale
        self.second_order_scale = second_order_scale
        self.fourth_order_scale = fourth_order_scale
        self.single_channel = single_channel
        self.conservative = conservative
        self.dealiasing_fraction = dealiasing_fraction

        if num_spatial_dims > 1:
            print(
                "Warning: The KS equation in conservative format does not generalize well to higher dimensions."
            )
            print(
                "Consider using the combustion format (`exponax.stepper.KuramotoSivashinsky`) instead."
            )

        if single_channel:
            num_channels = 1
        else:
            # number of channels grow with the spatial dimension
            num_channels = num_spatial_dims

        super().__init__(
            num_spatial_dims=num_spatial_dims,
            domain_extent=domain_extent,
            num_points=num_points,
            dt=dt,
            num_channels=num_channels,
            order=order,
            num_circle_points=num_circle_points,
            circle_radius=circle_radius,
        )

    def _build_linear_operator(
        self,
        derivative_operator: Complex[Array, "D ... (N//2)+1"],
    ) -> Complex[Array, "1 ... (N//2)+1"]:
        # Minuses are required to move the terms to the right-hand side
        linear_operator = -self.second_order_scale * build_laplace_operator(
            derivative_operator, order=2
        ) - self.fourth_order_scale * build_laplace_operator(
            derivative_operator, order=4
        )
        return linear_operator

    def _build_nonlinear_fun(
        self,
        derivative_operator: Complex[Array, "D ... (N//2)+1"],
    ) -> ConvectionNonlinearFun:
        return ConvectionNonlinearFun(
            self.num_spatial_dims,
            self.num_points,
            derivative_operator=derivative_operator,
            dealiasing_fraction=self.dealiasing_fraction,
            scale=self.convection_scale,
            single_channel=self.single_channel,
            conservative=self.conservative,
        )
__init__ ¤
__init__(
    num_spatial_dims: int,
    domain_extent: float,
    num_points: int,
    dt: float,
    *,
    convection_scale: float = 1.0,
    second_order_scale: float = 1.0,
    fourth_order_scale: float = 1.0,
    single_channel: bool = False,
    conservative: bool = True,
    dealiasing_fraction: float = 2 / 3,
    order: int = 2,
    num_circle_points: int = 16,
    circle_radius: float = 1.0
)

Using the fluid dynamics form of the KS equation (i.e. similar to the Burgers equation).

In 1d, the KS equation is given by

    uₜ + b₁ 1/2 (u²)ₓ + ψ₁ uₓₓ + ψ₂ uₓₓₓₓ = 0

with b₁ the convection coefficient, ψ₁ the second-order scale and ψ₂ the fourth-order. If the latter two terms were on the right-hand side, they could be interpreted as diffusivity and hyper-diffusivity, respectively. Here, the second-order term acts destabilizing (increases the energy of the system) and the fourth-order term acts stabilizing (decreases the energy of the system). A common configuration is b₁ = ψ₁ = ψ₂ = 1 and the dynamics are only adapted using the domain_extent. For this, we espect the KS equation to experience spatio-temporal chaos roughly once L > 60.

Info

In this fluid dynamics (=conservative) format, the number of channels grows with the spatial dimension. However, it seems that this format does not generalize well to higher dimensions. For higher dimensions, consider using the combustion format (exponax.stepper.KuramotoSivashinsky) instead.

Arguments:

  • num_spatial_dims: The number of spatial dimensions d.
  • domain_extent: The size of the domain L; in higher dimensions the domain is assumed to be a scaled hypercube Ω = (0, L)ᵈ.
  • num_points: The number of points N used to discretize the domain. This includes the left boundary point and excludes the right boundary point. In higher dimensions; the number of points in each dimension is the same. Hence, the total number of degrees of freedom is Nᵈ.
  • dt: The timestep size Δt between two consecutive states.
  • convection_scale: The convection coefficient b₁. Note that the convection term is already scaled by 1/2. This factor allows for further modification. Default: 1.0.
  • second_order_scale: The "diffusivity" ψ₁ in the KS equation.
  • fourth_order_diffusivity: The "hyper-diffusivity" ψ₂ in the KS equation.
  • single_channel: Whether to use a single channel for the spatial dimension. Default: False.
  • conservative: Whether to use the conservative format. Default: True.
  • dealiasing_fraction: The fraction of the wavenumbers to keep before evaluating the nonlinearity. The default 2/3 corresponds to Orszag's 2/3 rule. To fully eliminate aliasing, use 1/2. Default: 2/3.
  • order: The order of the Exponential Time Differencing Runge Kutta method. Must be one of {0, 1, 2, 3, 4}. The option 0 only solves the linear part of the equation. Use higher values for higher accuracy and stability. The default choice of 2 is a good compromise for single precision floats.
  • num_circle_points: How many points to use in the complex contour integral method to compute the coefficients of the exponential time differencing Runge Kutta method. Default: 16.
  • circle_radius: The radius of the contour used to compute the coefficients of the exponential time differencing Runge Kutta method. Default: 1.0.
Source code in exponax/stepper/_kuramoto_sivashinsky.py
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
def __init__(
    self,
    num_spatial_dims: int,
    domain_extent: float,
    num_points: int,
    dt: float,
    *,
    convection_scale: float = 1.0,
    second_order_scale: float = 1.0,
    fourth_order_scale: float = 1.0,
    single_channel: bool = False,
    conservative: bool = True,
    dealiasing_fraction: float = 2 / 3,
    order: int = 2,
    num_circle_points: int = 16,
    circle_radius: float = 1.0,
):
    """
    Using the fluid dynamics form of the KS equation (i.e. similar to the
    Burgers equation).

    In 1d, the KS equation is given by

    ```
        uₜ + b₁ 1/2 (u²)ₓ + ψ₁ uₓₓ + ψ₂ uₓₓₓₓ = 0
    ```

    with `b₁` the convection coefficient, `ψ₁` the second-order scale and
    `ψ₂` the fourth-order. If the latter two terms were on the right-hand
    side, they could be interpreted as diffusivity and hyper-diffusivity,
    respectively. Here, the second-order term acts destabilizing (increases
    the energy of the system) and the fourth-order term acts stabilizing
    (decreases the energy of the system). A common configuration is `b₁ = ψ₁
    = ψ₂ = 1` and the dynamics are only adapted using the `domain_extent`.
    For this, we espect the KS equation to experience spatio-temporal chaos
    roughly once `L > 60`.

    !!! info
        In this fluid dynamics (=conservative) format, the number of
        channels grows with the spatial dimension. However, it seems that
        this format does not generalize well to higher dimensions. For
        higher dimensions, consider using the combustion format
        (`exponax.stepper.KuramotoSivashinsky`) instead.

    **Arguments:**

    - `num_spatial_dims`: The number of spatial dimensions `d`.
    - `domain_extent`: The size of the domain `L`; in higher dimensions
        the domain is assumed to be a scaled hypercube `Ω = (0, L)ᵈ`.
    - `num_points`: The number of points `N` used to discretize the
        domain. This **includes** the left boundary point and **excludes**
        the right boundary point. In higher dimensions; the number of points
        in each dimension is the same. Hence, the total number of degrees of
        freedom is `Nᵈ`.
    - `dt`: The timestep size `Δt` between two consecutive states.
    - `convection_scale`: The convection coefficient `b₁`. Note that the
        convection term is already scaled by 1/2. This factor allows for
        further modification. Default: 1.0.
    - `second_order_scale`: The "diffusivity" `ψ₁` in the KS equation.
    - `fourth_order_diffusivity`: The "hyper-diffusivity" `ψ₂` in the KS
        equation.
    - `single_channel`: Whether to use a single channel for the spatial
        dimension. Default: `False`.
    - `conservative`: Whether to use the conservative format. Default:
        `True`.
    - `dealiasing_fraction`: The fraction of the wavenumbers to keep
        before evaluating the nonlinearity. The default 2/3 corresponds to
        Orszag's 2/3 rule. To fully eliminate aliasing, use 1/2. Default:
        2/3.
    - `order`: The order of the Exponential Time Differencing Runge
        Kutta method. Must be one of {0, 1, 2, 3, 4}. The option `0` only
        solves the linear part of the equation. Use higher values for higher
        accuracy and stability. The default choice of `2` is a good
        compromise for single precision floats.
    - `num_circle_points`: How many points to use in the complex contour
        integral method to compute the coefficients of the exponential time
        differencing Runge Kutta method. Default: 16.
    - `circle_radius`: The radius of the contour used to compute the
        coefficients of the exponential time differencing Runge Kutta
        method. Default: 1.0.
    """
    self.convection_scale = convection_scale
    self.second_order_scale = second_order_scale
    self.fourth_order_scale = fourth_order_scale
    self.single_channel = single_channel
    self.conservative = conservative
    self.dealiasing_fraction = dealiasing_fraction

    if num_spatial_dims > 1:
        print(
            "Warning: The KS equation in conservative format does not generalize well to higher dimensions."
        )
        print(
            "Consider using the combustion format (`exponax.stepper.KuramotoSivashinsky`) instead."
        )

    if single_channel:
        num_channels = 1
    else:
        # number of channels grow with the spatial dimension
        num_channels = num_spatial_dims

    super().__init__(
        num_spatial_dims=num_spatial_dims,
        domain_extent=domain_extent,
        num_points=num_points,
        dt=dt,
        num_channels=num_channels,
        order=order,
        num_circle_points=num_circle_points,
        circle_radius=circle_radius,
    )
__call__ ¤
__call__(
    u: Float[Array, "C ... N"]
) -> Float[Array, "C ... N"]

Perform one step of the time integration for a single state.

Arguments:

  • u: The state vector, shape (C, ..., N,).

Returns:

  • u_next: The state vector after one step, shape (C, ..., N,).

Tip

Use this call method together with exponax.rollout to efficiently produce temporal trajectories.

Info

For batched operation, use jax.vmap on this function.

Source code in exponax/_base_stepper.py
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
def __call__(
    self,
    u: Float[Array, "C ... N"],
) -> Float[Array, "C ... N"]:
    """
    Perform one step of the time integration for a single state.

    **Arguments:**

    - `u`: The state vector, shape `(C, ..., N,)`.

    **Returns:**

    - `u_next`: The state vector after one step, shape `(C, ..., N,)`.

    !!! tip
        Use this call method together with `exponax.rollout` to efficiently
        produce temporal trajectories.

    !!! info
        For batched operation, use `jax.vmap` on this function.
    """
    expected_shape = (self.num_channels,) + spatial_shape(
        self.num_spatial_dims, self.num_points
    )
    if u.shape != expected_shape:
        raise ValueError(
            f"Expected shape {expected_shape}, got {u.shape}. For batched operation use `jax.vmap` on this function."
        )
    return self.step(u)