Coverage for /dolfinx-env/lib/python3.12/site-packages/io4dolfinx/snapshot.py: 93%
15 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-08 09:09 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-08 09:09 +0000
1# Copyright (C) 2024 Jørgen Schartum Dokken
2#
3# This file is part of io4dolfinx
4#
5# SPDX-License-Identifier: MIT
7import logging
8from pathlib import Path
9from typing import Any
11import dolfinx
13from .backends import FileMode, get_backend
15__all__ = [
16 "snapshot_checkpoint",
17]
18logger = logging.getLogger(__name__)
21def snapshot_checkpoint(
22 uh: dolfinx.fem.Function,
23 file: Path,
24 mode: FileMode,
25 backend_args: dict[str, Any] | None = None,
26 backend: str = "adios2",
27):
28 """Read or write a snapshot checkpoint
30 This checkpoint is only meant to be used on the same mesh during the same simulation.
32 :param uh: The function to write data from or read to
33 :param file: The file to write to or read from
34 :param mode: Either read or write
35 """
36 logger.debug(f"Performing snapshot checkpoint with mode {mode} on file {file}")
37 logger.debug(f"Using backend {backend} with arguments {backend_args}")
38 backend_cls = get_backend(backend)
39 default_args = backend_cls.get_default_backend_args(backend_args)
40 if mode not in [FileMode.write, FileMode.read]:
41 raise ValueError(f"Got invalid mode {mode}")
42 backend_cls.snapshot_checkpoint(file, mode, uh, default_args)