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

import logging 

import numpy as num 

from pyrocko.guts import Object, Float, List, StringChoice 

 

logger = logging.getLogger('pyrocko.gf.tractions') 

km = 1e3 

d2r = num.pi/180. 

r2d = 180./num.pi 

 

 

def tukey_window(N, alpha): 

assert alpha <= 1. 

window = num.ones(N) 

n = num.arange(N) 

 

N_f = int((alpha * N)//2) 

window[:N_f] = .5 * (1. - num.cos((2*num.pi * n[:N_f])/(alpha * N))) 

window[(N-N_f):] = window[:N_f][::-1] 

return window 

 

 

def planck_window(N, epsilon): 

assert epsilon <= 1. 

window = num.ones(N) 

n = num.arange(N) 

 

N_f = int((epsilon * N)) 

window[:N_f] = \ 

(1. + num.exp((epsilon * N) / n[:N_f] - 

(epsilon * N) / ((epsilon * N - n[:N_f]))))**-1. 

window[(N-N_f):] = window[:N_f][::-1] 

return window 

 

 

class AbstractTractionField(Object): 

operation = 'mult' 

 

def get_tractions(self, nx, ny, patches): 

raise NotImplementedError 

 

 

class TractionField(AbstractTractionField): 

operation = 'add' 

 

def get_tractions(self, nx, ny, patches): 

raise NotImplementedError 

 

 

class TractionComposition(TractionField): 

 

components = List.T( 

AbstractTractionField.T(), 

default=[], 

help='Ordered list of tractions') 

 

def get_tractions(self, nx, ny, patches=None): 

npatches = nx * ny 

tractions = num.zeros((npatches, 3)) 

 

for comp in self.components: 

if comp.operation == 'add': 

tractions += comp.get_tractions(nx, ny, patches) 

elif comp.operation == 'mult': 

tractions *= comp.get_tractions(nx, ny, patches) 

else: 

raise AttributeError( 

'Component %s has an invalid operation %s.' % 

(comp, comp.operation)) 

 

return tractions 

 

def add_component(self, field): 

logger.debug('adding traction component') 

self.components.append(field) 

 

 

class UniformTractions(TractionField): 

traction = Float.T( 

default=1., 

help='Uniform traction in strike, dip and normal direction [Pa]') 

 

def get_tractions(self, nx, ny, patches=None): 

npatches = nx * ny 

return num.full((npatches, 3), self.traction) 

 

 

class HomogeneousTractions(TractionField): 

strike = Float.T( 

default=1., 

help='Tractions in strike direction [Pa]') 

dip = Float.T( 

default=1., 

help='Traction in dip direction (up) [Pa]') 

normal = Float.T( 

default=1., 

help='Traction in normal direction [Pa]') 

 

def get_tractions(self, nx, ny, patches=None): 

npatches = nx * ny 

 

return num.tile( 

(self.strike, self.dip, self.normal), npatches) \ 

.reshape(-1, 3) 

 

 

class DirectedTractions(TractionField): 

rake = Float.T( 

default=0., 

help='rake angle in [deg], ' 

'measured counter-clockwise from right-horizontal ' 

'in on-plane view. Rake is translated into homogenous tractions ' 

'in strike and up-dip direction.') 

traction = Float.T( 

default=1., 

help='Traction in rake direction [Pa]') 

 

def get_tractions(self, nx, ny, patches=None): 

npatches = nx * ny 

 

strike = num.cos(self.rake*d2r) * self.traction 

dip = num.sin(self.rake*d2r) * self.traction 

normal = 0. 

 

return num.tile((strike, dip, normal), npatches).reshape(-1, 3) 

 

 

class RectangularTaper(AbstractTractionField): 

width = Float.T( 

default=.2, 

help='Width of the taper as a fraction of the plane.') 

type = StringChoice.T( 

choices=('tukey', ), 

default='tukey', 

help='Type of the taper, default "tukey"') 

 

def get_tractions(self, nx, ny, patches=None): 

if self.type == 'tukey': 

x = tukey_window(nx, self.width) 

y = tukey_window(ny, self.width) 

return (x[:, num.newaxis] * y).ravel()[:, num.newaxis] 

 

raise AttributeError('unknown type %s' % self.type) 

 

 

class DepthTaper(AbstractTractionField): 

depth_start = Float.T( 

help='Depth where the taper begins [km]') 

 

depth_stop = Float.T( 

help='Depth where taper stops, and drops to 0. [km]') 

 

type = StringChoice.T( 

choices=('linear', ), 

default='linear', 

help='Type of the taper, default "linear"') 

 

def get_tractions(self, nx, ny, patches): 

assert self.depth_stop > self.depth_start 

depths = num.array([p.depth for p in patches]) 

 

if self.type == 'linear': 

slope = self.depth_stop - self.depth_start 

depths -= self.depth_stop 

depths /= -slope 

depths[depths > 1.] = 1. 

depths[depths < 0.] = 0. 

return depths[:, num.newaxis] 

 

 

def plot_tractions(tractions, nx=15, ny=12, depth=10*km, component='strike'): 

import matplotlib.pyplot as plt 

from pyrocko.modelling.okada import OkadaSource 

 

source = OkadaSource( 

lat=0., 

lon=0., 

depth=depth, 

al1=-20*km, al2=20*km, 

aw1=-15*km, aw2=15*km, 

 

strike=120., dip=90., rake=90., 

slip=5.) 

 

patches, _ = source.discretize(nx, ny) 

tractions = tractions.get_tractions(nx, ny, patches) 

tractions = tractions[:, 0].reshape(nx, ny) 

 

fig = plt.figure() 

ax = fig.gca() 

 

ax.imshow(tractions) 

 

plt.show() 

 

 

if __name__ == '__main__': 

tractions = TractionComposition( 

components=[ 

UniformTractions(traction=45e3), 

RectangularTaper(), 

DepthTaper(depth_start=10.*km, depth_stop=30.*km) 

]) 

 

plot_tractions(tractions)