def g(x, y): return cos(2 * pi * x) + sin(2 * pi * y) m = mesh.read("CarreMedium.msh") coords = m[0] elt2verts = m[1] nbVerts = coords.shape[0] nbElts = elt2verts.shape[0] print('nbVerts : {}'.format(nbVerts)) print('nbElts : {}'.format(nbElts)) begVert2Elts, vert2elts = mesh.compvert2elts(elt2verts) begRows, indCols = fem.comp_skel_csr_mat(elt2verts, (begVert2Elts, vert2elts)) nz = begRows[-1] print("Number of non zero in sparse matrix : {}".format(nz)) spCoefs = np.zeros((nz, ), np.double) for iElt in range(nbElts): iVertices = elt2verts[iElt, :] crd1 = coords[iVertices[0], :] crd2 = coords[iVertices[1], :] crd3 = coords[iVertices[2], :] matElem = laplacian.comp_eltmat((crd1[0], crd1[1]), (crd2[0], crd2[1]), (crd3[0], crd3[1])) fem.add_elt_mat_to_csr_mat((begRows, indCols, spCoefs), (iVertices, iVertices, matElem))
coords.shape[0]) #this is the inverse map of v_loc2glo for ind in range(len(v_loc2glo)): v_glo2loc[v_loc2glo[ind]] = ind #we give values for e2v_loc for ie_loc in range(len(ets_loc2glo)): ie = ets_loc2glo[ie_loc] e2v_loc[ie_loc, 0] = v_glo2loc[elt2verts[ie, 0]] e2v_loc[ie_loc, 1] = v_glo2loc[elt2verts[ie, 1]] e2v_loc[ie_loc, 2] = v_glo2loc[elt2verts[ie, 2]] #structure for the sparse local matrix begVert2Elts_loc, vert2elts_loc = mesh.compvert2elts(e2v_loc) begRows_loc, indCols_loc = fem.comp_skel_csr_mat( e2v_loc, (begVert2Elts_loc, vert2elts_loc)) nz = begRows_loc[-1] file.write("\nNumber of non zero in sparse matrix : {}".format(nz)) #number of vertices and number of elements in the local mesh nbV_loc = len(v_loc2glo) nbE_loc = e2v_loc.shape[0] spCoefs = np.zeros((nz, ), np.double) #coefficients of the sparse matrix #we add elementary matrices, only for each element in the local mesh for iElt in range(nbE_loc): iVertices = e2v_loc[iElt, :] crd1 = coords[v_loc2glo[iVertices[0]], :] crd2 = coords[v_loc2glo[iVertices[1]], :] crd3 = coords[v_loc2glo[iVertices[2]], :]