A `Field` represents a discretized physical quantity (like temperature field or velocity field). The sample points and their relation are encoded in the `geometry` property and the corresponding values are stored as one `Tensor` in `values`. The boundary conditions and values outside th
| 49 | @sliceable |
| 50 | @dataclass(frozen=True) |
| 51 | class Field(metaclass=_FieldType): |
| 52 | """ |
| 53 | A `Field` represents a discretized physical quantity (like temperature field or velocity field). |
| 54 | The sample points and their relation are encoded in the `geometry` property and the corresponding values are stored as one `Tensor` in `values`. |
| 55 | The boundary conditions and values outside the geometry are determined by `boundary`. |
| 56 | |
| 57 | Examples: |
| 58 | Create a periodic 2D grid, initialized via noise fluctuations. |
| 59 | >>> Field(UniformGrid(x=32, y=32), values=Noise(), boundary=PERIODIC) |
| 60 | |
| 61 | Create a field on an unstructured mesh loaded from a .gmsh file |
| 62 | >>> mesh = phi.geom.load_gmsh('cylinder.msh', ('y-', 'x+', 'y+', 'x-', 'cyl+', 'cyl-')) |
| 63 | >>> Field(mesh, values=vec(x=1, y=0), boundary={'x': ZERO_GRADIENT, 'y': 0, 'cyl': 0}) |
| 64 | |
| 65 | Create two cubes and compute a scalar values for each. |
| 66 | >>> Field(Cuboid(vec(x=[0, 2], y=0), x=1, y=1), values=lambda x,y: x) |
| 67 | |
| 68 | See the `phi.field` module documentation at https://tum-pbs.github.io/PhiFlow/Fields.html |
| 69 | """ |
| 70 | |
| 71 | geometry: Geometry |
| 72 | """ Discretization `Geometry`. This determines where in space the `values` are sampled as well as their relationship and interpretation. """ |
| 73 | values: Tensor |
| 74 | """ The sampled values, matching some point set of `geometry`, e.g. center points, see `Geometry.sets`.""" |
| 75 | boundary: Extrapolation = 0. |
| 76 | """ Boundary conditions describe the values outside of `geometry` and are used by numerical solvers to compute edge values. """ |
| 77 | |
| 78 | variable_attrs: Tuple[str, ...] = ('values',) |
| 79 | """ Which of the three attributes (geometry,values,boundary) should be traced / optimized. See `phiml.math.magic.PhiTreeNode.__variable_attrs__`""" |
| 80 | value_attrs: Tuple[str, ...] = ('values',) |
| 81 | """ Which of the three attributes (geometry,values,boundary) are considered values. See `phiml.math.magic.PhiTreeNode.__value_attrs__`""" |
| 82 | |
| 83 | def __post_init__(self): |
| 84 | math.merge_shapes(self.values, non_batch(self.sampled_elements).non_channel) # shape check |
| 85 | |
| 86 | @property |
| 87 | def grid(self) -> UniformGrid: |
| 88 | """Cast `self.geometry` to a `phi.geom.UniformGrid`.""" |
| 89 | assert isinstance(self.geometry, UniformGrid), f"Geometry is not a UniformGrid but {type(self.geometry)}" |
| 90 | return self.geometry |
| 91 | |
| 92 | @property |
| 93 | def mesh(self) -> Mesh: |
| 94 | """Cast `self.geometry` to a `phi.geom.Mesh`.""" |
| 95 | assert isinstance(self.geometry, Mesh), f"Geometry is not a mesh but {type(self.geometry)}" |
| 96 | return self.geometry |
| 97 | |
| 98 | @property |
| 99 | def graph(self) -> Graph: |
| 100 | """Cast `self.geometry` to a `phi.geom.Graph`.""" |
| 101 | assert isinstance(self.geometry, Graph), f"Geometry is not a mesh but {type(self.geometry)}" |
| 102 | return self.geometry |
| 103 | |
| 104 | @property |
| 105 | def faces(self): |
| 106 | return get_faces(self.geometry, self.boundary) |
| 107 | |
| 108 | @property |
no outgoing calls