Test that ('+') and ('-') match up with the correct DOFs for DG functions.
(cell_type, pm1, pm2, dtype)
| 399 | @parametrize_cell_types |
| 400 | @parametrize_dtypes |
| 401 | def test_plus_minus_vector(cell_type, pm1, pm2, dtype): |
| 402 | """Test that ('+') and ('-') match up with the correct DOFs for DG functions.""" |
| 403 | xtype = np.real(dtype(0)).dtype |
| 404 | results = [] |
| 405 | orders = [] |
| 406 | spaces = [] |
| 407 | for count in range(3): |
| 408 | for agree in [True, False]: |
| 409 | # Two cell mesh with randomly numbered points |
| 410 | mesh, order = two_unit_cells(cell_type, xtype, agree, return_order=True) |
| 411 | if cell_type in [CellType.interval, CellType.triangle, CellType.tetrahedron]: |
| 412 | V = functionspace(mesh, ("DG", 1)) |
| 413 | else: |
| 414 | V = functionspace(mesh, ("DQ", 1)) |
| 415 | |
| 416 | # Assemble vectors with combinations of + and - for a few |
| 417 | # different numberings |
| 418 | f = Function(V, dtype=dtype) |
| 419 | f.interpolate(lambda x: x[0] - 2 * x[1]) |
| 420 | v = ufl.TestFunction(V) |
| 421 | a = form(ufl.inner(f(pm1), v(pm2)) * ufl.dS, dtype=dtype) |
| 422 | result = assemble_vector(a) |
| 423 | spaces.append(V) |
| 424 | results.append(result.array) |
| 425 | orders.append(order) |
| 426 | |
| 427 | # Check that the above vectors all have the same values as the first |
| 428 | # one, but permuted due to differently ordered dofs |
| 429 | dofmap0 = spaces[0].mesh.geometry.dofmaps[0] |
| 430 | for result, space in zip(results[1:], spaces[1:]): |
| 431 | # Get the data relating to two results |
| 432 | dofmap1 = space.mesh.geometry.dofmaps[0] |
| 433 | |
| 434 | # For each cell |
| 435 | for cell in range(2): |
| 436 | # For each point in cell 0 in the first mesh |
| 437 | for dof0, point0 in zip(spaces[0].dofmap.cell_dofs(cell), dofmap0[cell]): |
| 438 | # Find the point in the cell 0 in the second mesh |
| 439 | for dof1, point1 in zip(space.dofmap.cell_dofs(cell), dofmap1[cell]): |
| 440 | if np.allclose( |
| 441 | spaces[0].mesh.geometry.x[point0], space.mesh.geometry.x[point1] |
| 442 | ): |
| 443 | break |
| 444 | else: |
| 445 | # If no matching point found, fail |
| 446 | assert False |
| 447 | |
| 448 | assert np.isclose(results[0][dof0], result[dof1], atol=1.0e-6) |
| 449 | |
| 450 | |
| 451 | @pytest.mark.skip_in_parallel |
nothing calls this directly
no test coverage detected