Exemplo n.º 1
0
def make_mesh_from_coordinates(coordinates):
    """Given a coordinate field build a new mesh, using said coordinate field.

    :arg coordinates: A :class:`~.Function`.
    """
    import firedrake.functionspace as functionspace
    from firedrake.ufl_expr import reconstruct_element

    if hasattr(coordinates, '_as_mesh_geometry'):
        mesh = coordinates._as_mesh_geometry()
        if mesh is not None:
            return mesh

    coordinates_fs = coordinates.function_space()
    if not isinstance(coordinates_fs, functionspace.VectorFunctionSpace):
        raise ValueError("Coordinates must have a VectorFunctionSpace.")
    assert coordinates_fs.mesh().ufl_cell().topological_dimension() <= coordinates_fs.dim
    # Build coordinate element
    element = coordinates.ufl_element()
    cell = element.cell().reconstruct(geometric_dimension=coordinates_fs.dim)
    element = reconstruct_element(element, cell=cell)

    mesh = MeshGeometry.__new__(MeshGeometry, element)
    mesh.__init__(coordinates)
    return mesh
Exemplo n.º 2
0
def make_mesh_from_coordinates(coordinates):
    """Given a coordinate field build a new mesh, using said coordinate field.

    :arg coordinates: A :class:`~.Function`.
    """
    from firedrake.ufl_expr import reconstruct_element

    if hasattr(coordinates, '_as_mesh_geometry'):
        mesh = coordinates._as_mesh_geometry()
        if mesh is not None:
            return mesh

    V = coordinates.function_space()
    element = coordinates.ufl_element()
    if V.rank != 1 or len(element.value_shape()) != 1:
        raise ValueError("Coordinates must be from a rank-1 FunctionSpace with rank-1 value_shape.")
    assert V.mesh().ufl_cell().topological_dimension() <= V.dim
    # Build coordinate element
    element = coordinates.ufl_element()
    cell = element.cell().reconstruct(geometric_dimension=V.dim)
    element = reconstruct_element(element, cell=cell)

    mesh = MeshGeometry.__new__(MeshGeometry, element)
    mesh.__init__(coordinates)
    return mesh
Exemplo n.º 3
0
def make_mesh_from_coordinates(coordinates):
    """Given a coordinate field build a new mesh, using said coordinate field.

    :arg coordinates: A :class:`~.Function`.
    """
    from firedrake.ufl_expr import reconstruct_element

    if hasattr(coordinates, '_as_mesh_geometry'):
        mesh = coordinates._as_mesh_geometry()
        if mesh is not None:
            return mesh

    V = coordinates.function_space()
    element = coordinates.ufl_element()
    if V.rank != 1 or len(element.value_shape()) != 1:
        raise ValueError("Coordinates must be from a rank-1 FunctionSpace with rank-1 value_shape.")
    assert V.mesh().ufl_cell().topological_dimension() <= V.dim
    # Build coordinate element
    element = coordinates.ufl_element()
    cell = element.cell().reconstruct(geometric_dimension=V.dim)
    element = reconstruct_element(element, cell=cell)

    mesh = MeshGeometry.__new__(MeshGeometry, element)
    mesh.__init__(coordinates)
    return mesh
Exemplo n.º 4
0
    def __init__(self, function_space, mesh):
        from firedrake.ufl_expr import reconstruct_element
        function_space = function_space.topological
        assert mesh.topology is function_space.mesh()
        assert mesh.topology is not mesh

        element = reconstruct_element(function_space.ufl_element(),
                                      cell=mesh.ufl_cell())
        super(WithGeometry, self).__init__(mesh, element)
        self.topological = function_space

        if function_space.parent is not None:
            self.parent = WithGeometry(function_space.parent, mesh)
        else:
            self.parent = None
Exemplo n.º 5
0
    def __init__(self, function_space, mesh):
        from firedrake.ufl_expr import reconstruct_element
        function_space = function_space.topological
        assert mesh.topology is function_space.mesh()
        assert mesh.topology is not mesh

        element = reconstruct_element(function_space.ufl_element(),
                                      cell=mesh.ufl_cell())
        super(WithGeometry, self).__init__(mesh, element)
        self.topological = function_space

        if function_space.parent is not None:
            self.parent = WithGeometry(function_space.parent, mesh)
        else:
            self.parent = None
Exemplo n.º 6
0
 def ufl_function_space(self):
     from firedrake.ufl_expr import reconstruct_element
     return ufl.FunctionSpace(
         self._mesh,
         reconstruct_element(self._topological.ufl_element(),
                             cell=self._mesh.ufl_cell()))
Exemplo n.º 7
0
 def ufl_function_space(self):
     from firedrake.ufl_expr import reconstruct_element
     return ufl.FunctionSpace(self._mesh,
                              reconstruct_element(self._topological.ufl_element(),
                                                  cell=self._mesh.ufl_cell()))