Exemple #1
0
 def test_1x1(self):
     try:
         regular_triangle_mesh(1, 0)
     except ValueError:
         pass
     else:
         raise Exception("regular_triangle_mesh(1,0) should throw an error")
Exemple #2
0
 def test_1x1(self):
     try:
         regular_triangle_mesh(1, 0)
     except ValueError:
         pass
     else:
         raise Exception('regular_triangle_mesh(1,0) should throw an error')
Exemple #3
0
    def test_3x2(self):
        Vert, E2V = regular_triangle_mesh(3, 2)

        assert_equal(
            Vert,
            [[0., 0.], [0.5, 0.], [1., 0.], [0., 1.], [0.5, 1.], [1., 1.]])

        assert_equal(E2V, [[0, 4, 3], [1, 5, 4], [0, 1, 4], [1, 2, 5]])
Exemple #4
0
    def test_2x2(self):
        Vert, E2V = regular_triangle_mesh(2, 2)

        assert_equal(Vert, [[0.,  0.],
                            [1.,  0.],
                            [0.,  1.],
                            [1.,  1.]])

        assert_equal(E2V, [[0, 3, 2],
                           [0, 1, 3]])
Exemple #5
0
    def test_3x2(self):
        Vert, E2V = regular_triangle_mesh(3, 2)

        assert_equal(Vert, [[0.,  0.],
                            [0.5,  0.],
                            [1.,  0.],
                            [0.,  1.],
                            [0.5,  1.],
                            [1.,  1.]])

        assert_equal(E2V, [[0, 4, 3],
                           [1, 5, 4],
                           [0, 1, 4],
                           [1, 2, 5]])
Exemple #6
0
import numpy as np
import scipy.sparse as sparse
import matplotlib.pyplot as plt
import pyamg

from helper import trimesh, graph_laplacian

meshnum = 2

if meshnum == 1:
    from pyamg.gallery import mesh
    V, E = mesh.regular_triangle_mesh(20, 6)
if meshnum == 2:
    from scipy.io import loadmat
    mesh = loadmat('crack_mesh.mat')
    V = mesh['V']
    E = mesh['E']

A = graph_laplacian(V, E)

# construct preconditioner
ml = pyamg.smoothed_aggregation_solver(A, coarse_solver='pinv2', max_coarse=10)
M = ml.aspreconditioner()

# solve for lowest two modes: constant vector and Fiedler vector
X = np.random.rand(A.shape[0], 2)
(eval, evec, res) = sparse.linalg.lobpcg(A, X, M=None, tol=1e-12, largest=False,
                                         verbosityLevel=0,
                                         retResidualNormsHistory=True)

fiedler = evec[:, 1]
Exemple #7
0
    Verttmp = numpy.meshgrid(numpy.arange(0, nx, dtype='float'),
                             numpy.arange(0, ny, dtype='float'))
    Verttmp = (Verttmp[0].ravel(), Verttmp[1].ravel())
    Vert = numpy.vstack(Verttmp).transpose()
    Vert[:, 0] = (1.0 / (nx - 1)) * Vert[:, 0]
    Vert[:, 1] = (1.0 / (ny - 1)) * Vert[:, 1]

    E2V1 = numpy.vstack((Vert1, Vert2, Vert3)).transpose()
    E2V2 = numpy.vstack((Vert1, Vert4, Vert2)).transpose()
    E2V = numpy.vstack((E2V1, E2V2))

    return Vert, E2V


if __name__ == '__main__':

    meshnum = 1

    if meshnum == 1:
        from pyamg.gallery import mesh
        V, E = mesh.regular_triangle_mesh(20, 6)

    if meshnum == 2:
        from scipy.io import loadmat
        mesh = loadmat('crack_mesh.mat')
        V = mesh['V']
        E = mesh['E']

    trimesh(V, E)
Exemple #8
0
from helper import *
from improve import *
from partition import *
from plotgraph import *
from test_graphs import *

from pyamg.util.utils import get_diagonal

names = ['lobpcg', 'tracemin']
method = 1 # partiton method : 1=isopermetric, 2=spectral
meshnum = 3
nodes = 100

if meshnum==1:
    from pyamg.gallery import mesh
    V,E = mesh.regular_triangle_mesh(nodes,nodes)
if meshnum==2:
    from scipy.io import loadmat
    graph_names = ['crack_mesh','random_disk_graph','random_disk_graph_1000']
    mesh = loadmat('data/'+graph_names[0])
    V=mesh['V']
    E=mesh['E']
if meshnum==3:
    from pyamg.gallery import poisson
    mesh = poisson((nodes,nodes),format='coo')
    N=mesh.shape[0]
    grid = numpy.meshgrid(range(nodes),range(nodes))
    V=numpy.vstack(map(numpy.ravel,grid)).T
    E=numpy.vstack((mesh.row,mesh.col)).T
if meshnum==4:
    mesh = load_graph(0)