示例#1
0
    def _get_point_data_map(self):
        """ get map for mesh pointwise data
        """

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

        dataMap = {}
        # take phase dependance away from the name
        dataNames = [dname.partition('.')[0] for dname in dataNames]

        for dataName in set(dataKeyMap.keys()).intersection(dataNames):
            if dataTypeMap[dataKeyMap[dataName]] == "scalar":
                if dataKeyMap[dataName] == CUBA.VOLUME_FRACTION:
                    dName = dataName + '.' + phaseNames[0]
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllPointData(self.name, dName)
                else:
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllPointData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "vector":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllPointVectorData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "tensor":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllPointTensorData(self.name, dataName)
        return dataMap
示例#2
0
    def _get_point_data_map(self):
        """ get map for mesh pointwise data
        """

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

        dataMap = {}
        # take phase dependance away from the name
        dataNames = [dname.partition('.')[0] for dname in dataNames]

        for dataName in set(dataKeyMap.keys()).intersection(dataNames):
            if dataTypeMap[dataKeyMap[dataName]] == "scalar":
                if dataKeyMap[dataName] == CUBA.VOLUME_FRACTION:
                    dName = dataName + '.' + phaseNames[0]
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllPointData(self.name, dName)
                else:
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllPointData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "vector":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllPointVectorData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "tensor":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllPointTensorData(self.name, dataName)
        return dataMap
示例#3
0
    def _get_cell_data_map(self):
        """ get map for mesh data
        """

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

        dataMap = {}
        for dataName in set(dataKeyMap.keys()).intersection(dataNames):
            if dataTypeMap[dataKeyMap[dataName]] == "scalar":
                if dataKeyMap[dataName] == CUBA.VOLUME_FRACTION:
                    dName = dataName + '.' + phaseNames[0]
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllCellData(self.name, dName)
                else:
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllCellData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "vector":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllCellVectorData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "tensor":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllCellTensorData(self.name, dataName)
        return dataMap
示例#4
0
    def _get_cell_data_map(self):
        """ get map for mesh data
        """

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

        dataMap = {}
        for dataName in set(dataKeyMap.keys()).intersection(dataNames):
            if dataTypeMap[dataKeyMap[dataName]] == "scalar":
                if dataKeyMap[dataName] == CUBA.VOLUME_FRACTION:
                    dName = dataName + '.' + phaseNames[0]
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllCellData(self.name, dName)
                else:
                    dataMap[dataKeyMap[dataName]] = \
                        foamface.getAllCellData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "vector":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllCellVectorData(self.name, dataName)
            elif dataTypeMap[dataKeyMap[dataName]] == "tensor":
                dataMap[dataKeyMap[dataName]] = \
                    foamface.getAllCellTensorData(self.name, dataName)
        return dataMap
示例#5
0
    def copy_cells(self, cell_data_map):
        """ Copy the information of a set of cells.

        Gets the mesh cell and copy its data
        with the one provided with the new cell. Cell points
        are not copied.

        Parameters
        ----------
        cell_data_map : dictionary
             map from data key to cell data values in
             mesh internal order

        """

        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 = []
        for key in cell_data_map:
            if key not in dataNameMap:
                error_str = "Data named " + key + " not supported"
                raise NotImplementedError(error_str)
            dataName = dataNameMap[key]
            if dataName not in dataNames and dataName not in newDataNames:
                newDataNames.append(dataName)
        for dataName in newDataNames:
            create_dummy_celldata(self.name, dataName, True)

        for key, data in cell_data_map.iteritems():
            dimension = dataDimensionMap[key]
            dataName = dataNameMap[key]
            if dataTypeMap[key] == "scalar":
                if key == CUBA.VOLUME_FRACTION:
                    foamface.setAllCellData(self.name,
                                            dataName + '.' + phaseNames[0], 0,
                                            data, dimension)
                else:
                    foamface.setAllCellData(self.name, dataName, 0, data,
                                            dimension)
            elif dataTypeMap[key] == "vector":
                foamface.setAllCellVectorData(self.name, dataName, 0, data,
                                              dimension)
            elif dataTypeMap[key] == "tensor":
                foamface.setAllCellTensorData(self.name, dataName, 0, data,
                                              dimension)
示例#6
0
    def copy_cells(self, cell_data_map):
        """ Copy the information of a set of cells.

        Gets the mesh cell and copy its data
        with the one provided with the new cell. Cell points
        are not copied.

        Parameters
        ----------
        cell_data_map : dictionary
             map from data key to cell data values in
             mesh internal order

        """

        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 = []
        for key in cell_data_map:
            if key not in dataNameMap:
                error_str = "Data named " + key + " not supported"
                raise NotImplementedError(error_str)
            dataName = dataNameMap[key]
            if dataName not in dataNames and dataName not in newDataNames:
                newDataNames.append(dataName)
        for dataName in newDataNames:
            create_dummy_celldata(self.name, dataName, True)

        for key, data in cell_data_map.iteritems():
            dimension = dataDimensionMap[key]
            dataName = dataNameMap[key]
            if dataTypeMap[key] == "scalar":
                if key == CUBA.VOLUME_FRACTION:
                    foamface.setAllCellData(self.name,
                                            dataName + '.' + phaseNames[0], 0,
                                            data, dimension)
                else:
                    foamface.setAllCellData(self.name, dataName, 0,
                                            data, dimension)
            elif dataTypeMap[key] == "vector":
                foamface.setAllCellVectorData(self.name, dataName, 0,
                                              data, dimension)
            elif dataTypeMap[key] == "tensor":
                foamface.setAllCellTensorData(self.name, dataName, 0,
                                              data, dimension)
示例#7
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)
示例#8
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
示例#9
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)
示例#10
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