Comments (4)
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.
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.
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.
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)
- Issue on Stokes equations with doubly periodic boundary conditions. HOT 2
- Error when evaluating derivatives for nonstandard domain HOT 7
- Installation problem: error in "cimport fastgl_wrap" HOT 2
- Old shenfun script for 2D Poisson equation dosn't work with new version HOT 2
- 1d poisson HOT 1
- Bug in FunctionSpace with bc as dictionary HOT 4
- Solve DGL with non-constant (discrete) variable? HOT 5
- AttributeError: 'tuple' object has no attribute 'copy' HOT 1
- Install problem HOT 1
- problems in solving 2D Allen Cahn equation HOT 2
- Two questions in the demo MixedPoisson.py HOT 7
- How to compute the numerical solution on the general points HOT 4
- 1. Solver for multidimensional problem 2. Product with variable coefficients HOT 5
- Two questions about the Legendre-Galerkin method for the Cahn-Hilliard equation HOT 2
- How to compute the integral about the nonlinear term in the Navier-Stokes equation? HOT 2
- How to assemble the right-hand side vector? HOT 3
- Understanding the chebyshev solver in poisson2ND.py HOT 3
- Time dependent boundary conditions in segments for Rayleigh-Benard 2D HOT 2
- Implementing the one-dimensional Kuramoto-Sivashinsky system HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shenfun.