Expose Solid 0.5.1 state APIs
This commit is contained in:
@@ -5,6 +5,34 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def write_state_050_compat(source: Path, target: Path, npart: int) -> None:
|
||||
lines = source.read_text(encoding="utf-8").splitlines()
|
||||
solid_material_count = 1
|
||||
solid_051_lines = 1 + 6 * solid_material_count + 8 + 9 * npart
|
||||
solid_start = len(lines) - solid_051_lines
|
||||
if solid_start <= 0:
|
||||
raise AssertionError("could not locate Solid restart block")
|
||||
lines[0] = "SPHLITE_RESTART 0 5 0 STATE_0_5"
|
||||
|
||||
def skip_solid_line(relative_line: int) -> bool:
|
||||
material_end = 1 + 6 * solid_material_count
|
||||
if relative_line in (material_end + 6, material_end + 7):
|
||||
return True
|
||||
particle_start = material_end + 9
|
||||
if relative_line < particle_start:
|
||||
return False
|
||||
particle_line = (relative_line - particle_start) % 9
|
||||
return particle_line in (5, 6, 7)
|
||||
|
||||
output: list[str] = []
|
||||
for index, line in enumerate(lines):
|
||||
relative_line = index - solid_start + 1
|
||||
if relative_line > 0 and skip_solid_line(relative_line):
|
||||
continue
|
||||
output.append(line)
|
||||
target.write_text("\n".join(output) + "\n", encoding="utf-8")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--library", required=True)
|
||||
@@ -39,6 +67,10 @@ def main() -> int:
|
||||
raise AssertionError("Python wrapper is missing Explosive ignition C ABI")
|
||||
if not hasattr(solver.lib, "sphlite_get_solid_summary"):
|
||||
raise AssertionError("Python wrapper is missing Solid C ABI diagnostics")
|
||||
if not hasattr(solver.lib, "sphlite_get_solid_particle_state"):
|
||||
raise AssertionError("Python wrapper is missing Solid particle state C ABI")
|
||||
if not hasattr(solver.lib, "sphlite_get_solid_diagnostics"):
|
||||
raise AssertionError("Python wrapper is missing Solid 0.5.1 diagnostics C ABI")
|
||||
if solver.version() != (0, 5, 1):
|
||||
raise AssertionError("Python version mismatch")
|
||||
|
||||
@@ -52,6 +84,11 @@ def main() -> int:
|
||||
state = solver.particle_state()
|
||||
if state["phase"][0] != PHASE_SOLID:
|
||||
raise AssertionError("unexpected particle phase")
|
||||
solid_state = solver.solid_particle_state()
|
||||
if len(solid_state["solid_values"]) != 22 * count:
|
||||
raise AssertionError("solid particle state value layout mismatch")
|
||||
if solid_state["solid_failure_status"][0] != STATUS_ACTIVE:
|
||||
raise AssertionError("solid particle failure status mismatch")
|
||||
solid_summary = solver.inspect(args.input)
|
||||
if solid_summary["particles"] != 4:
|
||||
raise AssertionError("solid inspect summary mismatch")
|
||||
@@ -69,6 +106,10 @@ def main() -> int:
|
||||
raise AssertionError("inspect helper did not include Solid diagnostics")
|
||||
if solid_summary["solid_dt_limits"][0] <= 0.0:
|
||||
raise AssertionError("inspect helper did not include Solid dt diagnostics")
|
||||
if "solid_max_strain_rate" not in solid_summary:
|
||||
raise AssertionError("inspect helper did not include Solid 0.5.1 diagnostics")
|
||||
if "solid_reference_neighbor_min" not in solid_summary:
|
||||
raise AssertionError("inspect helper did not include Solid reference quality")
|
||||
solver.set_output_directory(root / "build-codex-unix")
|
||||
solver.write_output(0, 0.0)
|
||||
restart = root / "build-codex-unix" / "python_restart.tmp"
|
||||
@@ -77,6 +118,15 @@ def main() -> int:
|
||||
restart_summary = solver.solid_summary()
|
||||
if restart_summary["solid_particles"] != 4:
|
||||
raise AssertionError("Solid restart summary mismatch")
|
||||
restart_050 = root / "build-codex-unix" / "python_restart_050.tmp"
|
||||
write_state_050_compat(restart, restart_050, count)
|
||||
solver.read_restart(restart_050)
|
||||
compat_summary = solver.solid_summary()
|
||||
if compat_summary["solid_particles"] != 4:
|
||||
raise AssertionError("Solid 0.5.0 restart summary mismatch")
|
||||
compat_state = solver.solid_particle_state()
|
||||
if len(compat_state["solid_values"]) != 22 * count:
|
||||
raise AssertionError("Solid 0.5.0 restart particle state mismatch")
|
||||
solver.run_explicit()
|
||||
finally:
|
||||
solver.finalize()
|
||||
|
||||
Reference in New Issue
Block a user