spectralDNS / shenfun

High performance computational platform in Python for the spectral Galerkin method

Home Page:http://shenfun.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KdV example has an error

francispoulin opened this issue · comments

I copied the KdV example into python and tried running it to find there was an error with the number of arguments in LinearRHS.

`# Error message

integrator.setup(dt)
  File "/home/fpoulin/software/anaconda3/envs/shenfun/lib/python3.8/site- 
packages/shenfun/utilities/integrators.py", line 195, in setup
    L = self.LinearRHS(**self.params)
 TypeError: LinearRHS() takes 0 positional arguments but 1 was given

`

`# KdV example

import numpy as np
from shenfun import *

N = 256
T = Basis(N, 'F', dtype='d')
u = TrialFunction(T)
v = TestFunction(T)
u_ = Array(T)
u_hat = Function(T)

def LinearRHS(**params):
    return -inner(Dx(u, 0, 3), v)

k = T.wavenumbers(scaled=True, eliminate_highest_freq=True)

def NonlinearRHS(u, u_hat, rhs, **params):
    rhs.fill(0)
    u_[:] = T.backward(u_hat, u_)
    rhs = T.forward(-0.5*u_**2, rhs)
    return rhs*1j*k   # return inner(grad(-0.5*Up**2), v)

A = 25.
B = 16.
x = T.points_and_weights()[0]
u_[:] = 3*A**2/np.cosh(0.5*A*(x-np.pi+2))**2 + 3*B**2/np.cosh(0.5*B*(x-np.pi+1))**2
u_hat = T.forward(u_, u_hat)

dt = 0.01/N**2
end_time = 0.006
integrator = ETDRK4(T, L=LinearRHS, N=NonlinearRHS)
integrator.setup(dt)
u_hat = integrator.solve(u_, u_hat, dt, (0, end_time))

`

Yes, I see. Again documentation is not up to date. If you look in the sandbox you'll find a version that runs.

Thanks.

I can confirm that it does run.