Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Umberto Zerbinati <[email protected]>
  • Loading branch information
Umberto Zerbinati committed Jan 31, 2024
1 parent d89e747 commit dd07ee6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 41 deletions.
29 changes: 16 additions & 13 deletions firedrake/mg/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 15 additions & 28 deletions tests/regression/test_netgen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from firedrake import *
import numpy as np
import gc
from petsc4py import PETSc
import pytest

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
assert error_estimators[-1] < 0.05

0 comments on commit dd07ee6

Please sign in to comment.