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

Function stack

phi/field/_field_math.py:946–983  ·  view source on GitHub ↗

Stacks the given `Field`s along `dim`. See Also: `concat()`. Args: fields: List of matching `Field` instances. dim: Stack dimension as `Shape`. Size is ignored. dim_bounds: `Box` defining the physical size for `dim`. Returns: `Field` matchi

(fields: Sequence[Field], dim: Shape, dim_bounds: Box = None)

Source from the content-addressed store, hash-verified

944
945
946def stack(fields: Sequence[Field], dim: Shape, dim_bounds: Box = None):
947 """
948 Stacks the given `Field`s along `dim`.
949
950 See Also:
951 `concat()`.
952
953 Args:
954 fields: List of matching `Field` instances.
955 dim: Stack dimension as `Shape`. Size is ignored.
956 dim_bounds: `Box` defining the physical size for `dim`.
957
958 Returns:
959 `Field` matching stacked fields.
960 """
961 assert all(isinstance(f, Field) for f in fields), f"All fields must be Fields of the same type but got {fields}"
962 assert all(isinstance(f, type(fields[0])) for f in fields), f"All fields must be Fields of the same type but got {fields}"
963 if any([f.sampled_at != fields[0].sampled_at for f in fields]):
964 return math.layout(fields, dim)
965 if any(f.boundary != fields[0].boundary for f in fields):
966 boundary = math.stack([f.boundary for f in fields], dim)
967 else:
968 boundary = fields[0].boundary
969 if fields[0].is_grid:
970 values = math.stack([f.values for f in fields], dim)
971 if spatial(dim):
972 if dim_bounds is None:
973 dim_bounds = Box(**{dim.name: len(fields)})
974 return grid(values, boundary, fields[0].bounds * dim_bounds)
975 else:
976 return fields[0].with_values(values).with_boundary(boundary)
977 else:
978 values = math.stack([f.values for f in fields], dim)
979 geometry = fields[0].geometry if all(f.geometry == fields[0].geometry for f in fields) else math.stack([f.geometry for f in fields], dim, layout_non_matching=True)
980 if isinstance(geometry, Tensor):
981 from phi.geom._geom_ops import GeometryStack
982 geometry = GeometryStack(geometry)
983 return Field(geometry, values, boundary)
984
985
986def assert_close(*fields: Field or Tensor or Number,

Callers 15

plotFunction · 0.90
cornersMethod · 0.90
corner_radiiMethod · 0.90
_central_tangentsMethod · 0.90
_central_uv_extentMethod · 0.90
_surface_cornersMethod · 0.90
_closest_surfaceMethod · 0.90
rectifyFunction · 0.90
transform_with_splineFunction · 0.90
build_facesFunction · 0.90
build_quadrilateralsFunction · 0.90

Calls 7

BoxClass · 0.90
GeometryStackClass · 0.90
gridFunction · 0.85
FieldClass · 0.85
stackMethod · 0.80
with_boundaryMethod · 0.80
with_valuesMethod · 0.45

Tested by 7

test_reshapingMethod · 0.72
test_point_reshapingMethod · 0.72
test_batch_sliceMethod · 0.72
test_reshapeMethod · 0.72