Expose water diagnostics through public APIs

This commit is contained in:
Codex
2026-07-02 21:20:51 +08:00
parent 61b81e9d50
commit 03c05d6931
10 changed files with 280 additions and 24 deletions
+64 -3
View File
@@ -60,6 +60,22 @@ class SPHLite:
self.lib.sphlite_read_restart.argtypes = [ctypes.c_char_p]
self.lib.sphlite_read_restart.restype = ctypes.c_int
self.lib.sphlite_get_water_summary.argtypes = [
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
]
self.lib.sphlite_get_water_summary.restype = ctypes.c_int
self.lib.sphlite_get_water_dt_limits.argtypes = [
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
]
self.lib.sphlite_get_water_dt_limits.restype = ctypes.c_int
self.lib.sphlite_get_particle_state.argtypes = [
ctypes.c_int,
ctypes.POINTER(ctypes.c_int),
@@ -189,13 +205,58 @@ class SPHLite:
def read_restart(self, filename: str | Path) -> None:
self._check(self.lib.sphlite_read_restart(str(filename).encode("utf-8")))
def inspect(self, filename: str | Path) -> dict[str, int]:
def water_summary(self) -> dict[str, float | list[float]]:
mass = ctypes.c_double(0.0)
momentum_type = ctypes.c_double * 3
momentum = momentum_type()
max_pressure = ctypes.c_double(0.0)
min_density = ctypes.c_double(0.0)
max_density = ctypes.c_double(0.0)
self._check(self.lib.sphlite_get_water_summary(
ctypes.byref(mass),
momentum,
ctypes.byref(max_pressure),
ctypes.byref(min_density),
ctypes.byref(max_density),
))
return {
"water_mass": float(mass.value),
"water_momentum": list(momentum),
"max_pressure": float(max_pressure.value),
"min_density": float(min_density.value),
"max_density": float(max_density.value),
}
def water_dt_limits(self) -> dict[str, float]:
dt_cfl = ctypes.c_double(0.0)
dt_accel = ctypes.c_double(0.0)
dt_viscous = ctypes.c_double(0.0)
self._check(self.lib.sphlite_get_water_dt_limits(
ctypes.byref(dt_cfl),
ctypes.byref(dt_accel),
ctypes.byref(dt_viscous),
))
return {
"dt_cfl": float(dt_cfl.value),
"dt_accel": float(dt_accel.value),
"dt_viscous": float(dt_viscous.value),
}
def inspect(self, filename: str | Path) -> dict[str, int | float | list[float]]:
self.read_inp(filename)
self.build_model()
return {"particles": self.particle_count(), "warnings": self.warning_count()}
summary: dict[str, int | float | list[float]] = {
"particles": self.particle_count(),
"warnings": self.warning_count(),
}
summary.update(self.water_summary())
summary.update(self.water_dt_limits())
return summary
def run(self, filename: str | Path) -> dict[str, int]:
def run(self, filename: str | Path) -> dict[str, int | float | list[float]]:
summary = self.inspect(filename)
self.run_explicit()
summary["particles"] = self.particle_count()
summary.update(self.water_summary())
summary.update(self.water_dt_limits())
return summary