-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement_matrices.py
More file actions
218 lines (145 loc) · 6.41 KB
/
element_matrices.py
File metadata and controls
218 lines (145 loc) · 6.41 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
import numpy as np
from sympy import *
#from IPython.display import display
def element_matrices(scaling):
"""
Calculates the element matrices used to construct the global system matrix.
In our case we assume linear rectangular elements with local indexing:
1 2
3 4.
@ scaling: size scale of the problem, i.e. 1e-9 we work in nanometers.
"""
a = scaling / 2 # Element size scaling
b = scaling / 2 # Element size scaling
def ip_quad_2o(a,b):
"""
Implementation for the interpolation functions of first order for linear rectangular elements.
In our case we assume linear rectangular elements with local indexing:
7 6 5
8 4
1 2 3
@ a: side of the rectangle in the X direction.
@ b: side of the rectangle in the Y direction.
"""
N_1 = lambda x,y: -0.25 * (1-x/a) * (1-y/b) * (1+x/a+y/b)
N_2 = lambda x,y: 0.5 * (1-x/a) * (1+x/a) * (1-y/b)
N_3 = lambda x,y: -0.25 * (1+x/a) * (1-y/b) * (1-x/a+y/b)
N_4 = lambda x,y: 0.5 * (1+x/a) * (1+y/b) * (1-y/b)
N_5 = lambda x,y: -0.25 * (1+x/a) * (1+y/b) * (1-x/a-y/b)
N_6 = lambda x,y: 0.5 * (1-x/a) * (1+x/a) * (1+y/b)
N_7 = lambda x,y: -0.25 * (1-x/a) * (1+y/b) * (1+x/a-y/b)
N_8 = lambda x,y: 0.5 * (1-x/a) * (1+y/b) * (1-y/b)
return N_1, N_2, N_3, N_4, N_5, N_6, N_7, N_8
def ip_edge_1o (a):
N_1 = lambda x,y: (1/(2*a)) * np.array([ a - y, 0.0])
N_2 = lambda x,y: (1/(2*a)) * np.array([ a + y, 0.0])
N_3 = lambda x,y: (1/(2*a)) * np.array([0.0, a - x])
N_4 = lambda x,y: (1/(2*a)) * np.array([0.0, a + x])
return N_1, N_2, N_3, N_4
def ip_edge_1o_dx (a):
N_1 = lambda x,y: (1/(2*a)) * np.array([0.0, 0.0])
N_2 = lambda x,y: (1/(2*a)) * np.array([0.0, 0.0])
N_3 = lambda x,y: (1/(2*a)) * np.array([0.0, -1.0])
N_4 = lambda x,y: (1/(2*a)) * np.array([0.0, 1.0])
return N_1, N_2, N_3, N_4
def ip_edge_1o_dy (a):
N_1 = lambda x,y: (1/(2*a)) * np.array([-1.0, 0.0])
N_2 = lambda x,y: (1/(2*a)) * np.array([1.0, 0.0])
N_3 = lambda x,y: (1/(2*a)) * np.array([0.0, 0.0])
N_4 = lambda x,y: (1/(2*a)) * np.array([0.0, 0.0])
return N_1, N_2, N_3, N_4
def calculate_integral(f, a, b):
"""
Function to calculate surface integrals in two dimensional spaces.
@
@ a: side of the rectangle in the X direction (i.e. start/end of integration domain).
@ b: side of the rectangle in the Y direction (i.e. start/end of integration domain).
"""
import scipy.integrate as integrate
return integrate.dblquad(f, -a, a, -b, b)
# -----------------------------------------------------------------------------------
# CACULATION OF THE A AND A' MATRICES
# -----------------------------------------------------------------------------------
ipf = list(ip_quad_2o(a,b)) # initialize the interpolation functions
ipf_dx = []
ipf_dy = []
x, y = symbols('x y')
for i in range(8):
ipf_dx.append(lambdify((x,y), ipf[i](x,y).diff(x)))
ipf_dy.append(lambdify((x,y), ipf[i](x,y).diff(y)))
ipf_edge = list(ip_edge_1o(a))
ipf_edge_dx = list(ip_edge_1o_dx(a))
ipf_edge_dy = list(ip_edge_1o_dy(a))
E = np.ones((4,4), dtype="complex128") # matrix for rectangular edge elements in Ming
# CHANGED INDICES WITH NEW LOCAL NUMBERING
E [0,1] = -1.0
E [1,0] = -1.0
E [0,2] = -1.0
E [2,0] = -1.0
E [3,1] = -1.0
E [1,3] = -1.0
E [3,2] = -1.0
E [2,3] = -1.0
F = np.zeros((4,4), dtype="complex128") # matrix for rectangular edge elements in Ming
fac = (4*a**2) / 6
F [0,0] = fac * 2
F [1,1] = fac * 2
F [2,2] = fac * 2
F [3,3] = fac * 2
F [0,1] = fac
F [1,0] = fac
F [2,3] = fac
F [3,2] = fac
E = np.zeros((4,4), dtype="complex128")
F = np.zeros((4,4), dtype="complex128")
BZT = np.zeros((8,4), dtype="complex128")
BTZ = np.zeros((4,8), dtype="complex128")
ZZ1 = np.zeros((8,8), dtype="complex128")
ZZ2 = np.zeros((8,8), dtype="complex128")
for i in range(4):
for j in range(4):
integrand_E = lambda x, y : (ipf_edge_dx [i] (x,y) [1] - ipf_edge_dy [i] (x,y) [0]) * (ipf_edge_dx [j] (x,y) [1] - ipf_edge_dy [j] (x,y) [0])
integrand_F = lambda x, y : np.dot(ipf_edge [i] (x,y), ipf_edge [j] (x,y))
F [i,j] = calculate_integral(integrand_F, a, b) [0]
E [i,j] = calculate_integral(integrand_E, a, b) [0]
for i in range(4):
for j in range(8):
integrand_btz = lambda x, y : np.dot(ipf_edge [i] (x,y), np.array([ipf_dx [j] (x,y), ipf_dy [j] (x,y)]))
BTZ [i,j] = calculate_integral(integrand_btz, a, b) [0]
for i in range(8):
for j in range(4):
integrand_bzt = lambda x, y : np.dot(np.array([ipf_dx [i] (x,y), ipf_dy [i] (x,y)]), ipf_edge [j] (x,y))
BZT [i,j] = calculate_integral(integrand_bzt, a, b) [0]
for i in range(8):
for j in range(8):
integrand_bzz1 = lambda x, y : np.dot(np.array([ipf_dx [i] (x,y), ipf_dy [i] (x,y)]), np.array([ipf_dx [j] (x,y), ipf_dy [j] (x,y)]))
integrand_bzz2 = lambda x, y : ipf [i] (x,y) * ipf [j] (x,y)
ZZ1 [i,j] = calculate_integral(integrand_bzz1, a, b) [0]
ZZ2 [i,j] = calculate_integral(integrand_bzz2, a, b) [0]
return E, F, BZT.T, BTZ.T, ZZ1, ZZ2
def ip_edge_1o (a):
N_1 = lambda x,y: (1/(2*a)) * np.array([ a - y, 0.0])
N_2 = lambda x,y: (1/(2*a)) * np.array([ a + y, 0.0])
N_3 = lambda x,y: (1/(2*a)) * np.array([0.0, a - x])
N_4 = lambda x,y: (1/(2*a)) * np.array([0.0, a + x])
return N_1, N_2, N_3, N_4
def evaluate_edge_at_el(scaling, ets1, ets2, ets3, ets4):
a = scaling / 2
N_1, N_2, N_3, N_4 = ip_edge_1o (a)
# node 0
x0 = -a
y0 = a
et1 = ets1 * N_1(x0,y0) + ets2 * N_2(x0,y0) + ets3 * N_3(x0,y0) + ets4 * N_4(x0,y0)
# node 1
x0 = a
y0 = a
et2 = ets1 * N_1(x0,y0) + ets2 * N_2(x0,y0) + ets3 * N_3(x0,y0) + ets4 * N_4(x0,y0)
# node 2
x0 = -a
y0 = -a
et3 = ets1 * N_1(x0,y0) + ets2 * N_2(x0,y0) + ets3 * N_3(x0,y0) + ets4 * N_4(x0,y0)
# node 3
x0 = a
y0 = -a
et4 = ets1 * N_1(x0,y0) + ets2 * N_2(x0,y0) + ets3 * N_3(x0,y0) + ets4 * N_4(x0,y0)
return et1, et2, et3, et4