1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

建築の計算

Last updated at Posted at 2025-03-13
import numpy as np

def beam_reaction(forces, positions, span_length):
    """
    単純支持梁の反力を計算する関数
    :param forces: 荷重リスト (N)
    :param positions: 荷重の作用位置 (m)
    :param span_length: 梁の全長 (m)
    """
    # 反力の計算(支点 A, B の反力を求める)
    sum_moment_b = sum(f * p for f, p in zip(forces, positions))  # 点 B を基準としたモーメント
    R_A = sum_moment_b / span_length  # 支点 A の反力
    R_B = sum(forces) - R_A  # 支点 B の反力

    print("\n【梁の反力計算】")
    print(f"支点 A の反力: {R_A:.2f} N")
    print(f"支点 B の反力: {R_B:.2f} N")

def column_axial_force(weight, axial_load):
    """
    柱の軸力を計算する関数
    :param weight: 柱にかかる重量 (N)
    :param axial_load: 軸方向の追加荷重 (N)
    """
    total_axial_force = weight + axial_load

    print("\n【柱の軸力計算】")
    print(f"柱にかかる合計軸力: {total_axial_force:.2f} N")

def truss_force(load, angle):
    """
    トラスの力を計算する関数(単純な三角形トラスを想定)
    :param load: 水平方向の外力 (N)
    :param angle: トラスの角度 (度)
    """
    radian = np.radians(angle)
    force_tension = load / np.sin(radian)  # 張力
    force_compression = load / np.tan(radian)  # 圧縮力

    print("\n【トラスの力の計算】")
    print(f"張力: {force_tension:.2f} N")
    print(f"圧縮力: {force_compression:.2f} N")

# === 計算例 ===
# 【梁の反力】長さ 5m の梁に 3m 位置で 10N の荷重
beam_reaction(forces=[10], positions=[3], span_length=5)

# 【柱の軸力】柱の自重 500N に追加荷重 1000N
column_axial_force(weight=500, axial_load=1000)

# 【トラスの力】水平荷重 500N、角度 30°
truss_force(load=500, angle=30)


def calculate_stress_strain(force, area, original_length, deformation, youngs_modulus):
    """
    フックの法則を用いた壁の応力・ひずみ計算関数
    :param force: かかる力 (N)
    :param area: 壁の断面積 (m²)
    :param original_length: 壁の元の高さ (m)
    :param deformation: 変形量 (m)
    :param youngs_modulus: ヤング率 (Pa)
    """
    # 応力 (Stress) 計算
    stress = force / area

    # ひずみ (Strain) 計算
    strain = deformation / original_length

    # フックの法則の適用 (σ = E * ε の検証)
    theoretical_stress = youngs_modulus * strain

    # 結果の表示
    print("\n【応力とひずみの計算結果】")
    print(f"応力 (Stress): {stress:.2f} Pa")
    print(f"ひずみ (Strain): {strain:.6f}")
    print(f"フックの法則による理論応力: {theoretical_stress:.2f} Pa")

    # 応力の理論値と計算値の比較
    if abs(stress - theoretical_stress) < 1e-3:
        print("✅ フックの法則が成り立っている")
    else:
        print("⚠ フックの法則が成り立たない可能性あり")

# === 計算例 ===
# 壁に作用する力 10000 N、断面積 2m²、元の高さ 3m、変形量 0.001m、ヤング率 2×10⁹ Pa (コンクリート)
calculate_stress_strain(force=10000, area=2, original_length=3, deformation=0.001, youngs_modulus=2e9)

import numpy as np
from scipy.linalg import eig

def vibration_analysis(stiffness_matrix, mass_matrix):
    """
    固有値問題を解いて振動解析を行う関数
    :param stiffness_matrix: 剛性マトリックス (K)
    :param mass_matrix: 質量マトリックス (M)
    """
    # 一般化固有値問題 Kx = λMx を解く
    eigenvalues, eigenvectors = eig(stiffness_matrix, mass_matrix)

    # 固有振動数(ω = sqrt(λ))を計算
    natural_frequencies = np.sqrt(np.real(eigenvalues))

    # 結果の表示
    print("\n【固有値問題(振動解析)の結果】")
    for i, freq in enumerate(natural_frequencies):
        print(f"モード {i+1}: 固有振動数 (Hz) = {freq:.2f}")

    # 共振防止のチェック(特定の周波数範囲を避ける)
    dangerous_freqs = [50, 60, 100]  # 共振を避けるべき周波数 (例: 電気機器や構造共振)
    for freq in natural_frequencies:
        for danger in dangerous_freqs:
            if abs(freq - danger) < 5:
                print(f"⚠ 注意: 固有振動数 {freq:.2f} Hz が共振リスクあり!")

# === 計算例 ===
# 2自由度系の剛性マトリックスと質量マトリックス
K = np.array([[10000, -5000], [-5000, 5000]])  # 剛性マトリックス
M = np.array([[2, 0], [0, 1]])  # 質量マトリックス

# 固有値解析
vibration_analysis(K, M)


import numpy as np

def finite_element_analysis(nodes, elements, forces, fixed_nodes, youngs_modulus, area):
    """
    2Dトラス構造の有限要素解析 (FEM)
    :param nodes: 節点座標 [(x1, y1), (x2, y2), ...]
    :param elements: 要素接続 [(n1, n2), (n3, n4), ...]
    :param forces: 外力 [Fx1, Fy1, Fx2, Fy2, ...]
    :param fixed_nodes: 固定節点のリスト [n1, n2, ...]
    :param youngs_modulus: ヤング率 (Pa)
    :param area: 断面積 (m²)
    """
    num_nodes = len(nodes)
    num_dof = num_nodes * 2  # 各節点にx, yの自由度がある

    # 全体剛性マトリックス K を初期化
    K_global = np.zeros((num_dof, num_dof))

    # 要素ごとの剛性マトリックスを計算し、全体剛性マトリックスに組み込む
    for (n1, n2) in elements:
        x1, y1 = nodes[n1]
        x2, y2 = nodes[n2]
        L = np.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)  # 要素の長さ
        c = (x2 - x1) / L
        s = (y2 - y1) / L

        k = (youngs_modulus * area / L) * np.array([
            [ c*c,  c*s, -c*c, -c*s],
            [ c*s,  s*s, -c*s, -s*s],
            [-c*c, -c*s,  c*c,  c*s],
            [-c*s, -s*s,  c*s,  s*s]
        ])

        # 剛性マトリックスを全体剛性マトリックスに配置
        indices = [n1 * 2, n1 * 2 + 1, n2 * 2, n2 * 2 + 1]
        for i in range(4):
            for j in range(4):
                K_global[indices[i], indices[j]] += k[i, j]

    # 境界条件の適用(固定節点の自由度をゼロにする)
    for node in fixed_nodes:
        index_x = node * 2
        index_y = node * 2 + 1
        K_global[index_x, :] = 0
        K_global[:, index_x] = 0
        K_global[index_x, index_x] = 1  # 1を設定
        K_global[index_y, :] = 0
        K_global[:, index_y] = 0
        K_global[index_y, index_y] = 1  # 1を設定

    # 変位を求める(K_global * U = F を解く)
    U = np.linalg.solve(K_global, forces)

    # 結果の表示
    print("\n【有限要素法による解析結果】")
    for i in range(num_nodes):
        print(f"節点 {i}: 変位 (Ux, Uy) = ({U[i*2]:.6f}, {U[i*2+1]:.6f}) m")

# === 解析例 ===
# 2Dトラスの節点座標
nodes = {
    0: (0, 0),   # 節点0
    1: (1, 0),   # 節点1
    2: (0.5, 1)  # 節点2(上部)
}

# 要素接続 (節点の組)
elements = [
    (0, 1),  # 底部横方向
    (1, 2),  # 右斜め
    (2, 0)   # 左斜め
]

# 外力ベクトル(全自由度)
forces = np.array([
    0, 0,   # 節点0 (固定)
    0, 0,   # 節点1 (固定)
    0, -10000  # 節点2(荷重 -10000N)
])

# 固定されている節点
fixed_nodes = [0, 1]

# 材料特性
youngs_modulus = 2e11  # Pa(鋼)
area = 0.01  # m²(断面積)

# 解析実行
finite_element_analysis(nodes, elements, forces, fixed_nodes, youngs_modulus, area)


def material_strength_calculation(material, force, area):
    """
    材料の強度計算を行い、許容応力を超えていないかチェックする関数
    :param material: 材料名 ("コンクリート", "鋼材", "木材")
    :param force: かかる荷重 (N)
    :param area: 断面積 (m²)
    """
    # 材料ごとの許容応力 (MPa = N/mm²)
    material_strengths = {
        "コンクリート": 20e6,  # 20 MPa = 20×10^6 N/m²
        "鋼材": 250e6,         # 250 MPa
        "木材": 10e6           # 10 MPa
    }

    # 材料の許容応力を取得
    if material not in material_strengths:
        print(f"⚠ エラー: 指定された材料 '{material}' は対応していません。")
        return

    allowable_stress = material_strengths[material]

    # 応力の計算
    stress = force / area  # N/m²(Pa)

    # 計算結果を表示
    print(f"\n【{material} の強度計算】")
    print(f"かかる荷重: {force:.2f} N")
    print(f"断面積: {area:.6f} m²")
    print(f"計算された応力: {stress / 1e6:.2f} MPa")
    print(f"許容応力: {allowable_stress / 1e6:.2f} MPa")

    # 許容応力を超えているかのチェック
    if stress > allowable_stress:
        print(f"⚠ 警告: 応力が許容値を超えています!({stress / 1e6:.2f} MPa > {allowable_stress / 1e6:.2f} MPa)")
    else:
        print(f"✅ 材料の強度は安全範囲内です。")

# === 計算例 ===
# コンクリート (荷重 100,000N, 断面積 0.02m²)
material_strength_calculation("コンクリート", force=100000, area=0.02)

# 鋼材 (荷重 200,000N, 断面積 0.005m²)
material_strength_calculation("鋼材", force=200000, area=0.005)

# 木材 (荷重 10,000N, 断面積 0.001m²)
material_strength_calculation("木材", force=10000, area=0.001)


import numpy as np

def section_moment_of_inertia(shape, **kwargs):
    """
    断面二次モーメントを計算する関数
    :param shape: "rectangle" または "circle"
    :param kwargs: 必要な寸法(b, h, d)
    :return: 断面二次モーメント I (m⁴)
    """
    if shape == "rectangle":
        b, h = kwargs["b"], kwargs["h"]
        I = (b * h**3) / 12
    elif shape == "circle":
        d = kwargs["d"]
        I = (np.pi * d**4) / 64
    else:
        raise ValueError("⚠ 形状は 'rectangle' または 'circle' を指定してください。")

    return I

def bending_stress(moment, I, c):
    """
    曲げ応力を計算する関数
    :param moment: 曲げモーメント (Nm)
    :param I: 断面二次モーメント (m⁴)
    :param c: 中立軸からの距離 (m)
    :return: 曲げ応力 σ (Pa)
    """
    stress = moment * c / I
    return stress

def buckling_load(E, I, L):
    """
    座屈荷重(オイラー座屈)を計算する関数
    :param E: ヤング率 (Pa)
    :param I: 断面二次モーメント (m⁴)
    :param L: 柱の長さ (m)
    :return: 座屈荷重 P_cr (N)
    """
    P_cr = (np.pi**2 * E * I) / (L**2)
    return P_cr

# === 計算例 ===
# 1. 矩形断面(幅 0.1m, 高さ 0.3m)
I_rect = section_moment_of_inertia("rectangle", b=0.1, h=0.3)
print(f"\n【矩形断面の断面二次モーメント】")
print(f"I = {I_rect:.6e} m⁴")

# 2. 円形断面(直径 0.1m)
I_circle = section_moment_of_inertia("circle", d=0.1)
print(f"\n【円形断面の断面二次モーメント】")
print(f"I = {I_circle:.6e} m⁴")

# 3. 曲げ応力(曲げモーメント 500Nm, 中立軸からの距離 h/2)
stress = bending_stress(moment=500, I=I_rect, c=0.3/2)
print(f"\n【矩形断面の曲げ応力】")
print(f"σ = {stress:.2f} Pa")

# 4. 座屈荷重(ヤング率 2×10^11 Pa(鋼), 長さ 2m)
P_cr = buckling_load(E=2e11, I=I_rect, L=2)
print(f"\n【矩形断面の座屈荷重】")
print(f"P_cr = {P_cr:.2f} N")


import numpy as np

def creep_shrinkage_analysis(time, initial_strain, creep_coefficient, shrinkage_max, shrinkage_rate):
    """
    クリープ変形と収縮変形を計算する関数
    :param time: 経過時間の配列(時間単位)
    :param initial_strain: 初期ひずみ(無次元)
    :param creep_coefficient: クリープ係数
    :param shrinkage_max: 最大収縮ひずみ(無次元)
    :param shrinkage_rate: 収縮速度定数
    """
    # クリープひずみの計算
    creep_strain = initial_strain + creep_coefficient * np.log(time + 1)

    # 収縮ひずみの計算
    shrinkage_strain = shrinkage_max * (1 - np.exp(-shrinkage_rate * time))

    # 結果を出力
    print("\n【クリープと収縮の解析結果】")
    for t, ε_c, ε_s in zip(time, creep_strain, shrinkage_strain):
        print(f"時間 {t}h: クリープひずみ = {ε_c:.6e}, 収縮ひずみ = {ε_s:.6e}")

# === 計算例 ===
time_hours = np.array([1, 10, 100, 1000, 10000])  # 経過時間(1h, 10h, 100h, 1000h, 10000h)
initial_strain = 0.0002  # 初期ひずみ(200με)
creep_coefficient = 0.0001  # クリープ係数
shrinkage_max = 0.0003  # 最大収縮ひずみ(300με)
shrinkage_rate = 0.0005  # 収縮速度定数

# 解析実行
creep_shrinkage_analysis(time_hours, initial_strain, creep_coefficient, shrinkage_max, shrinkage_rate)



import numpy as np
import matplotlib.pyplot as plt

def construction_error_analysis(n_samples, mean_error, std_dev, tolerance):
    """
    施工誤差の数値解析を行う関数 (Function to perform construction error analysis)
    
    Parameters:
    n_samples   (int):    サンプル数 (number of samples)
    mean_error  (float):  寸法誤差の平均値 [m] (mean error in meters)
    std_dev     (float):  寸法誤差の標準偏差 [m] (standard deviation of error in meters)
    tolerance   (float):  許容誤差範囲 [m] (tolerance in meters)
    """
    
    # 施工誤差を正規分布に基づいてシミュレーションする
    # (Simulate construction errors using a normal distribution)
    errors = np.random.normal(mean_error, std_dev, n_samples)

    # 統計解析 (Perform statistical analysis)
    mean_value = np.mean(errors)       # 平均誤差 (mean error)
    std_value = np.std(errors)         # 標準偏差 (standard deviation)
    within_tolerance = np.sum(np.abs(errors) <= tolerance) / n_samples * 100

    # 英語で結果を出力 (Print results in English)
    print("=== Construction Error Analysis ===")
    print(f"Number of samples: {n_samples}")
    print(f"Mean error: {mean_value:.6f} m")
    print(f"Standard deviation: {std_value:.6f} m")
    print(f"Percentage within ±{tolerance} m tolerance: {within_tolerance:.2f}%")

    # ヒストグラムを作成 (Create a histogram)
    plt.figure(figsize=(8, 5))
    plt.hist(errors, bins=30, density=True, alpha=0.7, edgecolor='black')
    
    # 赤い破線で許容範囲を示す (Draw red dashed lines for the tolerance range)
    plt.axvline(-tolerance, color='red', linestyle='dashed', label=f"-{tolerance} m tolerance")
    plt.axvline(tolerance, color='red', linestyle='dashed', label=f"+{tolerance} m tolerance")

    # 緑の実線で平均誤差を示す (Draw a green solid line for the mean error)
    plt.axvline(mean_value, color='green', linestyle='solid', label=f"Mean error: {mean_value:.6f} m")

    # 軸ラベルとタイトルを英語で設定 (Set the axis labels and title in English)
    plt.xlabel("Error (m)")
    plt.ylabel("Probability Density")
    plt.title("Construction Error Distribution")
    plt.legend()
    plt.grid()
    plt.show()


# === Example Usage ===
# サンプル数 (number of samples)
n_samples = 1000     

# 寸法誤差の平均値 (mean error) [m]
mean_error = 0.002  

# 寸法誤差の標準偏差 (standard deviation) [m]
std_dev = 0.005     

# 許容誤差範囲 (tolerance) [m]
tolerance = 0.01    

# 施工誤差の解析 (Perform the construction error analysis)
construction_error_analysis(n_samples, mean_error, std_dev, tolerance)

def lumen_method(lumen_output, utilization_factor, maintenance_factor, area):
    """
    ルーメン法を用いた照度計算関数 (Lumen Method for Illuminance Calculation)
    
    Parameters:
    lumen_output (float): 光源の全光束 (lm, ルーメン)
    utilization_factor (float): 利用率 (無次元)
    maintenance_factor (float): 保守率 (無次元)
    area (float): 照明する空間の面積 (m²)
    
    Returns:
    None
    """
    # 照度 (Illuminance) の計算
    illuminance = (lumen_output * utilization_factor * maintenance_factor) / area

    # 結果の表示
    print("\n=== 照明計算(ルーメン法) ===")
    print(f"光束 (Luminous Flux): {lumen_output:.2f} lm")
    print(f"利用率 (Utilization Factor): {utilization_factor:.2f}")
    print(f"保守率 (Maintenance Factor): {maintenance_factor:.2f}")
    print(f"空間面積 (Room Area): {area:.2f} m²")
    print(f"平均照度 (Illuminance): {illuminance:.2f} lx (ルクス)")

# === 計算例 ===
lumen_output = 10000  # 光源の全光束 (lm)
utilization_factor = 0.7  # 利用率
maintenance_factor = 0.8  # 保守率
area = 50  # 照明する空間の面積 (m²)

# 照度計算
lumen_method(lumen_output, utilization_factor, maintenance_factor, area)




# RC Structure Strength Calculation / RC構造の強度計算
# Calculate the moment capacity of a reinforced concrete beam using a simplified formula:
# M = (A_s * f_y * d) / 1e6, where:
#   A_s = area of reinforcement in mm^2
#   f_y = yield strength of reinforcement in MPa (N/mm^2)
#   d   = effective depth in mm
# M is expressed in kN-m.
# 単純化した式を用いて、鉄筋コンクリート梁の曲げ耐力を計算します:
# M = (A_s * f_y * d) / 1e6
#   A_s:鉄筋面積 (mm^2)
#   f_y:鉄筋の降伏強度 (MPa)
#   d  :有効深さ (mm)
# MはkN-mで表されます。

# RC beam parameters / RC梁のパラメータ
A_s = 1500    # Reinforcement area in mm^2 / 鉄筋面積 (mm^2)
f_y = 500     # Yield strength in MPa / 降伏強度 (MPa)
d   = 500     # Effective depth in mm / 有効深さ (mm)

# Calculate moment capacity for RC structure / RC構造の曲げ耐力計算
M_RC = (A_s * f_y * d) / 1e6  # kN-m
print("RC Ramen Structure Moment Capacity:")
print(f"  Moment Capacity: {M_RC:.2f} kN-m\n")

# Steel Structure Strength Calculation / 鉄骨構造の強度計算
# Calculate the moment capacity of a steel beam using the section modulus:
# M = (f_y_steel * S) / 1e6, where:
#   f_y_steel = yield strength of steel in MPa (N/mm^2)
#   S         = section modulus in mm^3
# M is expressed in kN-m.
# 鉄骨ビームの曲げ耐力は、断面係数を用いて次式で計算します:
# M = (f_y_steel * S) / 1e6
#   f_y_steel:鉄骨の降伏強度 (MPa)
#   S        :断面係数 (mm^3)
# MはkN-mで表されます。

# Steel beam parameters / 鉄骨梁のパラメータ
f_y_steel = 350      # Yield strength of steel in MPa / 降伏強度 (MPa)
S = 2000000          # Section modulus in mm^3 / 断面係数 (mm^3)

# Calculate moment capacity for steel structure / 鉄骨構造の曲げ耐力計算
M_S = (f_y_steel * S) / 1e6  # kN-m
print("S Ramen Structure Moment Capacity:")
print(f"  Moment Capacity: {M_S:.2f} kN-m")
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?