Coverage for  / dolfinx-env / lib / python3.12 / site-packages / io4dolfinx / snapshot.py: 91%

11 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-02-26 18:16 +0000

1# Copyright (C) 2024 Jørgen Schartum Dokken 

2# 

3# This file is part of io4dolfinx 

4# 

5# SPDX-License-Identifier: MIT 

6 

7from pathlib import Path 

8from typing import Any 

9 

10import dolfinx 

11 

12from .backends import FileMode, get_backend 

13 

14__all__ = [ 

15 "snapshot_checkpoint", 

16] 

17 

18 

19def snapshot_checkpoint( 

20 uh: dolfinx.fem.Function, 

21 file: Path, 

22 mode: FileMode, 

23 backend_args: dict[str, Any] | None = None, 

24 backend: str = "adios2", 

25): 

26 """Read or write a snapshot checkpoint 

27 

28 This checkpoint is only meant to be used on the same mesh during the same simulation. 

29 

30 :param uh: The function to write data from or read to 

31 :param file: The file to write to or read from 

32 :param mode: Either read or write 

33 """ 

34 

35 backend_cls = get_backend(backend) 

36 default_args = backend_cls.get_default_backend_args(backend_args) 

37 if mode not in [FileMode.write, FileMode.read]: 

38 raise ValueError(f"Got invalid mode {mode}") 

39 backend_cls.snapshot_checkpoint(file, mode, uh, default_args)