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

Is it possible to have full periodic boundaris?

yesint opened this issue · comments

I'm trying to solve 2D Poisson equation with the periodic boundaries for both X and Y directions. I took the code from 3D example with two periodic dimensions and modified it accordingly, but it gives me an an error, which I can't understand.

The code is the following:

import sys, os
import importlib
from sympy import symbols, cos, sin, lambdify
import numpy as np
from shenfun import inner, div, grad, TestFunction, TrialFunction, Array, \
    Function, Basis, TensorProductSpace
import time
from mpi4py import MPI


comm = MPI.COMM_WORLD

base = importlib.import_module('.'.join(('shenfun', 'legendre')))
Solver = base.la.Helmholtz

data = np.loadtxt('q_distrib.dat')
fe = np.array(data)

print(np.sum(fe))
fe -= np.mean(fe)
print(np.sum(fe))

# Size of discretization
N = fe.shape
print('N=',N)

K1 = Basis(N[0], family='F',  dtype='d',  domain=(0, 23.3273))
K2 = Basis(N[1], family='F',  dtype='d', domain=(0, 13.0217))
T = TensorProductSpace(comm, (K1, K2), axes=(0,1))
X = T.local_mesh(True)
u = TrialFunction(T)
v = TestFunction(T)

# Get f on quad points
fj = Array(T, buffer=fe)

# Compute right hand side of Poisson equation
f_hat = Function(T)
f_hat = inner(v, fj, output_array=f_hat)

# Get left hand side of Poisson equation
matrices = inner(v, div(grad(u)))

# Create Helmholtz linear algebra solver
H = Solver(*matrices)

# Solve and transform to real space
u_hat = Function(T)           # Solution spectral space
u_hat = H(u_hat, f_hat)       # Solve
uq = u_hat.backward()
uh = uq.forward()

np.savetxt('solution_2d.dat',uq)

The following error is produced:

Traceback (most recent call last):
  File "shen2d.py", line 29, in <module>
    T = TensorProductSpace(comm, (K1, K2), axes=(0,1))
  File "/home/syesylev/.local/lib/python3.6/site-packages/shenfun/tensorproductspace.py", line 158, in __init__
    xfftn.plan(pencilB.subshape, axes, dtype, kw)
  File "/home/syesylev/.local/lib/python3.6/site-packages/shenfun/fourier/bases.py", line 277, in plan
    xfftn_fwd = plan_fwd(U, s=s, axes=axis, threads=threads, flags=flags)
  File "/home/syesylev/.local/lib/python3.6/site-packages/mpi4py_fft/fftw/xfftn.py", line 229, in rfftn
    assert input_array.dtype.char in 'fdg'
AssertionError

Apparently I'm missing something but I can't figure out what exactly.

Hi

If you want to solve a 2D periodic problem, why don't you start with the 2D periodic Poisson example? There's no need for a Helmholtz solver if you do not have any non-periodic domains.

K1 and K2 cannot both be double precision, because one Fourier transform takes double to complex. Change K1 to dtype='D' and I think at least that part should be ok.

Hi!
If I change K1 to D another error appears:

Traceback (most recent call last):
  File "shen2d.py", line 45, in <module>
    H = Solver(*matrices)
TypeError: type object argument after * must be an iterable, not TPMatrix

Like I said, there's no need for a Helmholtz solver if you only have periodic boundaries.