-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex1_subset.py
93 lines (63 loc) · 2.41 KB
/
ex1_subset.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
82
83
84
85
86
87
88
89
90
91
92
93
import numpy as np
import pyvista as pv
import meshio as mi
import mplstereonet as mpl
import matplotlib.pyplot as plt
from fem2geo_lib import transform_funcs as tr
from fem2geo_lib import model_handler as mh
# =============================================================================
# Get Data
# =============================================================================
filename = './test_data/test_box.vtk'
### Read File with Pyvista
full_model = pv.read(filename)
### Select coordinates of circle center and radius
center = (22,22, -7)
radius = 0.8
### Get Submodel
Submodel = mh.get_submodel_sphere(full_model, center, radius )
### Save submodel for visualization as vtu
Submodel.save('./test_data/circle.vtu') #<<<<<<<< Visualize in paraview
### Get Submodel Sigma1 direction
print('Present CELL variables in model')
print(Submodel.cell_arrays.keys())
## We select dir_DevStress_1 and dir_DevStress_3 as variables
s1 = Submodel.cell_arrays['dir_DevStress_1']
s3 = Submodel.cell_arrays['dir_DevStress_3']
### We iterate over all s1 directions, to get its spherical coordinate
s1_sphe = []
for i in s1:
# force s1 direciton to point always upwards, to avoid azimuthal ambiguity
s1_up = i*np.sign(i[2])
# Convert ENU cartesian coordiantes to spherical (plunge/azimuth)
s1_i = tr.line_enu2sphe(s1_up)
# Save into the list
s1_sphe.append(s1_i)
### Same for s3
s3_sphe = []
for i in s3:
s3_up = i*np.sign(i[2])
s3_i = tr.line_enu2sphe(s3_up)
s3_sphe.append(s3_i)
# =============================================================================
# Plot Data
# =============================================================================
### Generical initialization of Stereoplots using the library mplstereonet
plt.close('all')
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111, projection='stereonet')
### add grid
ax.grid()
for n,i in enumerate(s1_sphe):
mylabel = None
if n==0:
mylabel = r'$\sigma_1$ orientation'
ax.line(i[0],i[1] , c='r', marker='o', markeredgecolor='k', label=mylabel)
for n, i in enumerate(s3_sphe):
mylabel = None
if n==0:
mylabel = r'$\sigma_3$ orientation'
ax.line(i[0],i[1] , c='b', marker='o', markeredgecolor='k', label=mylabel)
ax.legend()
ax.set_title('Stereoplot of $\sigma_1$ and $\sigma_3$ \n' +
'n of elements: %i' % Submodel.number_of_cells, y=1.08)