-
Notifications
You must be signed in to change notification settings - Fork 14
/
demo2.py
81 lines (71 loc) · 2.37 KB
/
demo2.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
73
74
75
76
77
78
79
80
81
# 3D example of viewing aggregates from SA using VTK
import pyamg
import pyamg.vis
# retrieve the problem
data = pyamg.gallery.load_example('unit_cube')
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='tet', fname='output_aggs.vtu')
# create the vtk file for a mesh
pyamg.vis.vtk_writer.write_basic_mesh(V=V, E2V=E2V,
mesh_type='tet', 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)
agg2 = []
agg3 = []
agg4 = []
for cell in gaggs.cells():
if len(cell) == 2:
agg2.append(cell)
elif len(cell) == 3:
agg3.append(cell)
else:
agg4.append(cell)
mesh2 = vedo.Mesh([gaggs.points(), agg2])
mesh3 = vedo.Mesh([gaggs.points(), agg3])
mesh4 = vedo.Mesh([gaggs.points(), agg4])
mesh2.lineColor('b').lineWidth(8)
mesh3.color('b').lineWidth(0)
mesh4.color('b').lineWidth(0)
figname = './output/vis_aggs3.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 += mesh4
plt.show(camera={'pos': (3, 3, 3)}).screenshot(figname)
else:
plt = vedo.Plotter()
plt += gmesh
plt += mesh2
plt += mesh3
plt += mesh4
plt.show(camera={'pos': (3, 3, 3)})
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
# selecting surface with edges and low opacity also helps
# 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)
# reduce the opacity, sometimes helps