-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRS_function.py
More file actions
136 lines (115 loc) · 5.54 KB
/
RS_function.py
File metadata and controls
136 lines (115 loc) · 5.54 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
"""
Created on Wed Jul 31 12:23:55 2019
@author: Loic
- Function to compute the response spectra of time series using the Duhamel integral technique.
Inputs:
- data: acceleration data in the time domain
- delta: Sampling rate of the time-series (in Hz)
- T: Output period range in second, Example (if delta>=20 Hz): T = np.concatenate((np.arange(.1, 1, .01), np.arange(1, 20, .1)))
- xi: Damping factor (Standard: 5% -> 0.05)
- Resp_type: Response type, choose between:
- 'SA' : Acceleration Spectra
- 'PSA' : Pseudo-acceleration Spectra
- 'SV' : Velocity Spectra
- 'PSV' : Pseudo-velocity Spectra
- 'SD' : Displacement Spectra
-'PSASD' : Return both Pseudo-acceleration and Displacement Spectra
-'PSAPSVSD' : Return Pseudo-acceleration, Pseudo-velocity and Displacement Spectra
Output:
- Response spectra in the unit specified by 'Resp_type'
"""
import numpy as np
import streamlit as st
@st.cache_data
def RS_function(data, delta, T, xi, Resp_type):
dt = 1/delta
w = 2*np.pi/T
mass = 1 # constant mass (=1)
c = 2*xi*w*mass
wd = w*np.sqrt(1-xi**2)
p1 = np.multiply(data, -mass)
# predefine output matrices
S=np.zeros((3,len(T)))
D1 = np.zeros(len(T))
for j in np.arange(len(T)):
# Duhamel time domain matrix form
I0 = 1/w[j]**2*(1-np.exp(-xi*w[j]*dt)*(xi*w[j]/wd[j]*np.sin(wd[j]*dt)+np.cos(wd[j]*dt)))
J0 = 1/w[j]**2*(xi*w[j]+np.exp(-xi*w[j]*dt)*(-xi*w[j]*np.cos(wd[j]*dt)+wd[j]*np.sin(wd[j]*dt)))
AA = [[np.exp(-xi*w[j]*dt)*(np.cos(wd[j]*dt)+xi*w[j]/wd[j]*np.sin(wd[j]*dt)) , np.exp(-xi*w[j]*dt)*np.sin(wd[j]*dt)/wd[j] ] ,
[-w[j]**2*np.exp(-xi*w[j]*dt)*np.sin(wd[j]*dt)/wd[j] ,np.exp(-xi*w[j]*dt)*(np.cos(wd[j]*dt)-xi*w[j]/wd[j]*np.sin(wd[j]*dt)) ]]
BB = [[I0*(1+xi/w[j]/dt)+J0/w[j]**2/dt-1/w[j]**2 , -xi/w[j]/dt*I0-J0/w[j]**2/dt+1/w[j]**2 ] ,
[J0-(xi*w[j]+1/dt)*I0, I0/dt] ]
u1 = np.zeros(len(data))
udre1 = np.zeros(len(data));
for xx in range(1,len(data),1) :
u1[xx] = AA[0][0]*u1[xx-1] + AA[0][1]*udre1[xx-1] + BB[0][0]*p1[xx-1] + BB[0][1]*p1[xx]
udre1[xx] = AA[1][0]*u1[xx-1] + AA[1][1]*udre1[xx-1] + BB[1][0]*p1[xx-1] + BB[1][1]*p1[xx]
if Resp_type == 'SA':
udd1 = -(w[j]**2*u1+c[j]*udre1)-data # calculate acceleration
S[0,j] = np.max(np.abs(udd1+data))
elif Resp_type == 'PSA':
D1[j] = np.max(np.abs(u1))
S[0,j] = D1[j]*w[j]**2
elif Resp_type == 'SV':
S[0,j] = np.max(np.abs(udre1))
elif Resp_type == 'PSV':
D1[j] = np.max(np.abs(u1))
S[0,j] = D1[j]*w[j]
elif Resp_type == 'SD':
S[0,j] = np.max(np.abs(u1))
elif Resp_type == 'PSASD':
D1[j] = np.max(np.abs(u1))
S[0,j] = D1[j]*w[j]**2
S[1,j] = np.max(np.abs(u1))
elif Resp_type == 'PSAPSVSD':
D1[j] = np.max(np.abs(u1))
S[0,j] = D1[j]*w[j]**2
S[1,j] = D1[j]*w[j]
S[2,j] = np.max(np.abs(u1))
return S
"""
Created on Wed October 22 2025
@author: HXB
Calculates D5-75 as a function of period
1. Calculate response using Duhamel integration for a given SDOF system with unit mass and period
2. Compute Arias intensity of response, normalize and compute D5-75
3. Repeat for next SDOF system with direct period
Inputs:
data = accelation time history
delta = sampling delta period
T = vector of periods for which to compute D5-75
xi = damping ratio
"""
@st.cache_data
def durt_function(data, delta, T, xi):
dt = 1/delta
T1 = np.arange(0.0,len(data)*dt, dt)
w = 2*np.pi/T
mass = 1 # constant mass (=1)
c = 2*xi*w*mass
wd = w*np.sqrt(1-xi**2)
p1 = np.multiply(data, -mass)
# predefine output matrices
S=np.zeros((2,len(T)))
D1 = np.zeros(len(T))
for j in np.arange(len(T)):
# Duhamel time domain matrix form
I0 = 1/w[j]**2*(1-np.exp(-xi*w[j]*dt)*(xi*w[j]/wd[j]*np.sin(wd[j]*dt)+np.cos(wd[j]*dt)))
J0 = 1/w[j]**2*(xi*w[j]+np.exp(-xi*w[j]*dt)*(-xi*w[j]*np.cos(wd[j]*dt)+wd[j]*np.sin(wd[j]*dt)))
AA = [[np.exp(-xi*w[j]*dt)*(np.cos(wd[j]*dt)+xi*w[j]/wd[j]*np.sin(wd[j]*dt)) , np.exp(-xi*w[j]*dt)*np.sin(wd[j]*dt)/wd[j] ] ,
[-w[j]**2*np.exp(-xi*w[j]*dt)*np.sin(wd[j]*dt)/wd[j] ,np.exp(-xi*w[j]*dt)*(np.cos(wd[j]*dt)-xi*w[j]/wd[j]*np.sin(wd[j]*dt)) ]]
BB = [[I0*(1+xi/w[j]/dt)+J0/w[j]**2/dt-1/w[j]**2 , -xi/w[j]/dt*I0-J0/w[j]**2/dt+1/w[j]**2 ] ,
[J0-(xi*w[j]+1/dt)*I0, I0/dt] ]
u1 = np.zeros(len(data))
udre1 = np.zeros(len(data));
for xx in range(1,len(data),1) :
u1[xx] = AA[0][0]*u1[xx-1] + AA[0][1]*udre1[xx-1] + BB[0][0]*p1[xx-1] + BB[0][1]*p1[xx]
udre1[xx] = AA[1][0]*u1[xx-1] + AA[1][1]*udre1[xx-1] + BB[1][0]*p1[xx-1] + BB[1][1]*p1[xx]
udd1 = -(w[j]**2*u1+c[j]*udre1)-data # calculate acceleration
x = udd1+data
arias = np.cumsum(np.square(x)*dt*np.pi/2/980.665/100)
normarias = arias/np.max(arias)
S[0,j] = round(T1[np.argmax(normarias > 0.75)] - T1[np.argmax(normarias > 0.05)],3)
S[1,j] = round(T1[np.argmax(normarias > 0.95)] - T1[np.argmax(normarias > 0.05)],3)
# print(len(data))
return S