def METHOD_NAME(bathymetry, delta_sigma=1.0, r_max=0.0, bg_diff=0.0,
                      alpha=1000.0, exponent=1, minimum_depth=None, solution=None,
                      niter=10):
    """
    Smooth bathymetry by minimizing mesh HCC metric r.
    Minimizes HCC metric r while maintaining original bathymetry as much as
    possible.
    """
    fs = bathymetry.function_space()
    mesh = fs.mesh()
    solution = Function(fs, name='bathymetry')
    tmp_bath = Function(fs, name='bathymetry').assign(bathymetry)
    test = TestFunction(fs)
    delta_x = sqrt(CellVolume(mesh))
    bath_grad = grad(tmp_bath)
    grad_h = sqrt(bath_grad[0]**2 + bath_grad[1]**2)
    hcc = (grad_h * delta_x)**exponent / (tmp_bath**0.5 * delta_sigma)
    cost = bg_diff + alpha*hcc
    f = inner(solution - tmp_bath, test)*dx
    f += cost*inner(grad(solution), grad(test))*dx
    prob = NonlinearVariationalProblem(f, solution)
    solver = NonlinearVariationalSolver(prob)
    for i in range(niter):
        # fixed point iteration
        solver.solve()
        if minimum_depth is not None:
            shallow_ix = solution.dat.data < minimum_depth
            solution.dat.data[shallow_ix] = minimum_depth
        tmp_bath.assign(solution)
    return solution