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

Function test_basic_assembly_constant

python/test/unit/fem/test_assembler.py:1457–1489  ·  view source on GitHub ↗

Tests assembly with Constant. The following test should be sensitive to order of flattening the matrix-valued constant.

(mode, dtype)

Source from the content-addressed store, hash-verified

1455@pytest.mark.parametrize("mode", [GhostMode.none, GhostMode.shared_facet])
1456@dtype_parametrize
1457def test_basic_assembly_constant(mode, dtype):
1458 """Tests assembly with Constant.
1459
1460 The following test should be sensitive to order of flattening the
1461 matrix-valued constant.
1462 """
1463 xtype = dtype(0).real.dtype
1464 mesh = create_unit_square(MPI.COMM_WORLD, 5, 5, ghost_mode=mode, dtype=xtype)
1465 V = functionspace(mesh, ("Lagrange", 1))
1466 u, v = ufl.TrialFunction(V), ufl.TestFunction(V)
1467
1468 c = Constant(mesh, np.array([[1.0, 2.0], [5.0, 3.0]], dtype=dtype))
1469
1470 a = inner(c[1, 0] * u, v) * dx + inner(c[1, 0] * u, v) * ds
1471 L = inner(c[1, 0], v) * dx + inner(c[1, 0], v) * ds
1472 a, L = form(a, dtype=dtype), form(L, dtype=dtype)
1473
1474 # Initial assembly
1475 A1 = assemble_matrix(a)
1476 A1.scatter_reverse()
1477
1478 b1 = assemble_vector(L)
1479 b1.scatter_reverse(la.InsertMode.add)
1480
1481 c.value = [[1.0, 2.0], [3.0, 4.0]]
1482
1483 A2 = assemble_matrix(a)
1484 A2.scatter_reverse()
1485 assert np.linalg.norm(A1.data * 3.0 - A2.data * 5.0) == pytest.approx(0.0, abs=1.0e-5)
1486
1487 b2 = assemble_vector(L)
1488 b2.scatter_reverse(la.InsertMode.add)
1489 assert np.linalg.norm(b1.array * 3.0 - b2.array * 5.0) == pytest.approx(0.0, abs=1.0e-5)
1490
1491
1492def test_lambda_assembler():

Callers

nothing calls this directly

Calls 9

create_unit_squareFunction · 0.90
functionspaceFunction · 0.90
ConstantClass · 0.90
formFunction · 0.90
assemble_matrixFunction · 0.90
assemble_vectorFunction · 0.90
normMethod · 0.80
arrayMethod · 0.45
scatter_reverseMethod · 0.45

Tested by

no test coverage detected