v0.14.0
create_mesh_links.py
Go to the documentation of this file.
1 cubit.cmd('reset')
2 cubit.cmd('set developer commands on')
3 cubit.cmd('set duplicate block elements on')
4 
5 one_master_node = False
6 
7 cubit.cmd('brick x 0.5 y 0.05 z 0.02')
8 
9 cubit.cmd('block 1 add volume 1')
10 cubit.cmd('block 1 name "BODY_FORCE"')
11 cubit.cmd('block 1 attribute count 3')
12 cubit.cmd('block 1 attribute index 1 0')
13 cubit.cmd('block 1 attribute index 2 -1 ')
14 cubit.cmd('block 1 attribute index 2 0')
15 
16 cubit.cmd('block 3 add surface 4 ')
17 cubit.cmd('block 3 name "FIX_ALL"')
18 
19 cubit.cmd('block 4 add volume 1')
20 cubit.cmd('block 4 name "MAT_ELASTIC"')
21 cubit.cmd('block 4 attribute count 2')
22 cubit.cmd('block 4 attribute index 1 100')
23 cubit.cmd('block 4 attribute index 2 0.3')
24 
25 cubit.cmd('webcut volume 1 with plane xplane offset 0.05')
26 cubit.cmd('webcut volume 2 with plane xplane offset 0')
27 
28 cubit.cmd('delete volume 2')
29 
30 cubit.cmd('volume all scheme tetmesh')
31 cubit.cmd('surface 22 size auto factor 9')
32 cubit.cmd('mesh surface 22 ')
33 cubit.cmd('volume all size auto factor 8')
34 
35 cubit.cmd('#copy mesh surface 22 onto surface 7 source curve 38 source vertex 22 target curve 15 target vertex 12 mirror ')
36 cubit.cmd('#mesh surface 7')
37 
38 cubit.cmd('surface 7 scheme copy source surface 22 source vertex 22 target vertex 12 source curve 38 target curve 15 ')
39 cubit.cmd('mesh surface 7')
40 cubit.cmd('mesh volume all')
41 
42 
43 node_list1 = cubit.parse_cubit_list("node", "all in surface 22")
44 node_list2 = cubit.parse_cubit_list("node", "all in surface 7")
45 
46 if len(node_list1) != len(node_list2):
47  print("ERROR: node list size in surface 7 and surface 22 are different")
48 
49 if one_master_node == True:
50  node_list2 = node_list2[:1]
51  # cubit.cmd('delete volume 1')
52 
53 
54 edges_ids = []
55 curve_ids = []
56 
57 for id1 in node_list1:
58  shortest_edge = 1e16
59  shortest_id2 = None
60  for id2 in node_list2:
61  cubit.cmd('create edge node {} {}'.format(id1, id2))
62  edge_id = cubit.get_last_id("edge")
63  dist = cubit.get_mesh_edge_length(edge_id)
64  cubit.cmd('delete edge {}'.format(edge_id))
65  if dist < shortest_edge:
66  shortest_id2 = id2
67  shortest_edge = dist
68  if shortest_id2 is not None:
69  cubit.cmd('create curve location at node {} location at node {} '.format(id1, shortest_id2))
70  curve_id = cubit.get_last_id("curve")
71  curve_ids.append(curve_id)
72  #cubit.cmd('create edge node {} {} owner curve {}'.format(id1, shortest_id2, curve_id))
73  # cubit.cmd('create edge node {} {}'.format(id1, shortest_id2))
74  # cubit.cmd('block 4 joint node {} spider node {} element type beam'.format(id1, shortest_id2))
75 
76  edge_id = cubit.get_last_id("edge")
77  edges_ids.append(edge_id)
78 
79 
80 print(curve_ids)
81 print(edges_ids)
82 
83 print("we are done")
84 cubit.cmd('merge all')
85 
86 curve_list = ' '.join(map(str, curve_ids))
87 
88 cubit.cmd('curve {} interval 1'.format(curve_list))
89 cubit.cmd('mesh curve {}'.format(curve_list))
90 cubit.cmd('')
91 
92 #cubit.cmd('disassociate mesh from volume all ')
93 #cubit.cmd('disassociate mesh from curve all ')
94 cubit.cmd('equivalence node all tolerance 0.001 force')
95 #cubit.cmd('delete volume all ')
96 #cubit.cmd('delete curve all ')
97 
98 edge_list2 = cubit.parse_cubit_list("edge", "all in curve {} ".format(curve_list))
99 edge_list = ' '.join(map(str, edges_ids))
100 edge_list = ' '.join(map(str, edge_list2))
101 
102 cubit.cmd('block 4 add edge {}'.format(edge_list))
103 
104 cubit.cmd('block 4 name "MPC_COUPLING_LINKS4"')
105 
106 #renumber Edge all start_id 99999
107 #renumber Edge all start_id 1
108 
109 
110 cubit.cmd('save as "/home/my_user/Desktop/beam3D_MPCs.cub" overwrite')
111 
112 if one_master_node == True:
113  cubit.cmd('delete volume 1')
114  cubit.cmd('create force on vertex 26 vector 1 0 0 0 0 0')
115  cubit.cmd('block 5 add node {}'.format(22))
116  cubit.cmd('block 5 add vertex {}'.format(26))
117  cubit.cmd('block 5 name "MPC_COUPLING_MASTER4"')
118  cubit.cmd('save as "/home/my_user/Desktop/beam3D_MPCs_MASTER_SINGLE.cub" overwrite')
119 
120 
121 #cubit.cmd('block 5 add node all in surface {}'.format(22))
122 cubit.cmd('block 5 add surface {}'.format(22))
123 cubit.cmd('block 5 name "MPC_COUPLING_MASTER4"')
124 
125 #cubit.cmd('block 6 add surface {}'.format(7))
126 #cubit.cmd('block 6 name "MPC_COUPLING_SLAVE4"')
127 
128 
129 cubit.cmd('save as "/home/my_user/Desktop/beam3D_MPCs_MASTER.cub" overwrite')