(mode, dtype)
| 121 | @pytest.mark.parametrize("mode", [GhostMode.none, GhostMode.shared_facet]) |
| 122 | @dtype_parametrize |
| 123 | def test_basic_assembly(mode, dtype): |
| 124 | mesh = create_unit_square(MPI.COMM_WORLD, 12, 12, ghost_mode=mode, dtype=dtype(0).real.dtype) |
| 125 | V = functionspace(mesh, ("Lagrange", 1)) |
| 126 | u, v = ufl.TrialFunction(V), ufl.TestFunction(V) |
| 127 | |
| 128 | f = Function(V, dtype=dtype) |
| 129 | f.x.array[:] = 10.0 |
| 130 | a = inner(f * u, v) * dx + inner(u, v) * ds |
| 131 | L = inner(f, v) * dx + inner(2.0, v) * ds |
| 132 | a, L = form(a, dtype=dtype), form(L, dtype=dtype) |
| 133 | |
| 134 | # Initial assembly |
| 135 | A = assemble_matrix(a) |
| 136 | A.scatter_reverse() |
| 137 | assert isinstance(A, la.MatrixCSR) |
| 138 | b = assemble_vector(L) |
| 139 | b.scatter_reverse(la.InsertMode.add) |
| 140 | assert isinstance(b, la.Vector) |
| 141 | |
| 142 | # Second assembly |
| 143 | normA = A.squared_norm() |
| 144 | A.set_value(0) |
| 145 | A = assemble_matrix(A, a) |
| 146 | A.scatter_reverse() |
| 147 | assert isinstance(A, la.MatrixCSR) |
| 148 | assert normA == pytest.approx(A.squared_norm()) |
| 149 | normb = la.norm(b) |
| 150 | b.array[:] = 0 |
| 151 | assemble_vector(b.array, L) |
| 152 | b.scatter_reverse(la.InsertMode.add) |
| 153 | assert normb == pytest.approx(la.norm(b)) |
| 154 | |
| 155 | # Vector re-assembly - no zeroing (but need to zero ghost entries) |
| 156 | b.array[b.index_map.size_local * b.block_size :] = 0 |
| 157 | assemble_vector(b.array, L) |
| 158 | b.scatter_reverse(la.InsertMode.add) |
| 159 | assert 2 * normb == pytest.approx(la.norm(b)) |
| 160 | |
| 161 | # Matrix re-assembly (no zeroing) |
| 162 | assemble_matrix(A, a) |
| 163 | A.scatter_reverse() |
| 164 | assert 4 * normA == pytest.approx(A.squared_norm()) |
| 165 | |
| 166 | |
| 167 | def nest_matrix_norm(A): |
nothing calls this directly
no test coverage detected