n = 200 dx = 1./n t0 = time.time() (topo,x,y) = lin_t3.mesh_t3(n,n,dx,dx) t1 = time.time() print('Mesh generation finished') print('dofs = ' + str(x.shape[0])) print('t mesh = ' + str(t1-t0)) T = 8 Theta = 0.5 t0 = time.time() K = assemble.gradu_gradv_p1(topo,x,y) M = assemble.u_v_p1(topo,x,y) t1 = time.time() print('Assembled mass and stiffness matrix') print('t = ' + str(t1-t0)) err_BDF1 = np.zeros((5)) err_BDF2 = np.zeros((5)) err_Theta = np.zeros((5)) for t_ind in range(0, 5): dt = 2**(-t_ind) u_0 = analytical(0) u_1 = analytical(dt) M_BDF1 = M + dt*K
write_mesh() ndofs_u = max(x_u.shape) ndofs_p = max(x_p.shape) + topo_p.shape[0] print('ndofs u = ' + str(2 * ndofs_u)) print('ndofs p = ' + str(ndofs_p)) u_n = np.zeros((2 * ndofs_u, 1)) p_n = np.zeros((ndofs_p, 1)) ux_n = np.zeros((ndofs_u, 1)) uy_n = np.zeros((ndofs_u, 1)) ux_n_old = np.zeros((ndofs_u, 1)) uy_n_old = np.zeros((ndofs_u, 1)) M11 = assemble.u_v_p1(topo_u, x_u, y_u) A11 = assemble.gradu_gradv_p1(topo_u, x_u, y_u) M22 = M11 (BT1, BT2) = assemble.divu_p_p1_iso_p2_p1p0(topo_p, x_p, y_p, topo_u, x_u, y_u, c2f) # (BT1,BT2) = assemble.divu_p_p1_iso_p2_p1(topo_p,x_p,y_p, # topo_u,x_u,y_u,c2f) BT = sparse.vstack([BT1, BT2]) B = BT.transpose() mean_p = np.zeros((1, ndofs_p)) for row in topo_p: x_l = x_p[row[0:3]] y_l = y_p[row[0:3]] eval_p = np.zeros((0, 2))
topo_p = np.load(f) x_p = np.load(f) y_p = np.load(f) topo_u = np.load(f) x_u = np.load(f) y_u = np.load(f) c2f = np.load(f) topo_s = np.load(f) xs_n = np.load(f) ys_n = np.load(f) s_lgr = np.load(f) t_lgr = np.load(f) f.close() ndofs_u = x_u.shape[0] mass_1D = assemble.u_v_p1(topo_u, x_u, y_u) mass_matrix_u = sparse.vstack([ sparse.hstack([mass_1D, sparse.csr_matrix((ndofs_u, ndofs_u))]), sparse.hstack([sparse.csr_matrix((ndofs_u, ndofs_u)), mass_1D]) ]) ie_s = np.arange(0, s_lgr.shape[0]) ndofs_s = max(ie_s) + 1 mass_1D = assemble.u_v_p1_periodic(topo_s, s_lgr, t_lgr, ie_s) mass_matrix_s = sparse.vstack([ sparse.hstack([mass_1D, sparse.csr_matrix((ndofs_s, ndofs_s))]), sparse.hstack([sparse.csr_matrix((ndofs_s, ndofs_s)), mass_1D]) ]) stiffness_1D = assemble.gradu_gradv_p1(topo_u, x_u, y_u) stiffness_matrix_u = sparse.vstack([
dx = 1./n print('dx = ' + str(dx)) T = 5 CN = 0.5 TOL = 1e-8 max_iter = 10 n_runs = 5 (topo_p,x_p,y_p,topo_u,x_u,y_u,c2f) = lin_t3.mesh_t3_iso_t6(n,n,dx,dx) (topo_p,x_p,y_p) = lin_t3.mesh_t3_t0(n,n,dx,dx) print('Mesh generation finished') K = assemble.gradu_gradv_p1(topo_u,x_u,y_u) M = assemble.u_v_p1(topo_u,x_u,y_u) (BT1,BT2) = assemble.divu_p_p1_iso_p2_p1p0(topo_p,x_p,y_p,topo_u,x_u,y_u,c2f) BT = sparse.vstack([BT1,BT2]) B = BT.transpose() ndofs_u = BT1.shape[0] ndofs_p = BT1.shape[1] print('dofs u = ' + str(2*ndofs_u)) print('dofs p = ' + str(ndofs_p)) bc_id = np.where(y_u > 1-dx/10) BT1 = la_utils.clear_rows(BT1,bc_id) BT2 = la_utils.clear_rows(BT2,bc_id) bc_id = np.where(y_u < dx/10) BT1 = la_utils.clear_rows(BT1,bc_id)