Add structural calculation worksheets
Collection of engineering calculation projects (Python + Typst), each with input, calc script, tests, results, and generated PDF where available.
This commit is contained in:
commit
d5ac3fca7e
81 changed files with 18668 additions and 0 deletions
65
wood-stud-column/test_wood_stud_column.py
Normal file
65
wood-stud-column/test_wood_stud_column.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
from pathlib import Path
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
spec = importlib.util.spec_from_file_location("wood_stud_column_calc", HERE / "calc.py")
|
||||
assert spec is not None and spec.loader is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
|
||||
def result():
|
||||
with (HERE / "input.yaml").open(encoding="utf-8") as handle:
|
||||
return module.compute(yaml.safe_load(handle))
|
||||
|
||||
|
||||
def test_typst_loads_match_checked_inputs():
|
||||
subprocess.run([sys.executable, str(HERE / "calc.py")], check=True, cwd=HERE.parents[1])
|
||||
query = subprocess.run(
|
||||
[
|
||||
"typst", "eval", "query(<wood-stud-column-loads>)", "--root", ".",
|
||||
"--in", "calcs/wood-stud-column/beam.typ", "--format", "json",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=HERE.parents[1],
|
||||
)
|
||||
published = json.loads(query.stdout)
|
||||
assert len(published) == 1
|
||||
derived = published[0]["value"]
|
||||
values = result()["values"]
|
||||
assert derived["P_lbf"] == pytest.approx(values["P_lbf"], abs=0.001)
|
||||
assert derived["A_in2"] == pytest.approx(values["A_in2"], abs=0.001)
|
||||
|
||||
|
||||
def test_ground_truth_column_stability():
|
||||
output = result()
|
||||
values = output["values"]
|
||||
assert values["A_in2"] == pytest.approx(5.25)
|
||||
assert values["Le_in"] == pytest.approx(72.0)
|
||||
assert values["Le_d_weak"] == pytest.approx(48.0, abs=0.01)
|
||||
assert values["FcE_weak_psi"] == pytest.approx(181.9, abs=0.5)
|
||||
assert values["Cp_weak"] == pytest.approx(0.107, abs=0.003)
|
||||
assert values["Cp_strong"] == pytest.approx(0.497, abs=0.005)
|
||||
assert values["Fc_prime_psi"] == pytest.approx(177.6, abs=0.5)
|
||||
assert values["Pa_lbf"] == pytest.approx(932.0, abs=3.0)
|
||||
assert output["checks"]["axial"]["ok"] is True
|
||||
|
||||
|
||||
def test_cli_can_write_json_to_stdout():
|
||||
completed = subprocess.run(
|
||||
[sys.executable, str(HERE / "calc.py"), "--input", str(HERE / "input.yaml"), "--stdout"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
output = json.loads(completed.stdout)
|
||||
assert output["values"]["P_lbf"] == pytest.approx(400)
|
||||
assert completed.stderr == ""
|
||||
Loading…
Reference in a new issue