Interface to manage XDMF files.
| 140 | |
| 141 | |
| 142 | class XDMFFile(_cpp.io.XDMFFile): |
| 143 | """Interface to manage XDMF files.""" |
| 144 | |
| 145 | Encoding = _cpp.io.XDMFFile.Encoding |
| 146 | |
| 147 | def __enter__(self): |
| 148 | """Enter context manager.""" |
| 149 | return self |
| 150 | |
| 151 | def __exit__(self, exception_type, exception_value, traceback): |
| 152 | """Exit context manager and close file.""" |
| 153 | self.close() |
| 154 | |
| 155 | def write_mesh(self, mesh: Mesh, xpath: str = "/Xdmf/Domain") -> None: |
| 156 | """Write mesh to file.""" |
| 157 | super().write_mesh(mesh._cpp_object, xpath) |
| 158 | |
| 159 | def write_meshtags( |
| 160 | self, |
| 161 | tags: MeshTags, |
| 162 | x: Geometry, |
| 163 | geometry_xpath: str = "/Xdmf/Domain/Grid/Geometry", |
| 164 | xpath: str = "/Xdmf/Domain", |
| 165 | ) -> None: |
| 166 | """Write mesh tags to file.""" |
| 167 | super().write_meshtags(tags._cpp_object, x._cpp_object, geometry_xpath, xpath) |
| 168 | |
| 169 | def write_function( |
| 170 | self, u: Function, t: float = 0.0, mesh_xpath="/Xdmf/Domain/Grid[@GridType='Uniform'][1]" |
| 171 | ): |
| 172 | """Write function to file for a given time. |
| 173 | |
| 174 | Note: |
| 175 | Function is interpolated onto the mesh nodes, as a Nth order |
| 176 | Lagrange function, where N is the order of the coordinate |
| 177 | map. If the Function is a cell-wise constant, it is saved as |
| 178 | a cell-wise constant. |
| 179 | |
| 180 | Args: |
| 181 | u: Function to write to file. |
| 182 | t: Time associated with Function output. |
| 183 | mesh_xpath: Path to mesh associated with the Function in the |
| 184 | XDMFFile. |
| 185 | """ |
| 186 | super().write_function(getattr(u, "_cpp_object", u), t, mesh_xpath) |
| 187 | |
| 188 | def read_mesh( |
| 189 | self, |
| 190 | ghost_mode=GhostMode.shared_facet, |
| 191 | name="mesh", |
| 192 | xpath="/Xdmf/Domain", |
| 193 | max_facet_to_cell_links: int = 2, |
| 194 | ) -> Mesh: |
| 195 | """Read mesh data from file. |
| 196 | |
| 197 | Note: |
| 198 | Changing `max_facet_to_cell_links` from the default value |
| 199 | should only be required when working on branching manifolds. |
no outgoing calls