Expose Solid summary interfaces

This commit is contained in:
Codex
2026-07-03 16:21:51 +08:00
parent d14ea370e5
commit 708016c9af
15 changed files with 486 additions and 51 deletions
+31 -23
View File
@@ -30,14 +30,12 @@ class SPHLite:
self._configure()
def _configure(self) -> None:
int_p = ctypes.POINTER(ctypes.c_int)
double_p = ctypes.POINTER(ctypes.c_double)
self.lib.sphlite_initialize.restype = ctypes.c_int
self.lib.sphlite_finalize.restype = ctypes.c_int
self.lib.sphlite_get_version.argtypes = [
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int),
]
self.lib.sphlite_get_version.argtypes = [int_p, int_p, int_p]
self.lib.sphlite_get_version.restype = ctypes.c_int
self.lib.sphlite_read_inp.argtypes = [ctypes.c_char_p]
@@ -67,28 +65,13 @@ 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.argtypes = [double_p] * 5
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.argtypes = [double_p] * 3
self.lib.sphlite_get_water_dt_limits.restype = ctypes.c_int
self.lib.sphlite_get_gas_summary.argtypes = [
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
]
self.lib.sphlite_get_gas_summary.argtypes = [double_p] * 4
self.lib.sphlite_get_gas_summary.restype = ctypes.c_int
self.lib.sphlite_get_gas_bubble_metrics.argtypes = [
@@ -142,6 +125,9 @@ class SPHLite:
ctypes.POINTER(ctypes.c_double),
]
self.lib.sphlite_get_explosive_release_balance.restype = ctypes.c_int
self.lib.sphlite_get_solid_summary.argtypes = [ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_double), ctypes.c_int]
self.lib.sphlite_get_solid_summary.restype = ctypes.c_int
self.lib.sphlite_get_particle_state.argtypes = [
ctypes.c_int,
@@ -454,6 +440,26 @@ class SPHLite:
"explosive_release_momentum_values": list(momentum_values),
}
def solid_summary(self) -> dict[str, int | float | list[float]]:
active, failed = ctypes.c_int(0), ctypes.c_int(0)
values = (ctypes.c_double * 16)()
self._check(self.lib.sphlite_get_solid_summary(
ctypes.byref(active), ctypes.byref(failed), values, len(values)))
v = list(values)
return {
"solid_particles": int(active.value),
"solid_failed_particles": int(failed.value),
"solid_mass": float(v[0]),
"solid_momentum": v[1:4],
"solid_kinetic_energy": float(v[4]),
"solid_internal_energy": float(v[5]),
"solid_max_von_mises": float(v[6]),
"solid_plastic_strain_range": v[7:9],
"solid_damage_range": v[9:11],
"solid_softening_range": v[11:13],
"solid_dt_limits": v[13:16],
}
def inspect(self, filename: str | Path) -> dict[str, int | float | list[float]]:
self.read_inp(filename)
self.build_model()
@@ -470,6 +476,7 @@ class SPHLite:
summary.update(self.gas_source_summary())
summary.update(self.explosive_summary())
summary.update(self.explosive_release_balance())
summary.update(self.solid_summary())
return summary
def run(self, filename: str | Path) -> dict[str, int | float | list[float]]:
@@ -485,4 +492,5 @@ class SPHLite:
summary.update(self.gas_source_summary())
summary.update(self.explosive_summary())
summary.update(self.explosive_release_balance())
summary.update(self.solid_summary())
return summary