Coverage for /dolfinx-env/lib/python3.14/site-packages/io4dolfinx/structures.py: 100%

74 statements  

« prev     ^ index     » next       coverage.py v7.18.0, created at 2026-11-30 11:58 +0000

1"""Internal library classes for storing mesh and function data""" 

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

3# 

4# This file is part of io4dolfinx 

5# 

6# SPDX-License-Identifier: MIT 

7 

8from __future__ import annotations 

9 

10from dataclasses import dataclass, field 

11from typing import Any 

12 

13import numpy as np 

14import numpy.typing as npt 

15from dolfinx.graph import AdjacencyList 

16 

17__all__ = ["MeshData", "FunctionData", "ReadMeshData", "ReadMixedMeshData", "MeshTagsData"] 

18 

19 

20@dataclass 

21class MeshData: 

22 """ 

23 Container for distributed mesh data that will be stored to disk 

24 """ 

25 

26 #: Two-dimensional array of node coordinates 

27 local_geometry: npt.NDArray[np.float32] | npt.NDArray[np.float64] 

28 local_geometry_pos: tuple[int, int] #: Insert range on current process for geometry nodes 

29 num_nodes_global: int #: Number of nodes in global geometry array 

30 

31 local_topology: npt.NDArray[np.int64] #: Two-dimensional connectivity array for mesh topology 

32 #: Insert range on current process for topology 

33 local_topology_pos: tuple[int, int] 

34 num_cells_global: int #: NUmber of cells in global topology 

35 

36 cell_type: str #: The cell type 

37 degree: int #: Degree of underlying Lagrange element 

38 lagrange_variant: int #: Lagrange-variant of DOFs 

39 

40 # Partitioning_information 

41 store_partition: bool #: Indicator if one should store mesh partitioning 

42 partition_processes: int | None = None #: Number of processes in partition 

43 ownership_array: npt.NDArray[np.int32] | None = None #: Ownership array for cells 

44 ownership_offset: npt.NDArray[np.int32] | None = None #: Ownership offset for cells 

45 partition_range: tuple[int, int] | None = ( 

46 None #: Local insert position for partitioning information 

47 ) 

48 partition_global: int | None = None #: Global size of partitioning array 

49 #: Metadata stored with the mesh when it is first written, see :mod:`io4dolfinx.format` 

50 metadata: dict[str, Any] = field(default_factory=dict) 

51 

52 

53@dataclass 

54class FunctionData: 

55 """ 

56 Container for distributed function data that will be written to file 

57 """ 

58 

59 cell_permutations: npt.NDArray[np.uint32] #: Cell permutations for dofmap 

60 local_cell_range: tuple[int, int] #: Range of cells on current process 

61 num_cells_global: int #: Number of cells in global topology 

62 dofmap_array: npt.NDArray[np.int64] #: Local function dofmap (using global indices) 

63 dofmap_offsets: npt.NDArray[np.int64] #: Global dofmap offsets 

64 dofmap_range: tuple[int, int] #: Range of dofmap on current process 

65 global_dofs_in_dofmap: int #: Number of entries in global dofmap 

66 values: npt.NDArray[np.floating] #: Local function values 

67 dof_range: tuple[int, int] #: Range of local function values 

68 num_dofs_global: int #: Number of global function values 

69 name: str #: Name of function 

70 #: Metadata stored with the function when it is first written, see :mod:`io4dolfinx.format` 

71 metadata: dict[str, Any] = field(default_factory=dict) 

72 

73 

74@dataclass 

75class ReadMeshData: 

76 """Container containing data that will be read into DOLFINx""" 

77 

78 #: Two-dimensional array containing global cell->node connectivity 

79 cells: npt.NDArray[np.int64] 

80 cell_type: str #: The cell type of the mesh 

81 x: npt.NDArray[np.floating] #: The mesh coordinates 

82 lvar: int #: The Lagrange variant 

83 degree: int #: The degree of the underlying Lagrange element 

84 #: Partitioning information per cell on the process 

85 partition_graph: AdjacencyList | None = None 

86 #: Geometry uses the degree 2 serendipity element with nodes at vertices and edge 

87 #: midpoints (8-node quadrilateral, 20-node hexahedron) instead of Lagrange 

88 serendipity: bool = False 

89 

90 

91@dataclass 

92class ReadMixedMeshData: 

93 """Container for a mesh with several cell types (mixed topology) read into DOLFINx""" 

94 

95 #: Global cell->node connectivity of each cell type, in DOLFINx node ordering, each 

96 #: of shape ``(num_cells, num_nodes_per_cell)`` 

97 cells: list[npt.NDArray[np.int64]] 

98 cell_types: list[str] #: The cell type of each entry in ``cells`` 

99 x: npt.NDArray[np.floating] #: The mesh coordinates 

100 lvar: int #: The Lagrange variant 

101 degree: int #: The degree of the underlying Lagrange elements 

102 

103 

104@dataclass 

105class MeshTagsData: 

106 name: str #: Name of tag 

107 values: npt.NDArray # Array of values 

108 indices: npt.NDArray[np.int64] # Global indices of the entities 

109 dim: int # Topological dimension of the entities 

110 

111 # Optional entries (used for writing to disk) 

112 num_entities_global: int | None = None #: Global number of entities that will be written out 

113 num_dofs_per_entity: int | None = None #: Number of dofs per entity 

114 #: Starting index in output array `(0<=local_start<num_entities_global)`` 

115 local_start: int | None = None 

116 

117 # Optional info to help visualization 

118 cell_type: str | None = None #: The cell type 

119 #: Metadata stored with the mesh tags when they are written, see :mod:`io4dolfinx.format` 

120 metadata: dict[str, Any] = field(default_factory=dict) 

121 

122 

123@dataclass 

124class ArrayData: 

125 name: str # Name of point data 

126 values: npt.NDArray # Array of values (num_entities, num_components) 

127 global_shape: tuple[int, int] # Global shape of data 

128 local_range: tuple[int, int] # Start and stop of local array in global array 

129 type: str # Type of array-data 

130 #: Value shape of the function the values come from (``()`` for a scalar), or ``None`` 

131 #: when unknown. Lets a backend lay out vectors and tensors for its file format. 

132 value_shape: tuple[int, ...] | None = None