-
Notifications
You must be signed in to change notification settings - Fork 12
/
vDefTempBC.py
executable file
·126 lines (109 loc) · 4.99 KB
/
vDefTempBC.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
#!/usr/bin/env python
import sys
def parse(args=None):
import argparse
### Get options from the command line
parser = argparse.ArgumentParser(description='Compute boundary displacement for a surfing computation')
parser.add_argument('-i','--inputfile',help='input file',default=None)
parser.add_argument('-o','--outputfile',help='output file',default=None)
parser.add_argument("--time_min",type=float,help="first time step",default=0.)
parser.add_argument("--time_max",type=float,help="last time step",default=1.)
parser.add_argument("--time_numstep",type=int,help="number of time step",default=11)
parser.add_argument("--tmin",type=float,help="Min. Temp.",default=20.)
parser.add_argument("--tmax",type=float,help="Max. Temp.",default=60.)
parser.add_argument("--lc",type=float,help="Characteristic width",default=.1)
return parser.parse_args()
def exoformat(e):
global_variable_name = ["Elastic Energy","Work","Surface Energy","Total Energy"]
if e.num_dimensions() == 2:
node_variable_name = ["Temperature","Damage","Displacement_X","Displacement_Y"]
element_variable_name = ["External_Temperature","Heat_Flux","Pressure_Force",
"Force_X","Force_Y",
"Stress_XX","Stress_YY","Stress_XY"]
else:
node_variable_name = ["Temperature","Damage","Displacement_X","Displacement_Y","Displacement_Z"]
element_variable_name = ["External_Temperature","Heat_Flux","Pressure_Force",
"Force_X","Force_Y","Force_Z",
"Stress_XX","Stress_YY","Stress_ZZ","Stress_YZ","Stress_XZ","Stress_XY"]
e.set_global_variable_number(0)
e.set_node_variable_number(len(node_variable_name))
for i in range(len(node_variable_name)):
e.put_node_variable_name(node_variable_name[i],i+1)
e.set_element_variable_number(len(element_variable_name))
for i in range(len(element_variable_name)):
e.put_element_variable_name(element_variable_name[i],i+1)
e.set_element_variable_truth_table([True] * e.numElemBlk.value * len(element_variable_name))
return(0)
def cart2polar(x, y):
import numpy as np
r = np.sqrt(x**2 + y**2)
theta = np.arctan2(y, x)
return r, theta
def surfingBC(e,t,Xc,cslist,vslist,E,nu,ampl):
import exodus as exo
import numpy as np
kappa = (3.0-nu)/(1.0+nu)
mu = E / (1. + nu) * .5
dim = e.num_dimensions()
X,Y,Z=e.get_coords()
U = np.zeros([3,len(X)],dtype=exo.c_double)
csoffset = [e.elem_blk_info(set)[1] for set in cslist]
for set in get_elem_blk_ids:
connect = e.get_elem_connectivity(set)
for cid in range(connect[1]):
vertices = [connect[0][cid*connect[2]+c] for c in range(connect[2])]
for v in vertices:
r,theta = cart2polar(X[v-1]-Xc[0]-t,Y[v-1]-Xc[1])
z = Z[v-1]-Xc[2]
U[0,v-1] = ampl * np.sqrt(r / np.pi * .5) / mu * .5 * np.cos(theta * .5) * (kappa - np.cos(theta))
U[1,v-1] = ampl * np.sqrt(r / np.pi * .5) / mu * .5 * np.sin(theta * .5) * (kappa - np.cos(theta))
U[2,v-1] = 0.0
for set in vslist:
for v in e.get_node_set_nodes(set):
r,theta = cart2polar(X[v-1]-xc-t,Y[v-1]-yc)
z = Z[v-1]
U[0,v-1] = ampl * np.sqrt(r / np.pi * .5) / mu * .5 * np.cos(theta * .5) * (kappa - np.cos(theta))
U[1,v-1] = ampl * np.sqrt(r / np.pi * .5) / mu * .5 * np.sin(theta * .5) * (kappa - np.cos(theta))
U[2,v-1] = 0.0
return U
def temperature(e,time,Tmin,Tmax,lc):
import exodus as exo
import numpy as np
dim = e.num_dimensions()
X,Y,Z=e.get_coords()
T = np.zeros([len(X)],dtype=exo.c_double)
for set in e.get_elem_blk_ids():
connect = e.get_elem_connectivity(set)
for cid in range(connect[1]):
vertices = [connect[0][cid*connect[2]+c] for c in range(connect[2])]
for v in vertices:
x = np.abs(X[v-1])
if x > lc:
T[v-1] = Tmin
else:
T[v-1] = Tmin + (time*(Tmax - Tmin)) * (lc-x) / lc
return T
def main():
import exodus as exo
import numpy as np
options = parse()
print options.inputfile
exoin = exo.exodus(options.inputfile,mode='r')
exoout = exoin.copy(options.outputfile)
exoin.close()
exoformat(exoout)
dim = exoout.num_dimensions()
step = 0
for t in np.linspace(options.time_min,options.time_max,options.time_numstep):
print "writing step",step+1,t
exoout.put_time(step+1,t)
T = temperature(exoout,t,options.tmin,options.tmax,options.lc)
X,Y,Z=exoout.get_coords()
exoout.put_node_variable_values("Temperature",step+1,T)
step += 1
exoout.close()
###
### compute boundary displacement at vertex sets
###
if __name__ == "__main__":
sys.exit(main())