-
Notifications
You must be signed in to change notification settings - Fork 2
/
model_change.py
205 lines (175 loc) · 7.79 KB
/
model_change.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!python
from numpy import cos,sin,arccos
import numpy as np
import cubit
cubit.init()
cubit.cmd("reset")
cubit.cmd("undo off")
def check_if_enclosed(vid1,vid2):
v1 = cubit.volume(vid1)
v2 = cubit.volume(vid2)
b_box1 = v1.bounding_box()
b_box2 = v2.bounding_box()
for i in range(3):
if b_box1[i] > b_box2[i]:
return False
if b_box1[i+3] < b_box2[i+3]:
return False
return True
def split_bodies():
body_list = cubit.get_entities("body")
for b in body_list:
if cubit.is_multi_volume(b):
cubit.cmd(f"split body {b}")
return True
def parametric_circle(t,xc,yc,R):
x = xc + R*cos(t)
y = yc + R*sin(t)
return x,y
plate_x = 200
plate_y = 100
plate_z = 5
cube_x = 5
cube_y = 5
cube_z = 5
cubit.cmd("create brick x " + str(plate_x) + " y " + str(plate_y) + " z " + str(plate_z))
cubit.cmd("create brick x " + str(cube_x) + " y " + str(cube_y) + " z " + str(cube_z))
cubit.cmd("move Volume 1 location " + str(plate_x/2) + " " + str(plate_y/2) + " " + str(plate_z/2))
cubit.cmd("move Volume 2 location " + str(cube_x/2 + plate_x/3 - plate_x/8) + " " + str(plate_y/2) + " " + str(plate_z + cube_z/2))
N = 25
R = plate_y*1/3
xc = 0
yc = 0
arc_T = np.linspace(3.14159265359/2, 3.14159265359*3/2, N)
X,Y = parametric_circle(arc_T, xc, yc, R)
vid = 0
for i in range(N):
cubit.cmd("Volume 2 copy move x " + str(X[i]) + " y " + str(Y[i]) + " z " + str(0))
vid_last = vid
vid = cubit.get_last_id( "volume")
if i!=0:
cubit.cmd(f"subtract volume {vid} from volume {vid_last} keep_tool")
cubit.cmd("move Volume 2 location " + str(cube_x/2 + plate_x*2/3 - plate_x/8) + " " + str(plate_y/2) + " " + str(plate_z + cube_z/2))
vid=0
for i in range(N):
cubit.cmd("Volume 2 copy move x " + str(X[i]) + " y " + str(Y[i]) + " z " + str(0))
vid_last = vid
vid = cubit.get_last_id( "volume")
if i!=0:
cubit.cmd(f"subtract volume {vid} from volume {vid_last} keep_tool")
vid=0
cubit.cmd("move Volume 2 location " + str(cube_x/2 + plate_x*4/5) + " " + str(plate_y/2) + " " + str(plate_z + cube_z/2))
X = np.linspace(-plate_y*1/5, plate_y*1/5, N)
Y = np.linspace(-plate_y*1/3, plate_y*1/3, N)
for i in range(N):
cubit.cmd("Volume 2 copy move x " + str(X[i]) + " y " + str(Y[i]) + " z " + str(0))
vid_last = vid
vid = cubit.get_last_id( "volume")
if i!=0:
cubit.cmd(f"subtract volume {vid} from volume {vid_last} keep_tool")
X = np.linspace(-plate_y*1/5, plate_y*1/5, N)
Y = np.linspace(plate_y*1/3, -plate_y*1/3, N)
for i in range(N):
cubit.cmd("Volume 2 copy move x " + str(X[i]) + " y " + str(Y[i]) + " z " + str(0))
vid = cubit.get_last_id("volume")
if i!=0:
overlapping_volumes = cubit.get_overlapping_volumes_at_volume(vid,cubit.get_entities("volume"))
for ov in overlapping_volumes:
if ov!=1 and ov!=2:
split_bodies()
if check_if_enclosed(vid,ov):
cubit.cmd(f"delete volume {ov}")
else:
cubit.cmd(f"subtract volume {vid} from volume {ov} keep_tool")
cubit.cmd("delete vol 2")
cubit.cmd("imprint vol all")
cubit.cmd("merge vol all")
cubit.cmd("vol all except 1 size 2.5")
cubit.cmd("vol 1 size 10")
cubit.cmd("surface all with z_coord = "+str(plate_z + cube_z)+" scheme pave")
cubit.cmd("mesh surface all with z_coord = "+ str(plate_z + cube_z))
cubit.cmd("mesh vol all except 1")
cubit.cmd("surface all in volume 1 with z_coord >= " + str(plate_z) +" scheme pave")
cubit.cmd("mesh surface all with z_coord >= "+str(plate_z))
cubit.cmd("mesh vol 1")
cubit.cmd("compress")
volume_list = cubit.get_entities("volume")
for v in volume_list:
cubit.cmd(f"block {v} add vol {v}")
cubit.cmd(f"nodeset {v} add vol {v}")
cubit.cmd(f"sideset {v} add surface all in vol 1 to {v} with is_merged = 0")
#material
cubit.cmd('create material "solid" property_group "CalculiX-FEA"')
cubit.cmd('modify material "solid" scalar_properties "CCX_ELASTIC_ISO_USE_CARD" 1')
cubit.cmd('modify material "solid" scalar_properties "CCX_PLASTIC_ISO_USE_CARD" 1')
cubit.cmd('modify material "solid" scalar_properties "CCX_DENSITY_USE_CARD" 1')
cubit.cmd('modify material "solid" matrix_property "CCX_DENSITY_DENSITY" 8 0 ')
cubit.cmd('modify material "solid" scalar_properties "CCX_SPECIFIC_HEAT_USE_CARD" 1')
cubit.cmd('modify material "solid" matrix_property "CCX_SPECIFIC_HEAT_SPECIFIC_HEAT" 420 0 ')
cubit.cmd('modify material "solid" scalar_properties "CCX_EXPANSION_ISO_USE_CARD" 1')
cubit.cmd('modify material "solid" scalar_properties "CCX_CONDUCTIVITY_USE_CARD" 1')
cubit.cmd('modify material "solid" scalar_properties "CCX_CONDUCTIVITY_ISO_USE_CARD" 1')
cubit.cmd('modify material "solid" matrix_property "CCX_CONDUCTIVITY_ISO_K_TEMPERATURE" 50 0 ')
cubit.cmd('modify material "solid" scalar_properties "CCX_ELASTIC_USE_CARD" 1')
cubit.cmd('modify material "solid" matrix_property "CCX_ELASTIC_ISO_MODULUS_VS_POISSON_VS_TEMPERATURE" 210000 0.3 0')
#section
cubit.cmd('ccx create section solid block all material 1')
#heatflux and initial temperature
volume_list = cubit.get_entities("volume")
for v in volume_list:
cubit.cmd(f"create heatflux on sideset {v} value -7.5")
#cubit.cmd(f"ccx modify heatflux {v} op new")
if v == 1:
cubit.cmd(f"create temperature on volume all value 100")
else:
cubit.cmd(f"create temperature on volume {v} value 2000")
cubit.cmd(f"ccx modify temperature {v} op new")
#cubit.cmd("modify temperature 1 value 100")
# field outputs
cubit.cmd('ccx create fieldoutput name "fo_node" node')
cubit.cmd('ccx modify fieldoutput 1 node frequency 1')
cubit.cmd('ccx modify fieldoutput 1 node key_on NT')
cubit.cmd('ccx modify fieldoutput 1 node key_off CP U DEPF DEPT DTF HCRI KEQ MACH MAXU MF PNT POT PRF PS PSF PT PTF PU RF RFL SEN TS TSF TT TTF TURB V VF ')
cubit.cmd('ccx create fieldoutput name "fo_element" element')
cubit.cmd('ccx modify fieldoutput 2 element frequency 1')
cubit.cmd('ccx modify fieldoutput 2 element key_on HFL')
cubit.cmd('ccx modify fieldoutput 2 element key_off CEEQ S E ECD EMFB EMFE ENER ERR HER HFLF MAXE MAXS ME PEEQ PHS SF SMID SNEG SPOS SVF SDV THE ZZS ')
# initial conditions
cubit.cmd("ccx create initialcondition temperature")
cubit.cmd(f"ccx modify initialcondition {1} temperature bc_id {1}")
cubit.cmd("ccx create step name 'dummy_step' heattransfer")
cubit.cmd("ccx step 1 add fieldoutput 1 2")
cubit.cmd("ccx step 1 add bc temperature 1")
cubit.cmd("ccx create step name 'deacivate_step' static")
cubit.cmd("ccx step 2 add fieldoutput 1 2")
cubit.cmd("ccx modify step 2 parameter nlgeom_yes")
cubit.cmd("ccx create customline name 'step_2_top' after step_begin item_id 2 cline '*MODEL CHANGE,TYPE=ELEMENT,REMOVE'")
volume_list = cubit.get_entities("volume")
for v in volume_list:
if v >1:
cubit.cmd(f"ccx create customline name '{v}' after step_begin item_id 2 cline 'Block_{v}'")
cs = 2
volume_list = cubit.get_entities("volume")
for v in volume_list:
# if v > 1 and v < 3:
if v > 1:
cs = cs + 1
cubit.cmd(f"ccx create step name 'heat_{cs}' heattransfer")
cubit.cmd(f"ccx modify step {cs} heattransfer initialtimeincrement 10 timeperiodofstep 10 minimumtimeincrement 1e-5 maximumtimeincrement 10")
cubit.cmd(f"ccx step {cs} add load heatflux {v}")
cubit.cmd(f"ccx step {cs} add bc temperature {v}")
cubit.cmd(f"ccx step {cs} add fieldoutput 1 2")
cubit.cmd(f"ccx create customline name 'step_{cs}_top' after step_begin item_id {cs} cline '*MODEL CHANGE,TYPE=ELEMENT,ADD'")
cubit.cmd(f"ccx create customline name '{v}' after step_begin item_id {cs} cline 'Block_{v}'")
cs = cs + 1
cubit.cmd(f"ccx create step name 'heat_{cs}' heattransfer")
cubit.cmd(f"ccx modify step {cs} heattransfer initialtimeincrement 10 timeperiodofstep 20 minimumtimeincrement 1e-5 maximumtimeincrement 10")
cubit.cmd(f"ccx step {cs} add load heatflux {v}")
cubit.cmd(f"ccx step {cs} add fieldoutput 1 2")
cubit.cmd("ccx create job name 'model_change'")
print("ccx run job 1 no_conversion")
command = ("ccx result convert job 1 block ")
for v in volume_list:
command = command + str(v) + " "
command = command + " partial"
print(command)