Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KdV example has an error #40

Closed
francispoulin opened this issue Mar 27, 2020 · 2 comments
Closed

KdV example has an error #40

francispoulin opened this issue Mar 27, 2020 · 2 comments

Comments

@francispoulin
Copy link

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))

`

@mikaem
Copy link
Member

mikaem commented Mar 27, 2020

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

@francispoulin
Copy link
Author

Thanks.

I can confirm that it does run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants