+ // --- get detailed info of number of cells of each type, allocate SMDS_downward structures
+
+ const SMDS_MeshInfo &meshInfo = _mesh->GetMeshInfo();
+
+ int nbLinTetra = meshInfo.NbTetras(ORDER_LINEAR);
+ int nbQuadTetra = meshInfo.NbTetras(ORDER_QUADRATIC);
+ int nbLinPyra = meshInfo.NbPyramids(ORDER_LINEAR);
+ int nbQuadPyra = meshInfo.NbPyramids(ORDER_QUADRATIC);
+ int nbLinPrism = meshInfo.NbPrisms(ORDER_LINEAR);
+ int nbQuadPrism = meshInfo.NbPrisms(ORDER_QUADRATIC);
+ int nbLinHexa = meshInfo.NbHexas(ORDER_LINEAR);
+ int nbQuadHexa = meshInfo.NbHexas(ORDER_QUADRATIC);
+
+ int nbLineGuess = int((4.0 / 3.0) * nbLinTetra + 2 * nbLinPrism + 2.5 * nbLinPyra + 3 * nbLinHexa);
+ int nbQuadEdgeGuess = int((4.0 / 3.0) * nbQuadTetra + 2 * nbQuadPrism + 2.5 * nbQuadPyra + 3 * nbQuadHexa);
+ int nbLinTriaGuess = 2 * nbLinTetra + nbLinPrism + 2 * nbLinPyra;
+ int nbQuadTriaGuess = 2 * nbQuadTetra + nbQuadPrism + 2 * nbQuadPyra;
+ int nbLinQuadGuess = int((2.0 / 3.0) * nbLinPrism + (1.0 / 2.0) * nbLinPyra + 3 * nbLinHexa);
+ int nbQuadQuadGuess = int((2.0 / 3.0) * nbQuadPrism + (1.0 / 2.0) * nbQuadPyra + 3 * nbQuadHexa);
+
+ int GuessSize[VTK_QUADRATIC_TETRA];
+ GuessSize[VTK_LINE] = nbLineGuess;
+ GuessSize[VTK_QUADRATIC_EDGE] = nbQuadEdgeGuess;
+ GuessSize[VTK_TRIANGLE] = nbLinTriaGuess;
+ GuessSize[VTK_QUADRATIC_TRIANGLE] = nbQuadTriaGuess;
+ GuessSize[VTK_QUAD] = nbLinQuadGuess;
+ GuessSize[VTK_QUADRATIC_QUAD] = nbQuadQuadGuess;
+ GuessSize[VTK_TETRA] = nbLinTetra;
+ GuessSize[VTK_QUADRATIC_TETRA] = nbQuadTetra;
+ GuessSize[VTK_PYRAMID] = nbLinPyra;
+ GuessSize[VTK_QUADRATIC_PYRAMID] = nbQuadPyra;
+ GuessSize[VTK_WEDGE] = nbLinPrism;
+ GuessSize[VTK_QUADRATIC_WEDGE] = nbQuadPrism;
+ GuessSize[VTK_HEXAHEDRON] = nbLinHexa;
+ GuessSize[VTK_QUADRATIC_HEXAHEDRON] = nbQuadHexa;
+
+ _downArray[VTK_LINE]->allocate(nbLineGuess);
+ _downArray[VTK_QUADRATIC_EDGE]->allocate(nbQuadEdgeGuess);
+ _downArray[VTK_TRIANGLE]->allocate(nbLinTriaGuess);
+ _downArray[VTK_QUADRATIC_TRIANGLE]->allocate(nbQuadTriaGuess);
+ _downArray[VTK_QUAD]->allocate(nbLinQuadGuess);
+ _downArray[VTK_QUADRATIC_QUAD]->allocate(nbQuadQuadGuess);
+ _downArray[VTK_TETRA]->allocate(nbLinTetra);
+ _downArray[VTK_QUADRATIC_TETRA]->allocate(nbQuadTetra);
+ _downArray[VTK_PYRAMID]->allocate(nbLinPyra);
+ _downArray[VTK_QUADRATIC_PYRAMID]->allocate(nbQuadPyra);
+ _downArray[VTK_WEDGE]->allocate(nbLinPrism);
+ _downArray[VTK_QUADRATIC_WEDGE]->allocate(nbQuadPrism);
+ _downArray[VTK_HEXAHEDRON]->allocate(nbLinHexa);
+ _downArray[VTK_QUADRATIC_HEXAHEDRON]->allocate(nbQuadHexa);
+
+ // --- iteration on vtkUnstructuredGrid cells, only faces
+ // for each vtk face:
+ // create a downward face entry with its downward id.
+ // compute vtk volumes, create downward volumes entry.
+ // mark face in downward volumes
+ // mark volumes in downward face
+
+ MESSAGE("--- iteration on vtkUnstructuredGrid cells, only faces");CHRONO(20);
+ int cellSize = this->Types->GetNumberOfTuples();
+ _cellIdToDownId.resize(cellSize, -1);
+
+ for (int i = 0; i < cellSize; i++)
+ {
+ int vtkFaceType = this->GetCellType(i);
+ if (SMDS_Downward::getCellDimension(vtkFaceType) == 2)
+ {
+ int vtkFaceId = i;
+ //ASSERT(_downArray[vtkFaceType]);
+ int connFaceId = _downArray[vtkFaceType]->addCell(vtkFaceId);
+ SMDS_Down2D* downFace = static_cast<SMDS_Down2D*> (_downArray[vtkFaceType]);
+ downFace->setTempNodes(connFaceId, vtkFaceId);
+ int vols[2] = { -1, -1 };
+ int nbVolumes = downFace->computeVolumeIds(vtkFaceId, vols);
+ //MESSAGE("nbVolumes="<< nbVolumes);
+ for (int ivol = 0; ivol < nbVolumes; ivol++)
+ {
+ int vtkVolId = vols[ivol];
+ int vtkVolType = this->GetCellType(vtkVolId);
+ //ASSERT(_downArray[vtkVolType]);
+ int connVolId = _downArray[vtkVolType]->addCell(vtkVolId);
+ _downArray[vtkVolType]->addDownCell(connVolId, connFaceId, vtkFaceType);
+ _downArray[vtkFaceType]->addUpCell(connFaceId, connVolId, vtkVolType);
+ // MESSAGE("Face " << vtkFaceId << " belongs to volume " << vtkVolId);
+ }
+ }
+ }
+
+ // --- iteration on vtkUnstructuredGrid cells, only volumes
+ // for each vtk volume:
+ // create downward volumes entry if not already done
+ // build a temporary list of faces described with their nodes
+ // for each face
+ // compute the vtk volumes containing this face
+ // check if the face is already listed in the volumes (comparison of ordered list of nodes)
+ // if not, create a downward face entry (resizing of structure required)
+ // (the downward faces store a temporary list of nodes to ease the comparison)
+ // create downward volumes entry if not already done
+ // mark volumes in downward face
+ // mark face in downward volumes
+
+ CHRONOSTOP(20);
+ MESSAGE("--- iteration on vtkUnstructuredGrid cells, only volumes");CHRONO(21);
+
+ for (int i = 0; i < cellSize; i++)
+ {
+ int vtkType = this->GetCellType(i);
+ if (SMDS_Downward::getCellDimension(vtkType) == 3)
+ {
+ //CHRONO(31);
+ int vtkVolId = i;
+ // MESSAGE("vtk volume " << vtkVolId);
+ //ASSERT(_downArray[vtkType]);
+ int connVolId = _downArray[vtkType]->addCell(vtkVolId);
+
+ // --- find all the faces of the volume, describe the faces by their nodes
+
+ SMDS_Down3D* downVol = static_cast<SMDS_Down3D*> (_downArray[vtkType]);
+ ListElemByNodesType facesWithNodes;
+ downVol->computeFacesWithNodes(vtkVolId, facesWithNodes);
+ // MESSAGE("vtk volume " << vtkVolId << " contains " << facesWithNodes.nbElems << " faces");
+ //CHRONOSTOP(31);
+ for (int iface = 0; iface < facesWithNodes.nbElems; iface++)
+ {
+ // --- find the volumes containing the face
+
+ //CHRONO(32);
+ int vtkFaceType = facesWithNodes.elems[iface].vtkType;
+ SMDS_Down2D* downFace = static_cast<SMDS_Down2D*> (_downArray[vtkFaceType]);
+ int vols[2] = { -1, -1 };
+ int *nodes = &facesWithNodes.elems[iface].nodeIds[0];
+ int lg = facesWithNodes.elems[iface].nbNodes;
+ int nbVolumes = downFace->computeVolumeIdsFromNodesFace(nodes, lg, vols);
+ // MESSAGE("vtk volume " << vtkVolId << " face " << iface << " belongs to " << nbVolumes << " volumes");
+
+ // --- check if face is registered in the volumes
+ //CHRONOSTOP(32);
+
+ //CHRONO(33);
+ int connFaceId = -1;
+ for (int ivol = 0; ivol < nbVolumes; ivol++)
+ {
+ int vtkVolId2 = vols[ivol];
+ int vtkVolType = this->GetCellType(vtkVolId2);
+ //ASSERT(_downArray[vtkVolType]);
+ int connVolId2 = _downArray[vtkVolType]->addCell(vtkVolId2);
+ SMDS_Down3D* downVol2 = static_cast<SMDS_Down3D*> (_downArray[vtkVolType]);
+ connFaceId = downVol2->FindFaceByNodes(connVolId2, facesWithNodes.elems[iface]);
+ if (connFaceId >= 0)
+ break; // --- face already created
+ }//CHRONOSTOP(33);
+
+ // --- if face is not registered in the volumes, create face
+
+ //CHRONO(34);
+ if (connFaceId < 0)
+ {
+ connFaceId = _downArray[vtkFaceType]->addCell();
+ downFace->setTempNodes(connFaceId, facesWithNodes.elems[iface]);
+ }//CHRONOSTOP(34);
+
+ // --- mark volumes in downward face and mark face in downward volumes
+
+ //CHRONO(35);
+ for (int ivol = 0; ivol < nbVolumes; ivol++)
+ {
+ int vtkVolId2 = vols[ivol];
+ int vtkVolType = this->GetCellType(vtkVolId2);
+ //ASSERT(_downArray[vtkVolType]);
+ int connVolId2 = _downArray[vtkVolType]->addCell(vtkVolId2);
+ _downArray[vtkVolType]->addDownCell(connVolId2, connFaceId, vtkFaceType);
+ _downArray[vtkFaceType]->addUpCell(connFaceId, connVolId2, vtkVolType);
+ // MESSAGE(" From volume " << vtkVolId << " face " << connFaceId << " belongs to volume " << vtkVolId2);
+ }//CHRONOSTOP(35);
+ }
+ }
+ }
+
+ // --- iteration on vtkUnstructuredGrid cells, only edges
+ // for each vtk edge:
+ // create downward edge entry
+ // store the nodes id's in downward edge (redundant with vtkUnstructuredGrid)
+ // find downward faces
+ // (from vtk faces or volumes, get downward faces, they have a temporary list of nodes)
+ // mark edge in downward faces
+ // mark faces in downward edge
+
+ CHRONOSTOP(21);
+ MESSAGE("--- iteration on vtkUnstructuredGrid cells, only edges");CHRONO(22);
+
+ for (int i = 0; i < cellSize; i++)
+ {
+ int vtkEdgeType = this->GetCellType(i);
+ if (SMDS_Downward::getCellDimension(vtkEdgeType) == 1)
+ {
+ int vtkEdgeId = i;
+ //ASSERT(_downArray[vtkEdgeType]);
+ int connEdgeId = _downArray[vtkEdgeType]->addCell(vtkEdgeId);
+ SMDS_Down1D* downEdge = static_cast<SMDS_Down1D*> (_downArray[vtkEdgeType]);
+ downEdge->setNodes(connEdgeId, vtkEdgeId);
+ vector<int> vtkIds;
+ int nbVtkCells = downEdge->computeVtkCells(connEdgeId, vtkIds);
+ int downFaces[1000];
+ unsigned char downTypes[1000];
+ int nbDownFaces = downEdge->computeFaces(connEdgeId, &vtkIds[0], nbVtkCells, downFaces, downTypes);
+ for (int n = 0; n < nbDownFaces; n++)
+ {
+ _downArray[downTypes[n]]->addDownCell(downFaces[n], connEdgeId, vtkEdgeType);
+ _downArray[vtkEdgeType]->addUpCell(connEdgeId, downFaces[n], downTypes[n]);
+ }
+ }
+ }
+
+ // --- iteration on downward faces (they are all listed now)
+ // for each downward face:
+ // build a temporary list of edges with their ordered list of nodes
+ // for each edge:
+ // find all the vtk cells containing this edge
+ // then identify all the downward faces containing the edge, from the vtk cells
+ // check if the edge is already listed in the faces (comparison of ordered list of nodes)
+ // if not, create a downward edge entry with the node id's
+ // mark edge in downward faces
+ // mark downward faces in edge (size of list unknown, to be allocated)
+
+ CHRONOSTOP(22);CHRONO(23);
+
+ for (int vtkFaceType = 0; vtkFaceType < VTK_QUADRATIC_PYRAMID; vtkFaceType++)
+ {
+ if (SMDS_Downward::getCellDimension(vtkFaceType) != 2)
+ continue;
+
+ // --- find all the edges of the face, describe the edges by their nodes
+
+ SMDS_Down2D* downFace = static_cast<SMDS_Down2D*> (_downArray[vtkFaceType]);
+ int maxId = downFace->getMaxId();
+ for (int faceId = 0; faceId < maxId; faceId++)
+ {
+ //CHRONO(40);
+ ListElemByNodesType edgesWithNodes;
+ downFace->computeEdgesWithNodes(faceId, edgesWithNodes);
+ // MESSAGE("downward face type " << vtkFaceType << " num " << faceId << " contains " << edgesWithNodes.nbElems << " edges");
+
+ //CHRONOSTOP(40);
+ for (int iedge = 0; iedge < edgesWithNodes.nbElems; iedge++)
+ {
+
+ // --- check if the edge is already registered by exploration of the faces
+
+ //CHRONO(41);
+ vector<int> vtkIds;
+ unsigned char vtkEdgeType = edgesWithNodes.elems[iedge].vtkType;
+ int *pts = &edgesWithNodes.elems[iedge].nodeIds[0];
+ SMDS_Down1D* downEdge = static_cast<SMDS_Down1D*> (_downArray[vtkEdgeType]);
+ int nbVtkCells = downEdge->computeVtkCells(pts, vtkIds);
+ //CHRONOSTOP(41);CHRONO(42);
+ int downFaces[1000];
+ unsigned char downTypes[1000];
+ int nbDownFaces = downEdge->computeFaces(pts, &vtkIds[0], nbVtkCells, downFaces, downTypes);
+ //CHRONOSTOP(42);
+
+ //CHRONO(43);
+ int connEdgeId = -1;
+ for (int idf = 0; idf < nbDownFaces; idf++)
+ {
+ int faceId2 = downFaces[idf];
+ int faceType = downTypes[idf];
+ //ASSERT(_downArray[faceType]);
+ SMDS_Down2D* downFace2 = static_cast<SMDS_Down2D*> (_downArray[faceType]);
+ connEdgeId = downFace2->FindEdgeByNodes(faceId2, edgesWithNodes.elems[iedge]);
+ if (connEdgeId >= 0)
+ break; // --- edge already created
+ }//CHRONOSTOP(43);
+
+ // --- if edge is not registered in the faces, create edge
+
+ if (connEdgeId < 0)
+ {
+ //CHRONO(44);
+ connEdgeId = _downArray[vtkEdgeType]->addCell();
+ downEdge->setNodes(connEdgeId, edgesWithNodes.elems[iedge].nodeIds);
+ //CHRONOSTOP(44);
+ }
+
+ // --- mark faces in downward edge and mark edge in downward faces
+
+ //CHRONO(45);
+ for (int idf = 0; idf < nbDownFaces; idf++)
+ {
+ int faceId2 = downFaces[idf];
+ int faceType = downTypes[idf];
+ //ASSERT(_downArray[faceType]);
+ SMDS_Down2D* downFace2 = static_cast<SMDS_Down2D*> (_downArray[faceType]);
+ _downArray[vtkEdgeType]->addUpCell(connEdgeId, faceId2, faceType);
+ _downArray[faceType]->addDownCell(faceId2, connEdgeId, vtkEdgeType);
+ // MESSAGE(" From face t:" << vtkFaceType << " " << faceId <<
+ // " edge " << connEdgeId << " belongs to face t:" << faceType << " " << faceId2);
+ }//CHRONOSTOP(45);
+ }
+ }
+ }
+
+ CHRONOSTOP(23);CHRONO(24);
+
+ // compact downward connectivity structure: adjust downward arrays size, replace vector<vector int>> by a single vector<int>
+ // 3D first then 2D and last 1D to release memory before edge upCells reorganization, (temporary memory use)
+
+ for (int vtkType = VTK_QUADRATIC_PYRAMID; vtkType >= 0; vtkType--)
+ {
+ if (SMDS_Downward *down = _downArray[vtkType])
+ {
+ down->compactStorage();
+ }
+ }
+
+ // --- Statistics
+
+ for (int vtkType = 0; vtkType <= VTK_QUADRATIC_PYRAMID; vtkType++)
+ {
+ if (SMDS_Downward *down = _downArray[vtkType])
+ {
+ if (down->getMaxId())
+ {
+ MESSAGE("Cells of Type " << vtkType << " : number of entities, est: "
+ << GuessSize[vtkType] << " real: " << down->getMaxId());
+ }
+ }
+ }CHRONOSTOP(24);CHRONOSTOP(2);
+ _counters->stats();
+}