otko/tests/integration/test_rc_frame_earthquake.py
smillmorel 61b850bf46
Some checks failed
CI / lint (pull_request) Has been cancelled
CI / type (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (macos-latest, 3.12) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (ubuntu-latest, 3.12) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.10) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.11) (pull_request) Has been cancelled
CI / test-headless (windows-latest, 3.12) (pull_request) Has been cancelled
CI / test-gui (pull_request) Has been cancelled
CI / test-integration (macos-latest) (pull_request) Has been cancelled
CI / test-integration (ubuntu-latest) (pull_request) Has been cancelled
CI / test-integration (windows-latest) (pull_request) Has been cancelled
style: resolve the remaining ruff findings
Auto-fixes (UP037, UP038, F401, I001, SIM105, RUF100) plus hand-fixes:
drop the now-unused `Union` imports, annotate mutable class attributes
with ClassVar, raise ValidationError instead of blind Exception in the
zero-length test, delete two dead locals, and bind the per-iteration
grid-builder closures to their loop variables (B023).
2026-09-16 13:20:36 -04:00

55 lines
2 KiB
Python

"""Integration test: RC Frame Earthquake example (OpenSees Ex 3.3)."""
from __future__ import annotations
import tempfile
from pathlib import Path
import pytest
pytest.importorskip("openseespy")
from otko.services import load_project, save_project
from otko.services.opensees_runner import OpenSeesRunner
pytestmark = pytest.mark.slow
def test_rc_frame_earthquake_runs_and_has_oscillatory_response(tmp_path) -> None: # type: ignore[no-untyped-def]
"""Synthetic ground motion produces bounded, oscillatory response."""
from examples.rc_frame_earthquake import (
N_PTS,
build_rc_frame_earthquake,
)
proj = build_rc_frame_earthquake()
proj.validate_references()
osmodel = tmp_path / "eq.osmodel"
save_project(proj, osmodel)
reloaded = load_project(osmodel)
reloaded.validate_references()
results_dir = Path(tempfile.mkdtemp(prefix="eq_"))
result = OpenSeesRunner(reloaded).run(reloaded.analyses[0], results_dir=results_dir)
# Simulation covers most of the 4-second record (ModifiedNewton
# fallback may trim a few steps at stiffness jumps; we allow that).
assert result.n_steps >= int(
0.9 * N_PTS
), f"Only {result.n_steps}/{N_PTS} steps — fallback didn't recover"
# Node 3 Ux history: bounded, non-trivial, some positive AND some
# negative (oscillation confirms the base excitation actually
# propagated through the mass + damping chain, not a one-shot push).
h3 = result.node_disp_history(3)
ux = h3[:, 0]
assert max(ux) > 0.05, f"max Ux {max(ux):.4f} too small — did excitation apply?"
assert min(ux) < -0.05, f"min Ux {min(ux):.4f} — no negative excursion"
# Drift stays reasonable (< 10% of column height).
assert max(abs(ux)) < 14.4, f"|Ux|_max = {max(abs(ux)):.2f} exceeds 10% drift"
# Uy on the top nodes — small compared to Ux (gravity holds, base
# excitation is horizontal).
uy = h3[:, 1]
assert max(abs(uy)) < 1.0, f"max |Uy| = {max(abs(uy)):.4f} in too large"