예제 #1
0
파일: mesh.py 프로젝트: hyharry/firedrake
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
예제 #2
0
파일: mesh.py 프로젝트: chawkm/firedrake
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
예제 #3
0
파일: mesh.py 프로젝트: jshipton/firedrake
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
예제 #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
예제 #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
예제 #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()))
예제 #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()))