|
39 | 39 | from pyop2 import op2
|
40 | 40 | from pyop2.exceptions import MapValueError, ModeValueError
|
41 | 41 | from pyop2.mpi import COMM_WORLD
|
| 42 | +from pyop2.datatypes import IntType |
42 | 43 |
|
43 | 44 | from petsc4py.PETSc import ScalarType
|
44 | 45 |
|
@@ -941,6 +942,45 @@ def test_assemble_mixed_rhs_vector(self, mset, mmap, mvdat):
|
941 | 942 | assert_allclose(dat[1].data_ro, exp, eps)
|
942 | 943 |
|
943 | 944 |
|
| 945 | +def test_matrices_sparsity_blockwise_specification(): |
| 946 | + # |
| 947 | + # 0 1 2 3 nodesetA |
| 948 | + # x----x----x----x |
| 949 | + # 0 1 2 setA |
| 950 | + # |
| 951 | + # 0 1 2 nodesetB |
| 952 | + # x----x----x |
| 953 | + # 0 1 setB |
| 954 | + # |
| 955 | + # 0 1 2 3 | 0 1 2 |
| 956 | + # 0 x | |
| 957 | + # 1 x | x x |
| 958 | + # 2 x | x x x |
| 959 | + # 3 x | x x sparsity |
| 960 | + # ----------+------ |
| 961 | + # 0 x x | x |
| 962 | + # 1 x x x | x |
| 963 | + # 2 x x | x |
| 964 | + # |
| 965 | + arity = 2 |
| 966 | + setA = op2.Set(3) |
| 967 | + nodesetA = op2.Set(4) |
| 968 | + setB = op2.Set(2) |
| 969 | + nodesetB = op2.Set(3) |
| 970 | + nodesetAB = op2.MixedSet((nodesetA, nodesetB)) |
| 971 | + datasetAB = nodesetAB ** 1 |
| 972 | + mapA = op2.Map(setA, nodesetA, arity, values=[[0, 1], [1, 2], [2, 3]]) |
| 973 | + mapB = op2.Map(setB, nodesetB, arity, values=[[0, 1], [1, 2]]) |
| 974 | + mapBA = op2.Map(setB, setA, 1, values=[1, 2]) |
| 975 | + mapAB = op2.Map(setA, setB, 1, values=[-1, 0, 1]) # "inverse" map |
| 976 | + s = op2.Sparsity((datasetAB, datasetAB), {(1, 0): [(mapB, op2.ComposedMap(mapA, mapBA), None)], |
| 977 | + (0, 1): [(mapA, op2.ComposedMap(mapB, mapAB), None)]}) |
| 978 | + assert np.all(s._blocks[0][0].nnz == np.array([1, 1, 1, 1], dtype=IntType)) |
| 979 | + assert np.all(s._blocks[0][1].nnz == np.array([0, 2, 3, 2], dtype=IntType)) |
| 980 | + assert np.all(s._blocks[1][0].nnz == np.array([2, 3, 2], dtype=IntType)) |
| 981 | + assert np.all(s._blocks[1][1].nnz == np.array([1, 1, 1], dtype=IntType)) |
| 982 | + |
| 983 | + |
944 | 984 | if __name__ == '__main__':
|
945 | 985 | import os
|
946 | 986 | pytest.main(os.path.abspath(__file__))
|
0 commit comments