def test_add_mesh(self):
        """Test addMesh method

        """

        pointCoordinates = foamface.getAllPointCoordinates(self.name)
        self.assertEqual(self.pointCoordinates, pointCoordinates)
        cellPoints = foamface.getAllCellPoints(self.name)
        self.assertEqual(set(self.cellPoints), set(cellPoints))
        facePoints = foamface.getAllFacePoints(self.name)
        self.assertEqual(self.facePoints, facePoints)
        patchNames = foamface.getBoundaryPatchNames(self.name)
        self.assertEqual(self.patchNames, patchNames)
        patchFaces = foamface.getBoundaryPatchFaces(self.name)
        self.assertEqual(self.patchFaces, patchFaces)
    def test_add_mesh(self):
        """Test addMesh method

        """

        pointCoordinates = foamface.getAllPointCoordinates(self.name)
        self.assertEqual(self.pointCoordinates, pointCoordinates)
        cellPoints = foamface.getAllCellPoints(self.name)
        self.assertEqual(set(self.cellPoints), set(cellPoints))
        facePoints = foamface.getAllFacePoints(self.name)
        self.assertEqual(self.facePoints, facePoints)
        patchNames = foamface.getBoundaryPatchNames(self.name)
        self.assertEqual(self.patchNames, patchNames)
        patchFaces = foamface.getBoundaryPatchFaces(self.name)
        self.assertEqual(self.patchFaces, patchFaces)
Example #3
0
    def _iter_cells_parallel(self):
        """Returns an iterator over all cells.

        Returns an iterator over the cells. Cell instances are
        made parallell.


        Returns
        -------
        iter
            Iterator over cells

        """

        pointLabels = foamface.getAllCellPoints(self.name)
        data_map = self._get_cell_data_map()

        n_jobs = cpu_count()
        cells_puids = self._find_cells_puids(pointLabels)

        n_cells = len(cells_puids)
        group_size = n_cells / n_jobs
        last_group_size = group_size + n_cells % n_jobs
        cell_indeces = []
        for i in range(n_jobs - 1):
            cellis = []
            cellis.append(i * group_size)
            cellis.append((i + 1) * group_size - 1)
            cell_indeces.append(cellis)
        cellis = []
        cellis.append((n_jobs - 1) * group_size)
        cellis.append((n_jobs - 1) * group_size + last_group_size - 1)
        cell_indeces.append(cellis)

        pool = Pool(n_jobs)
        args = [[
            cell_indeces[i][0], cell_indeces[i][1], cells_puids, data_map,
            self._foamCellLabelToUuid, self._foamPhaseNameToMaterial
        ] for i in range(n_jobs)]
        results = pool.map(get_cells_in_range, args)

        for res in results:
            for item in res:
                yield item
        pool.close()
        data_map.clear()
Example #4
0
    def _iter_cells_parallel(self):
        """Returns an iterator over all cells.

        Returns an iterator over the cells. Cell instances are
        made parallell.


        Returns
        -------
        iter
            Iterator over cells

        """

        pointLabels = foamface.getAllCellPoints(self.name)
        data_map = self._get_cell_data_map()

        n_jobs = cpu_count()
        cells_puids = self._find_cells_puids(pointLabels)

        n_cells = len(cells_puids)
        group_size = n_cells / n_jobs
        last_group_size = group_size + n_cells % n_jobs
        cell_indeces = []
        for i in range(n_jobs - 1):
            cellis = []
            cellis.append(i * group_size)
            cellis.append((i+1) * group_size - 1)
            cell_indeces.append(cellis)
        cellis = []
        cellis.append((n_jobs - 1) * group_size)
        cellis.append((n_jobs - 1) * group_size + last_group_size - 1)
        cell_indeces.append(cellis)

        pool = Pool(n_jobs)
        args = [[cell_indeces[i][0], cell_indeces[i][1],
                 cells_puids, data_map, self._foamCellLabelToUuid,
                 self._foamPhaseNameToMaterial]
                for i in range(n_jobs)]
        results = pool.map(get_cells_in_range, args)

        for res in results:
            for item in res:
                yield item
        pool.close()
        data_map.clear()
Example #5
0
 def _get_packed_cell_list(self):
     """ get packed list of celsl point labels
     """
     return foamface.getAllCellPoints(self.name)
Example #6
0
    def _iter_cells(self, cell_uuids=None):
        """ Returns an iterator over the selected cells.

        Returns an iterator over the cells with uuid in
        cell_uuids. If none of the uuids in cell_uuids exists,
        an empty iterator is returned. If there is no uuids
        inside cell_uuids, a iterator over all cells of
        the mesh is returned instead.

        Parameters
        ----------
        cell_uuids : list of uuids, optional
            Uuids of the desired cell, default empty

        Returns
        -------
        iter
            Iterator over the selected cells

        """

        if cell_uuids is None:
            pointLabels = foamface.getAllCellPoints(self.name)
            data_map = self._get_cell_data_map()
            cell_label = -1
            i = 0
            while i < len(pointLabels):
                cell_label += 1
                n_points = pointLabels[i]
                i += 1
                puids = []
                for j in range(n_points):
                    puids.append(self._foamPointLabelToUuid[pointLabels[i]])
                    i += 1
                cell = Cell(puids, self._foamCellLabelToUuid[cell_label])
                for dataKey, data in data_map.iteritems():
                    if dataTypeMap[dataKey] == "scalar":
                        if dataKey == CUBA.VOLUME_FRACTION:
                            if self._foamPhaseNameToMaterial:
                                material1 = self._foamPhaseNameToMaterial[
                                    phaseNames[0]]
                                material2 = self._foamPhaseNameToMaterial[
                                    phaseNames[1]]
                                vol_frac1 = data[cell_label]
                                phase1_vol_frac = PhaseVolumeFraction(
                                    material1, vol_frac1)
                                phase2_vol_frac = PhaseVolumeFraction(
                                    material2, 1 - vol_frac1)
                                cell.data[dataKey] = [
                                    phase1_vol_frac, phase2_vol_frac
                                ]
                        else:
                            cell.data[dataKey] = data[cell_label]
                    elif dataTypeMap[dataKey] == "vector":
                        cell.data[dataKey] = \
                            [data[cell_label * 3 + k] for k in range(3)]
                    elif dataTypeMap[dataKey] == "tensor":
                        cell.data[dataKey] = \
                            [data[cell_label * 9 + k] for k in range(9)]
                yield cell
            data_map.clear()
        else:
            for uid in cell_uuids:
                cell = self._get_cell(uid)
                yield cell
Example #7
0
 def _get_packed_cell_list(self):
     """ get packed list of celsl point labels
     """
     return foamface.getAllCellPoints(self.name)
Example #8
0
    def _iter_cells(self, cell_uuids=None):
        """ Returns an iterator over the selected cells.

        Returns an iterator over the cells with uuid in
        cell_uuids. If none of the uuids in cell_uuids exists,
        an empty iterator is returned. If there is no uuids
        inside cell_uuids, a iterator over all cells of
        the mesh is returned instead.

        Parameters
        ----------
        cell_uuids : list of uuids, optional
            Uuids of the desired cell, default empty

        Returns
        -------
        iter
            Iterator over the selected cells

        """

        if cell_uuids is None:
            pointLabels = foamface.getAllCellPoints(self.name)
            data_map = self._get_cell_data_map()
            cell_label = -1
            i = 0
            while i < len(pointLabels):
                cell_label += 1
                n_points = pointLabels[i]
                i += 1
                puids = []
                for j in range(n_points):
                    puids.append(self._foamPointLabelToUuid[pointLabels[i]])
                    i += 1
                cell = Cell(puids, self._foamCellLabelToUuid[cell_label])
                for dataKey, data in data_map.iteritems():
                    if dataTypeMap[dataKey] == "scalar":
                        if dataKey == CUBA.VOLUME_FRACTION:
                            if self._foamPhaseNameToMaterial:
                                material1 = self._foamPhaseNameToMaterial[
                                    phaseNames[0]]
                                material2 = self._foamPhaseNameToMaterial[
                                    phaseNames[1]]
                                vol_frac1 = data[cell_label]
                                phase1_vol_frac = PhaseVolumeFraction(
                                    material1, vol_frac1)
                                phase2_vol_frac = PhaseVolumeFraction(
                                    material2, 1 - vol_frac1)
                                cell.data[dataKey] = [phase1_vol_frac,
                                                      phase2_vol_frac]
                        else:
                            cell.data[dataKey] = data[cell_label]
                    elif dataTypeMap[dataKey] == "vector":
                        cell.data[dataKey] = \
                            [data[cell_label * 3 + k] for k in range(3)]
                    elif dataTypeMap[dataKey] == "tensor":
                        cell.data[dataKey] = \
                            [data[cell_label * 9 + k] for k in range(9)]
                yield cell
            data_map.clear()
        else:
            for uid in cell_uuids:
                cell = self._get_cell(uid)
                yield cell