예제 #1
0
def test_window_1d(shape):
    u = _sym.symarray(shape, 'u')
    s = Window(u)
    assert s[:].shape == shape

    Nn = s.neighbors(1)
    assert np.shape(Nn) == shape
    assert (Nn[0] == u[1])

    Np = s.neighbors(-1)
    assert np.shape(Np) == shape
    assert (Np[0] == u[-1])

    sdp = s.diff_prev()
    assert sdp[0] == u[0] - u[-1]
    sdn = s.diff_next()
    assert sdn[0] == u[1] - u[0]
    sdc = s.diff_central()
    assert sdc[0] == u[1] - 2 * u[0] + u[-1]

    wshape = shape + (2, )
    w = _sym.symarray(wshape, 'w')
    s = Window(w, 2)
    assert s.D == len(shape)
    assert s[:].shape == wshape
    assert s.neighbors(1).shape == wshape
예제 #2
0
def test_masking_2d_4x4():
    shape = (4, 4)
    u = _sym.symarray(shape, 'u')
    _shape = np.array(shape)

    s = Window(u, mask=s_[1:-1, 1:-1])
    Nn = s.neighbors(1)
    assert (Nn[0, 0, 0] == u[2, 1])
    assert (Nn[1, 0, 0] == u[1, 2])
    Np = s.neighbors(-1)
    assert (Np[0, 0, 0] == u[0, 1])
    assert (Np[1, 0, 0] == u[1, 0])
예제 #3
0
def test_masking_1d(shape):
    u = _sym.symarray(shape, 'u')
    _shape = np.array(shape)

    s = Window(u, mask=s_[1:])
    Nn = s.neighbors(1)
    assert (Nn[0] == u[2 % shape[0]])

    s = Window(u, mask=s_[1:])
    Np = s.neighbors(-1)
    assert (Np[0] == u[0])

    s = Window(u, mask=s_[:-1])
    Nn = s.neighbors(1)
    assert (Nn[0] == u[1])

    s = Window(u, mask=s_[:-1])
    Np = s.neighbors(-1)
    assert (Np[0] == u[-1])
예제 #4
0
def test_masking_2d(shape):
    shape = (2, 2)
    u = _sym.symarray(shape, 'u')
    _shape = np.array(shape)

    slice_shapediffs = [
        (s_[1:], (1, 0)),
        (s_[:-1], (1, 0)),
        (s_[1:-1], (2, 0)),
        (s_[:, 1:], (0, 1)),
        (s_[:, :-1], (0, 1)),
    ]
    for slices, shapediff in slice_shapediffs:
        s = Window(u, mask=slices)
        wshape = tuple(_shape - shapediff)
        assert s[:].shape == wshape
        Nn = s.neighbors(1)
        assert np.shape(Nn) == (2, ) + wshape

    s = Window(u, mask=s_[1:])
    Nn = s.neighbors(1)
    assert (Nn[0, 0, 0] == u[2 % shape[0], 0])
    assert (Nn[1, 0, 0] == u[1, 1])
    Np = s.neighbors(-1)
    assert (Np[0, 0, 0] == u[0, 0])
    assert (Np[1, 0, 0] == u[1, -1])

    s = Window(u, mask=s_[1:, 1:])
    Nn = s.neighbors(1)
    assert (Nn[0, 0, 0] == u[2 % shape[0], 1])
    assert (Nn[1, 0, 0] == u[1, 2 % shape[1]])
    Np = s.neighbors(-1)
    assert (Np[0, 0, 0] == u[0, 1])
    assert (Np[1, 0, 0] == u[1, 0])

    s = Window(u, mask=s_[:-1, :-1])
    Nn = s.neighbors(1)
    assert (Nn[0, 0, 0] == u[1, 0])
    assert (Nn[1, 0, 0] == u[0, 1])
    Np = s.neighbors(-1)
    assert (Np[0, 0, 0] == u[-1, 0])
    assert (Np[1, 0, 0] == u[0, -1])
예제 #5
0
def test_window_2d(shape):
    u = _sym.symarray(shape, 'u')
    s = Window(u)
    assert s[:].shape == shape

    Nn = s.neighbors(1)
    assert np.all(Nn[:, 0, 0] == [u[1, 0], u[0, 1]])

    Np = s.neighbors(-1)
    assert np.all(Np[:, 0, 0] == [u[-1, 0], u[0, -1]])

    sdp = s.diff_prev()
    assert sdp[0, 0, 0] == u[0, 0] - u[-1, 0]
    assert sdp[1, 0, 0] == u[0, 0] - u[0, -1]

    sdn = s.diff_next()
    assert sdn[0, 0, 0] == u[1, 0] - u[0, 0]
    assert sdn[1, 0, 0] == u[0, 1] - u[0, 0]

    sdc = s.diff_central()
    assert sdc[0, 0, 0] == u[1, 0] - 2 * u[0, 0] + u[-1, 0]
    assert sdc[1, 0, 0] == u[0, 1] - 2 * u[0, 0] + u[0, -1]
예제 #6
0
import numpy as np
from sympy import symbols

import _util
from _lib import Window
from _sym import symarray

import _10

nr = (4,4)
dx, dy = symbols('dx dy')
dr = np.array([dx, dy])
dt = symbols('dt')
p = symarray(nr, 'p')
b = symarray(nr, 'b')

def test_poisson():
    pnew = p.copy()
    pold = _10.poisson_old(p, b, dr, nt=1)
    pnew = _10.poisson(pnew.T, b.T, dr, nt=1).T

    assert np.all(pold == pnew)
예제 #7
0
from _lib import Window, s_
from _sym import symarray

import _11_old
import _11

simp = np.vectorize(cancel)

nr = (4,4)
mask = s_[1:-1,1:-1]

dx, dy, dt = symbols('dx dy dt')
rho, nu = symbols('rho nu')
dr = np.array([dx, dy])

u = symarray(nr, 'u')
v = symarray(nr, 'v')
b = symarray(nr, 'b')
p = symarray(nr, 'p')
uv = np.transpose((u, v), (1,2,0))

P = Window(p.copy(), mask=mask)
B = Window(b, mask=mask)

def test_b():
    uvt = (u.T, v.T)
    UV = Window(uv, 2, mask)
    bold = _11_old.build_b(rho, dt, uvt, dr).T
    bnew = _11.build_b(rho, dt, UV, dr).array
    assert np.all(bold == bnew)
예제 #8
0
import numpy as np
from sympy import symbols

import _util
from _lib import Window
from _sym import symarray

import _9

dx, dy = symbols('dx dy')
dr = np.array([dx, dy])
nr = (4, 4)
p = symarray(nr, 'p')
p11 = p[1, 1]
r = _util.linspaces([[0, 0], [2, 1]], nr)


def test_laplace():
    # swap beforehand because calc_* modifies array
    pold = p.copy().T
    pnew = p.copy()

    _9.calc_laplace_old(pold, dr, r)
    _9.calc_laplace(pnew, dr, r)
    assert np.all(pold.T == pnew)