11.2. 模块 dem

11.2.1. 子模块预览

core

dem.core module for DEM simulations.

cudem

cudem module for CUDA-accelerated DEM simulations.

rtdem

rtdem module for GPU-accelerated DEM simulations.

11.2.2. 子模块 core API函数

dem.core module for DEM simulations.

This module provides the basic components for Discrete Element Method (DEM) simulations. It includes fundamental classes for materials, walls, boundary conditions, hooks, and simulation base functionality. Most classes in this module serve as base classes or supporting components for higher-level simulation classes.

Key components: - Material: Defines material properties for DEM simulations - WallData, Wall and Box: Handle boundary conditions and wall definitions - PyHook and PeriodicHook: Enable custom Python callbacks during simulations - Bound: Provides bounding box functionality for spatial queries

class dem.core.Bound

A 3D bounding box implementation.

This class represents a 3D bounding box with minimum and maximum corners. It provides methods to extend the bounds, calculate center and span, and scale the box.

Example:

bound = dem.core.Bound() bound.extend([1.0, 2.0, 3.0]) bound.extend([-1.0, -2.0, -3.0]) center = bound.center() span = bound.span()

__init__(self: dem.core.Bound) None
property bounds_max

The upper-right corner of the box [x, y, z].

property bounds_min

The lower-left corner of the box [x, y, z].

center(self: dem.core.Bound) pySudoMath.Vector3f

Get the center of the bounding box.

Returns:

list: The center coordinates [x, y, z] of the bounding box.

Example:

bound = dem.core.Bound() # ... extend bound ... center = bound.center()

extend(*args, **kwargs)

Overloaded function.

  1. extend(self: dem.core.Bound, vert: pySudoMath.Vector3f) -> None

    Extend the bounding box to include a point.

    Args:

    vert (list): The point [x, y, z] to include in the bounding box.

    Example:

    bound = dem.core.Bound() bound.extend([1.0, 2.0, 3.0])

  2. extend(self: dem.core.Bound, bbox: dem.core.Bound) -> None

    Extend the bounding box to include another bounding box.

    Args:

    bbox (Bound): The other bounding box to include in this bounding box.

    Example:

    bound1 = dem.core.Bound() bound2 = dem.core.Bound() # ... extend both bounds ... bound1.extend(bound2)

resetCenter(self: dem.core.Bound) None

Reset the center of the bounding box to the origin.

This method moves the bounding box so that its center is at the origin.

Example:

bound = dem.core.Bound() # ... extend bound ... bound.resetCenter()

scale(*args, **kwargs)

Overloaded function.

  1. scale(self: dem.core.Bound, s: typing.SupportsFloat) -> None

    Scale the bounding box by a uniform factor.

    Args:

    s (float): The scale factor.

    Example:

    bound = dem.core.Bound() # ... extend bound ... bound.scale(2.0)

  2. scale(self: dem.core.Bound, s: pySudoMath.Vector3f) -> None

    Scale the bounding box by a scale vector.

    Args:

    s (list): The scale vector [x, y, z].

    Example:

    bound = dem.core.Bound() # ... extend bound ... bound.scale([2.0, 1.5, 3.0])

span(self: dem.core.Bound) pySudoMath.Vector3f

Get the span (dimensions) of the bounding box.

Returns:

list: The span [x, y, z] of the bounding box.

Example:

bound = dem.core.Bound() # ... extend bound ... span = bound.span()

class dem.core.Box

基类:WallData

Box with six walls, inheriting from WallData.

This class represents a box-shaped boundary in the simulation domain, consisting of six walls aligned with the coordinate axes. It inherits from WallData and provides convenient access to individual walls (left, right, front, back, bottom, top).

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) left_wall = box.left_wall() right_wall = box.right_wall()

__init__(self: dem.core.Box, lower_left: pySudoMath.Vector3f, upper_right: pySudoMath.Vector3f) None

Construct a new Box object.

Args:

lower_left (list): The coordinate [x, y, z] of the lower-left corner. upper_right (list): The coordinate [x, y, z] of the upper-right corner.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0])

addWall(self: dem.core.WallData, _pos: pySudoMath.Vector3f, _sense: SupportsInt, _axis: SupportsInt) None

Add a wall to the scene. Note: This operation is not allowed for Box.

Args:

_pos (list): The position [x, y, z] of the wall. _sense (int): The sense of the wall. _axis (int): The axis of the wall.

Note:

This operation is not allowed for Box as it already has six predefined walls.

back_wall(self: dem.core.Box) dem.core.Wall

Get the back wall.

Returns:

Wall: The back wall of the box.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) back_wall = box.back_wall()

bottom_wall(self: dem.core.Box) dem.core.Wall

Get the bottom wall.

Returns:

Wall: The bottom wall of the box.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) bottom_wall = box.bottom_wall()

front_wall(self: dem.core.Box) dem.core.Wall

Get the front wall.

Returns:

Wall: The front wall of the box.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) front_wall = box.front_wall()

left_wall(self: dem.core.Box) dem.core.Wall

Get the left wall.

Returns:

Wall: The left wall of the box.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) left_wall = box.left_wall()

right_wall(self: dem.core.Box) dem.core.Wall

Get the right wall.

Returns:

Wall: The right wall of the box.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) right_wall = box.right_wall()

top_wall(self: dem.core.Box) dem.core.Wall

Get the top wall.

Returns:

Wall: The top wall of the box.

Example:

box = dem.core.Box([-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]) top_wall = box.top_wall()

class dem.core.Material

The basic material class.

This class represents the material properties used in DEM simulations. Future materials can be built based on this base class. It contains properties such as density, Young's modulus, Poisson's ratio, friction coefficient, and contact parameters.

Example:

material = dem.core.Material() material.density = 2650.0 material.young = 1e7 material.poisson = 0.25 material.friction = 0.5

__init__(self: dem.core.Material) None
property density

float: The density of the material.

Example:

material = dem.core.Material() material.density = 2650.0 # Set density to 2650 kg/m³ density = material.density

property friction

float: Friction coefficient of the material.

Example:

material = dem.core.Material() material.friction = 0.5 # Set friction coefficient to 0.5 friction = material.friction

property kn

float: Normal stiffness of the material.

Example:

material = dem.core.Material() material.kn = 1e5 # Set normal stiffness to 1e5 N/m kn = material.kn

property ks

float: Shear stiffness of the material.

Example:

material = dem.core.Material() material.ks = 5e4 # Set shear stiffness to 5e4 N/m ks = material.ks

property poisson

float: Poisson's ratio of the material.

Example:

material = dem.core.Material() material.poisson = 0.25 # Set Poisson's ratio to 0.25 poisson = material.poisson

property vdamping

float: Viscous damping of the material applied to contacts.

Example:

material = dem.core.Material() material.vdamping = 0.1 # Set viscous damping to 0.1 damping = material.vdamping

property young

float: Young's modulus of the material.

Example:

material = dem.core.Material() material.young = 1e7 # Set Young's modulus to 1e7 Pa young = material.young

class dem.core.PyHook

This hook can be used to call Python functions at the user end.

This class represents a hook that can execute Python commands during the simulation. It inherits from PeriodicHook and allows users to inject custom Python code into the simulation cycle.

Example:

hook = dem.core.PyHook() hook.command = "print('Simulation step:', sim.iter())" hook.iterPeriod = 100 # Execute every 100 iterations

__init__(self: dem.core.PyHook) None
property command

str: Command for the pyhook. The command can be a pre-defined Python function.

WARNING: You cannot use the print function in the hook, or else it may encounter a crash in detached multi-threads. FIXME in the future. As a workaround, we use app.print in GUI.

Example:

hook = dem.core.PyHook() hook.command = "app.print('Simulation step:', sim.iter())" # Use app.print instead of print command = hook.command

property dead

bool: The hook is dead (True) or not.

Example:

hook = dem.core.PyHook() hook.dead = True # Set hook as dead is_dead = hook.dead

property iterLast

int: Iteration of last run (read-only).

Example:

hook = dem.core.PyHook() # After running simulation last_iter = hook.iterLast

property iterPeriod

int: Iteration periodicity of the hook.

Example:

hook = dem.core.PyHook() hook.iterPeriod = 100 # Set iteration period to 100 period = hook.iterPeriod

property realLast

float: Real time of last run (read-only).

Example:

hook = dem.core.PyHook() # After running simulation last_time = hook.realLast

property realPeriod

float: Real periodicity of the hook.

Example:

hook = dem.core.PyHook() hook.realPeriod = 0.05 # Set real period to 0.05 seconds period = hook.realPeriod

reset(self: dem.core.PyHook, **kwargs) None

Reset the period of the hook.

This method resets the periodicity settings of the hook.

Keyword Args:

virtPeriod (float): Virtual periodicity. realPeriod (float): Real periodicity. iterPeriod (int): Iteration periodicity. totalRuns (int): Total runs for the hook.

Example:

hook = dem.core.PyHook() hook.reset(virtPeriod=0.1, iterPeriod=100)

property totalRuns

int: The total runs for the hook.

Example:

hook = dem.core.PyHook() hook.totalRuns = 10 # Set total runs to 10 runs = hook.totalRuns

property virtLast

float: Virtual time of last run (read-only).

Example:

hook = dem.core.PyHook() # After running simulation last_time = hook.virtLast

property virtPeriod

float: Virtual periodicity of the hook.

Example:

hook = dem.core.PyHook() hook.virtPeriod = 0.1 # Set virtual period to 0.1 seconds period = hook.virtPeriod

class dem.core.Wall

An infinite plane wall with its axes parallel to that of the world coordinate system.

This class represents an infinite plane wall that can act as a boundary in the simulation. Walls are aligned with the coordinate axes and can be positioned anywhere in space. They can be configured to interact with particles on either the positive or negative side.

Example:

wall = dem.core.Wall() wall.setPos([0.0, 0.0, 0.0]) wall.sense = 1 # Positive side active wall.axis = 2 # Aligned with z-axis

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: dem.core.Wall) -> None

  2. __init__(self: dem.core.Wall, pos: pySudoMath.Vector3f, sense: typing.SupportsInt, axis: typing.SupportsInt) -> None

    Construct a new Wall object.

    Args:

    pos (list): Wall position [x, y, z]. sense (int): The sense of a wall (-1 for negative side, 1 for positive side). axis (int): The axis of the wall normal (0=x, 1=y, 2=z).

    Example:

    wall = dem.core.Wall([0.0, 0.0, 0.0], 1, 2)

property axis

int: The axis the wall is aligned with (0=x, 1=y, 2=z).

Example:

wall = dem.core.Wall() wall.axis = 2 # Aligned with z-axis wall_axis = wall.axis

getPos(self: dem.core.Wall) pySudoMath.Vector3f

Get the position of the wall.

Returns:

list: The position [x, y, z] of the wall.

Example:

wall = dem.core.Wall() position = wall.getPos()

property id

int: The unique identifier of the wall.

Example:

wall = dem.core.Wall() wall.id = 1 wall_id = wall.id

property sense

int: The sense of the wall (-1 for negative side, 1 for positive side).

Example:

wall = dem.core.Wall() wall.sense = 1 # Set positive side active sense = wall.sense

setPos(self: dem.core.Wall, _pos: pySudoMath.Vector3f) None

Set the position of the wall.

Args:

_pos (list): The new position [x, y, z] of the wall.

Example:

wall = dem.core.Wall() wall.setPos([1.0, 2.0, 3.0])

class dem.core.WallData

Wall data management class.

This class manages a collection of walls in the simulation domain. Walls are infinite planes aligned with the coordinate axes that can act as boundaries for particles. The class provides functionality for adding walls, building contacts between particles and walls, and managing the data needed for contact detection and force calculation.

Example:

wall_data = dem.core.WallData() wall_data.addWall([0.0, 0.0, 0.0], 1, 2) # Add wall at origin, positive side, z-axis

__init__(self: dem.core.WallData) None
addWall(*args, **kwargs)

Overloaded function.

  1. addWall(self: dem.core.WallData, _pos: pySudoMath.Vector3f, _sense: typing.SupportsInt, _axis: typing.SupportsInt) -> None

    Add a wall to the scene.

    Args:

    _pos (list): The position [x, y, z] of the wall. _sense (int): The sense of the wall (-1 for negative side, 1 for positive side). _axis (int): The axis the wall is aligned with (0=x, 1=y, 2=z).

    Example:

    wall_data = dem.core.WallData() wall_data.addWall([0.0, 0.0, 0.0], 1, 2) # Add wall at origin, positive side, z-axis

  2. addWall(self: dem.core.WallData, _wall: dem.core.Wall) -> None

    Add a wall to the scene.

    Args:

    _wall (Wall): The wall object to add.

    Example:

    wall_data = dem.core.WallData() wall = dem.core.Wall([0.0, 0.0, 0.0], 1, 2) wall_data.addWall(wall)

getNum(self: dem.core.WallData) int

Get the number of walls in the simulation.

Returns:

int: The number of walls.

Example:

wall_data = dem.core.WallData() num_walls = wall_data.getNum()

property material

dem.core.Material: The material attached to all walls.

Example:

wall_data = dem.core.WallData() material = dem.core.Material() wall_data.material = material

class dem.core.async_spdlogger

async_logger

__init__(self: dem.core.async_spdlogger, arg0: str, arg1: dem.core.pysink) None

init function

critical(self: dem.core.async_spdlogger, arg0: str) None

Send a message at the level of CRITICAL.

info(self: dem.core.async_spdlogger, arg0: str) None

Send a message at the level of INFO.

warn(self: dem.core.async_spdlogger, arg0: str) None

Send a message at the level of WARN.

class dem.core.pysink

pysink.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: dem.core.pysink) -> None

  2. __init__(self: dem.core.pysink, arg0: object) -> None

dem.core.register_async_logger(arg0: spdlog::async_logger) None

register logger

dem.core.register_logger(arg0: spdlog::logger) None

register logger

dem.core.set_async_logger(arg0: spdlog::async_logger) None

set the default logger.

dem.core.set_logger(arg0: spdlog::logger) None

set the default logger.

class dem.core.spdlogger

logger

__init__(self: dem.core.spdlogger, arg0: str, arg1: dem.core.pysink) None
critical(self: dem.core.spdlogger, arg0: str) None

Send a message at the level of CRITICAL.

info(self: dem.core.spdlogger, arg0: str) None

Send a message at the level of INFO.

warn(self: dem.core.spdlogger, arg0: str) None

Send a message at the level of WARN.

11.2.3. 子模块 cudem API函数

cudem module for CUDA-accelerated DEM simulations.

This module provides CUDA-accelerated components for Discrete Element Method (DEM) simulations optimized for spherical particles. It offers high-performance simulations leveraging GPU computing for particle interactions, neighbor list management, and force calculations.

Key components: - DEMSim: The main simulation class for CUDA-based DEM - ParticleData: Container for particle data (positions, velocities, etc.) - SphereData: Specialized data structure for spherical particles - PolySuperellipsoidData: Data structure for superellipsoid particles - Integrator: Integration of particle motion - ForceCompute: Force calculation between particles - NeighborList: Management of particle neighbor relationships - Domain: Spatial domain decomposition for efficient computation

The module is optimized for: - Fast computation of spherical particle interactions - Efficient neighbor list management - GPU-accelerated force calculations - Domain decomposition for large-scale simulations

Example:

import dem.cudem

# Create simulation sim = dem.cudem.DEMSim()

# Set up particles # Add spherical particles...

# Configure simulation sim.setTimestep(1e-5) sim.init()

# Run simulation sim.run(1000)

class dem.cudem.DEMSim

The DEM solver by CUDEM for CUDA-accelerated simulations.

This class implements the Discrete Element Method (DEM) simulation using CUDA acceleration for spherical and superellipsoidal particles. It provides functionality for particle motion integration, force calculation, and simulation state management.

Example:

import dem.cudem sim = dem.cudem.DEMSim() sim.setTimestep(1e-5) # Add particles and walls... sim.init() sim.run(100)

ParRadii(self: dem.cudem.DEMSim) list[float]
Pause(self: dem.cudem.DEMSim) None

Force pause the simulation when running with RunPthread.

This method pauses the simulation if it's running in a separate thread.

Example:

sim = dem.cudem.DEMSim() # In another thread sim.Pause()

PolysuperShapeParas(self: dem.cudem.DEMSim) object
PtsPos(self: dem.cudem.DEMSim) list[float]
RunPthread(self: dem.cudem.DEMSim, steps: SupportsInt) None

Run the simulation with n steps in a new thread.

Args:

steps (int): The number of steps to run.

Example:

sim = dem.cudem.DEMSim() sim.init() sim.RunPthread(1000) # Run for 1000 steps in a separate thread

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: dem.cudem.DEMSim) -> None

    Construct a new DEMSim object with default parameters.

    Example:

    sim = dem.cudem.DEMSim()

  2. __init__(self: dem.cudem.DEMSim, arg0: typing.SupportsInt) -> None

    Construct a new DEMSim object with a specific GPU device ID.

    Args:

    gpu_id (int): Device ID of GPU to use for computation.

    Example:

    sim = dem.cudem.DEMSim(0) # Use GPU 0

  3. __init__(self: dem.cudem.DEMSim, arg0: object) -> None

    Construct a new DEMSim object with a Python callback.

    Args:

    callback: Callback function in Python.

    Example:
    def my_callback():

    print("Simulation callback")

    sim = dem.cudem.DEMSim(my_callback)

  4. __init__(self: dem.cudem.DEMSim, arg0: typing.SupportsInt, arg1: object) -> None

    Construct a new DEMSim object with a specific GPU device ID and Python callback.

    Args:

    gpu_id (int): Device ID of GPU to use for computation. callback: Callback function in Python.

    Example:
    def my_callback():

    print("Simulation callback")

    sim = dem.cudem.DEMSim(0, my_callback) # Use GPU 0 with callback

property digitalElevation

digital elevation data

property domain
property dt

float: The time step size for the simulation.

Example:

sim = dem.cudem.DEMSim() sim.dt = 1e-5 # Set time step timestep = sim.dt # Get time step size

property elapsedTime

float: The elapsed time in seconds (read-only).

Example:

sim = dem.cudem.DEMSim() # After running simulation elapsed = sim.elapsedTime

property fcompute

compute contact forces

freeMem(self: dem.cudem.DEMSim) None

Free up GPU memory in the simulation.

This method releases GPU memory allocated for the simulation.

Example:

sim = dem.cudem.DEMSim() # After simulation is complete sim.freeMem()

getParNum(self: dem.cudem.DEMSim) int

Get the number of particles in the simulation.

Returns:

int: The number of particles.

Example:

sim = dem.cudem.DEMSim() particle_count = sim.getParNum()

getPosOri(self: dem.cudem.DEMSim) object
getShapeGroupInfo(self: dem.cudem.DEMSim) list
getSystemInfo(self: dem.cudem.DEMSim) None

Get the GPU information in the system.

This method prints information about the available GPUs and CUDA version.

Example:

sim = dem.cudem.DEMSim() sim.getSystemInfo()

property hooks

list: List of hooks attached to the simulation.

Example:

sim = dem.cudem.DEMSim() hooks = sim.hooks # Get hooks # Set hooks # sim.hooks = [hook1, hook2]

init(self: dem.cudem.DEMSim) None

Initialize the simulation model before running.

This method must be called before starting the simulation to properly set up all necessary data structures.

Example:

sim = dem.cudem.DEMSim() sim.init() # Initialize the simulation sim.run(100)

property integrator

integrator for particle motion

isLoaded(self: dem.cudem.DEMSim) bool

Check if the simulation is loaded from a checkpoint.

Returns:

bool: True if the simulation was loaded from a checkpoint, False otherwise.

Example:

sim = dem.cudem.DEMSim() if sim.isLoaded():

print("Simulation was loaded from checkpoint")

isRunning(self: dem.cudem.DEMSim) bool

Get the isRunning flag to check if the simulation is running.

Returns:

bool: True if the simulation is running, False otherwise.

Example:

sim = dem.cudem.DEMSim() if sim.isRunning():

print("Simulation is running")

iter(self: dem.cudem.DEMSim) int

Get the current time step.

Returns:

int: The current iteration number.

Example:

sim = dem.cudem.DEMSim() # After running simulation current_iter = sim.iter()

load(self: dem.cudem.DEMSim, arg0: str) bool

load data

loadParticles(self: dem.cudem.DEMSim, arg0: str) None

load particle info from file

loadPthread(self: dem.cudem.DEMSim, arg0: str) None

load data

moveToNextTimeStep(self: dem.cudem.DEMSim) None

Advance the simulation by one time step.

This method performs all necessary calculations to advance the simulation by a single time step.

Example:

sim = dem.cudem.DEMSim() sim.init() sim.moveToNextTimeStep() # Advance one time step

property nlist

neighbor list

property nlistUpdates

int: Number of neighbor list updates (read-only).

Example:

sim = dem.cudem.DEMSim() # After running simulation updates = sim.nlistUpdates

particleScales(self: dem.cudem.DEMSim) object

scale factors of all particles in the scene

property pdata

particle data

printParInfo(self: dem.cudem.DEMSim, arg0: SupportsInt) None

print the particle info with id

property reorderInterval

int: Reorder data every N neighbor list updates.

Example:

sim = dem.cudem.DEMSim() sim.reorderInterval = 10 # Reorder every 10 updates interval = sim.reorderInterval

reorderParticles(self: dem.cudem.DEMSim) None

reorder particles in z-order pattern. [test only]

run(self: dem.cudem.DEMSim, steps: SupportsInt) None

Run the simulation with n steps.

Args:

steps (int): The number of steps to run.

Example:

sim = dem.cudem.DEMSim() sim.init() sim.run(1000) # Run for 1000 steps

save(self: dem.cudem.DEMSim, arg0: str) bool

save data

saveParticles(self: dem.cudem.DEMSim, arg0: str) None

save particle info (pos and rad) into file.

savePthread(self: dem.cudem.DEMSim, arg0: str) None

save data

setFilePrefix(self: dem.cudem.DEMSim, prefix: str) None

Set the prefix name of output files.

Args:

prefix (str): The prefix for output files.

Example:

sim = dem.cudem.DEMSim() sim.setFilePrefix("simulation")

setLoadedFlag(self: dem.cudem.DEMSim, flag: bool) None

Set the loaded flag.

Args:

flag (bool): The value to set the loaded flag to.

Example:

sim = dem.cudem.DEMSim() sim.setLoadedFlag(True)

setOutputDir(self: dem.cudem.DEMSim, path: str) None

Set the output directory for simulation results.

Args:

path (str): The path to the output directory.

Example:

sim = dem.cudem.DEMSim() sim.setOutputDir("./output/")

property speed

float: Simulation speed in iterations per second (read-only).

Example:

sim = dem.cudem.DEMSim() # After running simulation speed = sim.speed

property useORT

bool: Flag to use ORT (Optix Ray Tracing) for neighbor searching.

Example:

sim = dem.cudem.DEMSim() sim.useORT = True # Enable ORT use_ort = sim.useORT

property useReorder

turn on/off reorder.

vertsId(self: dem.cudem.DEMSim) object

ids for vertices

vertsNorms(self: dem.cudem.DEMSim) object

verts and norms of all shapes of polysuperellipsoids

property walls

wall container

writeVTK(self: dem.cudem.DEMSim, filename: str) None

Dump particle data into a VTK file.

This method writes the current particle data to a VTK file for visualization.

Example:

sim = dem.cudem.DEMSim() sim.writeVTK("particle_data")

class dem.cudem.DigitalElevation

Digital elevation model for terrain modeling.

This class represents a digital elevation model that can be used to model terrains in discrete element method simulations. It supports loading elevation data from 2D arrays and configuring material properties for the terrain surface.

Example:

import dem.cudem dem_model = dem.cudem.DigitalElevation() # Load elevation data...

__init__(self: dem.cudem.DigitalElevation) None

Construct a new DigitalElevation object with default parameters.

Example:

dem_model = dem.cudem.DigitalElevation()

loadData2d(self: dem.cudem.DigitalElevation, arg0: Annotated[numpy.typing.ArrayLike, numpy.float32]) None

Load data from 2D numpy array.

This method loads elevation data from a 2D numpy array into the digital elevation model.

Args:

data (numpy.ndarray): A 2D array containing elevation data.

Example:

import numpy as np dem_model = dem.cudem.DigitalElevation() elevation_data = np.array([[0, 1, 2], [1, 2, 3], [2, 3, 4]]) dem_model.loadData2d(elevation_data)

property material

Material: Material attached to the mesh.

This property defines the material properties used for the digital elevation model.

Example:

dem_model = dem.cudem.DigitalElevation() material = dem.core.Material() material.friction = 0.5 dem_model.material = material # Set terrain material mat = dem_model.material # Get current material

setCellSize(self: dem.cudem.DigitalElevation, arg0: SupportsFloat) None

Set cell size of each element.

This method sets the cell size for each element in the digital elevation model.

Args:

size (float): The size of each cell.

Example:

dem_model = dem.cudem.DigitalElevation() dem_model.setCellSize(1.0) # Set cell size to 1.0

class dem.cudem.Domain

The simulation domain that controls the model size.

This class represents the simulation domain and controls the model size. It is used for cell-based methods and provides functionality for domain partitioning and spatial management.

Example:

import dem.cudem domain = dem.cudem.Domain() domain.setAABB(10.0, 10.0, 10.0) # Set domain size

__init__(self: dem.cudem.Domain) None

Construct a new Domain object with default parameters.

Example:

domain = dem.cudem.Domain()

getMins(self: dem.cudem.Domain) pySudoMath.Vector3f

Get the lower-left corner of the domain.

Returns the coordinates of the lower-left corner of the domain.

Returns:

Vector3r: The coordinates of the lower-left corner.

Example:

domain = dem.cudem.Domain() domain.setAABB(10.0, 10.0, 10.0) mins = domain.getMins()

getSize(self: dem.cudem.Domain) pySudoMath.Vector3f

Get the AABB size of the domain.

Returns the size of the axis-aligned bounding box of the domain.

Returns:

Vector3r: The size of the domain (x, y, z dimensions).

Example:

domain = dem.cudem.Domain() domain.setAABB(10.0, 10.0, 10.0) size = domain.getSize()

printInfo(self: dem.cudem.Domain) None

Print information about the domain.

This method prints detailed information about the domain to the console.

Example:

domain = dem.cudem.Domain() domain.printInfo()

setAABB(*args, **kwargs)

Overloaded function.

  1. setAABB(self: dem.cudem.Domain, arg0: typing.SupportsFloat, arg1: typing.SupportsFloat, arg2: typing.SupportsFloat) -> None

    Set the AABB of the domain box with the lower-left corner at the origin.

    This method sets the axis-aligned bounding box of the domain with the lower-left corner at the origin (0, 0, 0).

    Args:

    x (float): The size of the domain in the x direction. y (float): The size of the domain in the y direction. z (float): The size of the domain in the z direction.

    Example:

    domain = dem.cudem.Domain() domain.setAABB(10.0, 10.0, 10.0) # Set domain size

  2. setAABB(self: dem.cudem.Domain, arg0: typing.SupportsFloat, arg1: typing.SupportsFloat, arg2: typing.SupportsFloat, arg3: typing.SupportsFloat, arg4: typing.SupportsFloat, arg5: typing.SupportsFloat) -> None

    Set the AABB of the domain box.

    This method sets the axis-aligned bounding box of the domain with specified minimum and maximum coordinates.

    Args:

    xmin (float): The minimum x coordinate. ymin (float): The minimum y coordinate. zmin (float): The minimum z coordinate. xmax (float): The maximum x coordinate. ymax (float): The maximum y coordinate. zmax (float): The maximum z coordinate.

    Example:

    domain = dem.cudem.Domain() domain.setAABB(0.0, 0.0, 0.0, 10.0, 10.0, 10.0) # Set domain bounds

setCellSize(self: dem.cudem.Domain, arg0: SupportsFloat) None

Set cell size in the domain (cubic cell with x=y=z).

This method sets the cell size for the domain, creating cubic cells with equal dimensions in all directions.

Args:

size (float): The size of each cubic cell.

Example:

domain = dem.cudem.Domain() domain.setCellSize(1.0) # Set cell size to 1.0

setDim(self: dem.cudem.Domain, arg0: SupportsInt, arg1: SupportsInt, arg2: SupportsInt) None

Set dimensions for subcells to partition the whole domain.

This method sets the dimensions for subcells used to partition the domain.

Args:

nx (int): Number of subcells in the x direction. ny (int): Number of subcells in the y direction. nz (int): Number of subcells in the z direction.

Example:

domain = dem.cudem.Domain() domain.setDim(10, 10, 10) # Set 10x10x10 subcell grid

class dem.cudem.ForceCompute

Solver for inter-object forces in CUDEM simulations.

This class computes contact forces between particles and between particles and walls in discrete element method simulations. It handles force calculations based on particle interactions and material properties.

Example:

import dem.cudem sim = dem.cudem.DEMSim() force_compute = sim.fcompute force_compute.Compute() # Compute contact forces

Compute(self: dem.cudem.ForceCompute, arg0: bool, arg1: bool) None

Compute contact forces.

This method calculates contact forces between all interacting particles and walls.

Example:

force_compute = dem.cudem.ForceCompute() force_compute.Compute() # Compute all contact forces

__init__(self: dem.cudem.ForceCompute) None

Construct a new ForceCompute object with default parameters.

Example:

force_compute = dem.cudem.ForceCompute()

property pdata

ParticleData: Particle data pointer (read-only).

This property provides access to the particle data used for force computations.

Example:

force_compute = dem.cudem.ForceCompute() pdata = force_compute.pdata # Get particle data

printInfo(self: dem.cudem.ForceCompute) None

Print force computation information for debugging purposes.

This method prints detailed information about the force computation settings to the console.

Example:

force_compute = dem.cudem.ForceCompute() force_compute.printInfo() # Print force computation settings

class dem.cudem.Integrator

Integrator for particle motion in CUDEM simulations.

This class handles the integration of particle motion in discrete element method simulations using the Newton integrator. It implements numerical integration schemes for updating particle positions and orientations based on calculated forces and torques.

Example:

import dem.cudem sim = dem.cudem.DEMSim() integrator = sim.integrator integrator.gravity = (0, 0, -9.81) # Set gravity

Integrate(self: dem.cudem.Integrator) cudaError

Perform one integration step for all particles.

This method updates the positions and orientations of all particles based on their current velocities, forces, and torques.

Example:

integrator = dem.cudem.Integrator() # After setting up simulation... integrator.Integrate() # Perform one integration step

__init__(self: dem.cudem.Integrator) None

Construct a new Integrator object with default parameters.

Example:

integrator = dem.cudem.Integrator()

property alpha

float: Skin size factor for neighbor list updates.

The neighbor list is updated when particle displacement exceeds alpha*radius with respect to the reference configuration.

Example:

integrator = dem.cudem.Integrator() integrator.alpha = 1.5 # Set neighbor list update threshold alpha = integrator.alpha

property damping

float: The mass damping coefficient applied to particles.

Example:

integrator = dem.cudem.Integrator() integrator.damping = 0.1 # Set mass damping damping = integrator.damping

property gravity

tuple: The gravity vector (x, y, z) applied to all particles.

Example:

integrator = dem.cudem.Integrator() integrator.gravity = (0, 0, -9.81) # Set gravity to Earth's gravity g = integrator.gravity # Get current gravity

printInfo(self: dem.cudem.Integrator) None

Print integrator information for debugging purposes.

This method prints detailed information about the integrator settings to the console.

Example:

integrator = dem.cudem.Integrator() integrator.printInfo() # Print integrator settings

class dem.cudem.NeighborList

Neighbor searching controller for CUDEM simulations.

This class controls neighbor searching in discrete element method simulations. It manages the construction and updating of neighbor lists for efficient contact detection. It also provides debugging functions for testing and optimization.

Example:

import dem.cudem sim = dem.cudem.DEMSim() nlist = sim.nlist nlist.build() # Build neighbor list

property ORTextend

float: AABB extend when using ORT (Optix Ray Tracing).

This property controls the extension of axis-aligned bounding boxes when using ORT.

Example:

nlist = dem.cudem.NeighborList() nlist.ORTextend = 1.0 # Set ORT extension extend = nlist.ORTextend

__init__(self: dem.cudem.NeighborList) None

Construct a new NeighborList object with default parameters.

Example:

nlist = dem.cudem.NeighborList()

build(self: dem.cudem.NeighborList, arg0: bool) None

Build a neighbor list.

This method constructs the neighbor list for efficient contact detection.

Example:

nlist = dem.cudem.NeighborList() nlist.build() # Build neighbor list

property delta

float: Threshold for potential contacts.

This property sets the threshold distance for considering particles as potential contacts.

Example:

nlist = dem.cudem.NeighborList() nlist.delta = 1.5 # Set contact threshold delta = nlist.delta

launchTest(self: dem.cudem.NeighborList) None

Test launch RT (Ray Tracing) time, debug only.

This method tests ray tracing launch time, intended for debugging purposes.

Example:

nlist = dem.cudem.NeighborList() nlist.launchTest() # Test ray tracing launch time

printInfo(self: dem.cudem.NeighborList) None

Print neighbor list information for debugging purposes.

This method prints detailed information about the neighbor list settings to the console.

Example:

nlist = dem.cudem.NeighborList() nlist.printInfo() # Print neighbor list settings

rebuildAS(self: dem.cudem.NeighborList) None

Rebuild AS (Acceleration Structure) for debug only.

This method rebuilds the acceleration structure, intended for debugging purposes.

Example:

nlist = dem.cudem.NeighborList() nlist.rebuildAS() # Rebuild acceleration structure

testORT(self: dem.cudem.NeighborList) int

Test ORT for BVH (Bounding Volume Hierarchy).

This method tests the ORT implementation for bounding volume hierarchy.

Example:

nlist = dem.cudem.NeighborList() nlist.testORT() # Test ORT implementation

updateAS(self: dem.cudem.NeighborList) None

Update AS (Acceleration Structure) for debug only.

This method updates the acceleration structure, intended for debugging purposes.

Example:

nlist = dem.cudem.NeighborList() nlist.updateAS() # Update acceleration structure

class dem.cudem.ParticleData

Base class for particle data in CUDEM simulations.

This class serves as the base class for all particle data implementations in CUDEM. It provides common functionality for managing particle properties such as positions, velocities, orientations, forces, and torques. It also includes methods for particle manipulation and energy calculations.

Example:

import dem.cudem pdata = dem.cudem.ParticleData() # Configure particle properties...

__init__(self: dem.cudem.ParticleData) None

Construct a new ParticleData object with default parameters.

Example:

pdata = dem.cudem.ParticleData()

fixParById(self: dem.cudem.ParticleData, arg0: SupportsInt) None

Fix a particle or wall by its global ID.

This method fixes (immobilizes) a particle or wall with the specified global ID.

Args:

id (int): The global ID of the particle/wall to fix.

Example:

pdata = dem.cudem.ParticleData() # After setting up particles... pdata.fixParById(0) # Fix particle 0 in place

fixParticlesbyIds(self: dem.cudem.ParticleData, arg0: std::vector<int, std::allocator<int> >) bool

Fix multiple particles by their IDs.

This method fixes (immobilizes) multiple particles specified by their IDs.

Args:

ids (list): List of particle IDs to fix.

Example:

pdata = dem.cudem.ParticleData() # After setting up particles... pdata.fixParticlesbyIds([0, 1, 2]) # Fix particles 0, 1, and 2

generatePacking(self: dem.cudem.ParticleData, arg0: pySudoMath.Vector3f, arg1: pySudoMath.Vector2f, arg2: SupportsInt) tuple

Generate a random packing of particles in the domain.

This method generates a random packing of particles within a specified box size, with particle radii within a specified range.

Args:

boxsize (Vector3r): The size of the box (x, y, z dimensions). radius_range (Vector2r): The range of particle radii (min, max). num (int): The number of particles to generate.

Returns:

tuple: A tuple containing lists of positions and radii.

Example:

pdata = dem.cudem.ParticleData() # Generate 100 particles in a 10x10x10 box with radii between 0.1 and 0.5 positions, radii = pdata.generatePacking((10.0, 10.0, 10.0), (0.1, 0.5), 100)

getAngVelById(self: dem.cudem.ParticleData, arg0: SupportsInt) pySudoMath.Vector3f

Get the angular velocity of a particle by its ID (debug only).

This method returns the angular velocity of a particle with the specified ID. It is intended primarily for debugging purposes.

Args:

id (int): The particle ID.

Returns:

Vector3r: The angular velocity of the particle.

Example:

pdata = dem.cudem.ParticleData() # After running simulation... ang_vel = pdata.getAngVelById(0) # Get angular velocity of particle 0 print(f"Angular velocity: {ang_vel}")

getForceTorqueById(self: dem.cudem.ParticleData, arg0: SupportsInt) numpy.typing.NDArray[numpy.float32]

Get the resultant contact force and torque by body ID.

This method returns the resultant contact force and torque acting on a body with the specified ID.

Args:

id (int): The body ID.

Returns:
numpy.ndarray: A 2x3 NumPy array where the first row contains the force components (fx, fy, fz)

and the second row contains the torque components (tx, ty, tz).

Example:

pdata = dem.cudem.ParticleData() # After running simulation... force_torque = pdata.getForceTorqueById(0) # Get force and torque for body 0 print(f"Force/Torque matrix shape: {force_torque.shape}")

getGravPotentialEnergy(self: dem.cudem.ParticleData, arg0: SupportsFloat, arg1: SupportsFloat) float

Get the gravitational potential energy of all particles.

This method calculates and returns the total gravitational potential energy of all particles in the system, relative to a reference position.

Args:

ref_pos (float): The reference position for calculating potential energy. grav_g (float): The gravitational acceleration.

Returns:

float: The total gravitational potential energy.

Example:

pdata = dem.cudem.ParticleData() # After running simulation... pe = pdata.getGravPotentialEnergy(0.0, 9.81) # Get gravitational potential energy print(f"Potential energy: {pe}")

getKineticEnergy(self: dem.cudem.ParticleData) float

Get the total kinetic energy of all particles.

This method calculates and returns the total kinetic energy of all particles in the system.

Returns:

float: The total kinetic energy.

Example:

pdata = dem.cudem.ParticleData() # After running simulation... ke = pdata.getKineticEnergy() # Get total kinetic energy print(f"Kinetic energy: {ke}")

getShapeType(self: dem.cudem.ParticleData) int

Get the shape type of particles.

Returns an integer representing the shape type of particles in this data structure.

Returns:

int: The shape type identifier (0: SPHERE, 1: POLYSUPER).

Example:

pdata = dem.cudem.ParticleData() shape_type = pdata.getShapeType()

getVelById(self: dem.cudem.ParticleData, arg0: SupportsInt) pySudoMath.Vector3f

Get the velocity of a particle by its ID (debug only).

This method returns the translational velocity of a particle with the specified ID. It is intended primarily for debugging purposes.

Args:

id (int): The particle ID.

Returns:

Vector3r: The velocity of the particle.

Example:

pdata = dem.cudem.ParticleData() # After running simulation... vel = pdata.getVelById(0) # Get velocity of particle 0 print(f"Velocity: {vel}")

property material

Material: The material properties for particles.

This property defines the material properties used for all particles in the system.

Example:

pdata = dem.cudem.ParticleData() material = dem.core.Material() material.density = 2650.0 pdata.material = material # Set particle material mat = pdata.material # Get current material

printInfo(self: dem.cudem.ParticleData, arg0: SupportsInt) None

Print information about a specific particle by ID.

This method prints detailed information about a particle with the specified ID to the console, useful for debugging purposes.

Args:

id (int): The particle ID to print information for.

Example:

pdata = dem.cudem.ParticleData() # After setting up particles... pdata.printInfo(0) # Print info for particle 0

setVelById(self: dem.cudem.ParticleData, arg0: pySudoMath.Vector3f, arg1: SupportsInt) None

Set the translational velocity of a particle by ID.

This method sets the translational velocity of a particle with the specified ID. Note that this is only recommended for limited usage.

Args:

id (int): The particle ID. vel (Vector3r): The new velocity for the particle.

Example:

pdata = dem.cudem.ParticleData() # After setting up particles... pdata.setVelById(0, (1.0, 0.0, 0.0)) # Set velocity for particle 0

updatePosById(self: dem.cudem.ParticleData, arg0: pySudoMath.Vector3f, arg1: SupportsInt) None

Update the position of a particle by its global ID.

This method updates the position of a particle with the specified global ID.

Args:

id (int): The global ID of the particle. pos (Vector3r): The new position for the particle.

Example:

pdata = dem.cudem.ParticleData() # After setting up particles... pdata.updatePosById(0, (1.0, 2.0, 3.0)) # Move particle 0 to new position

property wallMaterial

Material: The material properties for walls.

This property defines the material properties used for all walls in the system.

Example:

pdata = dem.cudem.ParticleData() wall_material = dem.core.Material() wall_material.friction = 0.5 pdata.wallMaterial = wall_material # Set wall material mat = pdata.wallMaterial # Get current wall material

class dem.cudem.PolySuperellipsoidData

基类:ParticleData

Particle data container for superellipsoidal particles in CUDEM simulations.

This class manages superellipsoidal particle data in CUDEM simulations. It extends the base ParticleData class with specialized functionality for superellipsoidal particles, including shape parameter management and particle creation methods.

Superellipsoids are a generalization of ellipsoids with additional shape parameters that control the "squareness" of the shape.

Example:

import dem.cudem poly_data = dem.cudem.PolySuperellipsoidData() # Configure superellipsoidal particles...

PtsPos(self: dem.cudem.PolySuperellipsoidData) list[float]

Get particle positions.

Returns the positions of all particles as a list of Vector3r.

Returns:

list: List of Vector3r representing particle positions.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() # After creating particles... positions = poly_data.PtsPos() print(f"First particle position: {positions[0]}")

__init__(self: dem.cudem.PolySuperellipsoidData) None

Construct a new PolySuperellipsoidData object with default parameters.

Example:

poly_data = dem.cudem.PolySuperellipsoidData()

getN(self: dem.cudem.PolySuperellipsoidData) int

Get the number of particles.

Returns the total number of particles in the system.

Returns:

int: The number of particles.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() # After creating particles... num_particles = poly_data.getN() print(f"Number of particles: {num_particles}")

getPosById(self: dem.cudem.PolySuperellipsoidData, arg0: SupportsInt) pySudoMath.Vector3f

Get the position of a particle by its ID.

This method returns the position of a particle with the specified ID.

Args:

id (int): The particle ID.

Returns:

Vector3r: The position of the particle.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() # After creating particles... pos = poly_data.getPosById(0) # Get position of particle 0 print(f"Particle position: {pos}")

getVertIndex(self: dem.cudem.PolySuperellipsoidData) list[pySudoMath.Vector3i]

Get vertex indices of discretized surfaces for visualization.

This method returns the vertex indices of discretized surfaces for visualization purposes.

Returns:

list: List of Vector3i representing vertex indices.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() # After setting up particles... indices = poly_data.getVertIndex() print(f"Vertex indices: {indices}")

loadPos(self: dem.cudem.PolySuperellipsoidData, arg0: str) None

Load particle positions from a binary file (test only).

This method loads particle positions from a binary file. Intended for testing purposes.

Args:

filename (str): The name of the file to load positions from.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() poly_data.loadPos("particle_positions.dat")

property material

Material: The material properties for superellipsoidal particles.

This property defines the material properties used for all superellipsoidal particles in the system.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() material = dem.core.Material() material.density = 2650.0 poly_data.material = material # Set particle material mat = poly_data.material # Get current material

savePos(self: dem.cudem.PolySuperellipsoidData, arg0: str) None

Save particle positions to a binary file.

This method saves particle positions to a binary file for later loading.

Args:

filename (str): The name of the file to save positions to.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() # After creating particles... poly_data.savePos("particle_positions.dat")

setPosOri(self: dem.cudem.PolySuperellipsoidData, arg0: collections.abc.Sequence[pySudoMath.Vector3f], arg1: collections.abc.Sequence[pySudoMath.Quaternionr]) bool

Set particle positions and orientations.

This method sets the positions and orientations for all particles in the system.

Args:

pos (list): List of Vector3r representing particle positions. ori (list): List of Quaternionr representing particle orientations.

Example:

poly_data = dem.cudem.PolySuperellipsoidData() positions = [(0, 0, 0), (1, 0, 0), (2, 0, 0)] orientations = [(1, 0, 0, 0), (1, 0, 0, 0), (1, 0, 0, 0)] # Identity quaternions poly_data.setPosOri(positions, orientations)

setShapePara(*args, **kwargs)

Overloaded function.

  1. setShapePara(self: dem.cudem.PolySuperellipsoidData, arg0: collections.abc.Sequence[pySudoMath.Vector2f], arg1: collections.abc.Sequence[pySudoMath.Vector2f], arg2: collections.abc.Sequence[pySudoMath.Vector2f], arg3: collections.abc.Sequence[pySudoMath.Vector2f]) -> bool

    Set shape parameters for superellipsoidal particles.

    This method sets the shape parameters for superellipsoidal particles using four lists:epsilon parameters, x-axis parameters, y-axis parameters, and z-axis parameters.

    Args:

    eps (list): List of Vector2r representing epsilon parameters (eps1, eps2). rx (list): List of Vector2r representing x-axis parameters (rx+, rx-). ry (list): List of Vector2r representing y-axis parameters (ry+, ry-). rz (list): List of Vector2r representing z-axis parameters (rz+, rz-).

    Returns:

    bool: True if shape parameters were set successfully, False otherwise.

    Example:

    poly_data = dem.cudem.PolySuperellipsoidData() eps = [(0.5, 0.5)] # Epsilon parameters rx = [(1.0, 1.0)] # X-axis parameters ry = [(0.5, 0.5)] # Y-axis parameters rz = [(0.5, 0.5)] # Z-axis parameters success = poly_data.setShapePara(eps, rx, ry, rz)

  2. setShapePara(self: dem.cudem.PolySuperellipsoidData, arg0: collections.abc.Sequence[pySudoMath.Vector2f], arg1: collections.abc.Sequence[pySudoMath.Vector2f], arg2: collections.abc.Sequence[pySudoMath.Vector2f], arg3: collections.abc.Sequence[pySudoMath.Vector2f], arg4: collections.abc.Sequence[typing.SupportsInt]) -> bool

    Set shape parameters for superellipsoidal particles with particle counts.

    This method sets the shape parameters for superellipsoidal particles and specifies the number of particles for each shape group.

    Args:

    eps (list): List of Vector2r representing epsilon parameters (eps1, eps2). rx (list): List of Vector2r representing x-axis parameters (rx+, rx-). ry (list): List of Vector2r representing y-axis parameters (ry+, ry-). rz (list): List of Vector2r representing z-axis parameters (rz+, rz-). num (list): List of integers representing particle count for each shape group.

    Returns:

    bool: True if shape parameters were set successfully, False otherwise.

    Example:

    poly_data = dem.cudem.PolySuperellipsoidData() eps = [(0.5, 0.5), (0.3, 0.3)] # Two shape groups rx = [(1.0, 1.0), (0.8, 0.8)] ry = [(0.5, 0.5), (0.4, 0.4)] rz = [(0.5, 0.5), (0.4, 0.4)] num = [50, 30] # 50 particles of first shape, 30 of second success = poly_data.setShapePara(eps, rx, ry, rz, num)

  3. setShapePara(self: dem.cudem.PolySuperellipsoidData, arg0: collections.abc.Sequence[pySudoMath.Vector2f], arg1: collections.abc.Sequence[pySudoMath.Vector2f], arg2: collections.abc.Sequence[pySudoMath.Vector2f], arg3: collections.abc.Sequence[pySudoMath.Vector2f], arg4: collections.abc.Sequence[typing.SupportsInt], arg5: collections.abc.Sequence[typing.SupportsFloat]) -> bool

    Set shape parameters for superellipsoidal particles with particle counts and scale factors.

    This method sets the shape parameters for superellipsoidal particles, specifies the number of particles for each shape group, and applies scale factors to all particles.

    Args:

    eps (list): List of Vector2r representing epsilon parameters (eps1, eps2). rx (list): List of Vector2r representing x-axis parameters (rx+, rx-). ry (list): List of Vector2r representing y-axis parameters (ry+, ry-). rz (list): List of Vector2r representing z-axis parameters (rz+, rz-). num (list): List of integers representing particle count for each shape group. scales (list): List of floats representing scale factors for all particles.

    Returns:

    bool: True if shape parameters were set successfully, False otherwise.

    Example:

    poly_data = dem.cudem.PolySuperellipsoidData() eps = [(0.5, 0.5)] rx = [(1.0, 1.0)] ry = [(0.5, 0.5)] rz = [(0.5, 0.5)] num = [100] # 100 particles scales = [1.0] * 100 # Scale factors for each particle success = poly_data.setShapePara(eps, rx, ry, rz, num, scales)

class dem.cudem.SphereData

基类:ParticleData

Particle data container for spherical particles in CUDEM simulations.

This class manages spherical particle data in CUDEM simulations. It extends the base ParticleData class with specialized functionality for spherical particles, including radius management and particle creation methods.

Example:

import dem.cudem sphere_data = dem.cudem.SphereData() # Configure spherical particles...

PtsPos(self: dem.cudem.SphereData) list[float]

Get particle positions.

Returns the positions of all particles as a list of Vector3r.

Returns:

list: List of Vector3r representing particle positions.

Example:

sphere_data = dem.cudem.SphereData() # After creating particles... positions = sphere_data.PtsPos() print(f"First particle position: {positions[0]}")

__init__(self: dem.cudem.SphereData) None

Construct a new SphereData object with default parameters.

Example:

sphere_data = dem.cudem.SphereData()

createParticles(*args, **kwargs)

Overloaded function.

  1. createParticles(self: dem.cudem.SphereData, arg0: collections.abc.Sequence[pySudoMath.Vector3f], arg1: collections.abc.Sequence[typing.SupportsFloat]) -> bool

    Create spherical particles with specified positions and radii.

    This method creates spherical particles with the specified positions and radii.

    Args:

    pos (list): List of Vector3r representing particle positions. r (list): List of floats representing particle radii.

    Returns:

    bool: True if particles were created successfully, False otherwise.

    Example:

    sphere_data = dem.cudem.SphereData() positions = [(0, 0, 0), (1, 0, 0), (2, 0, 0)] radii = [0.5, 0.5, 0.5] success = sphere_data.createParticles(positions, radii)

  2. createParticles(self: dem.cudem.SphereData, arg0: collections.abc.Sequence[pySudoMath.Vector3f], arg1: collections.abc.Sequence[typing.SupportsFloat], arg2: collections.abc.Sequence[typing.SupportsInt]) -> bool

    Create spherical particles with positions, radii, and type information.

    This method creates spherical particles with the specified positions, radii, and type information.

    Args:

    pos (list): List of Vector3r representing particle positions. r (list): List of floats representing particle radii. type_v (list): List of short integers representing particle types (0 for fixed, 1 for normal, 2 for wall, etc.).

    Returns:

    bool: True if particles were created successfully, False otherwise.

    Example:

    sphere_data = dem.cudem.SphereData() positions = [(0, 0, 0), (1, 0, 0), (2, 0, 0)] radii = [0.5, 0.5, 0.5] types = [1, 1, 1] # Particle types success = sphere_data.createParticles(positions, radii, types)

getN(self: dem.cudem.SphereData) int

Get the number of particles.

Returns the total number of particles in the system.

Returns:

int: The number of particles.

Example:

sphere_data = dem.cudem.SphereData() # After creating particles... num_particles = sphere_data.getN() print(f"Number of particles: {num_particles}")

getPosById(self: dem.cudem.SphereData, arg0: SupportsInt) pySudoMath.Vector3f

Get the position of a particle by its ID.

This method returns the position of a particle with the specified ID.

Args:

id (int): The particle ID.

Returns:

Vector3r: The position of the particle.

Example:

sphere_data = dem.cudem.SphereData() # After creating particles... pos = sphere_data.getPosById(0) # Get position of particle 0 print(f"Particle position: {pos}")

getRadii(self: dem.cudem.SphereData) list[float]

Get particle radii.

Returns the radii of all particles as a list of floats.

Returns:

list: List of floats representing particle radii.

Example:

sphere_data = dem.cudem.SphereData() # After creating particles... radii = sphere_data.getRadii() print(f"First particle radius: {radii[0]}")

loadPos(self: dem.cudem.SphereData, arg0: str) None

Load particle positions from a binary file (test only).

This method loads particle positions from a binary file. Intended for testing purposes.

Args:

filename (str): The name of the file to load positions from.

Example:

sphere_data = dem.cudem.SphereData() sphere_data.loadPos("particle_positions.dat")

property material

Material: The material properties for spherical particles.

This property defines the material properties used for all spherical particles in the system.

Example:

sphere_data = dem.cudem.SphereData() material = dem.core.Material() material.density = 2650.0 sphere_data.material = material # Set particle material mat = sphere_data.material # Get current material

property radius

list: Radii of all particles.

This property provides access to the radii of all particles in the system. It can be both read and written to modify particle radii.

Example:

sphere_data = dem.cudem.SphereData() # After creating particles... radii = sphere_data.radius # Get all radii sphere_data.radius = [0.6, 0.6, 0.6] # Set new radii for all particles

savePos(self: dem.cudem.SphereData, arg0: str) None

Save particle positions to a binary file.

This method saves particle positions to a binary file for later loading.

Args:

filename (str): The name of the file to save positions to.

Example:

sphere_data = dem.cudem.SphereData() # After creating particles... sphere_data.savePos("particle_positions.dat")

11.2.4. 子模块 rtdem API函数

rtdem module for GPU-accelerated DEM simulations.

This module provides the core components for high-performance Discrete Element Method (DEM) simulations using GPU acceleration through CUDA and OptiX ray tracing. It implements the RTDEM (Ray Tracing DEM) algorithm for contact detection between arbitrarily-shaped polyhedral particles.

Key components: - DEMSim: The main simulation class that orchestrates the entire DEM simulation - ParticleData: Container for particle data including positions, velocities, orientations, and forces - PolyhedronData: Represents polyhedral particle shapes and mesh data - Integrator: Handles integration of particle motion using numerical integration schemes

The module leverages GPU acceleration for: - Contact detection using OptiX ray tracing - Force calculation and integration - Particle motion updates - Neighbor list management

Example:

import dem.rtdem

# Create simulation sim = dem.rtdem.DEMSim()

# Set up particles pdata = sim.pdata # Add polyhedral particles...

# Configure simulation sim.setTimestep(1e-5) sim.init()

# Run simulation sim.run(1000)

class dem.rtdem.DEMSim

The DEM solver by RTDEM.

This class implements the Discrete Element Method (DEM) simulation using ray-tracing algorithms for arbitrarily-shaped particles. It provides functionality for particle motion integration, force calculation, and simulation state management.

Example:

import dem.rtdem sim = dem.rtdem.DEMSim() sim.setTimestep(1e-5) # Add particles and walls... sim.init() sim.run(100)

Pause(self: dem.rtdem.DEMSim) None

Force pause the simulation when running with RunPthread.

This method pauses the simulation if it's running in a separate thread.

Example:

sim = dem.rtdem.DEMSim() # In another thread sim.Pause()

RunPthread(self: dem.rtdem.DEMSim, steps: SupportsInt) None

Run the simulation with n steps in a new thread.

Args:

steps (int): The number of steps to run.

Example:

sim = dem.rtdem.DEMSim() sim.init() sim.RunPthread(1000) # Run for 1000 steps in a separate thread

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: dem.rtdem.DEMSim) -> None

    Construct a new DEMSim object with default parameters.

    Example:

    sim = dem.rtdem.DEMSim()

  2. __init__(self: dem.rtdem.DEMSim, gpu_id: typing.SupportsInt) -> None

    Construct a new DEMSim object with a specific GPU device ID.

    Args:

    gpu_id (int): Device ID of GPU to use for computation.

    Example:

    sim = dem.rtdem.DEMSim(0) # Use GPU 0

  3. __init__(self: dem.rtdem.DEMSim, callback: object) -> None

    Construct a new DEMSim object with a Python callback.

    Args:

    callback: Callback function in Python.

    Example:
    def my_callback():

    print("Simulation callback")

    sim = dem.rtdem.DEMSim(my_callback)

  4. __init__(self: dem.rtdem.DEMSim, gpu_id: typing.SupportsInt, callback: object) -> None

    Construct a new DEMSim object with a specific GPU device ID and Python callback.

    Args:

    gpu_id (int): Device ID of GPU to use for computation. callback: Callback function in Python.

    Example:
    def my_callback():

    print("Simulation callback")

    sim = dem.rtdem.DEMSim(0, my_callback) # Use GPU 0 with callback

property dt

float: The time step size for the simulation.

Example:

sim = dem.rtdem.DEMSim() sim.dt = 1e-5 # Set time step timestep = sim.dt # Get time step size

property elapsedTime

float: The elapsed time in seconds (read-only).

Example:

sim = dem.rtdem.DEMSim() # After running simulation elapsed = sim.elapsedTime

freeMem(self: dem.rtdem.DEMSim) None

Free up GPU memory in the simulation.

This method releases GPU memory allocated for the simulation.

Example:

sim = dem.rtdem.DEMSim() # After simulation is complete sim.freeMem()

getInstanceInfo(self: dem.rtdem.DEMSim) object

Get information about particle instances in the simulation.

Returns a NumPy array with information about each particle instance, including: - Number of particles - Number of indices - Number of vertices

Returns:

numpy.ndarray: A 2D array with instance information.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with particles... sim.init() # Get instance information info = sim.getInstanceInfo() print(f"Instance info shape: {info.shape}")

getMeshNum(self: dem.rtdem.DEMSim) int

Get the number of meshes (immovable particles such as walls) in the simulation.

Returns:

int: The number of meshes in the simulation.

Example:

sim = dem.rtdem.DEMSim() # Add some walls/meshes... mesh_count = sim.getMeshNum() print(f"Number of meshes: {mesh_count}")

getMeshPosOri(self: dem.rtdem.DEMSim, arg0: SupportsInt) object

Get the position and orientation of a mesh by its ID.

Returns a NumPy array containing the position (x, y, z) and orientation (x, y, z, w) of the specified mesh. Note that this currently only works for meshes with a single instance.

Args:

mesh_id (int): The ID of the mesh to get position and orientation for.

Returns:

numpy.ndarray: A 1D array with 7 elements (3 for position, 4 for orientation).

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with meshes... sim.init() # Get position and orientation of mesh with ID 0 pos_ori = sim.getMeshPosOri(0) print(f"Mesh position and orientation: {pos_ori}")

getOri(self: dem.rtdem.DEMSim) object

Get the orientations of all particles in the simulation.

Returns a NumPy array with the orientations of all particles, where each row contains the x, y, z, w components of the quaternion representing the orientation of each particle.

Returns:

numpy.ndarray: A 2D array with particle orientations.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with particles... sim.init() # Run some steps sim.run(100) # Get particle orientations orientations = sim.getOri() print(f"Particle orientations shape: {orientations.shape}")

getParNum(self: dem.rtdem.DEMSim) int

Get the number of particles in the simulation.

Returns:

int: The number of particles.

Example:

sim = dem.rtdem.DEMSim() particle_count = sim.getParNum()

getPos(self: dem.rtdem.DEMSim) object

Get the positions of all particles in the simulation.

Returns a NumPy array with the positions of all particles, where each row contains the x, y, z coordinates and w (usually 1.0) for each particle.

Returns:

numpy.ndarray: A 2D array with particle positions.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with particles... sim.init() # Run some steps sim.run(100) # Get particle positions positions = sim.getPos() print(f"Particle positions shape: {positions.shape}")

getPosOri(self: dem.rtdem.DEMSim) object

Get both positions and orientations of all particles in the simulation.

Returns a tuple of two NumPy arrays containing particle positions and orientations. The first array contains positions (x, y, z, w) and the second contains orientations (x, y, z, w) as quaternions.

Returns:

tuple: A tuple containing two 2D NumPy arrays (positions, orientations).

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with particles... sim.init() # Run some steps sim.run(100) # Get particle positions and orientations positions, orientations = sim.getPosOri() print(f"Positions shape: {positions.shape}") print(f"Orientations shape: {orientations.shape}")

getSystemInfo(self: dem.rtdem.DEMSim) None

Get the GPU information in the system.

This method prints information about the available GPUs and CUDA version.

Example:

sim = dem.rtdem.DEMSim() sim.getSystemInfo()

property hooks

list: List of hooks attached to the simulation.

Example:

sim = dem.rtdem.DEMSim() hooks = sim.hooks # Get hooks # Set hooks # sim.hooks = [hook1, hook2]

init(self: dem.rtdem.DEMSim) None

Initialize the simulation model before running.

This method must be called before starting the simulation to properly set up all necessary data structures.

Example:

sim = dem.rtdem.DEMSim() sim.init() # Initialize the simulation sim.run(100)

property integrator

Integrator for particle motion.

This attribute provides access to the integrator object responsible for updating particle positions and orientations based on calculated forces and torques.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation... sim.init() # Access integrator properties print(sim.integrator.getTimeStep())

isLoaded(self: dem.rtdem.DEMSim) bool

Check if the simulation is loaded from a checkpoint.

Returns:

bool: True if the simulation was loaded from a checkpoint, False otherwise.

Example:

sim = dem.rtdem.DEMSim() if sim.isLoaded():

print("Simulation was loaded from checkpoint")

isRunning(self: dem.rtdem.DEMSim) bool

Get the isRunning flag to check if the simulation is running.

Returns:

bool: True if the simulation is running, False otherwise.

Example:

sim = dem.rtdem.DEMSim() if sim.isRunning():

print("Simulation is running")

iter(self: dem.rtdem.DEMSim) int

Get the current time step.

Returns:

int: The current iteration number.

Example:

sim = dem.rtdem.DEMSim() # After running simulation current_iter = sim.iter()

load(self: dem.rtdem.DEMSim, arg0: str) bool

Load the simulation state from a file.

Loads a previously saved simulation state from the specified file path. The file format is determined by the file extension (.xml, .json, or binary).

Args:

path (str): The file path to load the simulation state from.

Returns:

bool: True if the load was successful, False otherwise.

Example:

sim = dem.rtdem.DEMSim() # Load simulation state success = sim.load("simulation_state.xml") if success:

print("Simulation state loaded successfully")

loadPthread(self: dem.rtdem.DEMSim, arg0: str) None

Load the simulation state from a file using a separate thread.

Loads a previously saved simulation state from the specified file path using a separate thread to avoid blocking the main simulation thread. The file format is determined by the file extension (.xml, .json, or binary).

Args:

path (str): The file path to load the simulation state from.

Example:

sim = dem.rtdem.DEMSim() # Load simulation state in a separate thread sim.loadPthread("simulation_state.xml")

moveMesh(self: dem.rtdem.DEMSim, arg0: SupportsInt, arg1: pySudoMath.Vector3f) None

Move a mesh to a new position by its ID.

Updates the position of the specified mesh to the given position vector.

Args:

mesh_id (int): The ID of the mesh to move. pos (Vector3r): The new position for the mesh.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with meshes... sim.init() # Move mesh with ID 0 to position (1.0, 2.0, 3.0) sim.moveMesh(0, Vector3r(1.0, 2.0, 3.0))

moveToNextTimeStep(self: dem.rtdem.DEMSim) None

Advance the simulation by one time step.

This method performs all necessary calculations to advance the simulation by a single time step, including force calculation, integration, and updating particle positions.

Example:

sim = dem.rtdem.DEMSim() sim.setTimestep(1e-5) # Setup simulation... sim.init() # Run simulation for 1000 steps for i in range(1000):

sim.moveToNextTimeStep()

particleScales(self: dem.rtdem.DEMSim) object

Get the scale factors of all polyhedrons in the scene.

Returns a NumPy array containing the scale factors for all movable polyhedrons in the scene. Each element in the array represents the scale factor for a particle instance.

Returns:

numpy.ndarray: A 1D array with scale factors.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with scaled polyhedron particles... sim.init() # Get all scale factors scales = sim.particleScales() print(f"Scale factors shape: {scales.shape}")

property pdata

Particle data container.

This attribute provides access to the particle data including positions, orientations, velocities, and other particle properties.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation... sim.init() particle = sim.pdata # Access particle data

printParInfo(self: dem.rtdem.DEMSim, arg0: SupportsInt) None

Print detailed information about a specific particle.

This method is primarily intended for debugging purposes and will print detailed information about a particle with the specified ID to the console.

Args:

pid (int): The particle ID to print information for.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with particles... sim.init() # Print information about particle with ID 0 sim.printParInfo(0)

rebuildIAS_debug(self: dem.rtdem.DEMSim) None

Rebuild the Instance Acceleration Structure (IAS) for debugging purposes only.

This method is intended for debugging and should not be used in production simulations. It forces a rebuild of the IAS which can be useful for troubleshooting rendering issues.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation... sim.rebuildIAS_debug() # Force rebuild IAS for debugging

run(self: dem.rtdem.DEMSim, steps: SupportsInt) None

Run the simulation with n steps.

Args:

steps (int): The number of steps to run.

Example:

sim = dem.rtdem.DEMSim() sim.init() sim.run(1000) # Run for 1000 steps

save(self: dem.rtdem.DEMSim, arg0: str) bool

Save the simulation state to a file.

Serializes the current simulation state and saves it to the specified file path. The file format is determined by the file extension (.xml, .json, or binary).

Args:

path (str): The file path to save the simulation state to.

Returns:

bool: True if the save was successful, False otherwise.

Example:

sim = dem.rtdem.DEMSim() # Setup and run simulation... sim.init() # Save simulation state success = sim.save("simulation_state.xml") if success:

print("Simulation state saved successfully")

savePthread(self: dem.rtdem.DEMSim, arg0: str) None

Save the simulation state to a file using a separate thread.

Serializes the current simulation state and saves it to the specified file path using a separate thread to avoid blocking the main simulation thread. The file format is determined by the file extension (.xml, .json, or binary).

Args:

path (str): The file path to save the simulation state to.

Example:

sim = dem.rtdem.DEMSim() # Setup and run simulation... sim.init() # Save simulation state in a separate thread sim.savePthread("simulation_state.xml")

setFilePrefix(self: dem.rtdem.DEMSim, prefix: str) None

Set the prefix name of output files.

Args:

prefix (str): The prefix for output files.

Example:

sim = dem.rtdem.DEMSim() sim.setFilePrefix("simulation")

setLoadedFlag(self: dem.rtdem.DEMSim, flag: bool) None

Set the loaded flag.

Args:

flag (bool): The value to set the loaded flag to.

Example:

sim = dem.rtdem.DEMSim() sim.setLoadedFlag(True)

setOutputDir(self: dem.rtdem.DEMSim, path: str) None

Set the output directory for simulation results.

Args:

path (str): The path to the output directory.

Example:

sim = dem.rtdem.DEMSim() sim.setOutputDir("./output/")

property speed

float: Simulation speed in iterations per second (read-only).

Example:

sim = dem.rtdem.DEMSim() # After running simulation speed = sim.speed

updatedMeshGUI(self: dem.rtdem.DEMSim) bool

Check if meshes need to be updated in the GUI.

Returns a boolean indicating whether meshes have been updated and need to be refreshed in the GUI.

Returns:

bool: True if meshes need to be updated in the GUI, False otherwise.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with meshes... sim.init() # Check if mesh update is needed if sim.updatedMeshGUI():

print("Meshes need to be updated in GUI")

verts(self: dem.rtdem.DEMSim) object

Get the vertices of all polyhedrons in the scene.

Returns a NumPy array containing the vertices of all movable polyhedrons in the scene. Each row in the array represents a vertex with its x, y, z coordinates.

Returns:

numpy.ndarray: A 2D array with vertex coordinates.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with polyhedron particles... sim.init() # Get all vertices vertices = sim.verts() print(f"Vertices shape: {vertices.shape}")

vertsId(self: dem.rtdem.DEMSim) object

Get the vertex indices for all polyhedrons in the scene.

Returns a NumPy array containing the vertex indices for all movable polyhedrons in the scene. Each row in the array represents a triangle face with three vertex indices.

Returns:

numpy.ndarray: A 2D array with vertex indices.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with polyhedron particles... sim.init() # Get all vertex indices indices = sim.vertsId() print(f"Vertex indices shape: {indices.shape}")

vertsIdMesh(self: dem.rtdem.DEMSim, arg0: SupportsInt) object

Get the vertex indices for a specific mesh by its ID.

Returns a NumPy array containing the vertex indices for the specified mesh. Each row in the array represents a triangle face with three vertex indices.

Args:

mesh_id (int): The ID of the mesh to get vertex indices for.

Returns:

numpy.ndarray: A 2D array with vertex indices.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with meshes... sim.init() # Get vertex indices of mesh with ID 0 indices = sim.vertsIdMesh(0) print(f"Mesh vertex indices shape: {indices.shape}")

vertsMesh(self: dem.rtdem.DEMSim, arg0: SupportsInt) object

Get the vertices of a specific mesh by its ID.

Returns a NumPy array containing the vertices of the specified mesh. Each row in the array represents a vertex with its x, y, z coordinates.

Args:

mesh_id (int): The ID of the mesh to get vertices for.

Returns:

numpy.ndarray: A 2D array with vertex coordinates.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with meshes... sim.init() # Get vertices of mesh with ID 0 vertices = sim.vertsMesh(0) print(f"Mesh vertices shape: {vertices.shape}")

vertsNormal(self: dem.rtdem.DEMSim) object

Get the normals for vertices of all polyhedrons in the scene.

Returns a NumPy array containing the normals for vertices of all movable polyhedrons in the scene. Each row in the array represents a normal vector with x, y, z components.

Returns:

numpy.ndarray: A 2D array with vertex normals.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with polyhedron particles... sim.init() # Get all vertex normals normals = sim.vertsNormal() print(f"Vertex normals shape: {normals.shape}")

vertsNormalDist(self: dem.rtdem.DEMSim) object

Get the normals multiplied by ray length for vertices of all polyhedrons in the scene.

Returns a NumPy array containing the normals multiplied by ray length for vertices of all movable polyhedrons in the scene. Each row in the array represents a normal vector with x, y, z components multiplied by the ray length.

Returns:

numpy.ndarray: A 2D array with vertex normals multiplied by ray length.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with polyhedron particles... sim.init() # Get all vertex normals multiplied by ray length normal_dists = sim.vertsNormalDist() print(f"Vertex normal distances shape: {normal_dists.shape}")

vertsNormalMesh(self: dem.rtdem.DEMSim, arg0: SupportsInt) object

Get the normals for vertices of a specific mesh by its ID.

Returns a NumPy array containing the normals for vertices of the specified mesh. Each row in the array represents a normal vector with x, y, z components.

Args:

mesh_id (int): The ID of the mesh to get vertex normals for.

Returns:

numpy.ndarray: A 2D array with vertex normals.

Example:

sim = dem.rtdem.DEMSim() # Setup simulation with meshes... sim.init() # Get vertex normals of mesh with ID 0 normals = sim.vertsNormalMesh(0) print(f"Mesh vertex normals shape: {normals.shape}")

writeVTK(self: dem.rtdem.DEMSim, filename: str) None

Dump particle data into a VTK file.

This method writes the current particle data to a VTK file for visualization.

Example:

sim = dem.rtdem.DEMSim() sim.writeVTK("particle_data")

class dem.rtdem.Integrator

Integrator for particle motion in RTDEM simulations.

This class handles the integration of particle motion in discrete element method simulations. It implements numerical integration schemes for updating particle positions and orientations based on calculated forces and torques. The integrator supports both linear and angular motion, with specialized algorithms for non-spherical particles.

Example:

import dem.rtdem sim = dem.rtdem.DEMSim() integrator = sim.integrator integrator.gravity = (0, 0, -9.81) # Set gravity integrator.damping = 0.1 # Set damping

Integrate(self: dem.rtdem.Integrator) cudaError

Perform one integration step for all particles.

This method updates the positions and orientations of all particles based on their current velocities, forces, and torques.

Example:

integrator = dem.rtdem.Integrator() # After setting up simulation... integrator.Integrate() # Perform one integration step

__init__(self: dem.rtdem.Integrator) None

Construct a new Integrator object with default parameters.

Example:

integrator = dem.rtdem.Integrator()

property alpha

float: Skin size factor for neighbor list updates.

The neighbor list is updated when particle displacement exceeds alpha*radius with respect to the reference configuration.

Example:

integrator = dem.rtdem.Integrator() integrator.alpha = 1.5 # Set neighbor list update threshold alpha = integrator.alpha

calmSystem(self: dem.rtdem.Integrator) None

Reset all particle velocities to zero.

This method sets all linear and angular velocities of particles to zero, effectively calming the system.

Example:

integrator = dem.rtdem.Integrator() # After running simulation... integrator.calmSystem() # Stop all particle motion

property damping

float: The mass damping coefficient applied to particles.

Note:

This parameter has been deprecated. Use viscousDamping of Material instead.

Example:

integrator = dem.rtdem.Integrator() integrator.damping = 0.1 # Set mass damping damping = integrator.damping

property dead

bool: Flag indicating if the integrator is active (False) or inactive (True).

When set to True, the integrator will not perform any integration steps.

Example:

integrator = dem.rtdem.Integrator() integrator.dead = True # Deactivate integrator is_dead = integrator.dead

property densityScaling

float: Density scaling factor for rotational motion only.

This parameter affects the rotational dynamics of particles, particularly useful for non-spherical particles.

Example:

integrator = dem.rtdem.Integrator() integrator.densityScaling = 0.5 # Set density scaling ds = integrator.densityScaling

property gravity

tuple: The gravity vector (x, y, z) applied to all particles.

Example:

integrator = dem.rtdem.Integrator() integrator.gravity = (0, 0, -9.81) # Set gravity to Earth's gravity g = integrator.gravity # Get current gravity

printInfo(self: dem.rtdem.Integrator) None

Print integrator information for debugging purposes.

This method prints detailed information about the integrator settings to the console.

Example:

integrator = dem.rtdem.Integrator() integrator.printInfo() # Print integrator settings

property viscousDamping

float: Viscous damping coefficient applied at particle contacts.

This damping is applied to reduce oscillations at particle contacts.

Example:

integrator = dem.rtdem.Integrator() integrator.viscousDamping = 0.05 # Set viscous damping damping = integrator.viscousDamping

class dem.rtdem.ParticleData

Container for particle data in RTDEM simulations.

This class manages all particle data in RTDEM simulations, including positions, velocities, orientations, forces, and torques. It provides methods for accessing and manipulating particle properties, as well as managing particle groups (objects) and materials.

Example:

import dem.rtdem sim = dem.rtdem.DEMSim() pdata = sim.pdata # Access particle data # Add objects, manipulate particles, etc.

__init__(self: dem.rtdem.ParticleData) None

Construct a new ParticleData object with default parameters.

Example:

pdata = dem.rtdem.ParticleData()

addObject(self: dem.rtdem.ParticleData, arg0: rtr::PolyhedronData) None

Add a polyhedron object to the particle system.

This method adds a PolyhedronData object to the particle system, which represents a group of particles with the same mesh template.

Args:

obj (dem.rtdem.PolyhedronData): The polyhedron object to add.

Example:

pdata = dem.rtdem.ParticleData() poly = dem.rtdem.PolyhedronData() # Configure polyhedron... pdata.addObject(poly) # Add to particle system

fixParById(self: dem.rtdem.ParticleData, arg0: SupportsInt) None

Fix a particle or wall by its global ID.

This method fixes (immobilizes) a particle or wall with the specified global ID.

Args:

id (int): The global ID of the particle/wall to fix.

Example:

pdata = dem.rtdem.ParticleData() # After setting up particles... pdata.fixParById(0) # Fix particle 0 in place

getAngVelById(self: dem.rtdem.ParticleData, arg0: SupportsInt) pySudoMath.Vector3f

Get the angular velocity of a particle by its ID (debug only).

This method returns the angular velocity of a particle with the specified ID. It is intended primarily for debugging purposes.

Args:

id (int): The particle ID.

Returns:

Vector3r: The angular velocity of the particle.

Example:

pdata = dem.rtdem.ParticleData() # After running simulation... ang_vel = pdata.getAngVelById(0) # Get angular velocity of particle 0 print(f"Angular velocity: {ang_vel}")

getForceTorqueById(self: dem.rtdem.ParticleData, arg0: SupportsInt) numpy.typing.NDArray[numpy.float32]

Get the resultant contact force and torque by body ID.

This method returns the resultant contact force and torque acting on a body with the specified ID.

Args:

id (int): The body ID.

Returns:

numpy.ndarray: A 2x3 NumPy array where the first row contains the force components (fx, fy, fz) and the second row contains the torque components (tx, ty, tz).

Example:

pdata = dem.rtdem.ParticleData() # After running simulation... force_torque = pdata.getForceTorqueById(0) # Get force and torque for body 0 print(f"Force/Torque matrix shape: {force_torque.shape}")

getGravPotentialEnergy(self: dem.rtdem.ParticleData, arg0: SupportsFloat, arg1: SupportsFloat) float

Get the gravitational potential energy of all particles.

This method calculates and returns the total gravitational potential energy of all particles in the system, relative to a reference position.

Args:

ref_pos (float): The reference position for calculating potential energy. grav_g (float): The gravitational acceleration.

Returns:

float: The total gravitational potential energy.

Example:

pdata = dem.rtdem.ParticleData() # After running simulation... pe = pdata.getGravPotentialEnergy(0.0, 9.81) # Get gravitational potential energy print(f"Potential energy: {pe}")

getKineticEnergy(self: dem.rtdem.ParticleData) float

Get the total kinetic energy of all particles.

This method calculates and returns the total kinetic energy of all particles in the system.

Returns:

float: The total kinetic energy.

Example:

pdata = dem.rtdem.ParticleData() # After running simulation... ke = pdata.getKineticEnergy() # Get total kinetic energy print(f"Kinetic energy: {ke}")

getVelById(self: dem.rtdem.ParticleData, arg0: SupportsInt) pySudoMath.Vector3f

Get the velocity of a particle by its ID (debug only).

This method returns the translational velocity of a particle with the specified ID. It is intended primarily for debugging purposes.

Args:

id (int): The particle ID.

Returns:

Vector3r: The velocity of the particle.

Example:

pdata = dem.rtdem.ParticleData() # After running simulation... vel = pdata.getVelById(0) # Get velocity of particle 0 print(f"Velocity: {vel}")

property material

Material: The material properties for particles.

This property defines the material properties used for all particles in the system.

Example:

pdata = dem.rtdem.ParticleData() material = dem.core.Material() material.density = 2650.0 pdata.material = material # Set particle material mat = pdata.material # Get current material

printInfo(self: dem.rtdem.ParticleData, arg0: SupportsInt) None

Print information about a specific particle by ID.

This method prints detailed information about a particle with the specified ID to the console, useful for debugging.

Args:

id (int): The particle ID to print information for.

Example:

pdata = dem.rtdem.ParticleData() # After setting up particles... pdata.printInfo(0) # Print info for particle 0

setVelById(self: dem.rtdem.ParticleData, arg0: pySudoMath.Vector3f, arg1: SupportsInt) None

Set the translational velocity of a particle by ID.

This method sets the translational velocity of a particle with the specified ID. Note that this is only recommended for limited usage.

Args:

id (int): The particle ID. vel (Vector3r): The new velocity for the particle.

Example:

pdata = dem.rtdem.ParticleData() # After setting up particles... pdata.setVelById(0, (1.0, 0.0, 0.0)) # Set velocity for particle 0

updatePosById(self: dem.rtdem.ParticleData, arg0: pySudoMath.Vector3f, arg1: SupportsInt) None

Update the position of a particle by its global ID.

This method updates the position of a particle with the specified global ID.

Args:

id (int): The global ID of the particle. pos (Vector3r): The new position for the particle.

Example:

pdata = dem.rtdem.ParticleData() # After setting up particles... pdata.updatePosById(0, (1.0, 2.0, 3.0)) # Move particle 0 to new position

property wallMaterial

Material: The material properties for walls.

This property defines the material properties used for all walls in the system.

Example:

pdata = dem.rtdem.ParticleData() wall_material = dem.core.Material() wall_material.density = 2650.0 pdata.wallMaterial = wall_material # Set wall material mat = pdata.wallMaterial # Get current wall material

class dem.rtdem.PolyhedronData

Container for polyhedron mesh data in RTDEM simulations.

This class manages polyhedron mesh data used in RTDEM simulations. It provides functionality for loading mesh files (STL, OBJ), defining geometric primitives (planes, boxes), and accessing mesh properties such as vertices, normals, and indices. Each PolyhedronData object represents a group of particles with the same mesh template.

Example:

import dem.rtdem poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") # Load a mesh file # Configure properties...

__init__(self: dem.rtdem.PolyhedronData) None

Construct a new PolyhedronData object with default parameters.

Example:

poly = dem.rtdem.PolyhedronData()

property bounds

Bound: The bounding box of the polyhedron (read-only).

This property provides access to the bounding box that encloses all vertices of the polyhedron model.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") bounds = poly.bounds # Get bounding box

computGeometry(self: dem.rtdem.PolyhedronData) None

Compute geometric properties of the polyhedron.

This method calculates geometric information such as moments of inertia, volume, and center of the polyhedron.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") poly.computGeometry() # Compute geometric properties

getParNum(self: dem.rtdem.PolyhedronData) int

Get the number of particles based on the polyhedron model.

This method returns the number of particles that are generated based on the polyhedron model.

Returns:

int: The number of particles.

Example:

poly = dem.rtdem.PolyhedronData() # After setting up particles... num_particles = poly.getParNum() # Get particle count print(f"Particle count: {num_particles}")

getVertexNum(self: dem.rtdem.PolyhedronData) int

Get the number of vertices in the polyhedron model.

This method returns the total number of vertices in the polyhedron mesh.

Returns:

int: The number of vertices.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") num_verts = poly.getVertexNum() # Get vertex count print(f"Vertex count: {num_verts}")

property label

str: Label for this group of particles.

This property provides a descriptive label for the particle group, useful for identification and organization.

Example:

poly = dem.rtdem.PolyhedronData() poly.label = "sand_particles" # Set label for particle group label = poly.label

loadBox(self: dem.rtdem.PolyhedronData, arg0: SupportsFloat, arg1: SupportsFloat, arg2: SupportsFloat) None

Load an axis-aligned box with specified dimensions.

This method creates an axis-aligned box with the specified dimensions. The bottom-left corner is at the origin.

Args:

length_x (float): Length of the box in the X direction. length_y (float): Length of the box in the Y direction. length_z (float): Length of the box in the Z direction.

Example:

poly = dem.rtdem.PolyhedronData() # Create a box with dimensions 2x3x4 poly.loadBox(2.0, 3.0, 4.0)

loadObj(*args, **kwargs)

Overloaded function.

  1. loadObj(self: dem.rtdem.PolyhedronData, arg0: str) -> None

    Load a polyhedron from an OBJ file.

    This method loads a polyhedron mesh from an OBJ file.

    Args:

    objFile (str): Full path to the OBJ file.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadObj("model.obj") # Load mesh from OBJ file

  2. loadObj(self: dem.rtdem.PolyhedronData, arg0: str, arg1: typing.SupportsFloat) -> None

    Load a polyhedron from an OBJ file with scaling.

    This method loads a polyhedron mesh from an OBJ file and applies uniform scaling.

    Args:

    objFile (str): Full path to the OBJ file. scale (float): Scale factor to apply to the mesh.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadObj("model.obj", 2.0) # Load and scale mesh by 2x

  3. loadObj(self: dem.rtdem.PolyhedronData, arg0: str, arg1: typing.SupportsFloat, arg2: bool) -> None

    Load a polyhedron from an OBJ file with scaling and optional centering.

    This method loads a polyhedron mesh from an OBJ file, applies uniform scaling, and optionally shifts the mesh to center it at the origin.

    Args:

    objFile (str): Full path to the OBJ file. scale (float): Scale factor to apply to the mesh. shift (bool): Flag to advise if the mesh will be shifted to make its center at the coordinate origin.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadObj("model.obj", 2.0, True) # Load, scale by 2x, and center at origin

  4. loadObj(self: dem.rtdem.PolyhedronData, arg0: str, arg1: pySudoMath.Vector3f) -> None

    Load a polyhedron from an OBJ file with vector scaling.

    This method loads a polyhedron mesh from an OBJ file and applies non-uniform scaling in x, y, and z directions.

    Args:

    objFile (str): Full path to the OBJ file. scale (Vector3r): Scale vector that will scale the OBJ file in x, y and z directions.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadObj("model.obj", (2.0, 1.5, 1.0)) # Scale x by 2x, y by 1.5x, z by 1x

  5. loadObj(self: dem.rtdem.PolyhedronData, arg0: str, arg1: pySudoMath.Vector3f, arg2: bool) -> None

    Load a polyhedron from an OBJ file with vector scaling and optional centering.

    This method loads a polyhedron mesh from an OBJ file, applies non-uniform scaling, and optionally shifts the mesh to center it at the origin.

    Args:

    objFile (str): Full path to the OBJ file. scale (Vector3r): Scale vector that will scale the OBJ file in x, y and z directions. shift (bool): Flag to advise if the mesh will be shifted to make its center at the coordinate origin.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadObj("model.obj", (2.0, 1.5, 1.0), True) # Scale and center at origin

loadPlane(self: dem.rtdem.PolyhedronData, arg0: SupportsFloat, arg1: SupportsFloat, arg2: SupportsInt) None

Load a plane with specified size and orientation.

This method creates a plane with the specified dimensions and orientation.

Args:

length (float): Length of the plane. width (float): Width of the plane. axisAndDir (int): Direction of the plane (1: yz, 2: xz, 3: xy; negative for opposite direction).

Example:

poly = dem.rtdem.PolyhedronData() # Create an XY plane with dimensions 2x3 poly.loadPlane(2.0, 3.0, 3) # Create a YZ plane facing the negative X direction poly.loadPlane(2.0, 3.0, -1)

loadRectangle(self: dem.rtdem.PolyhedronData, arg0: Annotated[numpy.typing.ArrayLike, numpy.float32]) None

Load a rectangular plane from vertex coordinates.

This method loads a rectangular plane from an array of 4 vertex coordinates.

Args:

vdata (numpy.ndarray): Two-dimensional array of 4 vertex coordinates with shape (4, 3).

Example:

poly = dem.rtdem.PolyhedronData() import numpy as np # Define vertices for a rectangle in the XY plane verts = np.array([

[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]

], dtype=np.float32) poly.loadRectangle(verts) # Load rectangular plane

loadSTL(*args, **kwargs)

Overloaded function.

  1. loadSTL(self: dem.rtdem.PolyhedronData, arg0: str) -> None

    Load a polyhedron from an STL file.

    This method loads a polyhedron mesh from an STL file.

    Args:

    stlFile (str): Full path to the STL file.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadSTL("model.stl") # Load mesh from STL file

  2. loadSTL(self: dem.rtdem.PolyhedronData, arg0: str, arg1: typing.SupportsFloat) -> None

    Load a polyhedron from an STL file with scaling.

    This method loads a polyhedron mesh from an STL file and applies uniform scaling.

    Args:

    stlFile (str): Full path to the STL file. scale (float): Scale factor to apply to the mesh.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadSTL("model.stl", 2.0) # Load and scale mesh by 2x

  3. loadSTL(self: dem.rtdem.PolyhedronData, arg0: str, arg1: typing.SupportsFloat, arg2: bool) -> None

    Load a polyhedron from an STL file with scaling and optional centering.

    This method loads a polyhedron mesh from an STL file, applies uniform scaling, and optionally shifts the mesh to center it at the origin.

    Args:

    stlFile (str): Full path to the STL file. scale (float): Scale factor to apply to the mesh. shift (bool): Flag to advise if the mesh will be shifted to make its center at the coordinate origin.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadSTL("model.stl", 2.0, True) # Load, scale by 2x, and center at origin

  4. loadSTL(self: dem.rtdem.PolyhedronData, arg0: str, arg1: pySudoMath.Vector3f) -> None

    Load a polyhedron from an STL file with vector scaling.

    This method loads a polyhedron mesh from an STL file and applies non-uniform scaling in x, y, and z directions.

    Args:

    stlFile (str): Full path to the STL file. scale (Vector3r): Scale vector that will scale the STL file in x, y and z directions.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadSTL("model.stl", (2.0, 1.5, 1.0)) # Scale x by 2x, y by 1.5x, z by 1x

  5. loadSTL(self: dem.rtdem.PolyhedronData, arg0: str, arg1: pySudoMath.Vector3f, arg2: bool) -> None

    Load a polyhedron from an STL file with vector scaling and optional centering.

    This method loads a polyhedron mesh from an STL file, applies non-uniform scaling, and optionally shifts the mesh to center it at the origin.

    Args:

    stlFile (str): Full path to the STL file. scale (Vector3r): Scale vector that will scale the STL file in x, y and z directions. shift (bool): Flag to advise if the mesh will be shifted to make its center at the coordinate origin.

    Example:

    poly = dem.rtdem.PolyhedronData() poly.loadSTL("model.stl", (2.0, 1.5, 1.0), True) # Scale and center at origin

loadVertFacet(self: dem.rtdem.PolyhedronData, arg0: Annotated[numpy.typing.ArrayLike, numpy.float32], arg1: Annotated[numpy.typing.ArrayLike, numpy.int32]) None

Load polyhedron from vertex coordinates and facet indices.

This method loads a polyhedron mesh from arrays of vertex coordinates and facet indices.

Args:

vdata (numpy.ndarray): Two-dimensional array of vertex coordinates with shape (Nv, 3). fdata (numpy.ndarray): Two-dimensional array of facet indices with shape (Nf, 3).

Example:

poly = dem.rtdem.PolyhedronData() import numpy as np # Define vertices (4 vertices for a tetrahedron) verts = np.array([

[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]

], dtype=np.float32) # Define facets (4 triangular faces) facets = np.array([

[0, 1, 2], [0, 1, 3], [0, 2, 3], [1, 2, 3]

], dtype=np.int32) poly.loadVertFacet(verts, facets) # Load tetrahedron

property material

Material: The material properties for this polyhedron group.

This property defines the material properties used for all particles in this polyhedron group.

Example:

poly = dem.rtdem.PolyhedronData() material = dem.core.Material() material.density = 2650.0 poly.material = material # Set material for this group mat = poly.material # Get current material

setMovable(self: dem.rtdem.PolyhedronData, arg0: bool) None

Set whether the polyhedron group is movable or not.

This method determines whether particles in this polyhedron group are movable (True) or immovable (False, typically used for walls).

Args:

flag (bool): True if the object is movable, False otherwise.

Example:

poly = dem.rtdem.PolyhedronData() poly.setMovable(True) # Make particles movable poly.setMovable(False) # Make particles immovable (wall)

setPosOri(self: dem.rtdem.PolyhedronData, arg0: collections.abc.Sequence[pySudoMath.Vector3f], arg1: collections.abc.Sequence[pySudoMath.Quaternionr]) None

Set positions and orientations for all particles in the group.

This method sets the positions and orientations for all particles in the polyhedron group.

Args:

pos (list): List of Vector3r representing particle positions. ori (list): List of Quaternionr representing particle orientations.

Example:

poly = dem.rtdem.PolyhedronData() positions = [(0, 0, 0), (1, 0, 0), (2, 0, 0)] orientations = [(1, 0, 0, 0), (1, 0, 0, 0), (1, 0, 0, 0)] # Identity quaternions poly.setPosOri(positions, orientations)

setPosition(self: dem.rtdem.PolyhedronData, arg0: collections.abc.Sequence[pySudoMath.Vector3f]) None

Set positions for all particles in the group.

This method sets the positions for all particles in the polyhedron group.

Args:

pos (list): List of Vector3r representing particle positions.

Example:

poly = dem.rtdem.PolyhedronData() positions = [(0, 0, 0), (1, 0, 0), (2, 0, 0)] poly.setPosition(positions)

setRayPara(self: dem.rtdem.PolyhedronData, arg0: bool, arg1: SupportsFloat) None

Set ray tracing parameters for contact detection.

This method configures the ray tracing parameters used for contact detection between particles.

Args:

useBVH (bool): Flag to use BVH (different ray lengths). weight (float): Weight parameter for the ray length if using different lengths.

Example:

poly = dem.rtdem.PolyhedronData() poly.setRayPara(True, 0.7) # Use BVH with weight 0.7

setScaleFactors(self: dem.rtdem.PolyhedronData, arg0: Annotated[numpy.typing.ArrayLike, numpy.float32]) None

Set scale factors for each particle in the group.

This method sets individual scale factors for each particle in the group with respect to a reference particle.

Args:

data (numpy.ndarray): One-dimensional array of scale factors.

Example:

poly = dem.rtdem.PolyhedronData() import numpy as np scales = np.array([1.0, 1.2, 0.8, 1.1]) # Scale factors for 4 particles poly.setScaleFactors(scales)

verts(self: dem.rtdem.PolyhedronData) object

Get the vertices of the polyhedron model.

This method returns the coordinates of all vertices in the polyhedron model as a NumPy array.

Returns:

numpy.ndarray: A 2D array with shape (N, 3) where N is the number of vertices.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") vertices = poly.verts() # Get vertex coordinates print(f"Vertices shape: {vertices.shape}")

vertsId(self: dem.rtdem.PolyhedronData) object

Get the vertex indices of the polyhedron facets.

This method returns the vertex indices that define each triangular facet of the polyhedron as a NumPy array.

Returns:

numpy.ndarray: A 2D array with shape (N, 3) where N is the number of facets.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") indices = poly.vertsId() # Get facet vertex indices print(f"Indices shape: {indices.shape}")

vertsNormal(self: dem.rtdem.PolyhedronData) object

Get the normals for vertices of the polyhedron.

This method returns the normal vectors for each vertex of the polyhedron as a NumPy array.

Returns:

numpy.ndarray: A 2D array with shape (N, 3) where N is the number of vertices.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") normals = poly.vertsNormal() # Get vertex normals print(f"Normals shape: {normals.shape}")

property visible

bool: Visibility flag during rendering.

This property controls whether the polyhedron group is visible during rendering. Only applicable to non-movable objects.

Example:

poly = dem.rtdem.PolyhedronData() poly.setMovable(False) # Make it a wall poly.visible = True # Make wall visible during rendering visible = poly.visible

property writeVTKflag

bool: Flag to control VTK file output.

When True, this group of particles will be included in VTK files when DEMSim calls writeVTK.

Example:

poly = dem.rtdem.PolyhedronData() poly.writeVTKflag = True # Enable VTK output for this group flag = poly.writeVTKflag

write_stl(self: dem.rtdem.PolyhedronData) None

Write the normalized template mesh to an STL file.

This method writes the normalized template mesh to an STL file.

Example:

poly = dem.rtdem.PolyhedronData() poly.loadSTL("mesh.stl") poly.write_stl() # Write normalized mesh to STL file