638 lines
30 KiB
Python
638 lines
30 KiB
Python
from __future__ import annotations
|
|
|
|
import csv
|
|
import math
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from collections import defaultdict
|
|
from pathlib import Path
|
|
|
|
|
|
ALPHAS = (15.0, 25.0, 35.0, 45.0)
|
|
MATERIAL_CASES = (1, 2)
|
|
FOS_TOL = 2.0e-2
|
|
L1 = 85.0
|
|
L2 = 20.0
|
|
H1 = 20.0
|
|
MESH_SIZE = 0.75
|
|
REFERENCE_DISPLACEMENT_SCALE = 0.3
|
|
ADJUST_CODES = {-1, 0, 1, 2, 3, 4}
|
|
TRUST_ROW_COLUMNS = (
|
|
"trust_radius", "next_trust_radius", "damping", "merit_ratio",
|
|
"trust_rejections", "trust_adjust",
|
|
)
|
|
TRUST_SUMMARY_KEYS = (
|
|
"trust_radius", "trust_min_radius", "trust_max_radius",
|
|
"trust_growth_factor", "trust_shrink_factor", "trust_accept_ratio",
|
|
"trust_good_ratio", "last_trust_radius", "next_trust_radius",
|
|
"last_damping", "last_merit_ratio", "last_trust_rejections",
|
|
"last_trust_adjust",
|
|
)
|
|
MC_ROW_COLUMNS = (
|
|
"mc_points", "mc_updated_points", "mc_substeps",
|
|
"mc_requested_substeps", "mc_limited_points", "mc_branch_mask",
|
|
"mc_max_yield", "mc_max_plastic_step",
|
|
)
|
|
MC_SUMMARY_KEYS = (
|
|
"mc_min_substeps", "mc_max_substeps", "mc_target_strain",
|
|
"mc_yield_tol", "mc_plastic_limit", *MC_ROW_COLUMNS,
|
|
)
|
|
|
|
|
|
def read_rows(path: Path) -> list[dict[str, str]]:
|
|
with path.open(newline="", encoding="utf-8") as handle:
|
|
return list(csv.DictReader(handle))
|
|
|
|
|
|
def read_key_values(path: Path) -> dict[str, str]:
|
|
return {row["key"]: row["value"].strip() for row in read_rows(path)}
|
|
|
|
|
|
def require(condition: bool, message: str) -> None:
|
|
if not condition:
|
|
raise RuntimeError(message)
|
|
|
|
|
|
def case_key(row: dict[str, str]) -> tuple[int, float]:
|
|
return int(row["material_case"]), round(float(row["alpha_deg"]), 6)
|
|
|
|
|
|
def find_tool(build_dirs: list[Path]) -> Path:
|
|
candidates: list[Path] = []
|
|
for build_dir in build_dirs:
|
|
candidates.extend(
|
|
[
|
|
build_dir / "strength_reduction_benchmark.exe",
|
|
build_dir / "strength_reduction_benchmark",
|
|
build_dir / "Release" / "strength_reduction_benchmark.exe",
|
|
build_dir / "Release" / "strength_reduction_benchmark",
|
|
]
|
|
)
|
|
for candidate in candidates:
|
|
if candidate.exists():
|
|
return candidate
|
|
searched = ", ".join(str(path) for path in build_dirs)
|
|
raise RuntimeError(f"missing strength_reduction_benchmark tool under {searched}")
|
|
|
|
|
|
def parse_inp_nodes_elements(input_file: Path) -> tuple[dict[int, tuple[float, float, float]], list[list[int]]]:
|
|
nodes: dict[int, tuple[float, float, float]] = {}
|
|
elements: list[list[int]] = []
|
|
section = ""
|
|
for raw_line in input_file.read_text(encoding="utf-8").splitlines():
|
|
line = raw_line.strip()
|
|
if not line or line.startswith("**"):
|
|
continue
|
|
if line.startswith("*"):
|
|
upper = line.upper()
|
|
if upper.startswith("*NODE"):
|
|
section = "NODE"
|
|
elif upper.startswith("*ELEMENT"):
|
|
section = "ELEMENT"
|
|
else:
|
|
section = ""
|
|
continue
|
|
parts = [part.strip() for part in line.split(",") if part.strip()]
|
|
if section == "NODE" and len(parts) >= 4:
|
|
nodes[int(parts[0])] = (float(parts[1]), float(parts[2]), float(parts[3]))
|
|
elif section == "ELEMENT" and len(parts) >= 5:
|
|
elements.append([int(part) for part in parts[1:]])
|
|
return nodes, elements
|
|
|
|
|
|
def interface_key(coord: tuple[float, float, float]) -> tuple[int, int, int]:
|
|
return (round(coord[0] * 1.0e6), round(coord[1] * 1.0e6),
|
|
round(coord[2] * 1.0e6))
|
|
|
|
|
|
def check_conforming_interface(input_file: Path) -> None:
|
|
nodes, elements = parse_inp_nodes_elements(input_file)
|
|
require(nodes, "input has no parsed nodes")
|
|
require(elements, "input has no parsed elements")
|
|
lower: set[tuple[int, int, int]] = set()
|
|
upper: set[tuple[int, int, int]] = set()
|
|
tol = 1.0e-7
|
|
for elem_nodes in elements:
|
|
coords = [nodes[node] for node in elem_nodes]
|
|
z_values = [coord[2] for coord in coords]
|
|
if max(z_values) <= H1 + tol:
|
|
target = lower
|
|
elif min(z_values) >= H1 - tol:
|
|
target = upper
|
|
else:
|
|
continue
|
|
for coord in coords:
|
|
x, _y, z = coord
|
|
if abs(z - H1) <= tol and L2 - tol <= x <= L1 + tol:
|
|
target.add(interface_key(coord))
|
|
|
|
shared = lower.intersection(upper)
|
|
expected = 2 * (math.ceil((L1 - L2) / MESH_SIZE) + 1)
|
|
require(len(shared) >= expected,
|
|
f"lower/upper slope interface is nonconforming: shared={len(shared)}, expected>={expected}")
|
|
|
|
|
|
def check_input(input_file: Path) -> None:
|
|
inp_text = input_file.read_text(encoding="utf-8").upper()
|
|
require("PDF: MODELS.GEOMECH.STRENGTH_REDUCTION_METHOD.PDF" in inp_text,
|
|
"input is not tied to the reference PDF")
|
|
require("PDF-SRM L1=85 L2=20 H1=20 H2=10" in inp_text,
|
|
"input does not record the PDF slope geometry")
|
|
require("PDF-SRM MESH_SIZE=0.75" in inp_text,
|
|
"input is not using the PDF 0.75 m maximum mesh size")
|
|
require("CONFORMING_INTERFACE=YES" in inp_text,
|
|
"input does not record the conforming lower/upper interface route")
|
|
require("PDF-SRM DEFAULT_ALPHA=45" in inp_text,
|
|
"input does not record the default 45 degree slope")
|
|
require("GRAVITY_DLOAD_GRAV=YES" in inp_text,
|
|
"input does not record the native gravity DLOAD route")
|
|
require("*DLOAD" in inp_text and "EMBANKMENT, GRAV, 9.81, 0.0, 0.0, -1.0" in inp_text,
|
|
"input does not use native DLOAD GRAV for gravity")
|
|
require("*CLOAD" not in inp_text,
|
|
"input still uses equivalent gravity CLOAD")
|
|
require("*ELEMENT, TYPE=C3D8" in inp_text, "input is not the full solid C3D8 model")
|
|
require("*MOHR COULOMB" in inp_text, "strength reduction input does not use Mohr-Coulomb")
|
|
require("ALLNODES, 4, 6, 0.0" in inp_text,
|
|
"solid-only model must constrain unused rotational DOFs")
|
|
require("ELASTIC_SOIL" not in inp_text, "input still uses the old elastic-soil placeholder")
|
|
check_conforming_interface(input_file)
|
|
|
|
|
|
def check_reference_cases(reference_file: Path) -> dict[tuple[int, float], float]:
|
|
rows = read_rows(reference_file)
|
|
expected: dict[tuple[int, float], float] = {}
|
|
for row in rows:
|
|
key = case_key(row)
|
|
expected[key] = float(row["reference_fos"])
|
|
require(len(expected) == len(ALPHAS) * len(MATERIAL_CASES),
|
|
"reference CSV does not cover all PDF material/alpha cases")
|
|
for material_case in MATERIAL_CASES:
|
|
for alpha in ALPHAS:
|
|
require((material_case, alpha) in expected,
|
|
f"missing reference FOS for material {material_case}, alpha {alpha:g}")
|
|
return expected
|
|
|
|
|
|
def check_summary(summary: dict[str, str]) -> None:
|
|
require(summary.get("status") == "CONVERGED",
|
|
f"unexpected SR status: {summary.get('status')}")
|
|
require(int(summary["case_count"]) == 8, "summary does not report 8 cases")
|
|
require(int(summary["alpha_count"]) == 4, "summary does not report 4 slope angles")
|
|
require(int(summary["material_case_count"]) == 2, "summary does not report 2 material cases")
|
|
require(int(summary["converged_cases"]) == 8, "not all SR cases converged")
|
|
require(int(summary["stable_count"]) >= 16, "not enough stable SR trials")
|
|
require(int(summary["unstable_count"]) >= 8, "not enough unstable SR trials")
|
|
require(float(summary["max_abs_error"]) <= FOS_TOL,
|
|
f"reference FOS error too large: {summary['max_abs_error']}")
|
|
|
|
|
|
def check_cases(rows: list[dict[str, str]], expected: dict[tuple[int, float], float]) -> None:
|
|
require(len(rows) == 8, f"expected 8 case rows, got {len(rows)}")
|
|
seen: dict[tuple[int, float], float] = {}
|
|
for row in rows:
|
|
key = case_key(row)
|
|
require(key in expected, f"unexpected case row {key}")
|
|
require(row["status"].strip() == "CONVERGED", f"case {key} did not converge")
|
|
reference = expected[key]
|
|
computed = float(row["computed_fos"])
|
|
lower = float(row["lower"])
|
|
upper = float(row["upper"])
|
|
abs_error = abs(computed - reference)
|
|
require(abs_error <= FOS_TOL,
|
|
f"case {key} FOS mismatch: computed={computed}, reference={reference}")
|
|
require(abs(float(row["abs_error"]) - abs_error) <= 5.0e-5,
|
|
f"case {key} abs_error column is inconsistent")
|
|
require(lower < computed < upper,
|
|
f"case {key} factor is not bracketed: lower={lower}, computed={computed}, upper={upper}")
|
|
require(int(row["stable_count"]) >= 1 and int(row["unstable_count"]) >= 1,
|
|
f"case {key} does not contain a real stable/unstable bracket")
|
|
seen[key] = computed
|
|
|
|
for material_case in MATERIAL_CASES:
|
|
values = [seen[(material_case, alpha)] for alpha in ALPHAS]
|
|
require(all(values[i] > values[i + 1] for i in range(len(values) - 1)),
|
|
f"material {material_case} FOS is not decreasing with slope angle")
|
|
for alpha in ALPHAS:
|
|
require(seen[(2, alpha)] >= seen[(1, alpha)],
|
|
f"associative material case is weaker than Davis-B case at alpha={alpha:g}")
|
|
|
|
|
|
def check_path(rows: list[dict[str, str]]) -> None:
|
|
grouped: dict[tuple[int, float], list[dict[str, str]]] = defaultdict(list)
|
|
for row in rows:
|
|
grouped[case_key(row)].append(row)
|
|
require(len(grouped) == 8, "trial path does not cover all 8 PDF cases")
|
|
for key, case_rows in grouped.items():
|
|
stable = [row for row in case_rows if row["stable"].strip() == "1"]
|
|
unstable = [row for row in case_rows if row["stable"].strip() == "0"]
|
|
require(len(stable) >= 1 and len(unstable) >= 1,
|
|
f"trial path for {key} does not bracket instability")
|
|
require(case_rows[-1]["status_after"].strip() == "CONVERGED",
|
|
f"trial path for {key} does not finish converged")
|
|
|
|
|
|
def check_plastic_zone(rows: list[dict[str, str]]) -> None:
|
|
grouped: dict[tuple[int, float], list[dict[str, str]]] = defaultdict(list)
|
|
for row in rows:
|
|
grouped[case_key(row)].append(row)
|
|
require(len(grouped) == 8, "plastic-zone output does not cover all 8 PDF cases")
|
|
total_active = 0
|
|
for key, case_rows in grouped.items():
|
|
active = [row for row in case_rows if row["plastic"].strip() == "1"]
|
|
total_active += len(active)
|
|
require(len(case_rows) == 6, f"plastic-zone case {key} does not have 6 probes")
|
|
require(len(active) >= 1, f"plastic-zone case {key} has no active MC branch")
|
|
require(total_active >= 32, f"plastic-zone output is too small: {total_active}")
|
|
|
|
|
|
def check_displacements(rows: list[dict[str, str]]) -> None:
|
|
require(len(rows) == 8, f"expected 8 displacement probe rows, got {len(rows)}")
|
|
for row in rows:
|
|
key = case_key(row)
|
|
crest_uz = float(row["crest_uz"])
|
|
toe_ux = float(row["toe_ux"])
|
|
max_displacement = float(row["max_displacement"])
|
|
stop_displacement = float(row["stop_displacement"])
|
|
require(crest_uz < 0.0, f"crest vertical displacement has wrong sign for {key}")
|
|
require(toe_ux > 0.0, f"toe horizontal displacement has wrong sign for {key}")
|
|
require(0.0 < max_displacement < stop_displacement,
|
|
f"displacement stop criterion is inconsistent for {key}")
|
|
|
|
|
|
def check_trust_row(row: dict[str, str], label: str) -> None:
|
|
radius = float(row["trust_radius"])
|
|
next_radius = float(row["next_trust_radius"])
|
|
damping = float(row["damping"])
|
|
merit_ratio = float(row["merit_ratio"])
|
|
rejections = int(row["trust_rejections"])
|
|
adjust = int(row["trust_adjust"])
|
|
require(radius >= 0.0, f"{label} trust_radius is negative")
|
|
require(next_radius >= 0.0, f"{label} next_trust_radius is negative")
|
|
require(0.0 <= damping <= 1.0 + 1.0e-12,
|
|
f"{label} damping is outside [0,1]")
|
|
require(math.isfinite(merit_ratio), f"{label} merit_ratio is not finite")
|
|
require(rejections >= 0, f"{label} trust_rejections is negative")
|
|
require(adjust in ADJUST_CODES, f"{label} trust_adjust is invalid")
|
|
|
|
|
|
def check_trust_summary(summary: dict[str, str], label: str) -> None:
|
|
radius = float(summary["trust_radius"])
|
|
min_radius = float(summary["trust_min_radius"])
|
|
max_radius = float(summary["trust_max_radius"])
|
|
growth = float(summary["trust_growth_factor"])
|
|
shrink = float(summary["trust_shrink_factor"])
|
|
accept = float(summary["trust_accept_ratio"])
|
|
good = float(summary["trust_good_ratio"])
|
|
last_radius = float(summary["last_trust_radius"])
|
|
next_radius = float(summary["next_trust_radius"])
|
|
damping = float(summary["last_damping"])
|
|
merit = float(summary["last_merit_ratio"])
|
|
rejections = int(summary["last_trust_rejections"])
|
|
adjust = int(summary["last_trust_adjust"])
|
|
require(radius >= 0.0, f"{label} trust_radius is negative")
|
|
require(min_radius > 0.0, f"{label} trust_min_radius must be positive")
|
|
require(max_radius >= 0.0, f"{label} trust_max_radius is negative")
|
|
if max_radius > 0.0:
|
|
require(max_radius >= min_radius,
|
|
f"{label} trust_max_radius is below trust_min_radius")
|
|
require(growth > 1.0, f"{label} trust_growth_factor must be greater than 1")
|
|
require(0.0 < shrink < 1.0,
|
|
f"{label} trust_shrink_factor must be in (0,1)")
|
|
require(0.0 <= accept < 1.0,
|
|
f"{label} trust_accept_ratio must be in [0,1)")
|
|
require(0.0 < good <= 1.0,
|
|
f"{label} trust_good_ratio must be in (0,1]")
|
|
require(good >= accept,
|
|
f"{label} trust_good_ratio is below trust_accept_ratio")
|
|
require(last_radius >= 0.0, f"{label} last_trust_radius is negative")
|
|
require(next_radius >= 0.0, f"{label} next_trust_radius is negative")
|
|
require(0.0 <= damping <= 1.0 + 1.0e-12,
|
|
f"{label} last_damping is outside [0,1]")
|
|
require(math.isfinite(merit), f"{label} last_merit_ratio is not finite")
|
|
require(rejections >= 0, f"{label} last_trust_rejections is negative")
|
|
require(adjust in ADJUST_CODES, f"{label} last_trust_adjust is invalid")
|
|
|
|
|
|
def check_mc_row(row: dict[str, str], label: str) -> None:
|
|
points = int(row["mc_points"])
|
|
updated = int(row["mc_updated_points"])
|
|
substeps = int(row["mc_substeps"])
|
|
requested = int(row["mc_requested_substeps"])
|
|
limited = int(row["mc_limited_points"])
|
|
branch_mask = int(row["mc_branch_mask"])
|
|
max_yield = float(row["mc_max_yield"])
|
|
max_plastic = float(row["mc_max_plastic_step"])
|
|
|
|
require(points > 0, f"{label} mc_points must be positive")
|
|
require(0 <= updated <= points,
|
|
f"{label} mc_updated_points is outside [0, mc_points]")
|
|
require(substeps >= 0, f"{label} mc_substeps is negative")
|
|
require(requested >= 0, f"{label} mc_requested_substeps is negative")
|
|
require(0 <= limited <= points,
|
|
f"{label} mc_limited_points is outside [0, mc_points]")
|
|
require(0 <= branch_mask <= 15, f"{label} mc_branch_mask is invalid")
|
|
require(math.isfinite(max_yield) and max_yield >= 0.0,
|
|
f"{label} mc_max_yield is invalid")
|
|
require(math.isfinite(max_plastic) and max_plastic >= 0.0,
|
|
f"{label} mc_max_plastic_step is invalid")
|
|
if updated > 0:
|
|
require(substeps >= updated,
|
|
f"{label} mc_substeps is smaller than updated points")
|
|
require(requested >= substeps,
|
|
f"{label} mc_requested_substeps is smaller than accepted substeps")
|
|
|
|
|
|
def check_mc_summary(summary: dict[str, str], label: str) -> None:
|
|
min_substeps = int(summary["mc_min_substeps"])
|
|
max_substeps = int(summary["mc_max_substeps"])
|
|
target_strain = float(summary["mc_target_strain"])
|
|
yield_tol = float(summary["mc_yield_tol"])
|
|
plastic_limit = float(summary["mc_plastic_limit"])
|
|
|
|
require(min_substeps >= 1, f"{label} mc_min_substeps must be positive")
|
|
require(max_substeps >= min_substeps,
|
|
f"{label} mc_max_substeps is below mc_min_substeps")
|
|
require(target_strain > 0.0, f"{label} mc_target_strain must be positive")
|
|
require(yield_tol >= 0.0, f"{label} mc_yield_tol is negative")
|
|
require(plastic_limit > 0.0, f"{label} mc_plastic_limit must be positive")
|
|
check_mc_row({key: summary[key] for key in MC_ROW_COLUMNS}, label)
|
|
|
|
|
|
def check_optional_nonlinear_chain(
|
|
rows: list[dict[str, str]], summary: dict[str, str]
|
|
) -> None:
|
|
require(rows, "nonlinear chain output is empty")
|
|
require(summary.get("chain_type") == "real_nonlinear_fe_trials",
|
|
"nonlinear summary does not identify real FE trials")
|
|
require(summary.get("status") in {"CONVERGED", "BRACKETED", "LIMITED", "INVALID"},
|
|
f"unexpected nonlinear chain status: {summary.get('status')}")
|
|
require(summary.get("continuation_method") == "1",
|
|
"nonlinear chain must record default continuation method 1")
|
|
summary_required = {
|
|
"target_newton", "growth_factor", "shrink_factor", "last_target_dt",
|
|
"last_actual_dt", "next_target_dt", "last_adjust",
|
|
*TRUST_SUMMARY_KEYS, *MC_SUMMARY_KEYS,
|
|
}
|
|
missing_summary = summary_required.difference(summary)
|
|
require(not missing_summary,
|
|
f"nonlinear summary is missing keys: {sorted(missing_summary)}")
|
|
require(int(summary["target_newton"]) > 0,
|
|
"nonlinear summary target_newton must be positive")
|
|
require(float(summary["growth_factor"]) > 1.0,
|
|
"nonlinear summary growth_factor must be greater than 1")
|
|
require(0.0 < float(summary["shrink_factor"]) < 1.0,
|
|
"nonlinear summary shrink_factor must be in (0,1)")
|
|
require(float(summary["last_target_dt"]) >= 0.0,
|
|
"nonlinear summary last_target_dt is negative")
|
|
require(float(summary["last_actual_dt"]) >= 0.0,
|
|
"nonlinear summary last_actual_dt is negative")
|
|
require(float(summary["next_target_dt"]) >= 0.0,
|
|
"nonlinear summary next_target_dt is negative")
|
|
require(int(summary["last_adjust"]) in ADJUST_CODES,
|
|
"nonlinear summary last_adjust is invalid")
|
|
check_trust_summary(summary, "nonlinear summary")
|
|
check_mc_summary(summary, "nonlinear summary")
|
|
|
|
required = {
|
|
"trial", "continuation_method", "factor", "solver_ierr",
|
|
"converged", "conv_status", "conv_failure", "cutbacks", "iterations",
|
|
"last_dt", "target_dt", "actual_dt", "next_dt", "adapt_adjust",
|
|
*TRUST_ROW_COLUMNS,
|
|
"accepted_time", "correction_norm", "linear_iterations",
|
|
"linear_residual", "linear_status", "relative_residual",
|
|
"combined_norm", "max_displacement", "plastic_share", "metric",
|
|
*MC_ROW_COLUMNS, "stable", "search_status",
|
|
}
|
|
missing = required.difference(rows[0])
|
|
require(not missing, f"nonlinear chain is missing columns: {sorted(missing)}")
|
|
|
|
for row in rows:
|
|
factor = float(row["factor"])
|
|
solver_ierr = int(row["solver_ierr"])
|
|
converged = int(row["converged"])
|
|
stable = int(row["stable"])
|
|
require(factor >= 1.0 - 1.0e-12,
|
|
f"nonlinear chain tried a sub-unit strength factor: {factor}")
|
|
require(float(row["relative_residual"]) >= 0.0, "negative nonlinear residual")
|
|
require(float(row["combined_norm"]) >= 0.0, "negative nonlinear combined norm")
|
|
require(float(row["max_displacement"]) >= 0.0, "negative nonlinear displacement")
|
|
require(0.0 <= float(row["accepted_time"]) <= 1.0 + 1.0e-12,
|
|
"nonlinear accepted time is outside the load step")
|
|
require(float(row["last_dt"]) >= 0.0, "negative nonlinear last_dt")
|
|
require(float(row["target_dt"]) >= 0.0, "negative target_dt")
|
|
require(float(row["actual_dt"]) >= 0.0, "negative actual_dt")
|
|
require(float(row["next_dt"]) >= 0.0, "negative next_dt")
|
|
require(int(row["adapt_adjust"]) in ADJUST_CODES,
|
|
"unexpected adaptive adjustment code")
|
|
check_trust_row(row, "nonlinear chain")
|
|
check_mc_row(row, "nonlinear chain")
|
|
require(float(row["correction_norm"]) >= 0.0, "negative nonlinear correction norm")
|
|
require(int(row["linear_iterations"]) >= 0, "negative linear iteration count")
|
|
require(float(row["linear_residual"]) >= 0.0, "negative linear residual")
|
|
require(0.0 <= float(row["plastic_share"]) <= 1.0,
|
|
"nonlinear plastic share is outside [0, 1]")
|
|
require(int(row["iterations"]) >= 0, "negative nonlinear iteration count")
|
|
require(int(row["cutbacks"]) >= 0, "negative nonlinear cutback count")
|
|
if solver_ierr != 0:
|
|
require(converged == 0, "failed nonlinear trial is marked converged")
|
|
require(stable == 0, "failed nonlinear trial is marked stable")
|
|
|
|
|
|
def check_optional_nonlinear_cloud(output_dir: Path, summary: dict[str, str]) -> None:
|
|
require(summary.get("cloud_type") == "real_nonlinear_fe_target",
|
|
"cloud summary does not identify a real target FE trial")
|
|
require(summary.get("status") in {"CONVERGED", "PARTIAL", "FAILED"},
|
|
f"unexpected cloud status: {summary.get('status')}")
|
|
require(summary.get("continuation_method") == "1",
|
|
"cloud summary must record default continuation method 1")
|
|
|
|
required = {
|
|
"material_case", "flow_rule", "alpha_deg", "continuation_method",
|
|
"factor", "reference_fos",
|
|
"vtk_file", "vtk_step", "nodes", "elements", "solver_ierr",
|
|
"converged", "conv_status", "conv_failure", "cutbacks", "iterations",
|
|
"last_dt", "accepted_time", "correction_norm", "linear_iterations",
|
|
"linear_residual", "linear_status", "residual", "relative_residual",
|
|
"combined_norm", "max_displacement", "reference_displacement_scale",
|
|
"displacement_scale_ratio", "stop_displacement", "plastic_share",
|
|
"max_eqps", "max_increments", "max_newton",
|
|
"target_newton", "growth_factor", "shrink_factor", "last_target_dt",
|
|
"last_actual_dt", "next_target_dt", "last_adjust", "solver_tol",
|
|
*TRUST_SUMMARY_KEYS, *MC_SUMMARY_KEYS,
|
|
}
|
|
missing = required.difference(summary)
|
|
require(not missing, f"cloud summary is missing keys: {sorted(missing)}")
|
|
|
|
factor = float(summary["factor"])
|
|
reference_fos = float(summary["reference_fos"])
|
|
accepted_time = float(summary["accepted_time"])
|
|
max_displacement = float(summary["max_displacement"])
|
|
reference_displacement_scale = float(summary["reference_displacement_scale"])
|
|
displacement_scale_ratio = float(summary["displacement_scale_ratio"])
|
|
plastic_share = float(summary["plastic_share"])
|
|
max_eqps = float(summary["max_eqps"])
|
|
converged = int(summary["converged"])
|
|
solver_ierr = int(summary["solver_ierr"])
|
|
nodes = int(summary["nodes"])
|
|
elements = int(summary["elements"])
|
|
|
|
require(factor >= 1.0 - 1.0e-12, "cloud factor must be a strength reduction factor")
|
|
require(reference_fos >= 1.0, "cloud reference FOS is invalid")
|
|
require(nodes > 0 and elements > 0, "cloud mesh sizes must be positive")
|
|
require(0.0 <= accepted_time <= 1.0 + 1.0e-12,
|
|
"cloud accepted time is outside [0, 1]")
|
|
require(max_displacement >= 0.0, "cloud max displacement is negative")
|
|
require(abs(reference_displacement_scale -
|
|
REFERENCE_DISPLACEMENT_SCALE) <= 1.0e-12,
|
|
"cloud reference displacement scale is not 0.3 m")
|
|
require(displacement_scale_ratio >= 0.0,
|
|
"cloud displacement scale ratio is negative")
|
|
require(abs(displacement_scale_ratio -
|
|
max_displacement / reference_displacement_scale) <= 1.0e-8,
|
|
"cloud displacement scale ratio is inconsistent")
|
|
require(0.0 <= plastic_share <= 1.0, "cloud plastic share is outside [0, 1]")
|
|
require(max_eqps >= 0.0, "cloud max eqps is negative")
|
|
require(int(summary["target_newton"]) > 0, "cloud target_newton must be positive")
|
|
require(float(summary["growth_factor"]) > 1.0,
|
|
"cloud growth_factor must be greater than 1")
|
|
require(0.0 < float(summary["shrink_factor"]) < 1.0,
|
|
"cloud shrink_factor must be in (0,1)")
|
|
require(float(summary["last_target_dt"]) >= 0.0, "cloud last_target_dt is negative")
|
|
require(float(summary["last_actual_dt"]) >= 0.0, "cloud last_actual_dt is negative")
|
|
require(float(summary["next_target_dt"]) >= 0.0, "cloud next_target_dt is negative")
|
|
require(int(summary["last_adjust"]) in ADJUST_CODES,
|
|
"cloud last_adjust is invalid")
|
|
check_trust_summary(summary, "cloud summary")
|
|
check_mc_summary(summary, "cloud summary")
|
|
if converged:
|
|
require(solver_ierr == 0, "converged cloud trial has nonzero solver error")
|
|
require(summary["status"] == "CONVERGED",
|
|
"converged cloud trial has inconsistent status")
|
|
require(accepted_time >= 1.0 - 1.0e-10,
|
|
"converged cloud trial did not reach the full load")
|
|
require(max_displacement > 0.0, "converged cloud trial has zero displacement")
|
|
|
|
vtk_file = output_dir / summary["vtk_file"]
|
|
check_cloud_vtk(vtk_file, nodes, elements)
|
|
|
|
|
|
def check_cloud_vtk(vtk_file: Path, nodes: int, elements: int) -> None:
|
|
require(vtk_file.exists(), f"missing nonlinear cloud VTK: {vtk_file}")
|
|
vtk_text = vtk_file.read_text(encoding="utf-8", errors="ignore")
|
|
require("DATASET UNSTRUCTURED_GRID" in vtk_text, "cloud VTK is not unstructured grid")
|
|
require("VECTORS displacement double" in vtk_text, "cloud VTK lacks displacement vectors")
|
|
require("SCALARS eqps double 1" in vtk_text, "cloud VTK lacks eqps cell scalar")
|
|
points_match = re.search(r"^POINTS\s+(\d+)\s+", vtk_text, re.MULTILINE)
|
|
cells_match = re.search(r"^CELLS\s+(\d+)\s+", vtk_text, re.MULTILINE)
|
|
require(points_match is not None, "cloud VTK lacks POINTS header")
|
|
require(cells_match is not None, "cloud VTK lacks CELLS header")
|
|
require(int(points_match.group(1)) == nodes,
|
|
"cloud VTK node count differs from summary")
|
|
require(int(cells_match.group(1)) == elements,
|
|
"cloud VTK element count differs from summary")
|
|
|
|
|
|
def check_no_linear_static_reference_vtk(output_dir: Path) -> None:
|
|
linear_vtk = output_dir / "result_00000001.vtk"
|
|
require(not linear_vtk.exists(),
|
|
"linear-static result_00000001.vtk is not valid nonlinear-cloud evidence")
|
|
|
|
|
|
def check_optional_partial_cloud(output_dir: Path, input_file: Path) -> None:
|
|
progress = output_dir / "strength_reduction_cloud_progress.csv"
|
|
vtk_file = output_dir / "result_00001525.vtk"
|
|
if not progress.exists() and not vtk_file.exists():
|
|
return
|
|
require(progress.exists(), "partial cloud VTK exists without progress CSV")
|
|
require(vtk_file.exists(), "partial cloud progress exists without VTK")
|
|
rows = read_rows(progress)
|
|
require(rows, "partial cloud progress is empty")
|
|
require("continuation_method" in rows[0],
|
|
"partial cloud progress must record continuation_method")
|
|
for column in (
|
|
"target_dt", "actual_dt", "next_dt", "adapt_adjust",
|
|
*TRUST_ROW_COLUMNS, *MC_ROW_COLUMNS,
|
|
):
|
|
require(column in rows[0], f"partial cloud progress lacks {column}")
|
|
require({row["continuation_method"] for row in rows} == {"1"},
|
|
"partial cloud progress must record default continuation method 1")
|
|
accepted = [float(row["accepted_time"]) for row in rows]
|
|
require(max(accepted) > 0.0, "partial cloud has no accepted nonlinear segment")
|
|
for row in rows:
|
|
require(float(row["target_dt"]) >= 0.0, "partial cloud target_dt is negative")
|
|
require(float(row["actual_dt"]) >= 0.0, "partial cloud actual_dt is negative")
|
|
require(float(row["next_dt"]) >= 0.0, "partial cloud next_dt is negative")
|
|
require(int(row["adapt_adjust"]) in ADJUST_CODES,
|
|
"partial cloud adaptive code is invalid")
|
|
check_trust_row(row, "partial cloud")
|
|
check_mc_row(row, "partial cloud")
|
|
nodes, elements = parse_inp_nodes_elements(input_file)
|
|
check_cloud_vtk(vtk_file, len(nodes), len(elements))
|
|
|
|
|
|
def main() -> int:
|
|
if len(sys.argv) != 2:
|
|
raise RuntimeError("usage: check_strength_reduction_results.py OUTPUT_DIR")
|
|
|
|
output_dir = Path(sys.argv[1]).resolve()
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
build_dirs = [output_dir.parents[1], repo_root / "build-win-gcc-16", repo_root / "build"]
|
|
case_dir = repo_root / "examples" / "strengthReduction"
|
|
input_file = case_dir / "strength_reduction_slope_static.inp"
|
|
reference_file = case_dir / "strength_reduction_reference_cases.csv"
|
|
tool = find_tool(build_dirs)
|
|
|
|
check_input(input_file)
|
|
expected = check_reference_cases(reference_file)
|
|
|
|
completed = subprocess.run(
|
|
[str(tool), str(input_file), str(output_dir)],
|
|
cwd=repo_root,
|
|
text=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
)
|
|
print(completed.stdout)
|
|
if completed.returncode != 0:
|
|
raise RuntimeError(f"{tool} exited with code {completed.returncode}")
|
|
|
|
path_csv = output_dir / "strength_reduction_path.csv"
|
|
cases_csv = output_dir / "strength_reduction_cases.csv"
|
|
summary_csv = output_dir / "strength_reduction_summary.csv"
|
|
plastic_zone = output_dir / "plastic_zone.csv"
|
|
displacement_probe = output_dir / "displacement_probe.csv"
|
|
|
|
for path in (path_csv, cases_csv, summary_csv, plastic_zone,
|
|
displacement_probe):
|
|
require(path.exists(), f"missing benchmark output: {path}")
|
|
|
|
check_summary(read_key_values(summary_csv))
|
|
check_cases(read_rows(cases_csv), expected)
|
|
check_path(read_rows(path_csv))
|
|
check_plastic_zone(read_rows(plastic_zone))
|
|
check_displacements(read_rows(displacement_probe))
|
|
check_no_linear_static_reference_vtk(output_dir)
|
|
|
|
nonlinear_chain = output_dir / "strength_reduction_nonlinear_chain.csv"
|
|
nonlinear_summary = output_dir / "strength_reduction_nonlinear_summary.csv"
|
|
if nonlinear_chain.exists() or nonlinear_summary.exists():
|
|
require(nonlinear_chain.exists(), "missing nonlinear chain CSV")
|
|
require(nonlinear_summary.exists(), "missing nonlinear summary CSV")
|
|
check_optional_nonlinear_chain(read_rows(nonlinear_chain),
|
|
read_key_values(nonlinear_summary))
|
|
|
|
nonlinear_cloud = output_dir / "strength_reduction_cloud_summary.csv"
|
|
if nonlinear_cloud.exists():
|
|
check_optional_nonlinear_cloud(output_dir, read_key_values(nonlinear_cloud))
|
|
else:
|
|
check_optional_partial_cloud(output_dir, input_file)
|
|
|
|
print("Mohr-Coulomb strength reduction benchmark passed: 8 cases, max FOS error <= 0.02")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|