Ejemplo n.º 1
0
def hat_function_collection(vertex_colors, color, element=None):
    """Return Expression on given element which takes values:
      1 ... if vertex_colors[node] == color
      0 ... at other nodes
    This is well defined just on Lagrange 1 element (default) and Dicontinuous
    Lagrange 1 element.

    NOTE: This expression provides a little hack as it lacks continuity across
    MPI partitions boundaries unless vertex_colors is compatible there. In fact,
    this behaviour is needed in FluxReconstructor."""
    assert isinstance(vertex_colors, cpp.VertexFunctionSizet)
    mesh = vertex_colors.mesh()
    if not element:
        element = FiniteElement('Lagrange', mesh.ufl_cell(), 1)
    assert element.family() in ['Lagrange', 'Discontinuous Lagrange']
    assert element.degree() == 1
    ufc_element, ufc_dofmap = jit(element, mpi_comm=mesh.mpi_comm())
    dolfin_element = cpp.FiniteElement(ufc_element)

    e = Expression(hats_cpp_code, element=element, domain=mesh)
    e.vertex_colors = vertex_colors
    e.color = color
    e.dolfin_element = dolfin_element

    return e
Ejemplo n.º 2
0
def hat_function(vertex):
    """Return Expression on Lagrange degree 1 element which is
      1 ... at given 'vertex'
      0 ... at other vertices
    """
    assert isinstance(vertex, Vertex)
    mesh = vertex.mesh()
    element = FiniteElement('Lagrange', mesh.ufl_cell(), 1)
    ufc_element, ufc_dofmap = jit(element, mpi_comm=mesh.mpi_comm())
    ufc_element = make_ufc_finite_element(ufc_element)
    dolfin_element = cpp.FiniteElement(ufc_element)

    e = Expression(hat_cpp_code, element=element, domain=mesh)
    e.vertex = vertex
    e.dolfin_element = dolfin_element

    return e