def test_get_cell_points(self):
        """Test getCellPoints method

        """

        for cell in self.cells:
            pointLabels = foamface.getCellPoints(
                self.name, self._uuidToFoamLabelAndType[cell.uid][0])
            puids = [self._foamPointLabelToUuid[lbl] for lbl in pointLabels]
            self.assertEqual(set(puids), set(cell.points))
    def test_get_cell_points(self):
        """Test getCellPoints method

        """

        for cell in self.cells:
            pointLabels = foamface.getCellPoints(
                self.name,
                self._uuidToFoamLabelAndType[cell.uid][0])
            puids = [self._foamPointLabelToUuid[lbl] for lbl in pointLabels]
            self.assertEqual(set(puids), set(cell.points))
Ejemplo n.º 3
0
    def _update_cells(self, cells):
        """ Updates the information of a set of cells.

        Gets the mesh cell identified by the same
        uuid as the provided cell and updates its information
        with the one provided with the new cell.

        Parameters
        ----------
        cells : iterable of Cell
            Cell set to be updated

        Raises
        ------
        KeyError
            If the cell was not found in the mesh

        TypeError
            If the object provided is not a cell

        """

        dataNames = foamface.getCellDataNames(self.name)
        dataNames += foamface.getCellVectorDataNames(self.name)
        dataNames += foamface.getCellTensorDataNames(self.name)

        # if cell data does not exists in the mesh at all, initialize it
        newDataNames = []
        dataNameKeyMap = {}
        cellList = list(cells)
        for cell in cellList:
            for data in cell.data:
                if data not in dataNameMap:
                    error_str = "Data named " + data + " not supported"
                    raise NotImplementedError(error_str)
                dataName = dataNameMap[data]
                if dataName not in dataNameKeyMap:
                    dataNameKeyMap[dataName] = data
                if dataName not in dataNames and dataName not in newDataNames:
                    newDataNames.append(dataName)
        for dataName in newDataNames:
            create_dummy_celldata(self.name, dataName)

        for cell in cellList:
            if cell.uid not in self._uuidToFoamLabelAndType:
                error_str = "Trying to update a non-existing cell with uuid: "\
                    + str(cell.uid)
                raise KeyError(error_str)

            # if points are changed raise warning
            pointLabels = \
                foamface.getCellPoints(
                    self.name,
                    self._uuidToFoamLabelAndType[cell.uid][0])
            puids = [self._foamPointLabelToUuid[lbl] for lbl in pointLabels]
            if set(puids) != set(cell.points):
                raise Warning("Cell points can't be updated")

        # check that if volume fraction is in data, phase names are mapped to
        # materials
        if CUBA.VOLUME_FRACTION in dataNameKeyMap.values() \
                and not self._foamPhaseNameToMaterial:
            cell = cellList[0]
            phase_vol_fracs = cell.data[CUBA.VOLUME_FRACTION]
            im = 0
            for phase_vol_frac in phase_vol_fracs:
                self._foamPhaseNameToMaterial[phaseNames[im]] = \
                    phase_vol_frac.material
                im += 1
        set_cells_data(self.name, cellList, dataNameKeyMap,
                       self._foamPhaseNameToMaterial)
Ejemplo n.º 4
0
    def _get_cell(self, uuid):
        """ Returns a cell with a given uuid.

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

        Parameters
        ----------
        uuid
            uuid of the desired cell.

        Returns
        -------
        Cell
            Cell with id identified by uuid

        Raises
        ------
        KeyError
            If the cell identified by uuid was not found

        """

        label, type = self._uuidToFoamLabelAndType[uuid]
        if type != CUBA.CELL:
            raise KeyError("No Cell with uuid {}".format(uuid))

        pointLabels = foamface.getCellPoints(self.name, label)
        puids = [self._foamPointLabelToUuid[lbl] for lbl in pointLabels]
        cell = Cell(puids, uuid)

        dataNames = foamface.getCellDataNames(self.name)
        dataNames += foamface.getCellVectorDataNames(self.name)
        dataNames += foamface.getCellTensorDataNames(self.name)
        if len(self._foamPhaseNameToMaterial) > 1:
            dataNames.append(dataNameMap[CUBA.VOLUME_FRACTION])
        for dataName in set(dataKeyMap.keys()).intersection(dataNames):
            if dataName == dataNameMap[CUBA.VOLUME_FRACTION]:
                # currently this is only for volume_fraction and for two phase
                dName = dataName + '.' + phaseNames[0]
                vol_frac1 = foamface.getCellData(self.name, label, dName)
                material1 = self._foamPhaseNameToMaterial[phaseNames[0]]
                material2 = self._foamPhaseNameToMaterial[phaseNames[1]]
                phase1_vol_frac = PhaseVolumeFraction(material1, vol_frac1)
                phase2_vol_frac = PhaseVolumeFraction(material2, 1 - vol_frac1)
                cell.data[dataKeyMap[dataName]] = [
                    phase1_vol_frac, phase2_vol_frac
                ]

            elif dataTypeMap[dataKeyMap[dataName]] == "scalar":
                cell.data[dataKeyMap[dataName]] = \
                    foamface.getCellData(self.name,
                                         label,
                                         dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "vector":
                cell.data[dataKeyMap[dataName]] = \
                    foamface.getCellVectorData(self.name,
                                               label,
                                               dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "tensor":
                cell.data[dataKeyMap[dataName]] = \
                    foamface.getCellTensorData(self.name,
                                               label,
                                               dataName)

        return cell
Ejemplo n.º 5
0
    def _update_cells(self, cells):
        """ Updates the information of a set of cells.

        Gets the mesh cell identified by the same
        uuid as the provided cell and updates its information
        with the one provided with the new cell.

        Parameters
        ----------
        cells : iterable of Cell
            Cell set to be updated

        Raises
        ------
        KeyError
            If the cell was not found in the mesh

        TypeError
            If the object provided is not a cell

        """

        dataNames = foamface.getCellDataNames(self.name)
        dataNames += foamface.getCellVectorDataNames(self.name)
        dataNames += foamface.getCellTensorDataNames(self.name)

        # if cell data does not exists in the mesh at all, initialize it
        newDataNames = []
        dataNameKeyMap = {}
        cellList = list(cells)
        for cell in cellList:
            for data in cell.data:
                if data not in dataNameMap:
                    error_str = "Data named "+data+" not supported"
                    raise NotImplementedError(error_str)
                dataName = dataNameMap[data]
                if dataName not in dataNameKeyMap:
                    dataNameKeyMap[dataName] = data
                if dataName not in dataNames and dataName not in newDataNames:
                    newDataNames.append(dataName)
        for dataName in newDataNames:
            create_dummy_celldata(self.name, dataName)

        for cell in cellList:
            if cell.uid not in self._uuidToFoamLabelAndType:
                error_str = "Trying to update a non-existing cell with uuid: "\
                    + str(cell.uid)
                raise KeyError(error_str)

            # if points are changed raise warning
            pointLabels = \
                foamface.getCellPoints(
                    self.name,
                    self._uuidToFoamLabelAndType[cell.uid][0])
            puids = [self._foamPointLabelToUuid[lbl] for lbl in pointLabels]
            if set(puids) != set(cell.points):
                raise Warning("Cell points can't be updated")

        # check that if volume fraction is in data, phase names are mapped to
        # materials
        if CUBA.VOLUME_FRACTION in dataNameKeyMap.values() \
                and not self._foamPhaseNameToMaterial:
            cell = cellList[0]
            phase_vol_fracs = cell.data[CUBA.VOLUME_FRACTION]
            im = 0
            for phase_vol_frac in phase_vol_fracs:
                self._foamPhaseNameToMaterial[phaseNames[im]] = \
                    phase_vol_frac.material
                im += 1
        set_cells_data(self.name, cellList, dataNameKeyMap,
                       self._foamPhaseNameToMaterial)
Ejemplo n.º 6
0
    def _get_cell(self, uuid):
        """ Returns a cell with a given uuid.

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

        Parameters
        ----------
        uuid
            uuid of the desired cell.

        Returns
        -------
        Cell
            Cell with id identified by uuid

        Raises
        ------
        KeyError
            If the cell identified by uuid was not found

        """

        label, type = self._uuidToFoamLabelAndType[uuid]
        if type != CUBA.CELL:
            raise KeyError("No Cell with uuid {}".format(uuid))

        pointLabels = foamface.getCellPoints(self.name, label)
        puids = [self._foamPointLabelToUuid[lbl] for lbl in pointLabels]
        cell = Cell(puids, uuid)

        dataNames = foamface.getCellDataNames(self.name)
        dataNames += foamface.getCellVectorDataNames(self.name)
        dataNames += foamface.getCellTensorDataNames(self.name)
        if len(self._foamPhaseNameToMaterial) > 1:
            dataNames.append(dataNameMap[CUBA.VOLUME_FRACTION])
        for dataName in set(dataKeyMap.keys()).intersection(dataNames):
            if dataName == dataNameMap[CUBA.VOLUME_FRACTION]:
                # currently this is only for volume_fraction and for two phase
                dName = dataName + '.' + phaseNames[0]
                vol_frac1 = foamface.getCellData(self.name, label, dName)
                material1 = self._foamPhaseNameToMaterial[phaseNames[0]]
                material2 = self._foamPhaseNameToMaterial[phaseNames[1]]
                phase1_vol_frac = PhaseVolumeFraction(material1, vol_frac1)
                phase2_vol_frac = PhaseVolumeFraction(material2, 1 - vol_frac1)
                cell.data[dataKeyMap[dataName]] = [phase1_vol_frac,
                                                   phase2_vol_frac]

            elif dataTypeMap[dataKeyMap[dataName]] == "scalar":
                cell.data[dataKeyMap[dataName]] = \
                    foamface.getCellData(self.name,
                                         label,
                                         dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "vector":
                cell.data[dataKeyMap[dataName]] = \
                    foamface.getCellVectorData(self.name,
                                               label,
                                               dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "tensor":
                cell.data[dataKeyMap[dataName]] = \
                    foamface.getCellTensorData(self.name,
                                               label,
                                               dataName)

        return cell