otko/tests/integration/test_ex1a_canti2d.py
smillmorel ba783718d4 chore: adopt remaining local development state
Catch-all for the intermixed residue of the unpushed otko-development
work ported into this tree: combinations/console-dock/quick-guide wiring
across commands, core, services, views and tests; repo-wide ruff-format
normalization; README/CONTRIBUTING updates; and the toolbar default
(both toolbars now open in the top area, quick guide text updated).

Splitting this further would require hunk-level surgery with low
confidence; the preceding commits in this branch isolate the
self-contained features.
2026-09-16 12:03:22 -04:00

69 lines
2.4 KiB
Python

"""Integration tests for OpenSees Example 1a cantilever column."""
from __future__ import annotations
import tempfile
from pathlib import Path
import pytest
pytest.importorskip("openseespy")
from otko.core import PushoverCase, TransientCase # noqa: E402
from otko.services import load_project, save_project # noqa: E402
from otko.services.opensees_runner import OpenSeesRunner # noqa: E402
pytestmark = pytest.mark.slow
def _reload(proj, tmp_path): # type: ignore[no-untyped-def]
path = tmp_path / "ex1a_canti2d.osmodel"
save_project(proj, path)
reloaded = load_project(path)
reloaded.validate_references()
return reloaded
def test_ex1a_canti2d_pushover_reaches_target(tmp_path) -> None: # type: ignore[no-untyped-def]
from examples.ex1a_canti2d import PUSH_STEP, PUSH_TARGET, build_ex1a_canti2d
proj = _reload(build_ex1a_canti2d(), tmp_path)
push_case = next(c for c in proj.analyses if isinstance(c, PushoverCase))
result = OpenSeesRunner(proj).run(push_case)
expected_pts = int(PUSH_TARGET / PUSH_STEP) + 1
assert len(result.control_disp) == expected_pts
assert result.control_disp[-1] == pytest.approx(PUSH_TARGET, rel=1e-6)
# Linear-elastic frame -> monotonic base shear and nearly constant tangent stiffness.
assert result.base_shear[-1] > 0.0
assert result.base_shear[200] > result.base_shear[100] > result.base_shear[1]
slope_early = (result.base_shear[10] - result.base_shear[0]) / (
result.control_disp[10] - result.control_disp[0]
)
slope_late = (result.base_shear[-1] - result.base_shear[-11]) / (
result.control_disp[-1] - result.control_disp[-11]
)
assert slope_early == pytest.approx(slope_late, rel=0.02)
def test_ex1a_canti2d_earthquake_runs_and_oscillates(tmp_path) -> None: # type: ignore[no-untyped-def]
from examples.ex1a_canti2d import ANALYSIS_DT, ANALYSIS_STEPS, build_ex1a_canti2d
proj = _reload(build_ex1a_canti2d(), tmp_path)
eq_case = next(c for c in proj.analyses if isinstance(c, TransientCase))
results_dir = Path(tempfile.mkdtemp(prefix="ex1a_canti2d_eq_"))
result = OpenSeesRunner(proj).run(eq_case, results_dir=results_dir)
time = result.time()
top = result.node_disp_history(2)
ux = top[:, 0]
uy = top[:, 1]
assert len(time) == ANALYSIS_STEPS
assert result.dt == pytest.approx(ANALYSIS_DT)
assert ux.max() > 0.001
assert ux.min() < -0.001
assert max(abs(uy)) < 1.0