Git Product home page Git Product logo

Comments (4)

mikaem avatar mikaem commented on August 26, 2024

Hi
Unfortunately, the integrators do not work for a MixedFunctionSpace in 1D. However, since it is 1D it is not very difficult to implement a timestepper on your own using a BlockMatrixSolver. See below.

The MixedFunctionSpace has not really been kept up to date and should probably be used with care. I noticed that it did not even have a get_dealiased function and I have now added that to the master branch in order for this to work. I need to fix it even more, but with dealiasing in place (you need the master branch) I think you can implement your equations with something like:


from sympy import symbols, pi
from sympy.functions import cos, sin
from shenfun import inner, div, grad, TestFunction, TrialFunction, Function, \
    ETDRK4, FunctionSpace, Array, \
    comm, get_simplified_tpmatrices, Dx, MixedFunctionSpace, la

# Use sympy to set up initial condition
x = symbols("x", real=True)
u_1_0 = cos(x*pi)
u_2_0 = sin(x*pi)

# Initial conditions
u0 = 20*cos(x*pi)
v0 = 20*sin(x*pi)

# Parameters
a = 2
b = 6
D = 10

# Size of discretization
T1 = FunctionSpace(100, 'F', dtype='D', domain=(0, 20))
T2 = FunctionSpace(100, 'F', dtype='D', domain=(0, 20))
T = MixedFunctionSpace([T1, T2])
u = TrialFunction(T)
v = TestFunction(T)
padding_factor = 1.5

# Declare solution arrays and work arrays
UV = Array(T, buffer=(u_1_0, u_2_0))
UV_hat = Function(T)
w0 = Function(T)       # Work array spectral space
Tp = T.get_dealiased(padding_factor=1.5)
w1 = Array(Tp)

#initialize
UV_hat = UV.forward(UV_hat)

u0, u1 = u
v0, v1 = v
dt = 0.01
A = inner(v0, u0 - dt*Dx(u0, 0, 2)) + inner(v1, u1-dt*Dx(u1, 0, 2))
sol = la.BlockMatrixSolver(A)

def NonlinearRHS(uv_hat, rhs):
    rhs.fill(0)
    UVp = uv_hat.backward(padding_factor=padding_factor) # 3/2-rule dealiasing for nonlinear term
    w1[0] = a + UVp[0]**2*UVp[1] - (b+1)*UVp[0]
    w1[1] = b*UVp[0] - UVp[0]**2*UVp[1]
    rhs += w1.forward(rhs)
    return rhs

if __name__ == '__main__':
    rhs = Function(T)
    Nt = 4
    for n in range(Nt):
        rhs[:] = NonlinearRHS(UV_hat, rhs)
        UV_hat = sol(UV_hat + dt*rhs, u=UV_hat)

from shenfun.

j-bowhay avatar j-bowhay commented on August 26, 2024

Thanks for the quick reply @mikaem! Would you kindly be able to explain the steps

A = inner(v0, u0 - dt*Dx(u0, 0, 2)) + inner(v1, u1-dt*Dx(u1, 0, 2))
sol = la.BlockMatrixSolver(A)

in the implementation, is this some form of backwards euler?

from shenfun.

mikaem avatar mikaem commented on August 26, 2024

Yes, this is supposed to be Backwards Euler. But please note I've not tested it. I actually just realised that the last line should be

UV_hat = sol(dt*rhs, u=UV_hat)

and not

UV_hat = sol(UV_hat + dt*rhs, u=UV_hat)

because the UV_hat is already in A.

from shenfun.

mikaem avatar mikaem commented on August 26, 2024

So sorry, got confused. Please disregard the last comment. It was correct in the first place.

Please note that you can also put parts of the (now) nonlinear term in the linear A.

from shenfun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.