Class NativeCollisionBackend
java.lang.Object
org.episteme.nativ.physics.classical.mechanics.collision.backends.NativeCollisionBackend
- All Implemented Interfaces:
AlgorithmProvider, Backend, ComputeBackend, CPUBackend, NativeCollisionProvider, NativeBackend, CollisionProvider, MechanicsBackend, SimulationProvider
@AutoService({MechanicsBackend.class,ComputeBackend.class,Backend.class,SimulationProvider.class})
public class NativeCollisionBackend
extends Object
implements NativeCollisionProvider, MechanicsBackend, CPUBackend, NativeBackend, SimulationProvider
Native implementation of
MechanicsBackend for general collision processing.
Acts as a bridge to native optimized collision kernels.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates and returns the backend instance (or returns self if it is the backend).Creates an execution context for running operations.createRigidBody(RigidBody body) Creates a backend representation for a RigidBody.This backend is specialized for high-performance batch collision detection and resolution using primitive arrays and direct FFM segments.intdetectSphereCollisions(double[] positions, double[] radii, int n, int[] collisions) intdetectSphereCollisions(float[] positions, float[] radii, int n, int[] collisions) Performs collision detection between spheres.intdetectSphereCollisions(MemorySegment positions, MemorySegment radii, int n, MemorySegment collisions, ValueLayout layout) Performs collision detection between spheres using MemorySegments.intdetectSphereCollisions(Real[] positions, Real[] radii, int n, int[] collisions) Returns the type of hardware accelerator used by this backend.Returns the unique category of the algorithm.Returns a description of the backend.getId()Returns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").getName()Returns the display name for UI presentation.Returns the name of the native library this backend depends on.intReturns the execution priority (higher is better).getType()Returns the backend type category (e.g., "plotting", "molecular", "tensor", "math").booleanChecks if the provider is available in the current environment.booleanisLoaded()Returns true if the native library is loaded and operational.voidparallelExecute(List<Runnable> tasks, int parallelism) voidresolveCollisions(double[] positions, double[] velocities, double[] masses, int n, int[] collisions, int numCollisions) voidresolveCollisions(float[] positions, float[] velocities, float[] masses, int n, int[] collisions, int numCollisions) voidresolveCollisions(MemorySegment positions, MemorySegment velocities, MemorySegment masses, int n, MemorySegment collisions, int numCollisions, ValueLayout layout) Resolves collisions using MemorySegments.voidresolveCollisions(Real[] positions, Real[] velocities, Real[] masses, int n, int[] collisions, int numCollisions) voidshutdown()Called when the provider is no longer needed (e.g., application shutdown).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AlgorithmProvider
description, getMetadata, scoreMethods inherited from interface Backend
getAlgorithmProviders, getStatusMessage, isExplicitlyDisabledMethods inherited from interface CPUBackend
supportsComplexNumbers, supportsFloatingPoint, supportsParallelOpsMethods inherited from interface MechanicsBackend
score
-
Constructor Details
-
NativeCollisionBackend
public NativeCollisionBackend()
-
-
Method Details
-
getId
-
getName
Description copied from interface:BackendReturns the display name for UI presentation.- Specified by:
getNamein interfaceAlgorithmProvider- Specified by:
getNamein interfaceBackend- Specified by:
getNamein interfaceSimulationProvider
-
getDescription
Description copied from interface:BackendReturns a description of the backend.- Specified by:
getDescriptionin interfaceBackend- Specified by:
getDescriptionin interfaceComputeBackend
-
isLoaded
public boolean isLoaded()Description copied from interface:NativeCollisionProviderReturns true if the native library is loaded and operational.- Specified by:
isLoadedin interfaceNativeBackend- Specified by:
isLoadedin interfaceNativeCollisionProvider- Returns:
- true if the native library has been successfully loaded
-
getNativeLibraryName
Description copied from interface:NativeBackendReturns the name of the native library this backend depends on.- Specified by:
getNativeLibraryNamein interfaceNativeBackend- Returns:
- library name (e.g., "openblas", "cuda", "fftw3")
-
isAvailable
public boolean isAvailable()Description copied from interface:AlgorithmProviderChecks if the provider is available in the current environment.- Specified by:
isAvailablein interfaceAlgorithmProvider- Specified by:
isAvailablein interfaceBackend- Specified by:
isAvailablein interfaceMechanicsBackend
-
getType
Description copied from interface:BackendReturns the backend type category (e.g., "plotting", "molecular", "tensor", "math").- Specified by:
getTypein interfaceBackend- Specified by:
getTypein interfaceComputeBackend- Specified by:
getTypein interfaceCPUBackend- Specified by:
getTypein interfaceMechanicsBackend
-
getAlgorithmType
Description copied from interface:AlgorithmProviderReturns the unique category of the algorithm.- Specified by:
getAlgorithmTypein interfaceAlgorithmProvider- Specified by:
getAlgorithmTypein interfaceCollisionProvider- Specified by:
getAlgorithmTypein interfaceMechanicsBackend
-
getPriority
public int getPriority()Description copied from interface:AlgorithmProviderReturns the execution priority (higher is better).- Specified by:
getPriorityin interfaceAlgorithmProvider- Specified by:
getPriorityin interfaceBackend- Specified by:
getPriorityin interfaceMechanicsBackend
-
getAcceleratorType
Description copied from interface:ComputeBackendReturns the type of hardware accelerator used by this backend.- Specified by:
getAcceleratorTypein interfaceComputeBackend- Specified by:
getAcceleratorTypein interfaceCPUBackend- Returns:
- the accelerator type
-
createWorld
This backend is specialized for high-performance batch collision detection and resolution using primitive arrays and direct FFM segments. It does not support higher-level world or rigid body abstractions.- Specified by:
createWorldin interfaceMechanicsBackend- Returns:
- a new PhysicsWorld instance
-
createRigidBody
Description copied from interface:MechanicsBackendCreates a backend representation for a RigidBody.- Specified by:
createRigidBodyin interfaceMechanicsBackend- Parameters:
body- the Episteme RigidBody definition- Returns:
- the backend implementation
-
detectSphereCollisions
public int detectSphereCollisions(float[] positions, float[] radii, int n, int[] collisions) Description copied from interface:CollisionProviderPerforms collision detection between spheres.- Specified by:
detectSphereCollisionsin interfaceCollisionProvider- Specified by:
detectSphereCollisionsin interfaceNativeCollisionProvider- Parameters:
positions- Flattened array [x0, y0, z0, x1, y1, z1, ...]radii- Array of radii [r0, r1, ...]n- Number of spherescollisions- Output array for collision pairs [idA, idB, ...]- Returns:
- Number of collisions found
-
resolveCollisions
public void resolveCollisions(float[] positions, float[] velocities, float[] masses, int n, int[] collisions, int numCollisions) - Specified by:
resolveCollisionsin interfaceCollisionProvider- Specified by:
resolveCollisionsin interfaceNativeCollisionProvider
-
detectSphereCollisions
public int detectSphereCollisions(double[] positions, double[] radii, int n, int[] collisions) - Specified by:
detectSphereCollisionsin interfaceCollisionProvider- Specified by:
detectSphereCollisionsin interfaceNativeCollisionProvider
-
resolveCollisions
public void resolveCollisions(double[] positions, double[] velocities, double[] masses, int n, int[] collisions, int numCollisions) - Specified by:
resolveCollisionsin interfaceCollisionProvider- Specified by:
resolveCollisionsin interfaceNativeCollisionProvider
-
detectSphereCollisions
public int detectSphereCollisions(MemorySegment positions, MemorySegment radii, int n, MemorySegment collisions, ValueLayout layout) Description copied from interface:NativeCollisionProviderPerforms collision detection between spheres using MemorySegments.- Specified by:
detectSphereCollisionsin interfaceCollisionProvider- Specified by:
detectSphereCollisionsin interfaceNativeCollisionProvider
-
resolveCollisions
public void resolveCollisions(MemorySegment positions, MemorySegment velocities, MemorySegment masses, int n, MemorySegment collisions, int numCollisions, ValueLayout layout) Description copied from interface:NativeCollisionProviderResolves collisions using MemorySegments.- Specified by:
resolveCollisionsin interfaceCollisionProvider- Specified by:
resolveCollisionsin interfaceNativeCollisionProvider
-
parallelExecute
- Specified by:
parallelExecutein interfaceSimulationProvider
-
shutdown
public void shutdown()Description copied from interface:AlgorithmProviderCalled when the provider is no longer needed (e.g., application shutdown). Use this to release local resources or close native segments.- Specified by:
shutdownin interfaceAlgorithmProvider- Specified by:
shutdownin interfaceBackend- Specified by:
shutdownin interfaceMechanicsBackend
-
createBackend
Description copied from interface:BackendCreates and returns the backend instance (or returns self if it is the backend).- Specified by:
createBackendin interfaceBackend- Specified by:
createBackendin interfaceComputeBackend- Specified by:
createBackendin interfaceMechanicsBackend- Returns:
- The backend implementation object
-
detectSphereCollisions
- Specified by:
detectSphereCollisionsin interfaceCollisionProvider
-
resolveCollisions
public void resolveCollisions(Real[] positions, Real[] velocities, Real[] masses, int n, int[] collisions, int numCollisions) - Specified by:
resolveCollisionsin interfaceCollisionProvider
-
createContext
Description copied from interface:ComputeBackendCreates an execution context for running operations.The context should be used within a try-with-resources block to ensure proper cleanup of resources.
- Specified by:
createContextin interfaceComputeBackend- Returns:
- new execution context
-