-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhandle_convergence_issues.py
177 lines (125 loc) · 6.9 KB
/
handle_convergence_issues.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
# Perform the analysis
# ------------------------------------------------------------------------
print("NTHA started.")
# ### RECORDERS
# BaseReactions = 0
# for node in ops.getNodeTags():
# forces = np.array(ops.nodeReaction(node))
# BaseReactions += forces
# eleForces = {}
# for ele in ops.getEleTags():
# forces = ops.eleForce(ele)
# eleForces[ele] = np.array(forces)
# nodalDisps = {}
# for node in ops.getNodeTags():
# disps = ops.nodeDisp(node)
# nodalDisps[node] = np.array(disps)
# NodeForces = {}
# for node in ops.getNodeTags():
# NForces = ops.nodeReaction(node)
# NodeForces[node] = np.array(NForces)
controlTime = ops.getTime() # Update the control time
while cIndex == 0 and controlTime <= Tmax and ok == 0: ## ONEMLI: 500 = GRAVITY ANALYSIS NUMBER OF STEPS
step=step+1
if step%100==0:
print("This is step:",step)
controlTime = ops.getTime() # Update the control time
ok = ops.analyze(1, Dt) # Run a step of the analysis
if ok!=0:
print('Regular Newton failed at time t=%.2f' % controlTime)
print("Trying Newton with Initial Tangent ..")
ops.algorithm('Newton','-initial')
ok = ops.analyze(1, Dt) # Run a step of the analysis
if ok!=0:
controlTime = ops.getTime() # Update the control time
print('"Newton -initial" failed at time t=%.2f' % controlTime)
print("Trying Broyden ..")
ops.algorithm('Broyden',20)
ok = ops.analyze(1, Dt) # Run a step of the analysis
if ok!=0:
print("Trying NewtonwithLineSearch..")
ops.algorithm('NewtonLineSearch',0.8)
ok = ops.analyze(1, Dt) # Run a step of the analysis
if ok!=0:
print("reducing time step.. ")
ops.test('NormDispIncr',1.0e-8,50,1)
ok = ops.analyze(1, Dt/10) # Run a step of the analysis
if ok!=0:
print("reducing tolerance..")
ops.test('NormDispIncr',1.0e-6,50,1)
ok = ops.analyze(1, Dt) # Run a step of the analysis
if ok==0:
print("~~~ Everything looks good! Doing Great!")
else:
print("Sorry for you, keep trying, unsuccessful trial.")
if ok==0:
### RECORDERS
BaseReactions = 0
for node in ops.getNodeTags():
forces = np.array(ops.nodeReaction(node))
BaseReactions += forces
eleForces = {}
for ele in ops.getEleTags():
forces = ops.eleForce(ele)
eleForces[ele] = np.array(forces)
nodalDisps = {}
for node in ops.getNodeTags():
disps = ops.nodeDisp(node)
nodalDisps[node] = np.array(disps)
NodeForces = {}
for node in ops.getNodeTags():
NForces = ops.nodeReaction(node)
NodeForces[node] = np.array(NForces)
# '''
# Filter nodal displacements results dictionary by rigid diaphragm list
# '''
# if ok==0:
Rdnodedisps = { Rdkeys: nodalDisps[Rdkeys] for Rdkeys in Rd_masternodes }
Story_Disps=[]
Story_Drifts=[]
IntersDriftRatio=[]
Story_Disps.append(0)
IntersDriftRatio.append(0)
Story_Heights=[]
for i in range(len(elev)-1):
h=round(elev[i+1]-elev[i],2)
Story_Heights.append(h)
for i in Rd_masternodes:
storydisp=Rdnodedisps[i][GMdirection-1] #x yonundeki deplasman alindi.
Story_Disps.append(storydisp)
# drift=Rdnodedisps[Rdnode][GMdirection-1]-Rdnodedisps[Rdnode+1][GMdirection-1]
for k in range(len(Story_Disps)-1):
story_drift=Story_Disps[k+1]-Story_Disps[k]
Story_Drifts.append(story_drift)
interstoryDriftRatio=story_drift/Story_Heights[k]
IntersDriftRatio.append(interstoryDriftRatio)
IntersDriftRatio=[abs(i) for i in IntersDriftRatio]
max_IntersDriftRatio=max(IntersDriftRatio)
story_number=list(range(len(elev)))
cur_Result={'MIDR':[max_IntersDriftRatio],
'TopDisp':[Story_Disps[-1]],
'IDRlist':IntersDriftRatio,
'story_number':story_number,}
analysis_results[f'ModelNo{model_dictname}_Results'][f'GM ID.{gmID_DD2[gm_no]}']=cur_Result
# Print the final status of the analysis
# ------------------------------------------------------------------------
# if cIndex == -1:
# Analysis = "Analysis is FAILED to converge at %.3f of %.3f" % (controlTime, Tmax)
if ok == 0:
# text = ["\nInterstorey drift: %.4f% at floor %d" % (IntersDriftRatio[i],i) for i in story_number]
Analysis = ''.join([f'ModelNo{model_dictname} GM ID.{gmID_DD2[gm_no]} Analysis is SUCCESSFULLY completed'])
# if cIndex == 1:
# Analysis = "Analysis is STOPPED, peak interstorey drift ratio, %d%%, is exceeded, global COLLAPSE is observed" % Dc
print('------------------------------------------------------------------------')
print(Analysis)
#### DETERMINE THE DURATION OF NTHA ####
print("\nNTHA completed.")
end_NTHA=timer()
duration_NTHA=round(end_NTHA-start_NTHA,2)
print('Time for NTHA:', duration_NTHA,'s')
print(f'Ground Motion No.{gmID_DD2[gm_no]} completed. ')
import json
with open(f'genericframes_story{num_story}_DD2X.json', 'w') as fp:
json.dump(analysis_results, fp, indent=2)
end_time = datetime.now()
print('Duration: {}'.format(end_time - start_time))