def _get_edge(self, uuid):
        """Returns an edge with a given uuid.

        Returns the edge stored in the mesh
        identified by uuid. If such edge do not
        exists an exception is raised.

        Parameters
        ----------
        uuid
            uuid of the desired edge.

        Returns
        -------
        Edge
            Edge identified by uuid

        Raises
        ------
        Exception
            If the edge identified by uuid was not found

        """

        try:
            pointLabels = self.pool.get_edge_points(self.name,
                                                    self._uuidToNumLabel[uuid])
            puids = [self._numPointLabelToUuid[lbl] for lbl in pointLabels]
            return Edge(puids, uuid)
        except KeyError:
            error_str = "Trying to get an non-existing edge with uuid: {}"
            raise ValueError(error_str.format(uuid))
    def test_update_edges(self):
        """Test update_edges method

        """

        num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool)
        with self.assertRaises(NotImplementedError):
            num_mesh.update([Edge([self.puids, self.puids[3]])])
    def setUp(self):

        self.mesh = TestMesh(name="mesh1")
        self.solver = 'pimpleFoam'

        self.points = [
            Point((0.0, 0.0, 0.0)),
            Point((1.0, 0.0, 0.0)),
            Point((1.0, 0.0, 1.0)),
            Point((0.0, 0.0, 1.0)),
            Point((0.0, 1.0, 0.0)),
            Point((1.0, 1.0, 0.0)),
            Point((1.0, 1.0, 1.0)),
            Point((0.0, 1.0, 1.0))
        ]

        puids = self.mesh.add(self.points)

        self.faces = [
            Face([puids[0], puids[3], puids[7], puids[4]]),
            Face([puids[1], puids[2], puids[6], puids[5]]),
            Face([puids[0], puids[1], puids[5], puids[4]]),
            Face([puids[3], puids[2], puids[6], puids[7]]),
            Face([puids[0], puids[1], puids[2], puids[3]]),
            Face([puids[4], puids[5], puids[6], puids[7]])
        ]

        self.edges = [Edge([puids[0], puids[3]])]

        self.fuids = self.mesh.add(self.faces)

        self.cells = [
            Cell(puids,
                 data=DataContainer({
                     CUBA.VELOCITY: [1, 0, 0],
                     CUBA.PRESSURE:
                     4.0,
                     CUBA.STRAIN_TENSOR: [1, 0, 0, 0, 1, 0, 0, 0, 1],
                     CUBA.STRESS_TENSOR: [1, 0, 0, 0, 1, 0, 0, 0, 1],
                     CUBA.HOMOGENIZED_STRESS_TENSOR:
                     [1, 0, 0, 0, 1, 0, 0, 0, 1]
                 }))
        ]

        self.puids = puids

        self.mesh.add(self.cells)

        self.boundaries = {
            "boundary" + str(i): [self.fuids[i]]
            for i in range(6)
        }
        self.mesh._boundaries = self.boundaries
    def setUp(self):
        self.mesh = Mesh(name="mesh1")
        numerrin.initlocal("", "PYNUMERRIN_LICENSE", liccode)
        self.points = [
            Point((0.0, 0.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 0.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 1.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((0.0, 1.0, 0.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((0.0, 0.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 0.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((1.0, 1.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  })),
            Point((0.0, 1.0, 1.0),
                  data=DataContainer({
                      CUBA.VELOCITY: (1, 0, 0),
                      CUBA.PRESSURE: 4.0
                  }))
        ]

        puids = self.mesh.add(self.points)

        self.faces = [
            Face([puids[0], puids[3], puids[7], puids[4]],
                 data=DataContainer({CUBA.LABEL: 0})),
            Face([puids[1], puids[2], puids[6], puids[5]],
                 data=DataContainer({CUBA.LABEL: 1})),
            Face([puids[0], puids[1], puids[5], puids[4]],
                 data=DataContainer({CUBA.LABEL: 2})),
            Face([puids[3], puids[2], puids[6], puids[7]],
                 data=DataContainer({CUBA.LABEL: 3})),
            Face([puids[0], puids[1], puids[2], puids[3]],
                 data=DataContainer({CUBA.LABEL: 4})),
            Face([puids[4], puids[5], puids[6], puids[7]],
                 data=DataContainer({CUBA.LABEL: 5}))
        ]

        self.edge = Edge([puids[0], puids[3]])

        self.mesh.add(self.faces)

        self.cells = [Cell(puids)]

        self.puids = puids

        self.mesh.add(self.cells)

        self.variablename = self.mesh.name + "Velocity"
        self.variable = tuple([(0.0, 0.0, 0.0) for _ in self.points])

        self.boundaries = {}
        for i in range(6):
            self.boundaries['boundary' + str(i)] = [self.faces[i].uid]
    def export_mesh(self, s_name, name, boundary_names):
        """ export Numerrin mesh from pool to SimPhoNy Mesh object

        Parameters
        ----------
        s_name : str
            Simphony mesh name

        name : str
            name of mesh

        boundary_names : list str
            list of boundary domain names

        Return
        ------
        (simphonyMesh, mmap) : tuple
            tuple of SimPhoNy mesh object and mapping from low
            level objects uuid to Numerrin label

        """

        simphonyMesh = Mesh(s_name)
        uuids = []
        mmap = {}
        meshsize = numerrin.meshsize(self.ph, name)
        spoints = []
        for i in range(meshsize[0]):
            coord = numerrin.getnode(self.ph, name, i)
            spoint = Point(coord, uid=generate_uuid())
            spoints.append(spoint)
            uuids.append(spoint.uid)
            mmap[spoint.uid] = i

        simphonyMesh.add(spoints)

        if len(meshsize) > 1:
            edges = []
            for i in range(meshsize[1]):
                plbl = numerrin.getelement(self.ph, name, 1, i, 0)
                points = []
                for pi in range(len(plbl)):
                    points.append(uuids[plbl[pi]])
                ed = Edge(points, uid=generate_uuid())
                edges.append(ed)
                mmap[ed.uid] = i
            simphonyMesh.add(edges)

        if len(meshsize) > 2:
            labeluidmap = {}
            faces = []
            for i in range(meshsize[2]):
                plbl = numerrin.getelement(self.ph, name, 2, i, 0)
                points = []
                for pi in range(len(plbl)):
                    points.append(uuids[plbl[pi]])
                face_renode(points)
                fa = Face(points, uid=generate_uuid())
                faces.append(fa)
                mmap[fa.uid] = i
                labeluidmap[i] = fa.uid
            simphonyMesh.add(faces)

            boundaries = {}
            for boundary in boundary_names:
                boundaries[boundary] = []
                boundary_faces = numerrin.getelementnumbers(
                    self.ph, name + boundary)
                for boundary_face in boundary_faces:
                    boundaries[boundary].append(labeluidmap[boundary_face])

        if len(meshsize) > 3:
            cells = []
            for i in range(meshsize[3]):
                plbl = numerrin.getelement(self.ph, name, 3, i, 0)
                points = []
                for pi in range(len(plbl)):
                    points.append(uuids[plbl[pi]])
                cell_renode(points)
                ce = Cell(points, uid=generate_uuid())
                cells.append(ce)
                mmap[ce.uid] = i
            simphonyMesh.add(cells)

        return (simphonyMesh, mmap, boundaries)
    def import_mesh(self, name, simphonyMesh, boundaries):
        """ import SimPhoNy mesh to Numerrin pool as Numerrin mesh

        Parameters
        ----------
        name : str
            name of mesh
        SimphonyMesh : Mesh
            Mesh object to import

        Return
        ------
        maps : list
            list of maps from SImPhoNy mesh low level objects
            uid's to corresponding Numerrin mesh objects
            mmap : dictionary
                map from uuid to Numerrin label
            pmap : dictionary
                map from Numerrin point label to uuid
            emap : dictionary
                map from Numerrin edge label to uuid
            fmap : dictionary
                map from Numerrin face label to uuid
            cmap : dictionary
                map from Numerrin cell label to uuid

        """

        nPoints = simphonyMesh.count_of(CUBA.POINT)
        nEdges = simphonyMesh.count_of(CUBA.EDGE)
        nFaces = simphonyMesh.count_of(CUBA.FACE)
        nCells = simphonyMesh.count_of(CUBA.CELL)

        sizes = (nPoints, nEdges, nFaces, nCells)
        numerrin.initmesh(self.ph, name, 3, sizes)

        mmap = {}
        pmap = {}
        indx = 0
        for point in simphonyMesh.iter(item_type=CUBA.POINT):
            numerrin.setnode(self.ph, name, indx, point.coordinates)
            mmap[point.uid] = indx
            pmap[indx] = point.uid
            indx += 1

        indx = 0
        emap = {}

        for edge in simphonyMesh.iter(item_type=CUBA.EDGE):
            pind = []
            for point in edge.points:
                pind.append(mmap[point])
            numerrin.setelementtype(self.ph, name, 1, indx, 1)
            numerrin.setelement(self.ph, name, 1, indx, 0, tuple(pind))
            mmap[edge.uid] = indx
            emap[indx] = edge.uid
            indx += 1

        indx = 0
        fmap = {}
        for face in simphonyMesh.iter(item_type=CUBA.FACE):
            pind = []
            for puid in face.points:
                pind.append(mmap[puid])
            face_renode(pind)
            if len(pind) == 3:
                numerrin.setelementtype(self.ph, name, 2, indx, 2)
            else:
                numerrin.setelementtype(self.ph, name, 2, indx, 3)
            numerrin.setelement(self.ph, name, 2, indx, 0, tuple(pind))
            mmap[face.uid] = indx
            fmap[indx] = face.uid
            indx += 1

        boundary_faces = {}
        for boundary in boundaries:
            boundary_faces[boundary] = []
            for fuid in boundaries[boundary]:
                boundary_faces[boundary].append(mmap[fuid])

        indx = 0
        cmap = {}
        cell_ids = []
        for cell in simphonyMesh.iter(item_type=CUBA.CELL):
            pind = []
            for point in cell.points:
                pind.append(mmap[point])
            cell_renode(pind)
            if len(pind) == 4:
                numerrin.setelementtype(self.ph, name, 3, indx, 4)
            elif len(pind) == 6:
                numerrin.setelementtype(self.ph, name, 3, indx, 6)
            else:
                numerrin.setelementtype(self.ph, name, 3, indx, 7)
            numerrin.setelement(self.ph, name, 3, indx, 0, tuple(pind))
            mmap[cell.uid] = indx
            cmap[indx] = cell.uid
            cell_ids.append(indx)
            indx += 1

        # create edges and faces if not exists
        if not simphonyMesh.has_type(CUBA.EDGE):
            numerrin.createedges(self.ph, name)
            # create mapping
            for i in range(self.mesh_size(name)[1]):
                points = []
                edge = Edge(points, uid=generate_uuid())
                emap[i] = edge.uid
                mmap[edge.uid] = i
        if not simphonyMesh.has_type(CUBA.FACE):
            numerrin.createfaces(self.ph, name)
            # create mapping
            for i in range(self.mesh_size(name)[2]):
                uid = generate_uuid()
                fmap[i] = uid
                mmap[uid] = i
        # create neighbor lists
        numerrin.createneighbors(self.ph, name, 1)
        numerrin.createneighbors(self.ph, name, 2)
        numerrin.createneighbors(self.ph, name, 3)
        # create references between different levels
        numerrin.createrefs(self.ph, name, 2, 1)
        numerrin.createrefs(self.ph, name, 3, 1)
        numerrin.createrefs(self.ph, name, 3, 2)

        # add inner domain
        numerrin.createdomain(self.ph, "omega", name, 3, tuple(cell_ids))
        # add boundary domains
        self.add_boundaries(name, boundaries, boundary_faces)

        return [mmap, pmap, emap, fmap, cmap]