!pip install PyniteFEA[all]
from google.colab import drive
drive.mount('/content/drive')
from Pynite import FEModel3D
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
data_file=open("/content/drive/My Drive/Colab Notebooks/elcentro.csv","r")
data_list = pd.read_csv(data_file, header=None)
data_array = data_list.values
plt.plot(data_array)
dt=0.02; m=1
# 모델 생성
model = FEModel3D()
# Add nodes (meter)
model.add_node('N1', 0, 0, 0)
model.add_node('N2', 0, 0, 2)
model.add_node('N3', 2, 0, 2)
model.add_node('N4', 2, 0, 0)
# Define a material
E = 30000000 # Modulus of elasticity (MPa)
G = 11200000 # Shear modulus of elasticity (MPa)
nu = 0.3 # Poisson's ratio
rho = 2500 # Density (kci)
model.add_material('Concrete', E, G, nu, rho)
# Add a section with the following properties:
# A = 0.09 m^2, Iy = 0.05 m^4, Iz = 0.75 m^4, J = 1 m^4
model.add_section('MySection', 0.09, 0.000675, 0.000675, 0.000975) # add_section(name: str, A: float, Iy: float, Iz: float, J: float)
#Add a member
model.add_member('M1', 'N1', 'N2', 'Concrete', 'MySection')
model.add_member('M2', 'N2', 'N3', 'Concrete', 'MySection')
model.add_member('M3', 'N3', 'N4', 'Concrete', 'MySection')
# DX, DY, DZ, RX, RY, RZ
# Provide simple supports
model.def_support('N1', True, True, True, True, True, True)
model.def_support('N4', True, True, True, True, True, True)
ux = np.zeros(len(data_array))
ug=data_array[0]
Pe = m*ug
print(Pe)
model.delete_loads()
model.add_load_combo('S', {'S': 1.0})
model.add_node_load('N2', direction='FX', P=Pe, case='S')
# Analyze the beam
model.analyze()
model.nodes['N2'].DX['S'].item()
ux[0] = model.nodes['N2'].DX['S'].item()
x = [0, 0+ux[0]*100000, 2+ux[0]*100000, 2]
y = [0, 2, 2, 0]
plt.plot(x, y, marker='o')
plt.show()
ug=data_array[1]
Pe = m*ug
model.delete_loads()
model.add_node_load('N2', direction='FX', P=Pe, case='S')
# Analyze the beam
model.analyze()
ux[1] = model.nodes['N2'].DX['S'].item()+ux[0]
x = [0, 0+ux[1]*100000, 2+ux[1]*100000, 2]
y = [0, 2, 2, 0]
plt.plot(x, y, marker='o')
plt.show()
ug=data_array[2]
Pe = m*ug
model.delete_loads()
model.add_node_load('N2', direction='FX', P=Pe, case='S')
# Analyze the beam
model.analyze()
ux[2] = model.nodes['N2'].DX['S'].item()+ux[1]
x = [0, 0+ux[2]*100000, 2+ux[2]*100000, 2]
y = [0, 2, 2, 0]
plt.plot(x, y, marker='o')
plt.show()
n = len(data_array)
from IPython.display import clear_output # ★ 핵심 모듈
import time
for i in range(3,n):
ua = ((ux[i-1]-ux[i-2])-(ux[i-2]-ux[i-3]))/(dt*dt)
ug=data_array[i]
Pe = m*(ug-ua)
model.delete_loads()
model.add_node_load('N2', direction='FX', P=Pe, case='S')
# Analyze the beam
model.analyze()
ux[i] = model.nodes['N2'].DX['S'].item()+ux[i-1]
x = [0, 0+ux[i]*10000, 2+ux[i]*10000, 2]
y = [0, 2, 2, 0]
fig, ax = plt.subplots(1, 2, figsize=(12, 5))
plt.cla()
ax[0].plot(x, y, marker='o')
ax[0].set_xlim(-1, 3)
ax[0].set_ylim(-1, 3)
ax[1].plot(data_array)
ax[1].plot(i,data_array[i], marker='o')
# --- 3. 출력 및 지우기 (핵심) ---
plt.show() # 그림을 화면에 출력
plt.pause(0.01) # 5. 0.01초 동안 화면 갱신하고 대기
clear_output(wait=True) # ★ 출력된 화면 지우기 (wait=True는 깜빡임 감소)