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

Method with_boundary

phi/field/_field.py:451–472  ·  view source on GitHub ↗

Returns a copy of this field with the `boundary` replaced.

(self, boundary)

Source from the content-addressed store, hash-verified

449 return Field(self.geometry, values, self.boundary)
450
451 def with_boundary(self, boundary):
452 """ Returns a copy of this field with the `boundary` replaced. """
453 boundary = as_boundary(boundary, self.geometry)
454 boundary_elements = 'boundary_faces' if self.is_staggered else 'boundary_elements'
455 old_determined_slices = {k: s for k, s in getattr(self.geometry, boundary_elements).items() if self.boundary.determines_boundary_values(k)}
456 new_determined_slices = {k: s for k, s in getattr(self.geometry, boundary_elements).items() if boundary.determines_boundary_values(k)}
457 if old_determined_slices.values() == new_determined_slices.values():
458 return Field(self.geometry, self.values, boundary) # ToDo unnecessary once the rest is implemented
459 to_add = {k: sl for k, sl in old_determined_slices.items() if sl not in new_determined_slices.values()}
460 to_remove = [sl for sl in new_determined_slices.values() if sl not in old_determined_slices.values()]
461 values = math.slice_off(self.values, *to_remove)
462 if to_add:
463 if self.is_mesh:
464 values = self.mesh.pad_boundary(values, to_add, self.boundary)
465 elif self.is_grid and self.is_staggered:
466 values = self.values.vector.dual.as_channel()
467 to_add = {k: {'vector' if dim == '~vector' else dim: v for dim, v in sl.items()} for k, sl in to_add.items()}
468 values = math.pad(values, list(to_add.values()), self.boundary, bounds=self.bounds)
469 values = values.vector.as_dual()
470 else:
471 values = math.pad(values, list(to_add.values()), self.boundary, bounds=self.bounds)
472 return Field(self.geometry, values, boundary)
473
474 with_extrapolation = with_boundary
475

Callers 5

sampleFunction · 0.95
masked_laplaceFunction · 0.80
curlFunction · 0.80
downsample2xFunction · 0.80
stackFunction · 0.80

Calls 6

as_boundaryFunction · 0.85
FieldClass · 0.85
valuesMethod · 0.80
pad_boundaryMethod · 0.80
padMethod · 0.80

Tested by

no test coverage detected