Exemplo n.º 1
0
elif case == "MKK":
    nu = 2e-5
    Re = 1./nu
    Re_tau = 180.
    utau = nu * Re_tau
    N = array([2**M, 2**M, 2])
    L = array([2, 4*pi, 4*pi/3.])

dx = (L / N).astype(float)
comm = MPI.COMM_WORLD
num_processes = comm.Get_size()
rank = comm.Get_rank()
Np = N / num_processes
# Get points and weights for Chebyshev weighted integrals
ST = ShenDirichletBasis(quad="GC")
SN = ShenNeumannBasis(quad="GL")
points, weights = ST.points_and_weights(N[0])
pointsp, weightsp = SN.points_and_weights(N[0])

x1 = arange(N[1], dtype=float)*L[1]/N[1]
x2 = arange(N[2], dtype=float)*L[2]/N[2]

# Get grid for velocity points
X = array(meshgrid(points[rank*Np[0]:(rank+1)*Np[0]], x1, x2, indexing='ij'), dtype=float)

Nf = N[2]/2+1 # Number of independent complex wavenumbers in z-direction 
Nu = N[0]-2   # Number of velocity modes in Shen basis
Nq = N[0]-3   # Number of pressure modes in Shen basis
u_slice = slice(0, Nu)
p_slice = slice(1, Nu)
polynomial of first kind. Solve using spectral Galerkin and the
weighted L_w norm (u, v)_w = \int_{-1}^{1} u v / \sqrt(1-x^2) dx

    (\nabla^ u, \phi_k)_w = (f, \phi_k)_w 
    

"""

# Use sympy to compute a rhs, given an analytical solution
x = Symbol("x")
u = cos(np.pi*x)
f = u.diff(x, 2) 

N = 40
banded = False
ST = ShenNeumannBasis()
points, weights = ST.points_and_weights(N)
k = ST.wavenumbers(N)

# Gauss-Chebyshev quadrature to compute rhs (zero mean)
fj = np.array([f.subs(x, j) for j in points], dtype=float)     # Get f on quad points
fj -= np.dot(fj, weights)/weights.sum()

def solve_neumann(f):    

    if banded:
        A = np.zeros((N-2, N-2))
        A[-1, :] = -2*np.pi*(k+1)*k**2/(k+2)
        for i in range(2, N-3, 2):
            A[-i-1, i:] = -4*np.pi*(k[:-i]+i)**2*(k[:-i]+1)/(k[:-i]+2)**2
            
Exemplo n.º 3
0
elif case == "MKK":
    nu = 2e-5
    Re = 1. / nu
    Re_tau = 180.
    utau = nu * Re_tau
    N = array([2**M, 2**M, 2])
    L = array([2, 4 * pi, 4 * pi / 3.])

dx = (L / N).astype(float)
comm = MPI.COMM_WORLD
num_processes = comm.Get_size()
rank = comm.Get_rank()
Np = N / num_processes
# Get points and weights for Chebyshev weighted integrals
ST = ShenDirichletBasis(quad="GL")
SN = ShenNeumannBasis(quad="GC")
points, weights = ST.points_and_weights(N[0])
pointsp, weightsp = SN.points_and_weights(N[0])

x1 = arange(N[1], dtype=float) * L[1] / N[1]
x2 = arange(N[2], dtype=float) * L[2] / N[2]

# Get grid for velocity points
X = array(meshgrid(points[rank * Np[0]:(rank + 1) * Np[0]],
                   x1,
                   x2,
                   indexing='ij'),
          dtype=float)

Nf = N[2] / 2 + 1  # Number of independent complex wavenumbers in z-direction
Nu = N[0] - 2  # Number of velocity modes in Shen basis
the three smallest diagonals. All other values are equal to U_(k, k+2)

"""

# Use sympy to compute a rhs, given an analytical solution
x = Symbol("x")
u = cos(np.pi*x)
kx = np.sqrt(0.0)
f = -u.diff(x, 2) + kx**2*u

# Choices
#solver = "sparse"
solver = "lu"
N = 20

ST = ShenNeumannBasis("GL")
SD = ShenDirichletBasis("GC")
points, weights = ST.points_and_weights(N) 

# Gauss-Chebyshev quadrature to compute rhs
fj = np.array([f.subs(x, j) for j in points], dtype=float)     # Get f on quad points
fj -= np.dot(fj, weights)/weights.sum()


#k = ST.wavenumbers(N)
#cij = [-np.pi*(k[1:]+1),
       #-np.pi*(2-(k[1:-1]/(k[1:-1]+2))**2*(k[1:-1]+3))]
#for i in range(3, N-3, 2):
    #cij.append(-2*np.pi*(1-((k[1:-i])/(k[1:-i]+2))**2))    
#C = diags(cij, range(0, N-2, 2), shape=(N-3, N-2))
Exemplo n.º 5
0
polynomial of first kind. Solve using spectral Galerkin and the
weighted L_w norm (u, v)_w = \int_{-1}^{1} u v / \sqrt(1-x^2) dx

    (\nabla^ u, \phi_k)_w = (f, \phi_k)_w 
    

"""

# Use sympy to compute a rhs, given an analytical solution
x = Symbol("x")
u = cos(np.pi * x)
f = u.diff(x, 2)

N = 40
banded = False
ST = ShenNeumannBasis()
points, weights = ST.points_and_weights(N)
k = ST.wavenumbers(N)

# Gauss-Chebyshev quadrature to compute rhs (zero mean)
fj = np.array([f.subs(x, j) for j in points],
              dtype=float)  # Get f on quad points
fj -= np.dot(fj, weights) / weights.sum()


def solve_neumann(f):

    if banded:
        A = np.zeros((N - 2, N - 2))
        A[-1, :] = -2 * np.pi * (k + 1) * k**2 / (k + 2)
        for i in range(2, N - 3, 2):