I am doing a little project on solving the heat equation using finite-volume method on a solid cube, I converted the polyhedral mesh of the cube to an OpenFOAM mesh.I have a Python code where I parse the points, faces, owner, neighbour and boundary files of the OF case mesh, I've managed to create a hash list (let's call it CellFacesMap) to map the cell number to the list of its owned faces and faces neighbours to it. Now, I am trying to generate a hash list (let's call it CellAdjacentsMap that maps each cell with all its adjacent cells, in order to apply the discretized heat equation to each cell (and also for generating the volume weighting factors).The only way I could think of now to do so is to visit each cell in CellFacesMap and for the owned faces I get the cells neighbor to this face (adjacent cells) and for faces neighbor the same cell I get the cells that owns theses faces (also adjacent cells), meaning I visit CellFacesMap over and over for each cell to check its faces.But this method is costly (time wise, it took 3.5 minutes to generate a map for 4000+ cell mesh). So is there any faster way to generate CellAdjacentsMap?
Getting adjacent cells map for an unstructured polyhedral mesh
finite volume;mesh;openfoam;unstructured mesh;mesh traversal
I'm assuming you are starting with a list of cell definitions, say,as a list of vertices defining the cell and a type defining thetopology of each cell. As part of the topology definition for eachcell, you can easily get the faces for that cell defined, say, asa list of vertices.The first step in creating the CellAdjacentsMap that you need is tofirst create a map that I'll call FaceCellMap that lists the cells(either one or two) that each face belongs to. You do this byiterating over all cells, adding each cell's faces to the map, oneby one.There are some implementation details in forming this FaceCellMap.The first is what data structure do you use? If you have a generalHashMap capability, the key can be face definition and the valuecan be a length-two array of cell IDs (one of the entries may bezero). The second issue is how do you compare faces? You can usea list of vertices but you have implement the comparison functionin such a way that it is insensitive to the starting vertex andwhether you traverse the vertex list in clockwise or counterclockwiseorder.But after you have created FaceCellMap, creating CellAdjacentsMap isstraightforward. You iterate through all the cells. For each cell, you iterate through all its faces. For each face, you check theFaceCellMap for that face to see if it has an adjacent cell. If soyou add it to the list of adjacencies for the current cell.