MCPcopy
hub / github.com/tum-pbs/PhiFlow / _distribute_points

Function _distribute_points

phi/physics/_boundaries.py:348–368  ·  view source on GitHub ↗

Generates points (either uniformly distributed or at the cell centers) according to the given tensor mask. Args: mask: Tensor with nonzero values at the indices where particles should get generated. points_per_cell: Number of particles to generate at each marked index

(mask: math.Tensor, points_per_cell: int = 1, center: bool = False)

Source from the content-addressed store, hash-verified

346
347
348def _distribute_points(mask: math.Tensor, points_per_cell: int = 1, center: bool = False) -> math.Tensor:
349 """
350 Generates points (either uniformly distributed or at the cell centers) according to the given tensor mask.
351
352 Args:
353 mask: Tensor with nonzero values at the indices where particles should get generated.
354 points_per_cell: Number of particles to generate at each marked index
355 center: Set points to cell centers. If False, points will be distributed using a uniform
356 distribution within each cell.
357
358 Returns:
359 A tensor containing the positions of the generated points.
360 """
361 indices = math.to_float(math.nonzero(mask, list_dim=instance('points')))
362 temp = []
363 for _ in range(points_per_cell):
364 if center:
365 temp.append(indices + 0.5)
366 else:
367 temp.append(indices + (math.random_uniform(indices.shape)))
368 return math.concat(temp, dim=instance('points'))

Callers 1

distribute_pointsMethod · 0.70

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected