1
votes

Now I face some problem when I use scipy.integrate.ode.

I want to use spectral method (fourier transform) solve a PDE including dispersive and convection term, such as du/dt = A * d^3 u / dx^3 + C * du/dx

Then from fourier transform this PDE will convert to a set of ODEs in complex space (uk is complex vector)

duk/dt = (A * coeff^3  + C * coeff) * uk 
coeff = (2 * pi * i * k) / L 

k is wavenumber, (e.g.. k = 0, 1, 2, 3, -4, -3, -2, -1) i^2 = -1, L is length of domain.

When I use r = ode(uODE).set_integrator('zvode', method='adams'), python will warn like:

c ZVODE-- At current T (=R1), MXSTEP (=I1) steps
taken on this call before reaching TOUT
In above message, I1 = 500 In above message, R1 = 0.2191432098050D+00

I feel it is because the time step I chosen is too large, however I cannot decrease time step as every step is time consuming for my real problem. Do I have any other way to resolve this problem?

1
What is the sign of A? Please include code that we can copy and run ourselves to reproduce the warning or error. - Warren Weckesser

1 Answers

0
votes

Did you consider solving the ODEs symbolically? With Sympy you can type

import sympy as sy
sy.init_printing()  # use IPython for better results

from sympy.abc import A, C, c, x, t  # variables

u = sy.Function(b'u')(x,t)
eq = sy.Eq(u.diff(t), c*u)
sl1 = sy.pde.pdsolve(eq, u)
print("The solution of:")
sy.pprint(eq)
print("was determined to be:")
sy.pprint(sl1)

print("")
print("Substituting the coefficient:")
k,L = sy.symbols("k L", real=True)
coeff = (2 * sy.pi * sy.I * k) / L
cc = (A * coeff**3  + C * coeff)
sl2 = sy.simplify(sl1.replace(c, cc))
sy.pprint(sl2)

gives the following output:

The solution of:
∂                      
──(u(x, t)) = c⋅u(x, t)
∂t                     
was determined to be:
                c⋅t
u(x, t) = F(x)⋅ℯ   

Substituting the coefficient:
                           ⎛   2    2      2⎞ 
                -2⋅ⅈ⋅π⋅k⋅t⋅⎝4⋅π ⋅A⋅k  - C⋅L ⎠ 
                ──────────────────────────────
                               3              
                              L               
u(x, t) = F(x)⋅ℯ      

Note that F(x) depends on your initial values of u(x,t=0), which you need to provide. Use sl2.rhs.evalf() to substitute in numbers.