forked from nobuyuki83/python_graphics_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30_laplace2_eigen.py
More file actions
59 lines (57 loc) · 1.99 KB
/
30_laplace2_eigen.py
File metadata and controls
59 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy
import scipy
import moderngl
from PyQt5 import QtWidgets
from util_moderngl_qt import DrawerMeshColormap, QGLWidgetViewer3, Colormap
from del_msh import TriMesh, PolyLoop
from del_fem import LaplacianMatrix, MassMatrix
if __name__ == "__main__":
vtxi2xyi = numpy.array([
[0, 0],
[1, 0],
[1, 0.6],
[0.6, 0.6],
[0.6, 1.0],
[0, 1]], dtype=numpy.float32)
##
tri2vtx, vtx2xy = PolyLoop.tesselation2d(
vtxi2xyi, resolution_edge=0.04, resolution_face=0.04)
print("# vtx: ", vtx2xy.shape[0])
smat = LaplacianMatrix.from_uniform_mesh(tri2vtx, vtx2xy)
assert scipy.sparse.linalg.norm(smat - smat.transpose()) < 1.0e-10
assert scipy.linalg.norm(smat * numpy.ones((vtx2xy.shape[0]))) < 1.0e-4
mmat = MassMatrix.from_uniform_mesh(tri2vtx, vtx2xy)
eig = scipy.sparse.linalg.eigsh(smat, M=mmat, sigma=0.0)
i_eig = 4
evec0 = eig[1].transpose()[i_eig].copy()
eval0 = eig[0][i_eig]
print(eval0)
evec0 /= scipy.linalg.norm(evec0)
assert abs(eval0*(mmat * evec0).dot(evec0)-(smat * evec0).dot(evec0)) < 1.0e-4
vtx2val = evec0.copy() * 10 + 0.5
edge2vtx = TriMesh.edge2vtx(tri2vtx, vtx2xy.shape[0])
drawer_edge = DrawerMeshColormap.Drawer(
vtx2xyz=vtx2xy,
list_elem2vtx=[
DrawerMeshColormap.ElementInfo(index=edge2vtx, color=(0, 0, 0), mode=moderngl.LINES),
DrawerMeshColormap.ElementInfo(index=tri2vtx, color=(1, 1, 1), mode=moderngl.TRIANGLES)
],
vtx2val=vtx2val,
color_map=Colormap.jet())
'''
numpy.array([
[0.0, 0.0, 0.5],
[0.0, 0.0, 1.0],
[0.0, 0.5, 1.0],
[0.0, 1.0, 1.0],
[0.5, 1.0, 0.5],
[1.0, 1.0, 0.0],
[1.0, 0.5, 0.0],
[1.0, 0.0, 0.0],
[0.5, 0.0, 0.0]])
'''
with QtWidgets.QApplication([]) as app:
win = QGLWidgetViewer3.QtGLWidget_Viewer3(
[drawer_edge])
win.show()
app.exec()