!pip install concreteproperties sectionproperties
import numpy as np
import matplotlib.pyplot as plt
from sectionproperties.pre.library.steel_sections import circular_hollow_section, i_section
from sectionproperties.pre.library.primitive_sections import circular_section
from concreteproperties.material import Concrete, Steel
from concreteproperties.stress_strain_profile import RectangularStressBlock, SteelElasticPlastic
from concreteproperties.concrete_section import ConcreteSection
from concreteproperties.stress_strain_profile import (
ConcreteLinear,
RectangularStressBlock,
SteelElasticPlastic,
)
# ==========================================
# 2. 재료 물성 정의 (Material Properties)
# ==========================================
# 콘크리트: fck = 30 MPa (KDS 기준 등가직사각형 응력블록)
concrete = Concrete(
name="30 MPa Concrete",
density=2.4e-6,
stress_strain_profile=ConcreteLinear(elastic_modulus=30.1e3),
ultimate_stress_strain_profile=RectangularStressBlock(
compressive_strength=30,
alpha=0.85, #0.85
gamma=0.80, #beta
ultimate_strain=0.0033,
),
flexural_tensile_strength=0,
colour="lightgrey",
)
# 외부 강관: fy = 400 MPa (완전 탄소성 거동)
tube_profile = SteelElasticPlastic(
yield_strength=400,
elastic_modulus=200000,
fracture_strain=0.05
)
tube_mat = Steel(
name="Steel Tube 400MPa",
density=7.85e-6,
stress_strain_profile=tube_profile,
colour="#1f77b4"
)
# 내부 H형강: fy = 275 MPa
h_profile = SteelElasticPlastic(
yield_strength=275,
elastic_modulus=200000,
fracture_strain=0.05
)
h_mat = Steel(
name="H-Beam 275MPa",
density=7.85e-6,
stress_strain_profile=h_profile,
colour="#2ca02c"
)
# ==========================================
# 3. 단면 형상 정의 (Geometry Definition)
# ==========================================
# 도심을 (0, 0)으로 맞추기 위해 shift_section 적용
# 외부 원형강관 (D=400, t=12)
tube = circular_hollow_section(d=400, t=12, n=64)
tube.material = tube_mat
# 내부 콘크리트 충전부 (D=376)
conc_core = circular_section(d=376, n=64)
# 내부 매입 H형강 (H=200, W=200, tw=8, tf=12)
h_beam = i_section(d=200, b=200, t_f=12, t_w=8, r=0, n_r=1).shift_section(-100, -100)
h_beam.material = h_mat
# 불리언 연산(Boolean Operation): 콘크리트 코어에서 H형강 영역 빼기 (재료 겹침 방지)
conc_core = conc_core - h_beam
conc_core.material = concrete
# 합성단면 결합
geom = tube + conc_core + h_beam
# 유한요소 메쉬(Mesh) 생성
# 각 파트(tube, conc_core, h_beam)의 최대 요소 면적을 200 mm^2로 제한
geom.create_mesh(mesh_sizes=[200, 200, 200])
# 최종 ConcreteSection 객체 생성
conc_sec = ConcreteSection(geom)
# ==========================================
# 4. 해석 수행 및 결과 시각화
# ==========================================
# 4-1. 단면도 시각화
print("단면 메쉬 및 형상을 시각화합니다...")
conc_sec.plot_section()
# 4-2. P-M 상관도 계산
print("P-M 상관도를 계산 중입니다 (시간이 약간 소요될 수 있습니다)...")
# control_points에 튜플(Tuple) 형태로 값을 전달합니다.
# 1. ("d_n", 10000): 중립축을 단면 외부 저 멀리(10,000mm) 보내어 순수 압축(상단 둥근 부분) 곡선을 확보합니다.
# 2. ("N", 0): 축력이 0인 상태, 즉 순수 휨 모멘트 지점을 명확히 짚어줍니다.
mi_res = conc_sec.moment_interaction_diagram(
control_points=[
("d_n", 10000),
("d_n", 1000),
("N", 0)
],
n_points=50
)
# 결과 데이터 추출
M_n, P_n = [], []
# 수정된 부분: mi_res.results 자체를 반복문으로 돌립니다.
for pt in mi_res.results:
# 최신 라이브러리 버전에 맞게 속성(n, m_x)을 직접 호출합니다.
m_val = pt.m_x # x축 기준 휨모멘트 (N-mm)
p_val = pt.n # 축력 (N)
M_n.append(m_val / 1e6) # N-mm -> kN-m 변환
P_n.append(p_val / 1e3) # N -> kN 변환
M_n = np.array(M_n)
P_n = np.array(P_n)
# 4-3. 강도감소계수 적용
phi = 0.65
M_u = M_n * phi
P_u = P_n * phi
# 4-4. 그래프 출력
plt.figure(figsize=(8, 6))
plt.plot(M_n, P_n, 'b-', linewidth=2, label='Nominal Strength (Pn-Mn)')
plt.plot(M_u, P_u, 'r--', linewidth=2, label=f'Design Strength (phi={phi})')
plt.xlabel('Moment, M (kN-m)', fontsize=12)
plt.ylabel('Axial Force, P (kN)', fontsize=12)
plt.title('P-M Interaction Diagram using concreteproperties', fontsize=14)
plt.axhline(0, color='black', linewidth=1)
plt.axvline(0, color='black', linewidth=1)
plt.grid(True, linestyle='--', alpha=0.7)
plt.legend(fontsize=11)
plt.tight_layout()
plt.show()