Manufactured Poisson and screened problem with exact solution u = x[1]**3.
(dtype)
| 26 | @pytest.mark.parametrize("dtype", [np.float32, np.float64, np.complex128]) |
| 27 | @pytest.mark.skipif(not dolfinx.has_superlu_dist, reason="No SuperLU_DIST") |
| 28 | def test_superlu_problem(dtype): |
| 29 | """Manufactured Poisson and screened problem with exact solution u = x[1]**3.""" |
| 30 | from dolfinx.fem.problems import LinearProblem |
| 31 | |
| 32 | mesh_dtype = dtype().real.dtype |
| 33 | mesh = create_unit_square(MPI.COMM_WORLD, 5, 5, dtype=mesh_dtype) |
| 34 | V = functionspace(mesh, ("Lagrange", 4)) |
| 35 | u, v = TrialFunction(V), TestFunction(V) |
| 36 | |
| 37 | a = inner(grad(u), grad(v)) * dx |
| 38 | |
| 39 | # Exact solution |
| 40 | def u_ex(x): |
| 41 | return x[1] ** 3 |
| 42 | |
| 43 | x = SpatialCoordinate(mesh) |
| 44 | f = -div(grad(u_ex(x))) |
| 45 | L = inner(f, v) * dx |
| 46 | |
| 47 | u_bc = Function(V, dtype=dtype) |
| 48 | u_bc.interpolate(u_ex) |
| 49 | |
| 50 | # Create Dirichlet boundary condition |
| 51 | facetdim = mesh.topology.dim - 1 |
| 52 | mesh.topology.create_connectivity(facetdim, mesh.topology.dim) |
| 53 | bndry_facets = exterior_facet_indices(mesh.topology) |
| 54 | bdofs = locate_dofs_topological(V, facetdim, bndry_facets) |
| 55 | bc = dirichletbc(u_bc, bdofs) |
| 56 | |
| 57 | def check_error(u_ex, uh): |
| 58 | M = (u_ex(x) - uh) ** 2 * dx |
| 59 | M = form(M, dtype=dtype) |
| 60 | error = mesh.comm.allreduce(assemble_scalar(M), op=MPI.SUM) |
| 61 | eps = np.sqrt(np.finfo(dtype).eps) |
| 62 | assert np.isclose(error, 0.0, atol=eps) |
| 63 | |
| 64 | problem = LinearProblem(a, L, [bc], dtype=dtype, superlu_dist_options={"SymmetricMode": "YES"}) |
| 65 | uh = problem.solve() |
| 66 | |
| 67 | check_error(u_ex, uh) |
| 68 | |
| 69 | # Second solve |
| 70 | uh = problem.solve() |
| 71 | check_error(u_ex, uh) |
| 72 | |
| 73 | |
| 74 | @pytest.mark.skipif(not dolfinx.has_superlu_dist, reason="No SuperLU_DIST") |
nothing calls this directly
no test coverage detected