Bases: AbsoluteObjectState
, LinkBasedStateMixin
Source code in object_states/fluid_sink.py
| class FluidSink(AbsoluteObjectState, LinkBasedStateMixin):
def __init__(self, obj, max_distance=m.MAX_SINK_DISTANCE):
super().__init__(obj)
# Store internal values
self.max_sink_distance = m.MAX_SINK_DISTANCE
@property
def fluid_system(self):
"""
Returns:
FluidSystem: Fluid system to use to generate / handle fluid particles
"""
raise NotImplementedError
@staticmethod
def get_state_link_name():
# Should be implemented by subclass
raise NotImplementedError
def _initialize(self):
super()._initialize()
self.initialize_link_mixin()
def _update(self):
fluid_sink_position = self.get_link_position()
if fluid_sink_position is None:
# Terminate early, this is a "dead" fluid sink
return
# We iterate over all active fluid groups in this sink's corresponding fluid system,
# and check to see if the group matches both the (a) distance and (b) fraction criteria in
# order to "sink" (delete) it
names_to_remove = []
for name, inst in self.fluid_system.particle_instancers.items():
# Grab particle positions, shape (N, 3)
particle_pos = inst.particle_positions
# Get distances and check fraction simultaneously
frac_in_sink = (np.linalg.norm(particle_pos - fluid_sink_position.reshape(1, 3), axis=-1) < self.max_sink_distance).mean()
if frac_in_sink >= m.MIN_GROUP_FRACTION:
names_to_remove.append(name)
# Delete all recorded groups
for name in names_to_remove:
self.fluid_system.remove_particle_instancer(name)
def _set_value(self, new_value):
raise ValueError("set_value not supported for FluidSink.")
def _get_value(self):
pass
@staticmethod
def get_optional_dependencies():
return []
@staticmethod
def get_dependencies():
return []
|
fluid_system
property
Returns:
Name | Type |
Description |
FluidSystem |
|
Fluid system to use to generate / handle fluid particles |