def buildCellArrayWithFunction(da, func, extra_args=()):
    """
    Construct a vector using a function applied on
    each cell of the mesh.

    Parameters
    ==========

    da : petsc.DMDA
        The mesh structure.

    func: function
        Function to apply on each cell.

    extra_args: tuple
        extra parameters of the function.

    Returns
    =======

    b: petsc.Vec
        The vector with the function values on each cell.

    """
    elem = da.getElements()
    coords = da.getCoordinatesLocal()
    dof = da.getDof()

    x = .5*(coords[dof*elem[:, 0]] + coords[dof*elem[:, 1]])
    y = .5*(coords[dof*elem[:, 0] + 1] + coords[dof*elem[:, 3] + 1])

    if da.getDim() == 2:
        return func(x, y, *extra_args)
    else:
        z= .5*(coords[dof*elem[:, 0] + 2] + coords[dof*elem[:, 4] + 2])
        return func(x, y, z, *extra_args)