Returns a copy of this field with the `boundary` replaced.
(self, boundary)
| 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 |
no test coverage detected