forked from Modelizacion-de-Materiales/finel3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyBST.py
117 lines (105 loc) · 4.2 KB
/
pyBST.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
##############################################################################
# Selecciona las condiciones de contorno sin necesidad de correr un ejecutable.
# Corresponde a la version 1.0 del protocolo $BoundariesFormat
# compatible con el BST usado anteriormente
#
# Codigos de nodos que interpreta la libreria boundaries handler
#
# Restricciones
# 2: Vinculo de 3ra especie
# 11: Restriccion en X
# 12: Restriccion en Y
#
# Fuerzas
# 3: Fuerza en X positiva
# 4: Fuerza en X negativa
#
###############################################################################
import numpy as np
import gmesh_handler as gmesh
import os
import platform
import pdb
def BST(file_name, num_of_nodes, elem_type):
nodos = np.zeros(num_of_nodes, dtype=int)
restricted = 0
x_restricted = 0
y_restricted = 0
x_force_pos = 0
neg_x_force_pos = 0
if 'Linux' in platform.system():
os.system('clear')
elif 'Darwin' in platform.system():
os.system('clear')
else:
os.system('cls')
print(' pyBST')
print()
print('q: quit c: continue')
print('r: restrict 3 DOF')
print('x: Positive force in x-axis x-: Negative force in x-axis')
print('rx: x restricted group ry: y-restricted group')
print('Code - Physical Group')
while True:
usr_input = input('> ')
if len(usr_input) > 1:
if usr_input[0] == 'r' and usr_input[1]==' ':
print('Physical Group {}, fully restricted!'.format(usr_input[-1]))
restricted = int(usr_input[-1])
elif usr_input[0] == 'x' and usr_input[1]==' ':
print('x force in Physical Group {}'.format(usr_input[-1]))
x_force_pos = int(usr_input[-1])
elif usr_input[0] == 'x' and usr_input[1]=='-':
print('Negative x force in Physical Group {}'.format(usr_input[-1]))
neg_x_force_pos = int(usr_input[-1])
elif usr_input[0] == 'r' and usr_input[1]=='x':
print('X restriction for Physical Group {}'.format(usr_input[-1]))
x_restricted = int(usr_input[-1])
elif usr_input[0] == 'r' and usr_input[1]=='y':
print('Y restriction for Physical Group {}'.format(usr_input[-1]))
y_restricted = int(usr_input[-1])
else:
if usr_input == 'q':
exit()
elif usr_input == 'c':
break
else:
print('Incorrect format!')
file = gmesh.read(file_name)
physical_lines = file.find_physical_elements(ElementType=elem_type)
if elem_type == 1:
for i in physical_lines:
if i[0] == restricted:
nodos[i[2]-1], nodos[i[3]-1] = 2, 2
elif i[0] == x_force_pos:
nodos[i[2]-1], nodos[i[3]-1] = 3, 3
elif i[0] == neg_x_force_pos:
nodos[i[2]-1], nodos[i[3]-1] = 4, 4
elif i[0] == x_restricted:
nodos[i[2]-1], nodos[i[3]-1] = 11, 11
elif i[0] == y_restricted:
nodos[i[2]-1], nodos[i[3]-1] = 12, 12
elif elem_type == 2:
for i in physical_lines:
if i[0] == restricted:
nodos[i[2]-1], nodos[i[3]-1], nodos[i[4]-1] = 2, 2, 2
elif i[0] == x_force_pos:
nodos[i[2]-1], nodos[i[3]-1], nodos[i[4]-1] = 3, 3, 3
elif i[0] == neg_x_force_pos:
nodos[i[2]-1], nodos[i[3]-1], nodos[i[4]-1] = 4, 4, 4
elif i[0] == x_restricted:
nodos[i[2]-1], nodos[i[3]-1], nodos[i[4]-1] = 11, 11, 11
elif i[0] == y_restricted:
nodos[i[2]-1], nodos[i[3]-1], nodos[i[4]-1] = 12, 12, 12
if os.path.exists('nodes_selection_file.dat'):
os.remove('nodes_selection_file.dat')
with open('nodes_selection_file.dat', 'a') as file:
file.write('$BoundariesFormat\n')
file.write('v1.0\n')
file.write('$Nodes\n')
file.write(str(num_of_nodes) + '\n')
for node in nodos:
file.write(str(node) + '\n')
file.write('$end\n')
if __name__ == '__main__':
BST(file_name = 'simple_cube1.msh', num_of_nodes = 14, elem_type=2)