def test_get_cell_count(self): """Test getCellCount method """ nCells = foamface.getCellCount(self.name) self.assertEqual(nCells, len(self.cells))
def count_of(self, item_type): """ Return the count of item_type in the container. Parameters ---------- item_type : CUBA item The CUBA enum of the type of the items to return the count of. Returns ------- count : int The number of items of item_type in the container. Raises ------ ValueError : If the type of the item is not supported in the current container. """ if item_type == CUBA.POINT: return foamface.getPointCount(self.name) elif item_type == CUBA.EDGE: return 0 elif item_type == CUBA.FACE: return foamface.getFaceCount(self.name) elif item_type == CUBA.CELL: return foamface.getCellCount(self.name) else: error_str = 'Item type {} not supported' raise ValueError(error_str.format(item_type))
def create_dummy_celldata(path, name, time, data_name, dimensionset): """Created dummy cell vector data Parameters ---------- data_name : str Name of data to be created dimensionset : tuple Data dimensionset """ version = '2.4' nCells = foamface.getCellCount(name) if dataTypeMap[dataKeyMap[data_name]] == 'scalar': values = [0.0 for item in range(nCells)] else: values = [(0.0, 0.0, 0.0) for item in range(nCells)] solver = 'generalFoam' foamFile = os.path.join(time, data_name) foamClass = foamTypeMap[dataTypeMap[dataKeyMap[data_name]]] location = '\"' + os.path.dirname(foamFile) + '\"' foamObject = os.path.basename(foamFile) heading = head.format(version=version, foamclass=foamClass, location=location, foamobject=foamObject) fileContent = heading + dataTemplates[solver][data_name] f = open(os.path.join(path, time, data_name), 'w') f.write(fileContent) f.close() set_all_cell_data(path, time, data_name, values, dataTypeMap[dataKeyMap[data_name]])
def _has_cells(self): """ Check if the mesh has cells Returns ------- bool True of there are cells inside the mesh, False otherwise """ numberCells = foamface.getCellCount(self.name) return numberCells > 0
def read_foammesh(name, path): """Read mesh from OpenFoam case files. Parameters ---------- name : str name to give to mesh path : str case directory Raises ------ Exception if some mesh from mesh names list not found """ mapContent = get_dictionary_maps('pimpleFoam', False) controlDict = parse_map(mapContent['controlDict']) foamface.init_IO(name, path, controlDict) foamface.readMesh(name) nPoints = foamface.getPointCount(name) nCells = foamface.getCellCount(name) nFaces = foamface.getFaceCount(name) nEdges = 0 foamMesh = FoamMesh(name, {}, 'pimpleFoam') foamMesh.generate_uuidmapping(nPoints, nEdges, nFaces, nCells) patchNames = foamface.getBoundaryPatchNames(name) patchFaces = foamface.getBoundaryPatchFaces(name) boundaries = {} i = 0 k = 0 while i < len(patchFaces): boundaries[patchNames[k]] = [] start = i+1 end = start+patchFaces[i] i += 1 for j in range(start, end): boundaries[patchNames[k]].append( foamMesh._foamFaceLabelToUuid[patchFaces[j]]) i += 1 k += 1 foamMesh._boundaries = boundaries return foamMesh
def read_foammesh(name, path): """Read mesh from OpenFoam case files. Parameters ---------- name : str name to give to mesh path : str case directory Raises ------ Exception if some mesh from mesh names list not found """ mapContent = get_dictionary_maps('pimpleFoam', False) controlDict = parse_map(mapContent['controlDict']) foamface.init_IO(name, path, controlDict) foamface.readMesh(name) nPoints = foamface.getPointCount(name) nCells = foamface.getCellCount(name) nFaces = foamface.getFaceCount(name) nEdges = 0 foamMesh = FoamMesh(name, {}, 'pimpleFoam') foamMesh.generate_uuidmapping(nPoints, nEdges, nFaces, nCells) patchNames = foamface.getBoundaryPatchNames(name) patchFaces = foamface.getBoundaryPatchFaces(name) boundaries = {} i = 0 k = 0 while i < len(patchFaces): boundaries[patchNames[k]] = [] start = i + 1 end = start + patchFaces[i] i += 1 for j in range(start, end): boundaries[patchNames[k]].append( foamMesh._foamFaceLabelToUuid[patchFaces[j]]) i += 1 k += 1 foamMesh._boundaries = boundaries return foamMesh
def create_dummy_celldata(name, data_name, io=False): """Creates dummy cell data to OpenFoams objectRegistry and writes to case directory if path defined Parameters ---------- name : str Name of mesh data_name : str Name of data to be created io : boolean if True write data to disk """ nCells = foamface.getCellCount(name) iomode = 1 if io else 0 if dataTypeMap[dataKeyMap[data_name]] in cellDataTypes: dimension = dataDimensionMap[dataKeyMap[data_name]] if dataTypeMap[dataKeyMap[data_name]] == 'vector': values = [0.0] * (3 * nCells) foamface.setAllCellVectorData(name, data_name, iomode, values, dimension) elif dataTypeMap[dataKeyMap[data_name]] == 'scalar': values = [0.0] * nCells if dataKeyMap[data_name] == CUBA.VOLUME_FRACTION: foamface.setAllCellData(name, data_name + '.' + phaseNames[0], iomode, values, dimension) else: foamface.setAllCellData(name, data_name, iomode, values, dimension) elif dataTypeMap[dataKeyMap[data_name]] == 'tensor': values = [0.0] * (nCells * 9) foamface.setAllCellTensorData(name, data_name, iomode, values, dimension)