-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdigital_twin.py
491 lines (420 loc) · 15 KB
/
digital_twin.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# %%
# ---
# jupyter:
# jupytext:
# cell_markers: '"""'
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.9.1
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---
# %% [markdown]
"""
# Defining a Model
This section demonstrates the model definition process.
## Model Definition Overview
The overall procedure for defining the elements of a model can be
broken down into the following steps:
- Set active levels
- Define components
- Execute pre-processing methods
The model can be visualized at any step in the process to confirm its validity.
**To see all the available arguments of each of the following methods,
please read the API reference or their docstrings**.
Alternatively, use the `help()` function inside a python shell.
e.g. `help(mdl.add_level)`
You can also use `pydoc <osmg.name_of_module>` in a terminal window.
"""
# %%
# imports
import numpy as np
from osmg import model
import osmg.defaults as defaults
from osmg.gen.section_gen import SectionGenerator
from osmg.ops.section import ElasticSection
from osmg.gen.component_gen import BeamColumnGenerator
from osmg.ops.element import ElasticBeamColumn
from osmg.graphics.preprocessing_3d import show
# %%
# Instantiate a model
mdl = model.Model('example_model')
# help(mdl.add_level)
# %%
# Define levels. Note: the first floor is index 0; then second floor is
mdl.add_level(1, 0.00) # 1st Floor
mdl.add_level(2, 20*12.00) # 2nd Floor
mdl.add_level(3, (20+14)*12.00) # 3rd Floor
mdl.add_level(4, (34+15)*12.00) # 4th Floor
mdl.add_level(5, (49+15)*12.00) # 5th Floor
for i in range(6,50): # 6th-49th Floor
mdl.add_level(i, (64+13*(i-4))*12.00)
mdl.add_level(50, (64+13*(44)+25)*12.00) # 50th Floor
mdl.add_level(51, (64+13*(44)+25+19)*12.00) # 51st Floor
mdl.add_level(52, (64+13*(44)+25+19+18)*12.00) # 52nd Floor
mdl.add_level(53, (64+13*(44)+25+19+18+18)*12.00) # Roof
# %%
defaults.load_default_steel(mdl)
steel_phys_mat = mdl.physical_materials.retrieve_by_attr(
'name', 'default steel')
# %%
# define line element sections
secg = SectionGenerator(mdl)
secg.load_aisc_from_database(
'W',
["W24X94"],
'default steel',
'default steel',
ElasticSection)
# %%
# Up to 45th floor
mdl.levels.set_active(range(1,46)) # Up to 45th floor
points = 12.0*np.array([[20.0, 0.00 ],
[65.0, 0.00 ],
[68.0, 3.00 ],
[88.0, 3.00 ],
[91.0, 0.00 ],
[136.0, 0.00 ],
[156.0, 20.0 ],
[156.0, 65.0 ],
[153.0, 68.0 ],
[153.0, 88.0 ],
[156.0, 91.0 ],
[156.0, 136.0],
[136.0, 156.0],
[91.0, 156.0],
[88.0, 153.0],
[68.0, 153.0],
[65.0, 156.0],
[20.0, 156.0],
[0.00, 136.0],
[0.00, 91.0 ],
[3.00, 88.0 ],
[3.00, 68.0 ],
[0.00, 65.0 ],
[0.00, 20.0 ],
])
npts = points.shape[0]
mcg = BeamColumnGenerator(mdl)
sec = mdl.elastic_sections.retrieve_by_attr('name', 'W24X94')
for pt in points:
mcg.add_vertical_active(
x_coord=pt[0], y_coord=pt[1],
offset_i=np.zeros(3), offset_j=np.zeros(3),
transf_type='Corotational',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='centroid',
angle=0.00)
for i in range(npts):
if i < npts-1:
pair = (points[i],points[i+1])
else:
pair = (points[i],points[0])
mcg.add_horizontal_active(
xi_coord=pair[0][0],
yi_coord=pair[0][1],
xj_coord=pair[1][0],
yj_coord=pair[1][1],
offset_i=np.zeros(3),
offset_j=np.zeros(3),
snap_i='centroid',
snap_j='centroid',
transf_type='Linear',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='top_center',
angle=0.00)
# %%
# 46th through 50th floor
mdl.levels.set_active(range(46,51)) # 46th through 50th floor
points = 12.0*np.array([[60.0, 10.00 ],
[65.0, 10.00 ],
[68.0, 13.00 ],
[88.0, 13.00 ],
[91.0, 10.00 ],
[96.0, 10.00 ],
[146.0, 60.0 ],
[146.0, 65.0 ],
[143.0, 68.0 ],
[143.0, 88.0 ],
[146.0, 91.0 ],
[146.0, 96.0 ],
[96.0, 146.0],
[91.0, 146.0],
[88.0, 143.0],
[68.0, 143.0],
[65.0, 146.0],
[60.0, 146.0],
[10.00, 96.0 ],
[10.00, 91.0 ],
[13.00, 88.0 ],
[13.00, 68.0 ],
[10.00, 65.0 ],
[10.00, 60.0 ],
])
npts = points.shape[0]
for pt in points:
mcg.add_vertical_active(
x_coord=pt[0], y_coord=pt[1],
offset_i=np.zeros(3), offset_j=np.zeros(3),
transf_type='Corotational',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='centroid',
angle=0.00)
for i in range(npts):
if i < npts-1:
pair = (points[i],points[i+1])
else:
pair = (points[i],points[0])
mcg.add_horizontal_active(
xi_coord=pair[0][0],
yi_coord=pair[0][1],
xj_coord=pair[1][0],
yj_coord=pair[1][1],
offset_i=np.zeros(3),
offset_j=np.zeros(3),
snap_i='centroid',
snap_j='centroid',
transf_type='Linear',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='top_center',
angle=0.00)
# %%
# 51st floor
mdl.levels.set_active([51]) # 51st floor
points = 12.0*np.array([[70.0, 15.0 ],
[86.0, 15.0 ],
[141.0, 73.0 ],
[141.0, 86.0 ],
[86.0, 141.0],
[73.0, 141.0],
[15.0, 86.0 ],
[15.0, 73.0 ],
])
npts = points.shape[0]
for pt in points:
mcg.add_vertical_active(
x_coord=pt[0], y_coord=pt[1],
offset_i=np.zeros(3), offset_j=np.zeros(3),
transf_type='Corotational',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='centroid',
angle=0.00)
for i in range(npts):
if i < npts-1:
pair = (points[i],points[i+1])
else:
pair = (points[i],points[0])
mcg.add_horizontal_active(
xi_coord=pair[0][0],
yi_coord=pair[0][1],
xj_coord=pair[1][0],
yj_coord=pair[1][1],
offset_i=np.zeros(3),
offset_j=np.zeros(3),
snap_i='centroid',
snap_j='centroid',
transf_type='Linear',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='top_center',
angle=0.00)
# %%
# 52nd floor
mdl.levels.set_active([52]) # 52nd floor
points = 12.0*np.array([[73.0, 20.0 ],
[83.0, 20.0 ],
[136.0, 73.0 ],
[136.0, 83.0 ],
[83.0, 136.0],
[73.0, 136.0],
[20.0, 83.0 ],
[20.0, 73.0 ],
])
npts = points.shape[0]
for pt in points:
mcg.add_vertical_active(
x_coord=pt[0], y_coord=pt[1],
offset_i=np.zeros(3), offset_j=np.zeros(3),
transf_type='Corotational',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='centroid',
angle=0.00)
for i in range(npts):
if i < npts-1:
pair = (points[i],points[i+1])
else:
pair = (points[i],points[0])
mcg.add_horizontal_active(
xi_coord=pair[0][0],
yi_coord=pair[0][1],
xj_coord=pair[1][0],
yj_coord=pair[1][1],
offset_i=np.zeros(3),
offset_j=np.zeros(3),
snap_i='centroid',
snap_j='centroid',
transf_type='Linear',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='top_center',
angle=0.00)
# %%
# Roof
mdl.levels.set_active([53]) # Roof
points = 12.0*np.array([[76.0, 25.0 ],
[80.0, 25.0 ],
[131.0, 76.0 ],
[131.0, 80.0 ],
[80.0, 131.0],
[76.0, 131.0],
[25.0, 80.0 ],
[25.0, 76.0 ],
])
npts = points.shape[0]
for pt in points:
mcg.add_vertical_active(
x_coord=pt[0], y_coord=pt[1],
offset_i=np.zeros(3), offset_j=np.zeros(3),
transf_type='Corotational',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='centroid',
angle=0.00)
for i in range(npts):
if i < npts-1:
pair = (points[i],points[i+1])
else:
pair = (points[i],points[0])
mcg.add_horizontal_active(
xi_coord=pair[0][0],
yi_coord=pair[0][1],
xj_coord=pair[1][0],
yj_coord=pair[1][1],
offset_i=np.zeros(3),
offset_j=np.zeros(3),
snap_i='centroid',
snap_j='centroid',
transf_type='Linear',
n_sub=4,
section=sec,
element_type=ElasticBeamColumn,
placement='top_center',
angle=0.00)
# %%
# fixing the base
for node in mdl.levels[1].nodes.values():
node.restraint = [True, True, True, False, False, False]
# %% [markdown]
"""
## Preprocessing
"""
# %% [markdown]
"""
Now that all the intended elements have been defined, we can apply
pre-processing methods to the model.
Some common methods are the following:
* `rigid_diaphragms` assigns rigid diaphragm constraints to all
specified levels. Only primary nodes are affected (not internal
nodes of component assemblies).
* `self_weight`, `self_mass` assign self-weight loads and lumped
self-mass to all the elements / nodes.
Loads, mass, and diaphragm constraints are load_case-specific.
"""
# %%
# imports
from osmg.load_case import LoadCase
from osmg.preprocessing.self_weight_mass import self_weight
from osmg.preprocessing.self_weight_mass import self_mass
# %%
testcase = LoadCase('test', mdl)
# %%
self_weight(mdl, testcase)
self_mass(mdl, testcase)
# %%
testcase.rigid_diaphragms(range(1,53))
# %%
# visualize the model and add mode shapes
fig = show(mdl, testcase, extrude=True, global_axes=False)
fig.update_layout(legend = dict(font=dict(size=20, family="Times")))
fig.write_html("out/twin.html")
import json
with open('out/shape_summary_table.json', 'r') as readfile:
shape_summary_table = json.load(readfile)
shapes = [value['FDD'] for value in shape_summary_table.values()]
dates = list(shape_summary_table.keys())
channel_numbers = [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
instrumented_floors = [14,22,35,49,53]
n_instrumented_floors = len(instrumented_floors)
north_core_channels = [9,11,14,17,20] # Direction 1
north_outr_channels = [9,12,15,18,20] # Direction 1
east_core_channels = [8,10,13,16,19] # Direction 2
core_coordinates = (156.0*12/2, 156.0*12/2)
outr_coordinates = (156.0*12, 156.0*12/2)
import plotly.graph_objects as go
from numpy import array as arr
level_heights = [mdl.levels[level].elevation for level in instrumented_floors]
# list_of_nodes = testcase.parent_nodes.values()
x_core_coords = arr([core_coordinates[0], *[core_coordinates[0] for height in level_heights]])
x_outr_coords = arr([156.0,156.0,156.0,156.0,146.0,131.0])*12
y_coords = arr([core_coordinates[1], *[core_coordinates[1] for height in level_heights]])
z_coords = arr([0, *level_heights])
MODE_SCALE = 2e3
fig.add_trace(go.Scatter3d(x=x_core_coords, y=y_coords, z=z_coords, name=f"core channels", mode="lines", opacity=1, line={'width':8, 'color':'gray'}))
for date,shape in zip(dates,shapes):
# Core
x_shape = x_core_coords + MODE_SCALE*arr([0, *[shape[channel_numbers.index(c)] for c in east_core_channels]])
y_shape = y_coords + MODE_SCALE*arr([0, *[shape[channel_numbers.index(c)] for c in north_core_channels]])
z_shape = z_coords
# fig.add_trace(go.Scatter3d(x=x_shape, y=y_shape, z=z_shape, name="mode shape", mode="lines", line_shape='spline', marker={'color':'red'}, line={'width':10}))
fig.add_trace(go.Scatter3d(x=x_shape, y=y_shape, z=z_shape, name=f"{date}", mode="lines", line={'width':8}))
fig.write_html("out/modes_core.html")
fig = show(mdl, testcase, extrude=True, global_axes=False)
fig.update_layout(legend = dict(font=dict(size=20, family="Times")))
fig.add_trace(go.Scatter3d(x=x_outr_coords, y=y_coords, z=z_coords, name=f"slab edge channels", mode="lines", opacity=1, line={'width':8, 'color':'gray'}))
for date,shape in zip(dates,shapes):
# Outrigger
x_shape = x_outr_coords + MODE_SCALE*arr([0, *[shape[channel_numbers.index(c)] for c in east_core_channels]])
y_shape = y_coords + MODE_SCALE*arr([0, *[shape[channel_numbers.index(c)] for c in north_outr_channels]])
z_shape = z_coords
fig.add_trace(go.Scatter3d(x=x_shape, y=y_shape, z=z_shape, name=f"{date}", mode="lines", line={'width':8}))
fig.write_html("out/modes_slab.html")
# # %%
# # make a modal analysis load case
# modalcase = LoadCase('modal', mdl)
# self_mass(mdl, modalcase)
# modalcase.rigid_diaphragms(range(1,53))
# # %%
# # solve the modal analysis
# from osmg import solver
# modal_analysis = solver.ModalAnalysis(
# mdl, {modalcase.name: modalcase}, num_modes=4)
# modal_analysis.run()
# # %%
# # modal analysis results
# print(modal_analysis.results[modalcase.name].periods)
# # %%
# # mode shapes
# from osmg.graphics.postprocessing_3d import show_deformed_shape
# show_deformed_shape(
# modal_analysis, modalcase.name, 3, 0.00,
# extrude=False, animation=False)
# %%