SPHEntity(光滑粒子流体动力学实体)#
- class genesis.engine.entities.sph_entity.SPHEntity(scene, solver, material, morph, surface, particle_size, idx, particle_start, name: str | None = None)[source]#
Bases:
ParticleEntitySPH-based particle entity.
- Parameters:
scene (Scene) – The simulation scene.
solver (Solver) – The solver handling the simulation logic.
material (Material) – Material properties (e.g., density, stiffness).
morph (Morph) – Morphological configuration.
surface (Surface) – Surface constraints or geometry.
particle_size (float) – The size of each particle.
idx (int) – Index of this entity in the scene.
particle_start (int) – Start index for the particles belonging to this entity.
- init_sampler()[source]#
Initialize the particle sampler based on the material’s sampling method.
- Raises:
GenesisException – If the sampler is not one of the supported types: ‘regular’, ‘pbs’, or ‘pbs-sdf_res’.
- add_grad_from_state(state)[source]#
Apply gradients from a given state.
- Parameters:
state (SPHEntityState) – The state from which to compute gradients.
- get_frame(f: <gstaichi._lib.core.gstaichi_python.DataTypeCxx object at 0x10917d0f0>, pos: NdarrayType(dtype=None, ndim=None, layout=Layout.AOS, needs_grad=None), vel: NdarrayType(dtype=None, ndim=None, layout=Layout.AOS, needs_grad=None))[source]#
Retrieve particle positions and velocities for the given frame.
- Parameters:
f (int) – Frame index.
pos (ndarray) – Output array for positions (n_envs, n_particles, 3).
vel (ndarray) – Output array for velocities (n_envs, n_particles, 3).
- get_state()[source]#
Get the current state of the SPHEntity including positions, velocities, .
- Returns:
state – The current particle state for the entity.
- Return type:
SPHEntityState
- set_particles_pos(poss, particles_idx_local=None, envs_idx=None)[source]#
Set the position of some particles.
- Parameters:
poss (torch.Tensor, shape (M, N, 3)) – Target position of each particle.
particles_idx_local (torch.Tensor, shape (M, N)) – Index of the particles relative to this entity. If None, all particles will be considered. Defaults to None.
envs_idx (torch.Tensor, shape (M,)) – The indices of the environments to set. If None, all environments will be considered. Defaults to None.
- get_particles_pos(envs_idx=None)[source]#
Retrieve current particle positions from the solver.
- Parameters:
envs_idx (None | int | array_like, shape (M,), optional) – The indices of the environments to set. If None, all environments will be considered. Defaults to None.
- Returns:
poss – Tensor of particle positions.
- Return type:
torch.Tensor, shape (M, n_particles, 3)
- set_particles_vel(vels, particles_idx_local=None, envs_idx=None)[source]#
Set the velocity of some particles.
- Parameters:
vels (torch.Tensor, shape (M, N, 3)) – Target velocity of each particle.
particles_idx_local (torch.Tensor, shape (M, N)) – Index of the particles relative to this entity. If None, all particles will be considered. Defaults to None.
envs_idx (torch.Tensor, shape (M,)) – The indices of the environments to set. If None, all environments will be considered. Defaults to None.
- get_particles_vel(envs_idx=None)[source]#
Retrieve current particle velocities from the solver.
- Parameters:
envs_idx (None | int | array_like, shape (M,), optional) – The indices of the environments to set. If None, all environments will be considered. Defaults to None.
- Returns:
poss – Tensor of particle velocities, shape (M, n_particles, 3).
- Return type:
torch.Tensor
- set_particles_active(actives, particles_idx_local=None, envs_idx=None)[source]#
Set the velocity of some particles.
- Parameters:
actives (torch.Tensor, shape (M, N, 3)) – Activeness boolean flags for each particle.
particles_idx_local (torch.Tensor, shape (M, N)) – Index of the particles relative to this entity. If None, all particles will be considered. Defaults to None.
envs_idx (torch.Tensor, shape (M,)) – The indices of the environments to set. If None, all environments will be considered. Defaults to None.
- get_particles_active(envs_idx=None)[source]#
Retrieve current particle activeness boolean flags from the solver.
- Parameters:
envs_idx (None | int | array_like, shape (M,), optional) – The indices of the environments to set. If None, all environments will be considered. Defaults to None.
- Returns:
poss – Tensor of particle activeness boolean flags.
- Return type:
torch.Tensor, shape (M, n_particles, 3)