diff --git a/Cassiopee/KCore/KCore/Connect/ngonTools.cpp b/Cassiopee/KCore/KCore/Connect/ngonTools.cpp index ead70cc30..f607fcc00 100644 --- a/Cassiopee/KCore/KCore/Connect/ngonTools.cpp +++ b/Cassiopee/KCore/KCore/Connect/ngonTools.cpp @@ -292,7 +292,7 @@ void K_CONNECT::reversi_connex(E_Int *pgs, E_Int *xpgs, E_Int npgs, for (E_Int i = xpgs[K]; i < xpgs[K+1]; i++) { E_Int nei = neighbours[i]; - if (processed[nei] || nei == -1) + if (nei == -1 || processed[nei]) continue; // get the shared edge between face K and face nei diff --git a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp index dda359181..ccba4d9ae 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_AssignRefData.cpp @@ -35,17 +35,19 @@ PyObject *K_XCORE::AdaptMesh_AssignRefData(PyObject *self, PyObject *args) Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh"); - //assert(M->cref == NULL); - //assert(M->fref == NULL); - XFREE(M->cref); - + Int *ptr = NULL; Int ret, nfld, size; - ret = K_NUMPY::getFromNumpyArray(CREF, M->cref, size, nfld, false); + ret = K_NUMPY::getFromNumpyArray(CREF, ptr, size, nfld, true); if (ret != 1 || size != M->nc || nfld != 1) { RAISE("Bad cref input."); return NULL; } + M->cref = (Int *)XRESIZE(M->cref, M->nc * sizeof(Int)); + for (Int i = 0; i < M->nc; i++) M->cref[i] = ptr[i]; + + Py_DECREF(CREF); + // Allocate patch buffers for (Int i = 0; i < M->npp; i++) { diff --git a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_ExtractData.cpp b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_ExtractData.cpp index 76a1a4538..7e43f656b 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_ExtractData.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_ExtractData.cpp @@ -35,7 +35,7 @@ PyObject *K_XCORE::AdaptMesh_ExtractOwners(PyObject *self, PyObject *args) Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh"); - if (M->pid == 0) puts("Extracting owners..."); + if (M->pid == 0) puts("Extracting face owners..."); npy_intp dims[2]; @@ -52,6 +52,39 @@ PyObject *K_XCORE::AdaptMesh_ExtractOwners(PyObject *self, PyObject *args) return (PyObject *)OWN; } +PyObject *K_XCORE::AdaptMesh_ExtractNeighbours(PyObject *self, PyObject *args) +{ + PyObject *MESH; + + if (!PYPARSETUPLE_(args, O_, &MESH)) { + RAISE("Wrong input."); + return NULL; + } + + if (!PyCapsule_IsValid(MESH, "AdaptMesh")) { + RAISE("Bad mesh hook."); + return NULL; + } + + Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh"); + + if (M->pid == 0) puts("Extracting face neighbours..."); + + npy_intp dims[2]; + + dims[1] = 1; + dims[0] = (npy_intp)M->nf; + PyArrayObject *NEI = (PyArrayObject *)PyArray_SimpleNew(1, dims, E_NPY_INT); + + Int *pn = (Int *)PyArray_DATA(NEI); + + for (Int i = 0; i < M->nf; i++) { + pn[i] = M->neigh[i]; + } + + return (PyObject *)NEI; +} + PyObject *K_XCORE::AdaptMesh_ExtractCellLevels(PyObject *self, PyObject *args) { PyObject *MESH; @@ -86,7 +119,40 @@ PyObject *K_XCORE::AdaptMesh_ExtractCellLevels(PyObject *self, PyObject *args) } -PyObject *K_XCORE::AdaptMesh_ExtractNeighbourCellLevels(PyObject *self, PyObject *args) +PyObject *K_XCORE::AdaptMesh_ExtractCellRanges(PyObject *self, PyObject *args) +{ + PyObject *MESH; + + if (!PYPARSETUPLE_(args, O_, &MESH)) { + RAISE("Wrong input."); + return NULL; + } + + if (!PyCapsule_IsValid(MESH, "AdaptMesh")) { + RAISE("Bad mesh hook."); + return NULL; + } + + Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh"); + + if (M->pid == 0) puts("Extracting cell ranges..."); + + PyObject *STR = K_NUMPY::buildNumpyArray(M->nc, 6, 1, 1); + + Int *ptr = K_NUMPY::getNumpyPtrI(STR); + + for (Int cid = 0; cid < M->nc; cid++) { + Int *crange = Mesh_get_crange(M, cid); + + for (Int j = 0; j < M->cstride[cid]; j++) { + ptr[cid + j*M->nc] = crange[j]; + } + } + + return (PyObject *)STR; +} + +PyObject *K_XCORE::AdaptMesh_ExtractHaloCellLevels(PyObject *self, PyObject *args) { PyObject *MESH; @@ -102,7 +168,7 @@ PyObject *K_XCORE::AdaptMesh_ExtractNeighbourCellLevels(PyObject *self, PyObject Mesh *M = (Mesh *)PyCapsule_GetPointer(MESH, "AdaptMesh"); - if (M->pid == 0) puts("Extracting neighbour cell levels..."); + if (M->pid == 0) puts("Extracting halo cell levels..."); // Allocate diff --git a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp index b1ac4add1..dbe290198 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/AdaptMesh_Init.cpp @@ -98,8 +98,12 @@ PyObject *K_XCORE::AdaptMesh_Init(PyObject *self, PyObject *args) assert(PyList_Size(PATCH) == 4); // TODO(Imad): error check - K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 0), M->bps[i].pf, - M->bps[i].nf, false); + Int *ptr = NULL; + K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 0), ptr, + M->bps[i].nf, true); + + M->bps[i].pf = IntArray(M->bps[i].nf); + for (Int j = 0; j < M->bps[i].nf; j++) M->bps[i].pf[j] = ptr[j]; M->bps[i].gid = PyLong_AsLong(PyList_GetItem(PATCH, 1)); @@ -153,12 +157,20 @@ PyObject *K_XCORE::AdaptMesh_Init(PyObject *self, PyObject *args) M->pps[i].nei = PyLong_AsLong(PyList_GetItem(PATCH, 0)); // TODO(Imad): error check + Int *ptr = NULL; K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 1), - M->pps[i].pf, M->pps[i].nf, false); + ptr, M->pps[i].nf, true); + + M->pps[i].pf = IntArray(M->pps[i].nf); + memcpy(M->pps[i].pf, ptr, M->pps[i].nf * sizeof(Int)); // TODO(Imad): error check + ptr = NULL; K_NUMPY::getFromNumpyArray(PyList_GetItem(PATCH, 2), - M->pps[i].pn, M->pps[i].nf, false); + ptr, M->pps[i].nf, true); + + M->pps[i].pn = IntArray(M->pps[i].nf); + memcpy(M->pps[i].pn, ptr, M->pps[i].nf * sizeof(Int)); // Zero-based for (Int j = 0; j < M->pps[i].nf; j++) { diff --git a/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp b/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp index ed08f370e..f2f5cfcc9 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/MeshComm.cpp @@ -575,6 +575,8 @@ Int Mesh_redistribute(Mesh *M, Int *cmap) assert(rpdist[M->npc] == np); + XFREE(rpoints); + // Send coordinates if (M->pid == 0) puts(" Exchanging point coordinates..."); diff --git a/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp b/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp index b11595721..13f68d13b 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/MeshIO.cpp @@ -610,6 +610,8 @@ PyObject *export_conformal_mesh(Mesh *M) } } + RELEASESHAREDU(karray, f, cn); + PyObject *out = PyList_New(0); PyList_Append(out, karray); diff --git a/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp b/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp index 59e714802..31998a8b4 100644 --- a/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp +++ b/Cassiopee/XCore/XCore/AdaptMesh/MeshRefine.cpp @@ -47,15 +47,15 @@ void Mesh_get_ref_entities(Mesh *M, std::vector &ref_cells, for (Int fid : ref_faces) { Int *face = Mesh_get_face(M, fid); Int *frange = Mesh_get_frange(M, fid); + Int size = 2 * M->fstride[fid]; + assert(size == 8); - for (Int i = 0; i < M->fstride[fid]; i++) { - if (frange[i] == 2) continue; + for (Int i = 0; i < size; i += 2) { + if (frange[i/2] == 2) continue; - Int *pn = face + 2*i; - - Int p = pn[0]; - assert(pn[1] == -1); - Int q = pn[2]; + Int p = face[i]; + assert(face[i+1] == -1); + Int q = face[(i+2)%size]; UEdge E(p, q); auto it = ref_edges.find(E); diff --git a/Cassiopee/XCore/XCore/PyTree.py b/Cassiopee/XCore/XCore/PyTree.py index 3f523ad36..0173efb9d 100644 --- a/Cassiopee/XCore/XCore/PyTree.py +++ b/Cassiopee/XCore/XCore/PyTree.py @@ -76,11 +76,17 @@ def AdaptMesh_ExtractMesh(t, conformize=1): def AdaptMesh_ExtractOwners(AM): return xcore.AdaptMesh_ExtractOwners(AM) +def AdaptMesh_ExtractNeighbours(AM): + return xcore.AdaptMesh_ExtractNeighbours(AM) + def AdaptMesh_ExtractCellLevels(AM): return xcore.AdaptMesh_ExtractCellLevels(AM) -def AdaptMesh_ExtractNeighbourCellLevels(AM): - return xcore.AdaptMesh_ExtractNeighbourCellLevels(AM) +def AdaptMesh_ExtractCellRanges(AM): + return xcore.AdaptMesh_ExtractCellRanges(AM) + +def AdaptMesh_ExtractHaloCellLevels(AM): + return xcore.AdaptMesh_ExtractHaloCellLevels(AM) ################################################################################ diff --git a/Cassiopee/XCore/XCore/chunk2partNGon.cpp b/Cassiopee/XCore/XCore/chunk2partNGon.cpp index 3ac13d27d..a43674f47 100644 --- a/Cassiopee/XCore/XCore/chunk2partNGon.cpp +++ b/Cassiopee/XCore/XCore/chunk2partNGon.cpp @@ -427,7 +427,7 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) } std::vector part(ncells); - ret = SCOTCH_dgraphPart(&graph, nproc, &strat, &part[0]); + ret = SCOTCH_dgraphPart(&graph, nproc, &strat, &part[0]); if (ret != 0) { fprintf(stderr, "SCOTCH_dgraphPart(): Failed to map graph\n"); @@ -436,6 +436,9 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) if (rank == 0) printf("Graph map OK\n"); + SCOTCH_dgraphExit(&graph); + SCOTCH_stratExit(&strat); + // Send cells to their target proc! std::vector c_scount(nproc, 0); std::vector c_rcount(nproc, 0); @@ -790,6 +793,9 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) &rdata[0], &rcount[0], &rdist[0], XMPI_INT, MPI_COMM_WORLD); + + XFREE(faces_dist); + std::vector pneis; E_Int nif = 0; @@ -1063,8 +1069,14 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) Py_DECREF(f); Py_DECREF(n); PyList_Append(comm_data, arr); + + delete ppatches[i]; } + delete [] ppatches; + + + PyList_Append(out, comm_data); Py_DECREF(comm_data); @@ -1118,6 +1130,8 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) Py_DECREF(clist); } + XFREE(cells_dist); + // 9 must be an array of FlowSolutions chunks o = PyList_GetItem(l, 8); E_Int psize = PyList_Size(o); @@ -1166,6 +1180,8 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) Py_DECREF(plist); } + XFREE(points_dist); + // 10 must be an array of PointList chunks o = PyList_GetItem(l, 9); E_Int nbc = PyList_Size(o); @@ -1191,6 +1207,9 @@ PyObject* K_XCORE::chunk2partNGon(PyObject *self, PyObject *args) // Note(Imad): we could free up plists[i] and bcsize[i] here } + XFREE(plists); + XFREE(bcsize); + // make local PE std::unordered_map> lPE; for (E_Int i = 0; i < nncells; i++) { diff --git a/Cassiopee/XCore/XCore/xcore.cpp b/Cassiopee/XCore/XCore/xcore.cpp index ba92c90bd..e48435f91 100644 --- a/Cassiopee/XCore/XCore/xcore.cpp +++ b/Cassiopee/XCore/XCore/xcore.cpp @@ -39,8 +39,10 @@ static PyMethodDef Pyxcore [] = {"AdaptMesh_ExtractMesh", K_XCORE::AdaptMesh_ExtractMesh, METH_VARARGS}, {"AdaptMesh_ExtractOwners", K_XCORE::AdaptMesh_ExtractOwners, METH_VARARGS}, + {"AdaptMesh_ExtractNeighbours", K_XCORE::AdaptMesh_ExtractNeighbours, METH_VARARGS}, {"AdaptMesh_ExtractCellLevels", K_XCORE::AdaptMesh_ExtractCellLevels, METH_VARARGS}, - {"AdaptMesh_ExtractNeighbourCellLevels", K_XCORE::AdaptMesh_ExtractNeighbourCellLevels, METH_VARARGS}, + {"AdaptMesh_ExtractCellRanges", K_XCORE::AdaptMesh_ExtractCellRanges, METH_VARARGS}, + {"AdaptMesh_ExtractHaloCellLevels", K_XCORE::AdaptMesh_ExtractHaloCellLevels, METH_VARARGS}, {"intersectSurf", K_XCORE::intersectSurf, METH_VARARGS}, {"removeIntersectingKPlanes", K_XCORE::removeIntersectingKPlanes, METH_VARARGS}, diff --git a/Cassiopee/XCore/XCore/xcore.h b/Cassiopee/XCore/XCore/xcore.h index dbd0eddae..f3235a085 100644 --- a/Cassiopee/XCore/XCore/xcore.h +++ b/Cassiopee/XCore/XCore/xcore.h @@ -48,8 +48,10 @@ namespace K_XCORE PyObject *AdaptMesh_ExtractMesh(PyObject *self, PyObject *args); PyObject *AdaptMesh_ExtractOwners(PyObject *self, PyObject *args); + PyObject *AdaptMesh_ExtractNeighbours(PyObject *self, PyObject *args); PyObject *AdaptMesh_ExtractCellLevels(PyObject *self, PyObject *args); - PyObject *AdaptMesh_ExtractNeighbourCellLevels(PyObject *self, PyObject *args); + PyObject *AdaptMesh_ExtractCellRanges(PyObject *self, PyObject *args); + PyObject *AdaptMesh_ExtractHaloCellLevels(PyObject *self, PyObject *args); PyObject *intersectSurf(PyObject *self, PyObject *args); PyObject *removeIntersectingKPlanes(PyObject *self, PyObject *args); diff --git a/Cassiopee/XCore/setup.scons b/Cassiopee/XCore/setup.scons index 9c0d2eee2..acf289327 100644 --- a/Cassiopee/XCore/setup.scons +++ b/Cassiopee/XCore/setup.scons @@ -56,25 +56,20 @@ if mpi: libraries += mpiLibs libraryDirs += paths; libraries += libs # Specific options for scotch -#opt1 =['-DCOMMON_FILE_COMPRESS_GZ','-DCOMMON_PTHREAD', -# '-DCOMMON_RANDOM_FIXED_SEED', '-DSCOTCH_DETERMINISTIC', -# '-DSCOTCH_RENAME','-DIDXSIZE64','-DSCOTCH_MPI_ASYNC_COLL', -# '-DSCOTCH_PTHREAD','-DSCOTCH_PTHREAD_MPI', -# '-DSCOTCH_VERSION_NUM=7','-DSCOTCH_RELEASE_NUM=0','-DSCOTCH_PATCHLEVEL_NUM=4', -# '-IXCore/scotch'] - -opt1 =['-DCOMMON_FILE_COMPRESS_GZ', +opt1 =['-DCOMMON_FILE_COMPRESS_GZ','-DCOMMON_PTHREAD', '-DCOMMON_RANDOM_FIXED_SEED', '-DSCOTCH_DETERMINISTIC', '-DSCOTCH_RENAME','-DIDXSIZE64','-DSCOTCH_MPI_ASYNC_COLL', + '-DSCOTCH_PTHREAD','-DSCOTCH_PTHREAD_MPI', '-DSCOTCH_VERSION_NUM=7','-DSCOTCH_RELEASE_NUM=0','-DSCOTCH_PATCHLEVEL_NUM=4', '-IXCore/scotch'] opt1_1 = ['-DSCOTCH_PTSCOTCH'] -#opt1_1 = [] + +if Dist.DEBUG: opt1 += ['-DSCOTCH_DEBUG_FULL'] if Dist.GDOUBLEINT: opt1 += ['-DINTSIZE64'] else: opt1 += ['-DINTSIZE32'] -if cc == 'gcc': opt1 += [] # ['-Wrestrict'] +if cc == 'gcc': opt1 += ['-Drestrict=__restrict'] # ['-Wrestrict'] elif cc == 'pgcc': opt1 += [] elif cc == 'nvc': opt1 += [] elif cc == 'icx': opt1 += []