Skip to content

Convection¤

exponax.stepper.generic.DifficultyConvectionStepper ¤

Bases: NormalizedConvectionStepper

Source code in exponax/stepper/generic/_convection.py
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
class DifficultyConvectionStepper(NormalizedConvectionStepper):
    linear_difficulties: tuple[float, ...]
    convection_difficulty: float

    def __init__(
        self,
        num_spatial_dims: int = 1,
        num_points: int = 48,
        *,
        linear_difficulties: tuple[float, ...] = (0.0, 0.0, 4.5),
        convection_difficulty: float = 5.0,
        single_channel: bool = False,
        conservative: bool = False,
        maximum_absolute: float = 1.0,
        order: int = 2,
        dealiasing_fraction: float = 2 / 3,
        num_circle_points: int = 16,
        circle_radius: float = 1.0,
    ):
        """
        Timestepper for the **difficulty-based** d-dimensional (`d ∈ {1, 2, 3}`)
        semi-linear PDEs consisting of a convection nonlinearity and an
        arbitrary combination of (isotropic) linear derivatives. Uses a
        difficulty-based interface where the "intensity" of the dynamics reduces
        with increasing resolution. This is intended such that emulator learning
        problems on two resolutions are comparibly difficult.

        Different to `exponax.stepper.generic.NormalizedConvectionStepper`, the
        dynamics are defined by difficulties. The difficulties are a different
        combination of normalized dynamics, `num_spatial_dims`, and
        `num_points`.

            γᵢ = αᵢ Nⁱ 2ⁱ⁻¹ d

        with `d` the number of spatial dimensions, `N` the number of points, and
        `αᵢ` the normalized coefficient.

        The difficulty of the nonlinear convection scale is defined by

            δ₁ = β₁ * M * N * D

        with `M` the maximum absolute value of the input state (typically `1.0`
        if one uses the `exponax.ic` random generators with the `max_one=True`
        argument).

        This interface is more natural than the normalized interface because the
        difficulties for all orders (given by `i`) are around 1.0. Additionally,
        they relate to stability condition of explicit Finite Difference schemes
        for the particular equations. For example, for advection (`i=1`), the
        absolute of the difficulty is the Courant-Friedrichs-Lewy (CFL) number.

        Under the default settings, this timestepper represents the Burgers
        equation.

        **Arguments:**

        - `num_spatial_dims`: The number of spatial dimensions `D`.
        - `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ᵈ`.
        - `linear_difficulties`: The list of difficulties `γᵢ` corresponding to
            the derivatives. The length of this tuple represents the highest
            occuring derivative. The default value `(0.0, 0.0, 4.5)` corresponds
            to the Burgers equation. Note that these coefficients are normalized
            on the unit domain and unit time step size.
        - `convection_difficulty`: The difficulty `δ` of the convection term.
            Default is `5.0`.
        - `single_channel`: Whether to use the single channel mode in higher
            dimensions. In this case the the convection is `δ (∇ ⋅ 1)(u²)`. In
            this case, the state always has a single channel, no matter the
            spatial dimension. Default: False.
        - `conservative`: Whether to use the conservative form of the convection
        - `maximum_absolute`: The maximum absolute value of the state. This is
            used to extract the normalized dynamics from the convection
            difficulty.
        - `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.
        - `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.
        - `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.linear_difficulties = linear_difficulties
        self.convection_difficulty = convection_difficulty
        normalized_coefficients = extract_normalized_coefficients_from_difficulty(
            linear_difficulties,
            num_spatial_dims=num_spatial_dims,
            num_points=num_points,
        )
        normalized_convection_scale = (
            extract_normalized_convection_scale_from_difficulty(
                convection_difficulty,
                num_spatial_dims=num_spatial_dims,
                num_points=num_points,
                maximum_absolute=maximum_absolute,
            )
        )
        super().__init__(
            num_spatial_dims=num_spatial_dims,
            num_points=num_points,
            normalized_linear_coefficients=normalized_coefficients,
            normalized_convection_scale=normalized_convection_scale,
            single_channel=single_channel,
            order=order,
            dealiasing_fraction=dealiasing_fraction,
            num_circle_points=num_circle_points,
            circle_radius=circle_radius,
            conservative=conservative,
        )
__init__ ¤
__init__(
    num_spatial_dims: int = 1,
    num_points: int = 48,
    *,
    linear_difficulties: tuple[float, ...] = (
        0.0,
        0.0,
        4.5,
    ),
    convection_difficulty: float = 5.0,
    single_channel: bool = False,
    conservative: bool = False,
    maximum_absolute: float = 1.0,
    order: int = 2,
    dealiasing_fraction: float = 2 / 3,
    num_circle_points: int = 16,
    circle_radius: float = 1.0
)

Timestepper for the difficulty-based d-dimensional (d ∈ {1, 2, 3}) semi-linear PDEs consisting of a convection nonlinearity and an arbitrary combination of (isotropic) linear derivatives. Uses a difficulty-based interface where the "intensity" of the dynamics reduces with increasing resolution. This is intended such that emulator learning problems on two resolutions are comparibly difficult.

Different to exponax.stepper.generic.NormalizedConvectionStepper, the dynamics are defined by difficulties. The difficulties are a different combination of normalized dynamics, num_spatial_dims, and num_points.

γᵢ = αᵢ Nⁱ 2ⁱ⁻¹ d

with d the number of spatial dimensions, N the number of points, and αᵢ the normalized coefficient.

The difficulty of the nonlinear convection scale is defined by

δ₁ = β₁ * M * N * D

with M the maximum absolute value of the input state (typically 1.0 if one uses the exponax.ic random generators with the max_one=True argument).

This interface is more natural than the normalized interface because the difficulties for all orders (given by i) are around 1.0. Additionally, they relate to stability condition of explicit Finite Difference schemes for the particular equations. For example, for advection (i=1), the absolute of the difficulty is the Courant-Friedrichs-Lewy (CFL) number.

Under the default settings, this timestepper represents the Burgers equation.

Arguments:

  • num_spatial_dims: The number of spatial dimensions D.
  • 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ᵈ.
  • linear_difficulties: The list of difficulties γᵢ corresponding to the derivatives. The length of this tuple represents the highest occuring derivative. The default value (0.0, 0.0, 4.5) corresponds to the Burgers equation. Note that these coefficients are normalized on the unit domain and unit time step size.
  • convection_difficulty: The difficulty δ of the convection term. Default is 5.0.
  • single_channel: Whether to use the single channel mode in higher dimensions. In this case the the convection is δ (∇ ⋅ 1)(u²). In this case, the state always has a single channel, no matter the spatial dimension. Default: False.
  • conservative: Whether to use the conservative form of the convection
  • maximum_absolute: The maximum absolute value of the state. This is used to extract the normalized dynamics from the convection difficulty.
  • 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.
  • 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.
  • 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/generic/_convection.py
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
def __init__(
    self,
    num_spatial_dims: int = 1,
    num_points: int = 48,
    *,
    linear_difficulties: tuple[float, ...] = (0.0, 0.0, 4.5),
    convection_difficulty: float = 5.0,
    single_channel: bool = False,
    conservative: bool = False,
    maximum_absolute: float = 1.0,
    order: int = 2,
    dealiasing_fraction: float = 2 / 3,
    num_circle_points: int = 16,
    circle_radius: float = 1.0,
):
    """
    Timestepper for the **difficulty-based** d-dimensional (`d ∈ {1, 2, 3}`)
    semi-linear PDEs consisting of a convection nonlinearity and an
    arbitrary combination of (isotropic) linear derivatives. Uses a
    difficulty-based interface where the "intensity" of the dynamics reduces
    with increasing resolution. This is intended such that emulator learning
    problems on two resolutions are comparibly difficult.

    Different to `exponax.stepper.generic.NormalizedConvectionStepper`, the
    dynamics are defined by difficulties. The difficulties are a different
    combination of normalized dynamics, `num_spatial_dims`, and
    `num_points`.

        γᵢ = αᵢ Nⁱ 2ⁱ⁻¹ d

    with `d` the number of spatial dimensions, `N` the number of points, and
    `αᵢ` the normalized coefficient.

    The difficulty of the nonlinear convection scale is defined by

        δ₁ = β₁ * M * N * D

    with `M` the maximum absolute value of the input state (typically `1.0`
    if one uses the `exponax.ic` random generators with the `max_one=True`
    argument).

    This interface is more natural than the normalized interface because the
    difficulties for all orders (given by `i`) are around 1.0. Additionally,
    they relate to stability condition of explicit Finite Difference schemes
    for the particular equations. For example, for advection (`i=1`), the
    absolute of the difficulty is the Courant-Friedrichs-Lewy (CFL) number.

    Under the default settings, this timestepper represents the Burgers
    equation.

    **Arguments:**

    - `num_spatial_dims`: The number of spatial dimensions `D`.
    - `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ᵈ`.
    - `linear_difficulties`: The list of difficulties `γᵢ` corresponding to
        the derivatives. The length of this tuple represents the highest
        occuring derivative. The default value `(0.0, 0.0, 4.5)` corresponds
        to the Burgers equation. Note that these coefficients are normalized
        on the unit domain and unit time step size.
    - `convection_difficulty`: The difficulty `δ` of the convection term.
        Default is `5.0`.
    - `single_channel`: Whether to use the single channel mode in higher
        dimensions. In this case the the convection is `δ (∇ ⋅ 1)(u²)`. In
        this case, the state always has a single channel, no matter the
        spatial dimension. Default: False.
    - `conservative`: Whether to use the conservative form of the convection
    - `maximum_absolute`: The maximum absolute value of the state. This is
        used to extract the normalized dynamics from the convection
        difficulty.
    - `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.
    - `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.
    - `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.linear_difficulties = linear_difficulties
    self.convection_difficulty = convection_difficulty
    normalized_coefficients = extract_normalized_coefficients_from_difficulty(
        linear_difficulties,
        num_spatial_dims=num_spatial_dims,
        num_points=num_points,
    )
    normalized_convection_scale = (
        extract_normalized_convection_scale_from_difficulty(
            convection_difficulty,
            num_spatial_dims=num_spatial_dims,
            num_points=num_points,
            maximum_absolute=maximum_absolute,
        )
    )
    super().__init__(
        num_spatial_dims=num_spatial_dims,
        num_points=num_points,
        normalized_linear_coefficients=normalized_coefficients,
        normalized_convection_scale=normalized_convection_scale,
        single_channel=single_channel,
        order=order,
        dealiasing_fraction=dealiasing_fraction,
        num_circle_points=num_circle_points,
        circle_radius=circle_radius,
        conservative=conservative,
    )
__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)