Add 0.8.1 coupling output restart APIs
This commit is contained in:
+248
-2
@@ -35,10 +35,24 @@ COUPLING_IMPORT_FORCE = 1
|
||||
COUPLING_IMPORT_FACET_LOAD = 2
|
||||
COUPLING_IMPORT_MOTION = 3
|
||||
|
||||
COUPLING_LOAD_PARTICLE_FORCE = 1
|
||||
COUPLING_LOAD_FACET_FORCE = 2
|
||||
COUPLING_LOAD_PRESSURE = 3
|
||||
COUPLING_LOAD_TRACTION = 4
|
||||
|
||||
COUPLING_DISTRIBUTION_UNIFORM = 1
|
||||
COUPLING_DISTRIBUTION_AREA = 2
|
||||
COUPLING_DISTRIBUTION_MASS = 3
|
||||
|
||||
COUPLING_CONTACT_STATE_NONE = 0
|
||||
COUPLING_CONTACT_STATE_IMPORT = 1
|
||||
|
||||
COUPLING_PARTICLE_SCALAR_COUNT = 7
|
||||
COUPLING_PARTICLE_VECTOR_COUNT = 3
|
||||
COUPLING_DIAGNOSTIC_VALUE_COUNT = 22
|
||||
COUPLING_DIAGNOSTIC_COUNT_COUNT = 5
|
||||
COUPLING_DIAGNOSTIC_VALUE_COUNT = 27
|
||||
COUPLING_DIAGNOSTIC_COUNT_COUNT = 12
|
||||
COUPLING_CONTACT_DIAGNOSTIC_VALUE_COUNT = 1
|
||||
COUPLING_CONTACT_DIAGNOSTIC_COUNT_COUNT = 7
|
||||
|
||||
|
||||
class SPHLiteError(RuntimeError):
|
||||
@@ -165,6 +179,13 @@ class SPHLite:
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
]
|
||||
self.lib.sphlite_coupling_get_region_info.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_get_region_modes.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
]
|
||||
self.lib.sphlite_coupling_get_region_modes.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_export_particles.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
@@ -186,6 +207,60 @@ class SPHLite:
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
]
|
||||
self.lib.sphlite_coupling_apply_particle_forces.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_apply_facet_pressures.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
]
|
||||
self.lib.sphlite_coupling_apply_facet_pressures.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_apply_facet_tractions.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
]
|
||||
self.lib.sphlite_coupling_apply_facet_tractions.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_apply_facet_resultants.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
]
|
||||
self.lib.sphlite_coupling_apply_facet_resultants.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_apply_contact_state.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_int,
|
||||
]
|
||||
self.lib.sphlite_coupling_apply_contact_state.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_get_load_balance.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),
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
]
|
||||
self.lib.sphlite_coupling_get_load_balance.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_get_contact_diagnostics.argtypes = [
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
ctypes.c_int,
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_int,
|
||||
]
|
||||
self.lib.sphlite_coupling_get_contact_diagnostics.restype = ctypes.c_int
|
||||
self.lib.sphlite_coupling_get_diagnostics.argtypes = [
|
||||
ctypes.POINTER(ctypes.c_double),
|
||||
ctypes.c_int,
|
||||
@@ -530,6 +605,9 @@ class SPHLite:
|
||||
enabled = ctypes.c_int(0)
|
||||
particle_count = ctypes.c_int(0)
|
||||
facet_count = ctypes.c_int(0)
|
||||
load_mode = ctypes.c_int(0)
|
||||
distribution_mode = ctypes.c_int(0)
|
||||
contact_state_mode = ctypes.c_int(0)
|
||||
self._check(self.lib.sphlite_coupling_get_region_info(
|
||||
int(region_index),
|
||||
buffer,
|
||||
@@ -541,11 +619,20 @@ class SPHLite:
|
||||
ctypes.byref(particle_count),
|
||||
ctypes.byref(facet_count),
|
||||
))
|
||||
self._check(self.lib.sphlite_coupling_get_region_modes(
|
||||
int(region_index),
|
||||
ctypes.byref(load_mode),
|
||||
ctypes.byref(distribution_mode),
|
||||
ctypes.byref(contact_state_mode),
|
||||
))
|
||||
return {
|
||||
"name": buffer.value.decode("utf-8", errors="replace"),
|
||||
"region_type": int(region_type.value),
|
||||
"export_mode": int(export_mode.value),
|
||||
"import_mode": int(import_mode.value),
|
||||
"load_mode": int(load_mode.value),
|
||||
"distribution_mode": int(distribution_mode.value),
|
||||
"contact_state_mode": int(contact_state_mode.value),
|
||||
"enabled": int(enabled.value),
|
||||
"particle_count": int(particle_count.value),
|
||||
"facet_count": int(facet_count.value),
|
||||
@@ -609,6 +696,153 @@ class SPHLite:
|
||||
force_array,
|
||||
))
|
||||
|
||||
def coupling_apply_facet_pressures(
|
||||
self,
|
||||
region_index: int,
|
||||
facet_ids: list[int],
|
||||
pressures: list[float],
|
||||
distribution_mode: int,
|
||||
coupling_step: int,
|
||||
) -> None:
|
||||
count = len(facet_ids)
|
||||
if len(pressures) != count:
|
||||
raise ValueError("coupling pressure vector size mismatch")
|
||||
id_array = (ctypes.c_int * max(1, count))(*facet_ids)
|
||||
pressure_array = (ctypes.c_double * max(1, count))(*pressures)
|
||||
self._check(self.lib.sphlite_coupling_apply_facet_pressures(
|
||||
int(region_index),
|
||||
count,
|
||||
id_array,
|
||||
pressure_array,
|
||||
int(distribution_mode),
|
||||
int(coupling_step),
|
||||
))
|
||||
|
||||
def coupling_apply_facet_tractions(
|
||||
self,
|
||||
region_index: int,
|
||||
facet_ids: list[int],
|
||||
tractions: list[float],
|
||||
distribution_mode: int,
|
||||
coupling_step: int,
|
||||
) -> None:
|
||||
count = len(facet_ids)
|
||||
if len(tractions) != 3 * count:
|
||||
raise ValueError("coupling traction vector size mismatch")
|
||||
id_array = (ctypes.c_int * max(1, count))(*facet_ids)
|
||||
traction_array = (ctypes.c_double * max(1, 3 * count))(*tractions)
|
||||
self._check(self.lib.sphlite_coupling_apply_facet_tractions(
|
||||
int(region_index),
|
||||
count,
|
||||
id_array,
|
||||
traction_array,
|
||||
int(distribution_mode),
|
||||
int(coupling_step),
|
||||
))
|
||||
|
||||
def coupling_apply_facet_resultants(
|
||||
self,
|
||||
region_index: int,
|
||||
facet_ids: list[int],
|
||||
resultants: list[float],
|
||||
distribution_mode: int,
|
||||
coupling_step: int,
|
||||
) -> None:
|
||||
count = len(facet_ids)
|
||||
if len(resultants) != 3 * count:
|
||||
raise ValueError("coupling resultant vector size mismatch")
|
||||
id_array = (ctypes.c_int * max(1, count))(*facet_ids)
|
||||
resultant_array = (ctypes.c_double * max(1, 3 * count))(*resultants)
|
||||
self._check(self.lib.sphlite_coupling_apply_facet_resultants(
|
||||
int(region_index),
|
||||
count,
|
||||
id_array,
|
||||
resultant_array,
|
||||
int(distribution_mode),
|
||||
int(coupling_step),
|
||||
))
|
||||
|
||||
def coupling_apply_contact_state(
|
||||
self,
|
||||
region_index: int,
|
||||
facet_ids: list[int],
|
||||
normals: list[float],
|
||||
gaps: list[float],
|
||||
penetrations: list[float],
|
||||
contact_pressures: list[float],
|
||||
coupling_step: int,
|
||||
) -> None:
|
||||
count = len(facet_ids)
|
||||
if (
|
||||
len(normals) != 3 * count
|
||||
or len(gaps) != count
|
||||
or len(penetrations) != count
|
||||
or len(contact_pressures) != count
|
||||
):
|
||||
raise ValueError("coupling contact state vector size mismatch")
|
||||
id_array = (ctypes.c_int * max(1, count))(*facet_ids)
|
||||
normal_array = (ctypes.c_double * max(1, 3 * count))(*normals)
|
||||
gap_array = (ctypes.c_double * max(1, count))(*gaps)
|
||||
penetration_array = (ctypes.c_double * max(1, count))(*penetrations)
|
||||
pressure_array = (ctypes.c_double * max(1, count))(*contact_pressures)
|
||||
self._check(self.lib.sphlite_coupling_apply_contact_state(
|
||||
int(region_index),
|
||||
count,
|
||||
id_array,
|
||||
normal_array,
|
||||
gap_array,
|
||||
penetration_array,
|
||||
pressure_array,
|
||||
int(coupling_step),
|
||||
))
|
||||
|
||||
def coupling_load_balance(self) -> dict[str, float | list[float]]:
|
||||
vector_type = ctypes.c_double * 3
|
||||
input_force = vector_type()
|
||||
distributed_force = vector_type()
|
||||
input_moment = vector_type()
|
||||
distributed_moment = vector_type()
|
||||
force_error = ctypes.c_double(0.0)
|
||||
moment_error = ctypes.c_double(0.0)
|
||||
self._check(self.lib.sphlite_coupling_get_load_balance(
|
||||
input_force,
|
||||
distributed_force,
|
||||
ctypes.byref(force_error),
|
||||
input_moment,
|
||||
distributed_moment,
|
||||
ctypes.byref(moment_error),
|
||||
))
|
||||
return {
|
||||
"coupling_input_force": list(input_force),
|
||||
"coupling_distributed_force": list(distributed_force),
|
||||
"coupling_force_balance_error": float(force_error.value),
|
||||
"coupling_input_moment": list(input_moment),
|
||||
"coupling_distributed_moment": list(distributed_moment),
|
||||
"coupling_moment_balance_error": float(moment_error.value),
|
||||
}
|
||||
|
||||
def coupling_contact_diagnostics(self) -> dict[str, float | int]:
|
||||
count_array = ctypes.c_int * COUPLING_CONTACT_DIAGNOSTIC_COUNT_COUNT
|
||||
value_array = ctypes.c_double * COUPLING_CONTACT_DIAGNOSTIC_VALUE_COUNT
|
||||
counts = count_array()
|
||||
values = value_array()
|
||||
self._check(self.lib.sphlite_coupling_get_contact_diagnostics(
|
||||
counts,
|
||||
COUPLING_CONTACT_DIAGNOSTIC_COUNT_COUNT,
|
||||
values,
|
||||
COUPLING_CONTACT_DIAGNOSTIC_VALUE_COUNT,
|
||||
))
|
||||
return {
|
||||
"coupling_active_contacts": int(counts[0]),
|
||||
"coupling_skipped_contacts": int(counts[1]),
|
||||
"coupling_stale_loads": int(counts[2]),
|
||||
"coupling_repeated_imports": int(counts[3]),
|
||||
"coupling_nonfinite_contact_imports": int(counts[4]),
|
||||
"coupling_bad_facet_areas": int(counts[5]),
|
||||
"coupling_invalid_weights": int(counts[6]),
|
||||
"coupling_max_penetration": float(values[0]),
|
||||
}
|
||||
|
||||
def coupling_diagnostics(self) -> dict[str, float | int | list[float]]:
|
||||
value_array = ctypes.c_double * COUPLING_DIAGNOSTIC_VALUE_COUNT
|
||||
count_array = ctypes.c_int * COUPLING_DIAGNOSTIC_COUNT_COUNT
|
||||
@@ -634,11 +868,23 @@ class SPHLite:
|
||||
"coupling_max_acceleration": values_list[19],
|
||||
"coupling_max_velocity_error": values_list[20],
|
||||
"coupling_max_position_error": values_list[21],
|
||||
"coupling_force_balance_error": values_list[22],
|
||||
"coupling_moment_balance_error": values_list[23],
|
||||
"coupling_max_pressure": values_list[24],
|
||||
"coupling_max_traction": values_list[25],
|
||||
"coupling_max_penetration": values_list[26],
|
||||
"coupling_stale_loads": int(counts[0]),
|
||||
"coupling_skipped_particles": int(counts[1]),
|
||||
"coupling_nonfinite_imports": int(counts[2]),
|
||||
"coupling_imported_forces": int(counts[3]),
|
||||
"coupling_step_load_consumed": int(counts[4]),
|
||||
"coupling_repeated_imports": int(counts[5]),
|
||||
"coupling_duplicate_facets": int(counts[6]),
|
||||
"coupling_invalid_weights": int(counts[7]),
|
||||
"coupling_active_contacts": int(counts[8]),
|
||||
"coupling_skipped_contacts": int(counts[9]),
|
||||
"coupling_nonfinite_contact_imports": int(counts[10]),
|
||||
"coupling_bad_facet_areas": int(counts[11]),
|
||||
}
|
||||
|
||||
def inspect(self, filename: str | Path) -> dict[str, int | float | list[float]]:
|
||||
|
||||
Reference in New Issue
Block a user