-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_CreateConstantAttributePerRegion.py
More file actions
122 lines (117 loc) · 5.59 KB
/
test_CreateConstantAttributePerRegion.py
File metadata and controls
122 lines (117 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright 2023-2024 TotalEnergies.
# SPDX-FileContributor: Romain Baville
# SPDX-License-Identifier: Apache 2.0
# ruff: noqa: E402 # disable Module level import not at top of file
# mypy: disable-error-code="operator"
import pytest
from typing import Union, Any
from vtkmodules.vtkCommonDataModel import ( vtkDataSet, vtkMultiBlockDataSet )
from geos.mesh.processing.CreateConstantAttributePerRegion import CreateConstantAttributePerRegion, np
@pytest.mark.parametrize(
"meshType, newAttributeName, regionName, dictRegionValues, componentNames, componentNamesTest, valueNpType, succeed",
[
# Test the name of the new attribute (new on the mesh, one present on the other piece).
## For vtkDataSet.
( "dataset", "newAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32, True ),
( "dataset", "CellAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32, True ),
## For vtkMultiBlockDataSet.
( "multiblock", "newAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32, True ),
( "multiblock", "CellAttribute", "GLOBAL_IDS_POINTS", {}, (), (), np.float32, True ),
( "multiblock", "GLOBAL_IDS_CELLS", "GLOBAL_IDS_POINTS", {}, (), (), np.float32, True ),
# Test if the region attribute is on cells or on points.
( "dataset", "newAttribute", "FAULT", {}, (), (), np.float32, True ),
# Test the component name.
( "dataset", "newAttribute", "FAULT", {}, ( "X" ), (), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {}, (), ( "Component0", "Component1" ), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {}, ( "X" ), ( "Component0", "Component1" ), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {}, ( "X", "Y" ), ( "X", "Y" ), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {}, ( "X", "Y", "Z" ), ( "X", "Y" ), np.float32, True ),
# Test the type of value.
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int8, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int16, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int32, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.int64, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint8, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint16, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint32, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.uint64, True ),
( "dataset", "newAttribute", "FAULT", {}, (), (), np.float64, True ),
# Test index/value.
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ]
}, (), (), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ],
101: [ 2 ]
}, (), (), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ],
101: [ 2 ],
2: [ 3 ]
}, (), (), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ]
}, (), ( "Component0", "Component1" ), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ],
101: [ 2, 2 ]
}, (), ( "Component0", "Component1" ), np.float32, True ),
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ],
101: [ 2, 2 ],
2: [ 3, 3 ]
}, (), ( "Component0", "Component1" ), np.float32, True ),
# Test common error.
## Number of components.
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1, 1 ]
}, (), (), np.float32, False ), # Number of value inconsistent.
( "dataset", "newAttribute", "FAULT", {
0: [ 0, 0 ],
100: [ 1, 1 ]
}, (), (), np.float32, False ), # More values than components.
( "dataset", "newAttribute", "FAULT", {
0: [ 0 ],
100: [ 1 ]
}, ( "X", "Y" ), ( "X", "Y" ), np.float32, False ), # More components than value.
## Attribute name.
( "dataset", "PERM", "FAULT", {}, (), (), np.float32, False ), # The attribute name already exist.
## Region attribute.
( "dataset", "newAttribute", "PERM", {}, (),
(), np.float32, False ), # Region attribute has too many components.
( "multiblock", "newAttribute", "FAULT", {}, (), (), np.float32, False ), # Region attribute is partial.
] )
def test_CreateConstantAttributePerRegion(
dataSetTest: Union[ vtkMultiBlockDataSet, vtkDataSet ],
meshType: str,
newAttributeName: str,
regionName: str,
dictRegionValues: dict[ Any, Any ],
componentNames: tuple[ str, ...],
componentNamesTest: tuple[ str, ...],
valueNpType: int,
succeed: bool,
) -> None:
"""Test CreateConstantAttributePerRegion."""
mesh: Union[ vtkMultiBlockDataSet, vtkDataSet ] = dataSetTest( meshType )
nbComponents: int = len( componentNamesTest )
if nbComponents == 0: # If the attribute has one component, the component has no name.
nbComponents += 1
filter: CreateConstantAttributePerRegion = CreateConstantAttributePerRegion(
mesh,
regionName,
dictRegionValues,
newAttributeName,
valueNpType=valueNpType,
nbComponents=nbComponents,
componentNames=componentNames,
)
assert filter.applyFilter() == succeed