def test_fast_stiffness_geo_2d(): kv = bspline.make_knots(3, 0.0, 1.0, 15) geo = geometry.bspline_quarter_annulus() A = stiffness_fast((kv,kv), geo, verbose=0) A_ref = read_sparse_matrix(os.path.join(os.path.dirname(__file__), "poisson_neu_d2_p3_n15_stiff.mtx.gz")) assert abs(A - A_ref).max() < 1e-9
def test_mass_geo_2d(): kv = bspline.make_knots(3, 0.0, 1.0, 15) geo = geometry.bspline_quarter_annulus() M = mass((kv,kv), geo) M_ref = read_sparse_matrix(os.path.join(os.path.dirname(__file__), "poisson_neu_d2_p3_n15_mass.mtx.gz")) assert abs(M - M_ref).max() < 1e-14
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()
def test_divdiv_geo_2d(): kv = bspline.make_knots(3, 0.0, 1.0, 15) geo = geometry.bspline_quarter_annulus() A = divdiv((kv,kv), geo, layout='packed') # construct divergence-free function from pyiga.approx import interpolate u = interpolate((kv,kv), lambda x,y: (x,-y), geo=geo).ravel() assert abs(A.dot(u)).max() < 1e-12
def test_compare_intproj(): f = lambda x,y: np.cos(x)*np.exp(y) kvs = 2 * (bspline.make_knots(3, 0.0, 1.0, 50),) x1 = interpolate(kvs, f) x2 = project_L2(kvs, f) assert abs(x1-x2).max() < 1e-5 geo = geometry.bspline_quarter_annulus() x1 = interpolate(kvs, f, geo=geo) x2 = project_L2(kvs, f, f_physical=True, geo=geo) assert abs(x1-x2).max() < 1e-5
def test_divdiv_geo_2d(): kv = bspline.make_knots(3, 0.0, 1.0, 15) geo = geometry.bspline_quarter_annulus() A = divdiv((kv,kv), geo, layout='packed', format='bsr') # construct divergence-free function u = interpolate((kv,kv), lambda x,y: (x,-y), geo=geo) assert abs(A.dot(u.ravel())).max() < 1e-12 # test blocked layout A = divdiv((kv,kv), geo, layout='blocked') u_blocked = np.moveaxis(u, -1, 0) # move last axis to the front assert abs(A.dot(u_blocked.ravel())).max() < 1e-12
def test_hierarchical_assemble(): hs = create_example_hspace(p=4, dim=2, n0=4, disparity=1, num_levels=3) geo = geometry.bspline_quarter_annulus() hdiscr = HDiscretization(hs, vform.stiffness_vf(dim=2), {'geo': geo}) A = hdiscr.assemble_matrix() # compute matrix on the finest level for comparison A_fine = assemble.stiffness(hs.knotvectors(-1), geo=geo) I_hb = hs.represent_fine() A_hb = (I_hb.T @ A_fine @ I_hb) assert np.allclose(A.A, A_hb.A) # A3 = assemble.assemble(vform.stiffness_vf(dim=2), hs, geo=geo) assert np.allclose(A.A, A3.A) # def f(x, y): return np.cos(x) * np.exp(y) f_hb = assemble.inner_products( hs.knotvectors(-1), f, f_physical=True, geo=geo).ravel() @ I_hb f2 = assemble.assemble('f * v * dx', hs, f=f, geo=geo) assert np.allclose(f_hb, f2)