示例#1
0
def test_D():
    
    g = Grid_2D.periodic(3, 3)
        
    f = form(0, c, (cos(x)+cos(y),))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D

    f = form(1, c, (cos(x),cos(y),))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D

    g = Grid_2D.chebyshev(3, 3)
    
    f = form(0, c, (x+y,))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)

    f = form(1, c, (-y,x))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)

    g = Grid_2D.chebyshev(4, 5)
    
    f = form(0, c, (x*y,))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)

    f = form(1, c, (x,y))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)
示例#2
0
def test_refine():
  
    g = Grid_2D.chebyshev(3, 3)
    compare_comps(g, form(0, c, (x+y,)),  True)
    compare_comps(g, form(0, c, (x+y,)),  False)
      
    compare_comps(g, form(1, c, ( x, y)), True)
    compare_comps(g, form(1, c, ( x, y)), False)
    compare_comps(g, form(1, c, (-y, x)), True)
    compare_comps(g, form(1, c, (-y, x)), False)
  
    compare_comps(g, form(2, c, ( x+y,)), True)
    compare_comps(g, form(2, c, ( x+y,)), False)
    compare_comps(g, form(2, c, ( x,)),   True)
    compare_comps(g, form(2, c, ( y,)),   False)
  
    g = Grid_2D.periodic(3, 3)
    compare_comps(g, form(0, c, (sin(x)+cos(y),)), True)
    compare_comps(g, form(0, c, (sin(x)+cos(y),)), False)
    compare_comps(g, form(1, c, (sin(x),sin(y),)), True)
    compare_comps(g, form(1, c, (sin(x),sin(y),)), False)
    compare_comps(g, form(1, c, (cos(x),cos(y),)), True)
    compare_comps(g, form(1, c, (cos(x),cos(y),)), False)
    compare_comps(g, form(1, c, (-sin(y),sin(x),)), True)
    compare_comps(g, form(1, c, (-sin(y),sin(x),)), False)
    compare_comps(g, form(1, c, (-cos(y),cos(x),)), True)
    compare_comps(g, form(1, c, (-cos(y),cos(x),)), False)
    compare_comps(g, form(2, c, (sin(x),)), True)
    compare_comps(g, form(2, c, (sin(x),)), False)
示例#3
0
def test_H():
    
    g = Grid_2D.periodic(5, 5)

    f = form(0, c, (cos(x),))    
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H
    
    f = form(1, c, (sin(x),cos(y)))    
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    g = Grid_2D.chebyshev(10, 10)
    
    f = form(0, c, (x**4,))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    f = form(1, c, (-y, x**2))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    f = form(2, c, (x**2*y,))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H
示例#4
0
def test_H():

    g = Grid_2D.periodic(5, 5)

    f = form(0, c, (cos(x), ))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    f = form(1, c, (sin(x), cos(y)))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    g = Grid_2D.chebyshev(10, 10)

    f = form(0, c, (x**4, ))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    f = form(1, c, (-y, x**2))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H

    f = form(2, c, (x**2 * y, ))
    assert f.H.P(g, False) == f.P(g, True).H
    assert f.H.P(g, True) == f.P(g, False).H
示例#5
0
def test_D():

    g = Grid_2D.periodic(3, 3)

    f = form(0, c, (cos(x) + cos(y), ))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D

    f = form(1, c, (
        cos(x),
        cos(y),
    ))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D

    g = Grid_2D.chebyshev(3, 3)

    f = form(0, c, (x + y, ))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)

    f = form(1, c, (-y, x))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)

    g = Grid_2D.chebyshev(4, 5)

    f = form(0, c, (x * y, ))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)

    f = form(1, c, (x, y))
    assert f.D.P(g, True) == f.P(g, True).D
    assert f.D.P(g, False) == f.P(g, False).D + g.BC(f)
示例#6
0
def test_refine():

    g = Grid_2D.chebyshev(3, 3)
    compare_comps(g, form(0, c, (x + y, )), True)
    compare_comps(g, form(0, c, (x + y, )), False)

    compare_comps(g, form(1, c, (x, y)), True)
    compare_comps(g, form(1, c, (x, y)), False)
    compare_comps(g, form(1, c, (-y, x)), True)
    compare_comps(g, form(1, c, (-y, x)), False)

    compare_comps(g, form(2, c, (x + y, )), True)
    compare_comps(g, form(2, c, (x + y, )), False)
    compare_comps(g, form(2, c, (x, )), True)
    compare_comps(g, form(2, c, (y, )), False)

    g = Grid_2D.periodic(3, 3)
    compare_comps(g, form(0, c, (sin(x) + cos(y), )), True)
    compare_comps(g, form(0, c, (sin(x) + cos(y), )), False)
    compare_comps(g, form(1, c, (
        sin(x),
        sin(y),
    )), True)
    compare_comps(g, form(1, c, (
        sin(x),
        sin(y),
    )), False)
    compare_comps(g, form(1, c, (
        cos(x),
        cos(y),
    )), True)
    compare_comps(g, form(1, c, (
        cos(x),
        cos(y),
    )), False)
    compare_comps(g, form(1, c, (
        -sin(y),
        sin(x),
    )), True)
    compare_comps(g, form(1, c, (
        -sin(y),
        sin(x),
    )), False)
    compare_comps(g, form(1, c, (
        -cos(y),
        cos(x),
    )), True)
    compare_comps(g, form(1, c, (
        -cos(y),
        cos(x),
    )), False)
    compare_comps(g, form(2, c, (sin(x), )), True)
    compare_comps(g, form(2, c, (sin(x), )), False)
示例#7
0
def test_N():
    def check_N(g):
        f = form(0, c, (0, ))
        assert g.P(f, True).array.shape[0] == g.N[0, True]
        assert g.P(f, False).array.shape[0] == g.N[0, False]
        f = form(1, c, (0, 0))
        assert g.P(f, True).array.shape[0] == g.N[1, True]
        assert g.P(f, False).array.shape[0] == g.N[1, False]
        f = form(2, c, (0, ))
        assert g.P(f, True).array.shape[0] == g.N[2, True]
        assert g.P(f, False).array.shape[0] == g.N[2, False]

    check_N(Grid_2D.periodic(4, 3))
    check_N(Grid_2D.periodic(3, 5))
    check_N(Grid_2D.chebyshev(2, 3))
    check_N(Grid_2D.chebyshev(5, 4))
示例#8
0
def test_N():

    def check_N(g):
        f = form(0, c, (0,))
        assert g.P(f, True).array.shape[0] == g.N[0, True]
        assert g.P(f, False).array.shape[0] == g.N[0, False]
        f = form(1, c, (0,0))
        assert g.P(f, True).array.shape[0] == g.N[1, True]
        assert g.P(f, False).array.shape[0] == g.N[1, False]
        f = form(2, c, (0,))
        assert g.P(f, True).array.shape[0] == g.N[2, True]
        assert g.P(f, False).array.shape[0] == g.N[2, False]

    check_N(Grid_2D.periodic(4, 3))
    check_N(Grid_2D.periodic(3, 5))
    check_N(Grid_2D.chebyshev(2, 3))
    check_N(Grid_2D.chebyshev(5, 4))
示例#9
0
 def primaldual(t):
     g = Grid_2D.periodic(5, 3)
     
     f = form(0, c, (sin(x)+sin(y),))
     assert P(f, t, g)  == g.P(f, t)
     f = form(1, c, (sin(x),sin(y),))
     assert P(f, t, g)  == g.P(f, t) 
     f = form(2, c, (sin(x)+sin(y),))
     assert P(f, t, g)  == g.P(f, t)
     
     g = Grid_2D.chebyshev(3, 6)
     
     f = form(0, c, (x+y,))
     assert P(f, t, g)  == g.P(f, t)
     f = form(1, c, (x,y))
     assert P(f, t, g)  == g.P(f, t)
     f = form(2, c, (x+y,))
     assert P(f, t, g)  == g.P(f, t)
示例#10
0
    def primaldual(t):
        g = Grid_2D.periodic(5, 3)

        f = form(0, c, (sin(x) + sin(y), ))
        assert P(f, t, g) == g.P(f, t)
        f = form(1, c, (
            sin(x),
            sin(y),
        ))
        assert P(f, t, g) == g.P(f, t)
        f = form(2, c, (sin(x) + sin(y), ))
        assert P(f, t, g) == g.P(f, t)

        g = Grid_2D.chebyshev(3, 6)

        f = form(0, c, (x + y, ))
        assert P(f, t, g) == g.P(f, t)
        f = form(1, c, (x, y))
        assert P(f, t, g) == g.P(f, t)
        f = form(2, c, (x + y, ))
        assert P(f, t, g) == g.P(f, t)
示例#11
0
def test_W_C():
    
    g = Grid_2D.chebyshev(4, 4)
      
    f0 = form(0, c, (x,))
    f1 = form(1, c, (x**2,-y))
    f2 = form(2, c, (x+y,))
    f = [f0, f1, f2]

    h0 = form(0, c, (y,))
    h1 = form(1, c, (-y,x))
    h2 = form(2, c, (x-y,))
    h = [h0, h1, h2]
    
    for ((d1, p1), (d2, p2), p3) in g.dec.W.keys():
        assert (f[d1]^h[d2]).P(g, p3) == f[d1].P(g, p1).W(h[d2].P(g, p2), toprimal=p3)

    for (p1, (d2, p2), p3) in g.dec.C.keys():
        assert f[1].C(h[d2]).P(g, p3) == f[1].P(g, p1).C(h[d2].P(g, p2), toprimal=p3)
示例#12
0
def test_W_C():

    g = Grid_2D.chebyshev(4, 4)

    f0 = form(0, c, (x, ))
    f1 = form(1, c, (x**2, -y))
    f2 = form(2, c, (x + y, ))
    f = [f0, f1, f2]

    h0 = form(0, c, (y, ))
    h1 = form(1, c, (-y, x))
    h2 = form(2, c, (x - y, ))
    h = [h0, h1, h2]

    for ((d1, p1), (d2, p2), p3) in g.dec.W.keys():
        assert (f[d1] ^ h[d2]).P(g, p3) == f[d1].P(g, p1).W(h[d2].P(g, p2),
                                                            toprimal=p3)

    for (p1, (d2, p2), p3) in g.dec.C.keys():
        assert f[1].C(h[d2]).P(g, p3) == f[1].P(g, p1).C(h[d2].P(g, p2),
                                                         toprimal=p3)
示例#13
0
import numpy as np
from dec.grid2 import Grid_2D, basis_fn
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d

g = Grid_2D.periodic(7, 7)
X = np.linspace(g.gx.xmin, g.gx.xmax, 100)
Y = np.linspace(g.gy.xmin, g.gy.xmax, 100)
X, Y = np.meshgrid(X, Y)
B = basis_fn(g.gx.dec.B, g.gy.dec.B)

fig = plt.figure()
ax = fig.gca(projection='3d')
for i, j, c in [(0, 0, 'r'), 
                (2, 2, 'g'), 
                (4, 4, 'b')]:
    Z = B[0, True](i, j)(X,Y)
    ax.plot_surface(X, Y, Z, rstride=3, cstride=3, color=c, alpha=0.4)

fig = plt.figure()
ax = fig.gca(projection='3d')
for i, j, c in [(0, 0, 'r'), 
                (2, 2, 'g'), 
                (4, 4, 'b')]:
    Z = B[0, False](i, j)(X,Y)
    ax.plot_surface(X, Y, Z, rstride=3, cstride=3, color=c, alpha=0.4)

fig = plt.figure()
ax = fig.gca(projection='3d')
for i, j, c in [(0, 0, 'r'), 
                (2, 2, 'g'), 
示例#14
0
import matplotlib.pyplot as plt
from numpy import *
from dec.grid2 import Grid_2D

X = linspace(0, 2*pi, 30)
Y = linspace(0, 2*pi, 30)
X, Y = meshgrid(X, Y)

g = Grid_2D.periodic(5, 5)

plt.scatter(*g.verts)

B = g.dec.B
U, V = B[1, True](12)(X, Y)

plt.quiver(X, Y, U, V)

plt.show()