Ejemplo n.º 1
0
"""
from pydec import simplicial_complex, d, delta, whitney_innerproduct, \
     simplex_quivers
from numpy import loadtxt
from scipy import real, zeros
from scipy.linalg import eig
from matplotlib.pylab import quiver, figure, triplot, show

# Read in mesh data from files and construct complex
vertices = loadtxt('vertices.txt', dtype=float)
triangles = loadtxt('triangles.txt', dtype=int)
sc = simplicial_complex((vertices,triangles))

# Construct stiffness and mass matrices 
K = sc[1].d.T * whitney_innerproduct(sc,2) * sc[1].d
M = whitney_innerproduct(sc,1)

# Eliminate Boundaries from matrices
boundary_edges = sc.boundary()
non_boundary_edges = set(sc[1].simplex_to_index.keys()) - set(boundary_edges)
non_boundary_indices = [sc[1].simplex_to_index[e] for e in non_boundary_edges]

# Eliminate boundary conditions
K = K[non_boundary_indices,:][:,non_boundary_indices]
M = M[non_boundary_indices,:][:,non_boundary_indices]

# Compute eigenvalues and eigenvectors
# (could use sparse eigenvalue solver instead)
eigenvalues, eigenvectors = eig(K.todense(), M.todense())
Ejemplo n.º 2
0
import numpy as np
from scipy.io import loadmat, savemat
from pydec import simplicial_complex, whitney_innerproduct

X = loadmat('pyamg.mat')
del X['__version__']
del X['__header__']
del X['__globals__']

sc = simplicial_complex(X['vertices'], X['elements'].astype('intc'))

d = sc[0].d
M = whitney_innerproduct(sc, 1)
A = d.T.tocsr() * M * d

X['A'] = A
X['B'] = np.ones((A.shape[0], 1))

savemat('pyamg.mat', X)