From 183780b225dfb9a3453f13b99a4c5b7c89cc4e75 Mon Sep 17 00:00:00 2001 From: Felix Koehler Date: Thu, 25 Apr 2024 13:26:34 +0200 Subject: [PATCH 1/6] Fix scaling of injection --- exponax/nonlin_fun/_vorticity_convection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/exponax/nonlin_fun/_vorticity_convection.py b/exponax/nonlin_fun/_vorticity_convection.py index 45e8fa2..db69e7c 100644 --- a/exponax/nonlin_fun/_vorticity_convection.py +++ b/exponax/nonlin_fun/_vorticity_convection.py @@ -148,13 +148,15 @@ def __init__( dealiasing_fraction=dealiasing_fraction, ) - # TODO: shouldn't this be scaled differently sine we are in the - # streamfunction-vorticity formulation? wavenumbers = build_wavenumbers(num_spatial_dims, num_points) injection_mask = (wavenumbers[0] == 0) & (wavenumbers[1] == injection_mode) self.injection = jnp.where( injection_mask, - injection_scale * build_scaling_array(num_spatial_dims, num_points), + # Need to additional scale the `injection_scale` with the + # `injection_mode`, because we apply the forcing on the vorticity. + injection_mode + * injection_scale + * build_scaling_array(num_spatial_dims, num_points), 0.0, ) From ce3ca4757bc3578f46e84a35632b2d2b6974da57 Mon Sep 17 00:00:00 2001 From: Felix Koehler Date: Thu, 25 Apr 2024 13:27:00 +0200 Subject: [PATCH 2/6] Fix docstring formatting --- exponax/nonlin_fun/_vorticity_convection.py | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/exponax/nonlin_fun/_vorticity_convection.py b/exponax/nonlin_fun/_vorticity_convection.py index db69e7c..49e03f4 100644 --- a/exponax/nonlin_fun/_vorticity_convection.py +++ b/exponax/nonlin_fun/_vorticity_convection.py @@ -125,20 +125,20 @@ def __init__( **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. - - `convection_scale`: The scale `b` of the convection term. Defaults to - `1.0`. + 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. + - `convection_scale`: The scale `b` of the convection term. Defaults + to `1.0`. - `injection_mode`: The wavenumber `k` at which energy is injected. Defaults to `4`. - - `injection_scale`: The intensity `γ` of the injection term. Defaults - to `1.0`. - - `derivative_operator`: A complex array of shape `(d, ..., N//2+1)` that - represents the derivative operator in Fourier space. - - `dealiasing_fraction`: The fraction of the highest resolved modes that - are not aliased. Defaults to `2/3` which corresponds to Orszag's 2/3 - rule. + - `injection_scale`: The intensity `γ` of the injection term. + Defaults to `1.0`. + - `derivative_operator`: A complex array of shape `(d, ..., N//2+1)` + that represents the derivative operator in Fourier space. + - `dealiasing_fraction`: The fraction of the highest resolved modes + that are not aliased. Defaults to `2/3` which corresponds to + Orszag's 2/3 rule. """ super().__init__( num_spatial_dims, From ca9fbfbbf386b05184ec74d28beda867cc5eb46e Mon Sep 17 00:00:00 2001 From: Felix Koehler Date: Thu, 25 Apr 2024 13:28:07 +0200 Subject: [PATCH 3/6] Fix docstring formatting --- exponax/nonlin_fun/_vorticity_convection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exponax/nonlin_fun/_vorticity_convection.py b/exponax/nonlin_fun/_vorticity_convection.py index 49e03f4..415c921 100644 --- a/exponax/nonlin_fun/_vorticity_convection.py +++ b/exponax/nonlin_fun/_vorticity_convection.py @@ -154,7 +154,7 @@ def __init__( injection_mask, # Need to additional scale the `injection_scale` with the # `injection_mode`, because we apply the forcing on the vorticity. - injection_mode + -injection_mode * injection_scale * build_scaling_array(num_spatial_dims, num_points), 0.0, From 60a8ddbb672c03e88d6f2ce11c19b75b5f01776d Mon Sep 17 00:00:00 2001 From: Felix Koehler Date: Thu, 25 Apr 2024 14:28:31 +0200 Subject: [PATCH 4/6] Add more notes --- exponax/nonlin_fun/_vorticity_convection.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exponax/nonlin_fun/_vorticity_convection.py b/exponax/nonlin_fun/_vorticity_convection.py index 415c921..46231ab 100644 --- a/exponax/nonlin_fun/_vorticity_convection.py +++ b/exponax/nonlin_fun/_vorticity_convection.py @@ -120,7 +120,10 @@ def __init__( f = -k (2π/L) γ cos(k (2π/L) x₁) ``` - i.e., energy of intensity `γ` is injected at wavenumber `k`. + i.e., energy of intensity `γ` is injected at wavenumber `k`. Note that + the forcing is on the **vorticity**. As such, we get the prefactor `k + (2π/L)` and the `sin(...)` turns into a `-cos(...)` (minus sign because + the vorticity is derived via the curl). **Arguments:** - `num_spatial_dims`: The number of spatial dimensions `d`. From 9808e11ec403c0de02535319f90f5ae2346ca283 Mon Sep 17 00:00:00 2001 From: Felix Koehler Date: Thu, 25 Apr 2024 14:33:11 +0200 Subject: [PATCH 5/6] Fix docstring --- exponax/stepper/_navier_stokes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exponax/stepper/_navier_stokes.py b/exponax/stepper/_navier_stokes.py index 1010fd5..6ecc649 100644 --- a/exponax/stepper/_navier_stokes.py +++ b/exponax/stepper/_navier_stokes.py @@ -218,8 +218,8 @@ def __init__( convection term. Default is `1.0`. - `drag`: The drag coefficient `λ`. Default is `-0.1`. - `injection_mode`: The mode of the injection. Default is `4`. - - `injection_scale`: The scaling factor for the injection. Default is - `1.0`. + - `injection_scale`: The scaling factor for the injection. Default + is `1.0`. - `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 From 54fb74f4cc441134db72b4a97529e8e598e1add0 Mon Sep 17 00:00:00 2001 From: Felix Koehler Date: Thu, 25 Apr 2024 14:42:21 +0200 Subject: [PATCH 6/6] Add notes to Kolmogorov stepper --- exponax/stepper/_navier_stokes.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/exponax/stepper/_navier_stokes.py b/exponax/stepper/_navier_stokes.py index 6ecc649..3f9b612 100644 --- a/exponax/stepper/_navier_stokes.py +++ b/exponax/stepper/_navier_stokes.py @@ -201,6 +201,35 @@ def __init__( A negative drag coefficient `λ` is needed to remove some of the energy piling up in low modes. + According to + + Chandler, G.J. and Kerswell, R.R. (2013) ‘Invariant recurrent + solutions embedded in a turbulent two-dimensional Kolmogorov flow’, + Journal of Fluid Mechanics, 722, pp. 554–595. + doi:10.1017/jfm.2013.122. + + equation (2.5), the Reynolds number of the Kolmogorov flow is given by + + Re = √ζ / ν √(L / (2π))³ + + with `ζ` being the scaling of the Kolmogorov forcing, i.e., the + `injection_scale`. Hence, in the case of `L = 2π`, `ζ = 1`, the Reynolds + number is `Re = 1 / ν`. If one uses the default value of `ν = 0.001`, + the Reynolds number is `Re = 1000` which also corresponds to the main + experiments in + + Kochkov, D., Smith, J.A., Alieva, A., Wang, Q., Brenner, M.P. and + Hoyer, S., 2021. Machine learning–accelerated computational fluid + dynamics. Proceedings of the National Academy of Sciences, 118(21), + p.e2101784118. + + together with `injection_mode = 4`. Note that they required a resolution + of `num_points = 2048` (=> 2048^2 = 4.2M degrees of freedom in 2d) to + fully resolve all scales at that Reynolds number. Using `Re = 0.01` + which corresponds to `ν = 0.01` can be a good starting for + `num_points=128`. + + **Arguments:** - `num_spatial_dims`: The number of spatial dimensions `d`. - `domain_extent`: The size of the domain `L`; in higher dimensions