MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / test_basic_assembly

Function test_basic_assembly

python/test/unit/fem/test_assembler.py:123–164  ·  view source on GitHub ↗
(mode, dtype)

Source from the content-addressed store, hash-verified

121@pytest.mark.parametrize("mode", [GhostMode.none, GhostMode.shared_facet])
122@dtype_parametrize
123def 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
167def nest_matrix_norm(A):

Callers

nothing calls this directly

Calls 10

create_unit_squareFunction · 0.90
functionspaceFunction · 0.90
FunctionClass · 0.90
formFunction · 0.90
assemble_matrixFunction · 0.90
assemble_vectorFunction · 0.90
set_valueMethod · 0.80
normMethod · 0.80
scatter_reverseMethod · 0.45
squared_normMethod · 0.45

Tested by

no test coverage detected