-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcomputeRayleighEquations.py
executable file
·235 lines (193 loc) · 9.05 KB
/
computeRayleighEquations.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 23 08:56:44 2019
Creates a unit normalized field of Rayleigh damping (picture frame)
Works the old fashioned way with lots of nested loops... so sue me!
@author: -
"""
import math as mt
import numpy as np
import bottleneck as bn
import scipy.special as ssp
import scipy.sparse as sps
checkPlots = False
def computeRayleighField(DIMS, X, Z, height, width, applyTop, applyLateral):
# Get DIMS data
L1 = DIMS[0]
L2 = DIMS[1]
ZH = DIMS[2]
RP = 2.0
T1 = 0.1
S1 = 0.25 / (1.0 - T1)
# Get domain data
NX = X.shape[1]
NZ = Z.shape[0]
RF = 0.1
FM = 1.0
# Set the layer bounds
width2 = width * (1.0 - RF * np.sin(FM * mt.pi / ZH * Z[:,-1]))
dLayerR = L2 - width2
width1 = width * (1.0 - RF * np.sin(FM * mt.pi / ZH * Z[:,0]))
dLayerL = L1 + width1
shift = 0.5 * abs(L2 - L1)
depth = ZH - height
depth *= (1.0 + RF * np.sin(FM * mt.pi / (L2 - L1) * (X[-1,:] - shift)))
dLayerZ = ZH - depth
# Assemble the Rayleigh field
RL_inl = np.zeros((NZ, NX))
RL_inr = np.zeros((NZ, NX))
RL_top = np.zeros((NZ, NX))
RL_all = np.zeros((NZ, NX))
for ii in range(0,NZ):
for jj in range(0,NX):
# Get this X location
XRL = X[ii,jj]
ZRL = Z[ii,jj]
if applyLateral:
RFX1 = 0.0
RFX2 = 0.0
# Left layer or right layer or not? [1 0]
if XRL > dLayerR[ii]:
dNormX = 2.0 * S1 * mt.pi * ((L2 - XRL) / width2[ii] - T1)
RFX1 = 0.0
#RFX2 = 1.0 / (1.0 + (mt.tan(dNormX))**RP)
#'''
if dNormX > 0.0:
RFX2 = 1.0 / (1.0 + (mt.tan(dNormX))**RP)
elif dNormX <= 0.0:
RFX2 = 1.0
#'''
elif XRL < dLayerL[ii]:
dNormX = 2.0 * S1 * mt.pi * ((XRL - L1) / width1[ii] - T1)
#RFX1 = 1.0 / (1.0 + (mt.tan(dNormX))**RP)
RFX2 = 0.0
#'''
if dNormX > 0.0:
RFX1 = 1.0 / (1.0 + (mt.tan(dNormX))**RP)
elif dNormX <= 0.0:
RFX1 = 1.0
#'''
else:
dNormX = 1.0
RFX1 = 0.0
RFX2 = 0.0
else:
RFX1 = 0.0
RFX2 = 0.0
if applyTop:
# In the top layer?
if ZRL > dLayerZ[jj]:
# This maps [depth ZH] to [1 0]
dNormZ = 2.0 * S1 * mt.pi * ((ZH - ZRL) / depth[jj] - T1)
if dNormZ > 0.0:
RFZ = 1.0 / (1.0 + (mt.tan(dNormZ))**RP)
elif dNormZ <= 0.0:
RFZ = 1.0
else:
dNormZ = 1.0
RFZ = 0.0
else:
RFZ = 0.0
if RFX1 < 0.0:
RFX1 = 0.0
if RFX2 < 0.0:
RFX2 = 0.0
if RFZ < 0.0:
RFZ = 0.0
# Absorption to the inflow lateral boundary
RL_inl[ii,jj] = RFX1
# Absorption to the outflow lateral boundary
RL_inr[ii,jj] = RFX2
# Absorption to the model top boundary
RL_top[ii,jj] = RFZ
# Complete absorption frame
RL_all[ii,jj] = bn.nanmax([RFX1, RFX2, RFZ])
'''
RL_all[ii,jj] = ssp.logsumexp([RFX1, RFX2, RFZ]) - mt.log(3.0)
rlyr = np.array([RFX1, RFX2, RFZ])
rmax = bn.nanmax(rlyr)
nnz = np.flatnonzero(rlyr)
if nnz.shape[0] > 1:
RL_all[ii,jj] = rmax + \
mt.log(np.exp(rlyr[nnz] - rmax).sum()) - \
mt.log(nnz.shape[0])
else:
RL_all[ii,jj] = rmax
'''
# Assemble the Grid Matching Layer field X and Z directions
GML = np.ones((NZ, NX))
GMLX1 = np.ones((NZ, NX))
GMLX2 = np.ones((NZ, NX))
GMLZ = np.ones((NZ, NX))
def sigma_func(x):
eps = 0.0
p = 4.0
q = 4.0
sf = (1.0 - eps) * np.power(1.0 - np.power(1.0 - x, p), q)
return sf
for ii in range(0,NZ):
for jj in range(0,NX):
# Get this X location
XRL = X[ii,jj]
ZRL = Z[ii,jj]
if applyLateral:
# Left layer or right layer or not? [0 1]
if XRL > dLayerR[ii]:
GFX1 = 0.0
dNormX = (XRL - dLayerR[ii]) / width2[ii]
GFX2 = sigma_func(dNormX)
elif XRL < dLayerL[ii]:
GFX2 = 0.0
dNormX = (dLayerL[ii] - XRL) / width1[ii]
GFX1 = sigma_func(dNormX)
else:
dNormX = 0.0
GFX1 = 0.0
GFX2 = 0.0
else:
GFX1 = 0.0
GFX2 = 0.0
if applyTop:
# In the top layer?
if ZRL > dLayerZ[jj]:
dNormZ = (ZRL - dLayerZ[jj]) / depth[jj]
GFZ = sigma_func(dNormZ)
else:
GFZ = 0.0
else:
GFZ = 0.0
GMLX2[ii,jj] = (1.0 - GFX2)
GMLZ[ii,jj] = (1.0 - GFZ)
# Set the field to max(lateral, top) to handle corners
GML[ii,jj] = np.amin([GMLX2[ii,jj], GMLZ[ii,jj]])
if checkPlots:
from matplotlib import cm
import matplotlib.pyplot as plt
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ax.plot_surface(X, Z, RL_all, cmap=cm.jet,
linewidth=0, antialiased=False)
plt.show()
input('CHECK BOUNDARY LAYERS...')
return (GML, GMLX2, GMLZ), (RL_inl, RL_inr, RL_top, RL_all)
def computeRayleighEquations(DIMS, X, Z, depth, RLOPT):
# Get options data
width = RLOPT[1]
applyTop = RLOPT[2]
applyLateral = RLOPT[3]
# Set up the Rayleigh field
GL, RL = computeRayleighField(DIMS, X, Z, depth, width, \
applyTop, applyLateral)
# Compute the diagonal for full Rayleigh field as matrices
OPS = RL[0].shape[0] * RL[0].shape[1]
rl1 = np.reshape(RL[0], (OPS,1), order='F')
RLML = np.hstack((rl1,rl1,rl1,rl1))
rl2 = np.reshape(RL[1], (OPS,1), order='F')
RLMR = np.hstack((rl2,rl2,rl2,rl2))
rl3 = np.reshape(RL[2], (OPS,1), order='F')
RLMT = np.hstack((rl3,rl3,rl3,rl3))
RLMA = np.reshape(RL[3], (OPS,1), order='F')
GLM = sps.spdiags(np.reshape(GL[0], (OPS,), order='F'), 0, OPS, OPS)
GLMX = sps.spdiags(np.reshape(GL[1], (OPS,), order='F'), 0, OPS, OPS)
GLMZ = sps.spdiags(np.reshape(GL[2], (OPS,), order='F'), 0, OPS, OPS)
return [RLML, RLMR, RLMT, RLMA], (GLM, GLMX, GLMZ)