コード例 #1
0
def test_grid_eval():
    hs = create_example_hspace(p=3, dim=2, n0=6, num_levels=3)
    u = rand(hs.numdofs)
    grid = 2 * (np.linspace(0, 1, 50), )
    f_fine = bspline.BSplineFunc(hs.knotvectors(-1), hs.represent_fine() @ u)
    hsf = HSplineFunc(hs, u)
    assert hsf.dim == 1 and hsf.sdim == 2
    assert hsf.support == ((0.0, 1.0), (0.0, 1.0))
    #
    assert np.allclose(f_fine.grid_eval(grid), hsf.grid_eval(grid))
    assert np.allclose(f_fine.grid_jacobian(grid), hsf.grid_jacobian(grid))
    assert np.allclose(f_fine.grid_hessian(grid), hsf.grid_hessian(grid))
    #
    assert np.allclose(hsf(grid[1][7], grid[0][19]),
                       hsf.grid_eval(grid)[19, 7])
    ## test THBs
    f_fine = bspline.BSplineFunc(hs.knotvectors(-1),
                                 hs.represent_fine(truncate=True) @ u)
    hsf = HSplineFunc(hs, u, truncate=True)
    assert np.allclose(f_fine.grid_eval(grid), hsf.grid_eval(grid))
    assert np.allclose(f_fine.grid_jacobian(grid), hsf.grid_jacobian(grid))
    assert np.allclose(f_fine.grid_hessian(grid), hsf.grid_hessian(grid))
    #
    assert np.allclose(hsf(grid[1][7], grid[0][19]),
                       hsf.grid_eval(grid)[19, 7])
コード例 #2
0
ファイル: test_vform.py プロジェクト: pshriwise/pyiga
def test_parse():
    from pyiga import bspline, geometry
    kvs = 2 * (bspline.make_knots(2, 0.0, 1.0, 5), )

    vf = parse_vf('u * v * dx', kvs, bfuns=[('u', 1), ('v', 1)])
    assert vf.hash() == mass_vf(2).hash()

    f = bspline.BSplineFunc(kvs, np.ones(bspline.numdofs(kvs)))
    vf = parse_vf('f * v * dx', kvs, {'f': f})
    assert vf.hash() == L2functional_vf(2, physical=False).hash()

    f = lambda x, y: 1.0
    vf = parse_vf('f * v * dx', kvs, {'f': f})
    assert vf.hash() == L2functional_vf(2, physical=True).hash()

    vf = parse_vf('div(u) * div(v) * dx', kvs, bfuns=[('u', 2), ('v', 2)])
    assert vf.hash() == divdiv_vf(2).hash()

    # some other features
    vf = parse_vf('f * v * ds', kvs[:1], {'f': geometry.circular_arc(1.4)[0]})

    vf = parse_vf('inner(f, v) * ds',
                  kvs,
                  bfuns=[('v', 2)],
                  args={
                      'f': lambda x, y: (-y, x)
                  })
コード例 #3
0
ファイル: test_vis.py プロジェクト: pshriwise/pyiga
def test_animate_field():
    kvs = 2 * (bspline.make_knots(2, 0.0, 1.0, 5),)
    fields = [ bspline.BSplineFunc(kvs,
        approx.interpolate(kvs, lambda x,y: np.sin(t+x) * np.exp(y)))
        for t in range(3) ]
    anim = animate_field(fields, geo=geometry.bspline_quarter_annulus(), res=10)
    anim.to_jshtml()
コード例 #4
0
def test_prolongators():
    hs = create_example_hspace(p=3, dim=2, n0=4, disparity=1, num_levels=1)
    n0 = hs.mesh(0).numbf

    # create a coarse B-spline function
    u_tp = rand(n0)
    f0 = bspline.BSplineFunc(hs.knotvectors(0), u_tp)
    # bring its coefficients into canonical order (active, then deactivated)
    u_lv0 = np.concatenate((
        u_tp[hs.active_indices()[0]],
        u_tp[hs.deactivated_indices()[0]],
    ))
    X = 2 * (np.linspace(0, 1, 20), )

    #### prolongators for HB-splines ####
    # prolongate f to the finest space (hs itself)
    P_hb = hs.virtual_hierarchy_prolongators()
    u = u_lv0
    for P in P_hb:
        u = P @ u
    f_hb = HSplineFunc(hs, u)
    # compare it to the original function
    assert np.allclose(f0.grid_eval(X), f_hb.grid_eval(X))

    #### prolongators for THB-splines ####
    hs.truncate = True
    # prolongate f to the finest space (hs itself)
    P_thb = hs.virtual_hierarchy_prolongators()
    u = u_lv0
    for P in P_thb:
        u = P @ u
    f_thb = HSplineFunc(hs, u)
    # compare it to the original function
    assert np.allclose(f0.grid_eval(X), f_thb.grid_eval(X))
コード例 #5
0
ファイル: test_vis.py プロジェクト: pshriwise/pyiga
def test_plot_field():
    def f(x, y): return np.sin(x) * np.exp(y)
    geo = geometry.quarter_annulus()
    plot_field(f, physical=True, geo=geo, res=10)
    #
    kvs = 2 * (bspline.make_knots(2, 0.0, 1.0, 5),)
    u = bspline.BSplineFunc(kvs, approx.interpolate(kvs, f))
    plot_field(u, res=10)
    plot_field(u, geo=geo, res=10)