diff --git a/firedrake/mg/mesh.py b/firedrake/mg/mesh.py index 48ea376481..327e6ecae4 100644 --- a/firedrake/mg/mesh.py +++ b/firedrake/mg/mesh.py @@ -90,34 +90,37 @@ def MeshHierarchy(mesh, refinement_levels, mesh_builder=firedrake.Mesh): """Build a hierarchy of meshes by uniformly refining a coarse mesh. - mesh: :func:`~.Mesh` + Parameters + ---------- + mesh : ``Mesh`` the coarse mesh to refine - :arg refinement_levels : int + refinement_levels : int the number of levels of refinement - :arg refinements_per_level : int - the number of refinements for each - level in the hierarchy. - :arg degree : int + refinements_per_level : int + the number of refinements for each level in the hierarchy. + degree : int the degree of the finite element space used for isoparametric representation of the geometry. Only relevant if mesh is a Netgen mesh. - :arg distribution_parameters : dict - options controlling mesh distribution, see :func:`~.Mesh` + distribution_parameters : dict + options controlling mesh distribution, see ``Mesh`` for details. If ``None``, use the same distribution parameters as were used to distribute the coarse mesh, otherwise, these options override the default. - :arg reorder : bool + reorder : bool optional flag indicating whether to reorder the refined meshes. - :arg callbacks: tuple + callbacks : tuple A 2-tuple of callbacks to call before and after refinement of the DM. The before callback receives the DM to be refined (and the current level), the after callback receives the refined DM (and the current level). - :arg mesh_builder: function + mesh_builder : function Function to turn a DM into a ``Mesh``. Used by pyadjoint. - :returns: a :class:`HierarchyBase` object representing the - mesh hierarchy. + Returns + ------- + A :py:class:`~.HierarchyBase` object representing the + mesh hierarchy. """ if netgen and hasattr(mesh, 'netgen_mesh'): try: diff --git a/tests/regression/test_netgen.py b/tests/regression/test_netgen.py index aa8856115a..2e121628f2 100644 --- a/tests/regression/test_netgen.py +++ b/tests/regression/test_netgen.py @@ -1,6 +1,5 @@ from firedrake import * import numpy as np -import gc from petsc4py import PETSc import pytest @@ -252,28 +251,24 @@ def solve_poisson(mesh): solve(F == 0, uh, bc) return uh - def estimate_error(mesh, uh): W = FunctionSpace(mesh, "DG", 0) eta_sq = Function(W) w = TestFunction(W) f = Constant(1) - h = CellDiameter(mesh) + h = CellDiameter(mesh) n = FacetNormal(mesh) v = CellVolume(mesh) # Compute error indicator cellwise - G = ( - inner(eta_sq / v, w)*dx - - inner(h**2 * (f + div(grad(uh)))**2, w) * dx - - inner(h('+')/2 * jump(grad(uh), n)**2, w('+')) * dS - ) + G = inner(eta_sq / v, w)*dx + G = G - inner(h**2 * (f + div(grad(uh)))**2, w) * dx + G = G - inner(h('+')/2 * jump(grad(uh), n)**2, w('+')) * dS # Each cell is an independent 1x1 solve, so Jacobi is exact sp = {"mat_type": "matfree", "ksp_type": "richardson", - "pc_type": "jacobi" - } + "pc_type": "jacobi"} solve(G == 0, eta_sq, solver_parameters=sp) eta = Function(W) eta.interpolate(sqrt(eta_sq)) # the above computed eta^2 @@ -282,7 +277,6 @@ def estimate_error(mesh, uh): error_est = sqrt(eta_.dot(eta_)) return (eta, error_est) - def adapt(mesh, eta): W = FunctionSpace(mesh, "DG", 0) markers = Function(W) @@ -296,9 +290,8 @@ def adapt(mesh, eta): refined_mesh = mesh.refine_marked_elements(markers) return refined_mesh - - rect1 = WorkPlane(Axes((0,0,0), n=Z, h=X)).Rectangle(1,2).Face() - rect2 = WorkPlane(Axes((0,1,0), n=Z, h=X)).Rectangle(2,1).Face() + rect1 = WorkPlane(Axes((0, 0, 0), n=Z, h=X)).Rectangle(1, 2).Face() + rect2 = WorkPlane(Axes((0, 1, 0), n=Z, h=X)).Rectangle(2, 1).Face() L = rect1 + rect2 geo = OCCGeometry(L, dim=2) @@ -334,28 +327,24 @@ def solve_poisson(mesh): solve(F == 0, uh, bc) return uh - def estimate_error(mesh, uh): W = FunctionSpace(mesh, "DG", 0) eta_sq = Function(W) w = TestFunction(W) f = Constant(1) - h = CellDiameter(mesh) + h = CellDiameter(mesh) n = FacetNormal(mesh) v = CellVolume(mesh) # Compute error indicator cellwise - G = ( - inner(eta_sq / v, w)*dx - - inner(h**2 * (f + div(grad(uh)))**2, w) * dx - - inner(h('+')/2 * jump(grad(uh), n)**2, w('+')) * dS - ) + G = inner(eta_sq / v, w)*dx + G = G - inner(h**2 * (f + div(grad(uh)))**2, w) * dx + G = G - inner(h('+')/2 * jump(grad(uh), n)**2, w('+')) * dS # Each cell is an independent 1x1 solve, so Jacobi is exact sp = {"mat_type": "matfree", "ksp_type": "richardson", - "pc_type": "jacobi" - } + "pc_type": "jacobi"} solve(G == 0, eta_sq, solver_parameters=sp) eta = Function(W) eta.interpolate(sqrt(eta_sq)) # the above computed eta^2 @@ -364,7 +353,6 @@ def estimate_error(mesh, uh): error_est = sqrt(eta_.dot(eta_)) return (eta, error_est) - def adapt(mesh, eta): W = FunctionSpace(mesh, "DG", 0) markers = Function(W) @@ -378,9 +366,8 @@ def adapt(mesh, eta): refined_mesh = mesh.refine_marked_elements(markers) return refined_mesh - - rect1 = WorkPlane(Axes((0,0,0), n=Z, h=X)).Rectangle(1,2).Face() - rect2 = WorkPlane(Axes((0,1,0), n=Z, h=X)).Rectangle(2,1).Face() + rect1 = WorkPlane(Axes((0, 0, 0), n=Z, h=X)).Rectangle(1, 2).Face() + rect2 = WorkPlane(Axes((0, 1, 0), n=Z, h=X)).Rectangle(2, 1).Face() L = rect1 + rect2 geo = OCCGeometry(L, dim=2) @@ -396,4 +383,4 @@ def adapt(mesh, eta): error_estimators.append(error_est) dofs.append(uh.function_space().dim()) mesh = adapt(mesh, eta) - assert error_estimators[-1] < 0.05 \ No newline at end of file + assert error_estimators[-1] < 0.05