-
Notifications
You must be signed in to change notification settings - Fork 14
/
demo1.py
72 lines (62 loc) · 2.01 KB
/
demo1.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
# 2D example of viewing aggregates from SA using VTK
import pyamg
import pyamg.vis
# retrieve the problem
data = pyamg.gallery.load_example('unit_square')
A = data['A'].tocsr()
V = data['vertices']
E2V = data['elements']
# perform smoothed aggregation
AggOp, rootnodes = pyamg.aggregation.standard_aggregation(A)
# create the vtk file of aggregates
pyamg.vis.vis_coarse.vis_aggregate_groups(V=V, E2V=E2V, AggOp=AggOp,
mesh_type='tri', fname='output_aggs.vtu')
# create the vtk file for a mesh
pyamg.vis.vtk_writer.write_basic_mesh(V=V, E2V=E2V,
mesh_type='tri', fname='output_mesh.vtu')
try:
import vedo
gmesh = vedo.load('output_mesh.vtu')
gaggs = vedo.load('output_aggs.vtu')
gmesh = gmesh.tomesh().color('w').alpha(0.1)
gmesh.color('gray')
gmesh.lw(3.0)
agg3 = []
agg2 = []
for cell in gaggs.cells():
if len(cell) == 2:
agg2.append(cell)
else:
agg3.append(cell)
mesh2 = vedo.Mesh([gaggs.points(), agg2])
mesh3 = vedo.Mesh([gaggs.points(), agg3])
mesh2.lineColor('b').lineWidth(8)
mesh3.color('b').lineWidth(0)
figname = './output/vis_aggs2.png'
import sys
if len(sys.argv) > 1:
if sys.argv[1] == '--savefig':
plt = vedo.Plotter(offscreen=True)
plt += gmesh
plt += mesh2
plt += mesh3
plt.show().screenshot(figname)
else:
plt = vedo.Plotter()
plt += gmesh
plt += mesh2
plt += mesh3
plt.show()
except:
pass
# to use Paraview:
# start Paraview: Paraview --data=output_mesh.vtu
# apply
# under display in the object inspector:
# select wireframe representation
# select a better solid color
# open file: output_aggs.vtu
# under display in the object inspector:
# select surface with edges representation
# select a better solid color
# increase line width and point size to see these aggs (if present)