118 lines
4.0 KiB
Python
118 lines
4.0 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import ctypes
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
|
||
|
|
def configure_solid_api(lib: ctypes.CDLL) -> None:
|
||
|
|
lib.sphlite_get_solid_summary.argtypes = [
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_double),
|
||
|
|
ctypes.c_int,
|
||
|
|
]
|
||
|
|
lib.sphlite_get_solid_summary.restype = ctypes.c_int
|
||
|
|
lib.sphlite_get_solid_particle_state.argtypes = [
|
||
|
|
ctypes.c_int,
|
||
|
|
ctypes.POINTER(ctypes.c_double),
|
||
|
|
ctypes.c_int,
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
]
|
||
|
|
lib.sphlite_get_solid_particle_state.restype = ctypes.c_int
|
||
|
|
lib.sphlite_get_solid_diagnostics.argtypes = [
|
||
|
|
ctypes.POINTER(ctypes.c_double),
|
||
|
|
ctypes.c_int,
|
||
|
|
]
|
||
|
|
lib.sphlite_get_solid_diagnostics.restype = ctypes.c_int
|
||
|
|
lib.sphlite_get_solid_reference_quality.argtypes = [
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_int),
|
||
|
|
ctypes.POINTER(ctypes.c_double),
|
||
|
|
ctypes.c_int,
|
||
|
|
]
|
||
|
|
lib.sphlite_get_solid_reference_quality.restype = ctypes.c_int
|
||
|
|
|
||
|
|
|
||
|
|
def solid_summary(owner: Any) -> dict[str, int | float | list[float]]:
|
||
|
|
active, failed = ctypes.c_int(0), ctypes.c_int(0)
|
||
|
|
values = (ctypes.c_double * 16)()
|
||
|
|
owner._check(owner.lib.sphlite_get_solid_summary(
|
||
|
|
ctypes.byref(active), ctypes.byref(failed), values, len(values)))
|
||
|
|
v = list(values)
|
||
|
|
summary = {
|
||
|
|
"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],
|
||
|
|
}
|
||
|
|
summary.update(solid_diagnostics(owner))
|
||
|
|
summary.update(solid_reference_quality(owner))
|
||
|
|
return summary
|
||
|
|
|
||
|
|
|
||
|
|
def solid_particle_state(owner: Any) -> dict[str, list[float] | list[int]]:
|
||
|
|
count = owner.particle_count()
|
||
|
|
value_count = 22
|
||
|
|
values = (ctypes.c_double * (value_count * count))()
|
||
|
|
int_array = ctypes.c_int * count
|
||
|
|
failure_status = int_array()
|
||
|
|
reference_neighbor_count = int_array()
|
||
|
|
reference_degenerate = int_array()
|
||
|
|
correction_status = int_array()
|
||
|
|
actual = ctypes.c_int(0)
|
||
|
|
owner._check(owner.lib.sphlite_get_solid_particle_state(
|
||
|
|
count,
|
||
|
|
values,
|
||
|
|
len(values),
|
||
|
|
failure_status,
|
||
|
|
reference_neighbor_count,
|
||
|
|
reference_degenerate,
|
||
|
|
correction_status,
|
||
|
|
ctypes.byref(actual),
|
||
|
|
))
|
||
|
|
return {
|
||
|
|
"solid_values": list(values),
|
||
|
|
"solid_failure_status": list(failure_status),
|
||
|
|
"solid_reference_neighbor_count": list(reference_neighbor_count),
|
||
|
|
"solid_reference_degenerate": list(reference_degenerate),
|
||
|
|
"solid_correction_status": list(correction_status),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def solid_diagnostics(owner: Any) -> dict[str, float]:
|
||
|
|
values = (ctypes.c_double * 3)()
|
||
|
|
owner._check(owner.lib.sphlite_get_solid_diagnostics(values, len(values)))
|
||
|
|
return {
|
||
|
|
"solid_max_strain_rate": float(values[0]),
|
||
|
|
"solid_max_acceleration": float(values[1]),
|
||
|
|
"solid_internal_force_residual": float(values[2]),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def solid_reference_quality(owner: Any) -> dict[str, int | float]:
|
||
|
|
reference_neighbor_min = ctypes.c_int(0)
|
||
|
|
correction_status = ctypes.c_int(0)
|
||
|
|
values = (ctypes.c_double * 1)()
|
||
|
|
owner._check(owner.lib.sphlite_get_solid_reference_quality(
|
||
|
|
ctypes.byref(reference_neighbor_min),
|
||
|
|
ctypes.byref(correction_status),
|
||
|
|
values,
|
||
|
|
len(values),
|
||
|
|
))
|
||
|
|
return {
|
||
|
|
"solid_reference_neighbor_min": int(reference_neighbor_min.value),
|
||
|
|
"solid_correction_det_min": float(values[0]),
|
||
|
|
"solid_correction_status": int(correction_status.value),
|
||
|
|
}
|