From: ageay Date: Thu, 14 Jun 2012 14:05:46 +0000 (+0000) Subject: duplication of nodes along meshdim-1 group. X-Git-Tag: V6_main_FINAL~647 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0e0c698d4f236026c6a915b2f92a677eba2e9868;p=tools%2Fmedcoupling.git duplication of nodes along meshdim-1 group. --- diff --git a/src/MEDCoupling_Swig/MEDCoupling.i b/src/MEDCoupling_Swig/MEDCoupling.i index 3a007ff18..4728fb379 100644 --- a/src/MEDCoupling_Swig/MEDCoupling.i +++ b/src/MEDCoupling_Swig/MEDCoupling.i @@ -237,6 +237,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingMesh::buildUnstructured; %newobject ParaMEDMEM::MEDCouplingMesh::MergeMeshes; %newobject ParaMEDMEM::MEDCouplingPointSet::zipCoordsTraducer; +%newobject ParaMEDMEM::MEDCouplingPointSet::findBoundaryNodes; %newobject ParaMEDMEM::MEDCouplingPointSet::buildBoundaryMesh; %newobject ParaMEDMEM::MEDCouplingPointSet::MergeNodesArray; %newobject ParaMEDMEM::MEDCouplingPointSet::BuildInstanceFromMeshType; @@ -253,6 +254,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::MEDCouplingUMesh::buildExtrudedMesh; %newobject ParaMEDMEM::MEDCouplingUMesh::MergeUMeshes; %newobject ParaMEDMEM::MEDCouplingUMesh::MergeUMeshesOnSameCoords; +%newobject ParaMEDMEM::MEDCouplingUMesh::ComputeSpreadZoneGradually; %newobject ParaMEDMEM::MEDCouplingUMesh::buildNewNumberingFromCommNodesFrmt; %newobject ParaMEDMEM::MEDCouplingUMesh::rearrange2ConsecutiveCellTypes; %newobject ParaMEDMEM::MEDCouplingUMesh::sortCellsInMEDFileFrmt; @@ -709,6 +711,7 @@ namespace ParaMEDMEM const std::vector& littleStrings) throw(INTERP_KERNEL::Exception); virtual void getCellsInBoundingBox(const INTERP_KERNEL::DirectedBoundingBox& bbox, double eps, std::vector& elems) throw(INTERP_KERNEL::Exception) = 0; virtual DataArrayInt *zipCoordsTraducer() throw(INTERP_KERNEL::Exception) = 0; + virtual DataArrayInt *findBoundaryNodes() const = 0; %extend { std::string __str__() const @@ -808,15 +811,7 @@ namespace ParaMEDMEM return convertMesh(ret, SWIG_POINTER_OWN | 0 ); } } - PyObject *findBoundaryNodes() const throw(INTERP_KERNEL::Exception) - { - std::vector nodes; - self->findBoundaryNodes(nodes); - DataArrayInt *ret=DataArrayInt::New(); - ret->alloc((int)nodes.size(),1); - std::copy(nodes.begin(),nodes.end(),ret->getPointer()); - return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); - } + void renumberNodes(PyObject *li, int newNbOfNodes) throw(INTERP_KERNEL::Exception) { void *da=0; @@ -929,6 +924,27 @@ namespace ParaMEDMEM return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); } + void duplicateNodesInCoords(PyObject *li) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->duplicateNodesInCoords(&singleVal,&singleVal+1); + case 2: + return self->duplicateNodesInCoords(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->duplicateNodesInCoords(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("MEDCouplingPointSet::duplicateNodesInCoords : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + static void Rotate2DAlg(PyObject *center, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) { int sz; @@ -1088,6 +1104,7 @@ namespace ParaMEDMEM static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); + static DataArrayInt *ComputeSpreadZoneGradually(const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception); %extend { std::string __str__() const { @@ -1156,6 +1173,70 @@ namespace ParaMEDMEM } } + void __setitem__(PyObject *li, const MEDCouplingUMesh& otherOnSameCoordsThanThis) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + int nbc=self->getNumberOfCells(); + convertObjToPossibleCpp2(li,nbc,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + if(singleVal>=nbc) + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + if(singleVal>=0) + { + self->setPartOfMySelf(&singleVal,&singleVal+1,otherOnSameCoordsThanThis); + break; + } + else + { + if(nbc+singleVal>0) + { + int tmp=nbc+singleVal; + self->setPartOfMySelf(&tmp,&tmp+1,otherOnSameCoordsThanThis); + break; + } + else + { + std::ostringstream oss; + oss << "Requesting for cell id " << singleVal << " having only " << nbc << " cells !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + case 2: + { + self->setPartOfMySelf(&multiVal[0],&multiVal[0]+multiVal.size(),otherOnSameCoordsThanThis); + break; + } + case 3: + { + MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::Range(slic.first,slic.second.first,slic.second.second); + self->setPartOfMySelf(d0->begin(),d0->end(),otherOnSameCoordsThanThis); + break; + } + case 4: + { + if(!daIntTyypp) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__setitem__ : null instance has been given in input !"); + daIntTyypp->checkAllocated(); + self->setPartOfMySelf(daIntTyypp->begin(),daIntTyypp->end(),otherOnSameCoordsThanThis); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::__setitem__ : unrecognized type in input ! Possibilities are : int, list or tuple of int DataArrayInt instance !"); + } + } + void insertNextCell(INTERP_KERNEL::NormalizedCellType type, int size, PyObject *li) throw(INTERP_KERNEL::Exception) { int sz; @@ -1264,6 +1345,58 @@ namespace ParaMEDMEM return ret; } + PyObject *findNodesToDuplicate(MEDCouplingUMesh& otherDimM1OnSameCoords) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *tmp0=0,*tmp1=0; + self->findNodesToDuplicate(otherDimM1OnSameCoords,tmp0,tmp1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(tmp0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(tmp1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + void duplicateNodes(PyObject *li) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->duplicateNodes(&singleVal,&singleVal+1); + case 2: + return self->duplicateNodes(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->duplicateNodes(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::duplicateNodes : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + void duplicateNodesInConn(PyObject *li, int offset) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(li,self->getNumberOfNodes(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->duplicateNodesInConn(&singleVal,&singleVal+1,offset); + case 2: + return self->duplicateNodesInConn(&multiVal[0],&multiVal[0]+multiVal.size(),offset); + case 4: + return self->duplicateNodesInConn(daIntTyypp->begin(),daIntTyypp->end(),offset); + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::duplicateNodesInConn : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + void renumberNodesInConn(PyObject *li) throw(INTERP_KERNEL::Exception) { void *da=0; @@ -1296,6 +1429,19 @@ namespace ParaMEDMEM return ret; } + static PyObject *AggregateSortedByTypeMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) + { + std::vector meshes; + convertPyObjToVecUMeshesCst(ms,meshes); + DataArrayInt *ret1=0,*ret2=0; + MEDCouplingUMesh *ret0=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(meshes,ret1,ret2); + PyObject *ret=PyTuple_New(3); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,2,SWIG_NewPointerObj(SWIG_as_voidptr(ret2),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + static PyObject *MergeUMeshesOnSameCoords(PyObject *ms) throw(INTERP_KERNEL::Exception) { std::vector meshes; @@ -1335,6 +1481,138 @@ namespace ParaMEDMEM MEDCouplingUMesh::MergeNodesOnUMeshesSharingSameCoords(meshes,eps); } + static bool RemoveIdsFromIndexedArrays(PyObject *li, DataArrayInt *arr, DataArrayInt *arrIndx, int offsetForRemoval=0) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!arrIndx) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : null pointer as arrIndex !"); + convertObjToPossibleCpp2(li,arrIndx->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(&singleVal,&singleVal+1,arr,arrIndx,offsetForRemoval); + case 2: + return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arr,arrIndx,offsetForRemoval); + case 4: + return MEDCouplingUMesh::RemoveIdsFromIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arr,arrIndx,offsetForRemoval); + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::RemoveIdsFromIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + static PyObject *ExtractFromIndexedArrays(PyObject *li, const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn) throw(INTERP_KERNEL::Exception) + { + DataArrayInt *arrOut=0,*arrIndexOut=0; + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!arrIndxIn) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : null pointer as arrIndxIn !"); + convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + MEDCouplingUMesh::ExtractFromIndexedArrays(&singleVal,&singleVal+1,arrIn,arrIndxIn,arrOut,arrIndexOut); + break; + } + case 2: + { + MEDCouplingUMesh::ExtractFromIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,arrOut,arrIndexOut); + break; + } + case 4: + { + MEDCouplingUMesh::ExtractFromIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,arrOut,arrIndexOut); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::ExtractFromIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(arrOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(arrIndexOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + static PyObject *SetPartOfIndexedArrays(PyObject *li, + const DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, + const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex) throw(INTERP_KERNEL::Exception) + { + DataArrayInt *arrOut=0,*arrIndexOut=0; + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!arrIndxIn) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : null pointer as arrIndex !"); + convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + MEDCouplingUMesh::SetPartOfIndexedArrays(&singleVal,&singleVal+1,arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); + break; + } + case 2: + { + MEDCouplingUMesh::SetPartOfIndexedArrays(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); + break; + } + case 4: + { + MEDCouplingUMesh::SetPartOfIndexedArrays(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,srcArr,srcArrIndex,arrOut,arrIndexOut); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArrays : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(arrOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(arrIndexOut),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + + static void SetPartOfIndexedArraysSameIdx(PyObject *li, DataArrayInt *arrIn, const DataArrayInt *arrIndxIn, + const DataArrayInt *srcArr, const DataArrayInt *srcArrIndex) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + if(!arrIndxIn) + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : null pointer as arrIndex !"); + convertObjToPossibleCpp2(li,arrIndxIn->getNumberOfTuples()-1,sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + { + MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(&singleVal,&singleVal+1,arrIn,arrIndxIn,srcArr,srcArrIndex); + break; + } + case 2: + { + MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(&multiVal[0],&multiVal[0]+multiVal.size(),arrIn,arrIndxIn,srcArr,srcArrIndex); + break; + } + case 4: + { + MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx(daIntTyypp->begin(),daIntTyypp->end(),arrIn,arrIndxIn,srcArr,srcArrIndex); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::SetPartOfIndexedArraysSameIdx : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + PyObject *are2DCellsNotCorrectlyOriented(PyObject *vec, bool polyOnly) const throw(INTERP_KERNEL::Exception) { std::vector cells; @@ -1466,6 +1744,16 @@ namespace ParaMEDMEM return ret; } + PyObject *computeNeighborsOfCellsAdv(const DataArrayInt *desc, const DataArrayInt *descI, const DataArrayInt *revDesc, const DataArrayInt *revDescI) const throw(INTERP_KERNEL::Exception) + { + DataArrayInt *neighbors=0,*neighborsIdx=0; + self->computeNeighborsOfCellsAdv(desc,descI,revDesc,revDescI,neighbors,neighborsIdx); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(neighbors),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(neighborsIdx),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } + PyObject *emulateMEDMEMBDC(const MEDCouplingUMesh *nM1LevMesh) { MEDCouplingAutoRefCountObjectPtr d0=DataArrayInt::New(); @@ -2550,7 +2838,7 @@ namespace ParaMEDMEM DataArrayDouble *__setitem__(PyObject *obj, PyObject *value) throw(INTERP_KERNEL::Exception) { self->checkAllocated(); - const char msg[]="Unexpected situation in __setitem__ !"; + const char msg[]="Unexpected situation in DataArrayDouble::__setitem__ !"; int nbOfTuples=self->getNumberOfTuples(); int nbOfComponents=self->getNumberOfComponents(); int sw1,sw2; @@ -3802,6 +4090,48 @@ namespace ParaMEDMEM } } + DataArrayInt *getIdsEqualList(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->getIdsEqualList(&singleVal,&singleVal+1); + case 2: + return self->getIdsEqualList(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->getIdsEqualList(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsEqualList : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + + DataArrayInt *getIdsNotEqualList(PyObject *obj) throw(INTERP_KERNEL::Exception) + { + int sw; + int singleVal; + std::vector multiVal; + std::pair > slic; + ParaMEDMEM::DataArrayInt *daIntTyypp=0; + convertObjToPossibleCpp2(obj,self->getNumberOfTuples(),sw,singleVal,multiVal,slic,daIntTyypp); + switch(sw) + { + case 1: + return self->getIdsNotEqualList(&singleVal,&singleVal+1); + case 2: + return self->getIdsNotEqualList(&multiVal[0],&multiVal[0]+multiVal.size()); + case 4: + return self->getIdsNotEqualList(daIntTyypp->begin(),daIntTyypp->end()); + default: + throw INTERP_KERNEL::Exception("DataArrayInt::getIdsNotEqualList : unrecognized type entered, expected list of int, tuple of int or DataArrayInt !"); + } + } + PyObject *splitByValueRange(PyObject *li) const throw(INTERP_KERNEL::Exception) { DataArrayInt *ret0=0,*ret1=0,*ret2=0; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 6fb0a0535..f34755503 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -1462,11 +1462,7 @@ int MEDFileUMesh::getSizeAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERN const DataArrayInt *MEDFileUMesh::getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception) { if(meshDimRelToMaxExt==1) - { - if(!((const DataArrayInt *)_fam_coords)) - throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamilyFieldAtLevel : no coordinates specified !"); - return _fam_coords; - } + return _fam_coords; const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); return l1->getFamilyField(); } @@ -1545,7 +1541,10 @@ MEDCouplingUMesh *MEDFileUMesh::getFamilies(int meshDimRelToMaxExt, const std::v } std::vector famIds=getFamiliesIds(fams); const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getFamilyPart(famIds,renum); + if(!famIds.empty()) + return l1->getFamilyPart(&famIds[0],&famIds[0]+famIds.size(),renum); + else + return l1->getFamilyPart(0,0,renum); } DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::vector& fams, bool renum) const throw(INTERP_KERNEL::Exception) @@ -1555,7 +1554,11 @@ DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::ve { if((const DataArrayInt *)_fam_coords) { - MEDCouplingAutoRefCountObjectPtr da=_fam_coords->getIdsEqualList(famIds); + MEDCouplingAutoRefCountObjectPtr da; + if(!famIds.empty()) + da=_fam_coords->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); + else + da=_fam_coords->getIdsEqualList(0,0); if(renum) return MEDFileUMeshSplitL1::Renumber(_num_coords,da); else @@ -1568,7 +1571,10 @@ DataArrayInt *MEDFileUMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::ve throw INTERP_KERNEL::Exception("MEDFileUMesh::getFamiliesArr : no family array specified on nodes !"); } const MEDFileUMeshSplitL1 *l1=getMeshAtLevSafe(meshDimRelToMaxExt); - return l1->getFamilyPartArr(famIds,renum); + if(!famIds.empty()) + return l1->getFamilyPartArr(&famIds[0],&famIds[0]+famIds.size(),renum); + else + return l1->getFamilyPartArr(0,0,renum); } MEDCouplingUMesh *MEDFileUMesh::getMeshAtLevel(int meshDimRelToMaxExt, bool renum) const throw(INTERP_KERNEL::Exception) @@ -1661,6 +1667,8 @@ void MEDFileUMesh::checkMeshDimCoherency(int meshDim, int meshDimRelToMax) const void MEDFileUMesh::setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception) { + if(!coords) + throw INTERP_KERNEL::Exception("MEDFileUMesh::setCoords : null pointer in input !"); coords->checkAllocated(); int nbOfTuples=coords->getNumberOfTuples(); _coords=coords; @@ -1721,6 +1729,84 @@ void MEDFileUMesh::optimizeFamilies() throw(INTERP_KERNEL::Exception) _groups.erase(*it); } +void MEDFileUMesh::duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified) throw(INTERP_KERNEL::Exception) +{ + std::vector levs=getNonEmptyLevels(); + if(std::find(levs.begin(),levs.end(),0)==levs.end() || std::find(levs.begin(),levs.end(),-1)==levs.end()) + throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : This method works only for mesh definied on level 0 and -1 !"); + MEDCouplingAutoRefCountObjectPtr m0=getMeshAtLevel(0); + MEDCouplingAutoRefCountObjectPtr m1=getMeshAtLevel(-1); + int nbNodes=m0->getNumberOfNodes(); + MEDCouplingAutoRefCountObjectPtr m11=getGroup(-1,grpNameM1); + DataArrayInt *tmp00=0,*tmp11=0; + m0->findNodesToDuplicate(*m11,tmp00,tmp11); + MEDCouplingAutoRefCountObjectPtr nodeIdsToDuplicate(tmp00); + MEDCouplingAutoRefCountObjectPtr cellsToModifyConn0(tmp11); + m11=getGroup(-1,grpNameM1); + MEDCouplingAutoRefCountObjectPtr tmp0=static_cast(m0->buildPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),true)); + tmp0->duplicateNodes(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end()); + m0->setCoords(tmp0->getCoords()); + m0->setPartOfMySelf(cellsToModifyConn0->begin(),cellsToModifyConn0->end(),*tmp0); + m1->setCoords(m0->getCoords()); + const DataArrayInt *fam=getFamilyFieldAtLevel(1); + fam->incrRef(); + _coords=m0->getCoords(); _coords->incrRef(); + DataArrayInt *famTmp=const_cast(getFamilyFieldAtLevel(1)); + famTmp->setPartOfValues1(fam,0,fam->getNumberOfTuples(),1,0,1,1,true); + fam->decrRef(); + // + m11->duplicateNodesInConn(nodeIdsToDuplicate->begin(),nodeIdsToDuplicate->end(),nbNodes); m11->setCoords(m0->getCoords()); + std::vector v(2); v[0]=m1; v[1]=m11; + MEDCouplingAutoRefCountObjectPtr newm1=MEDCouplingUMesh::AggregateSortedByTypeMeshesOnSameCoords(v,tmp00,tmp11); + MEDCouplingAutoRefCountObjectPtr szOfCellGrpOfSameType(tmp00); + MEDCouplingAutoRefCountObjectPtr idInMsOfCellGrpOfSameType(tmp11); + // + newm1->setName(getName()); + fam=getFamilyFieldAtLevel(-1); + if(!fam) + throw INTERP_KERNEL::Exception("MEDFileUMesh::duplicateNodesOnM1Group : internal problem !"); + MEDCouplingAutoRefCountObjectPtr newFam=DataArrayInt::New(); + newFam->alloc(newm1->getNumberOfCells(),1); + int idd=getMaxFamilyId()+1; + int globStart=0,start=0,end,globEnd; + int nbOfChunks=szOfCellGrpOfSameType->getNumberOfTuples(); + for(int i=0;igetIJ(i,0); + if(idInMsOfCellGrpOfSameType->getIJ(i,0)==0) + { + end=start+szOfCellGrpOfSameType->getIJ(i,0); + MEDCouplingAutoRefCountObjectPtr part=fam->selectByTupleId2(start,end,1); + newFam->setPartOfValues1(part,globStart,globEnd,1,0,1,1,true); + start=end; + } + else + { + newFam->setPartOfValuesSimple1(idd,globStart,globEnd,1,0,1,1); + } + globStart=globEnd; + } + newm1->setCoords(getCoords()); + setMeshAtLevel(-1,newm1); + setFamilyFieldArr(-1,newFam); + std::ostringstream famName; famName << "Family_" << idd; + std::string grpName2(grpNameM1); grpName2+="_dup"; + addFamily(famName.str().c_str(),idd); + addFamilyOnGrp(grpName2.c_str(),famName.str().c_str()); + // + fam=_fam_coords; + if(fam) + { + int newNbOfNodes=getCoords()->getNumberOfTuples(); + newFam=DataArrayInt::New(); newFam->alloc(newNbOfNodes,1); + newFam->setPartOfValues1(fam,0,nbNodes,1,0,1,1,true); + newFam->setPartOfValuesSimple1(0,nbNodes,newNbOfNodes,1,0,1,1); + _fam_coords=newFam; + } + nodesDuplicated=nodeIdsToDuplicate; nodeIdsToDuplicate->incrRef(); + cellsModified=cellsToModifyConn0; cellsToModifyConn0->incrRef(); +} + void MEDFileUMesh::addNodeGroup(const std::string& name, const std::vector& ids) throw(INTERP_KERNEL::Exception) { const DataArrayDouble *coords=_coords; @@ -2305,7 +2391,11 @@ DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::ve { if((const DataArrayInt *)_fam_nodes) { - MEDCouplingAutoRefCountObjectPtr da=_fam_nodes->getIdsEqualList(famIds); + MEDCouplingAutoRefCountObjectPtr da; + if(!famIds.empty()) + da=_fam_nodes->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); + else + da=_fam_nodes->getIdsEqualList(0,0); if(renum) return MEDFileUMeshSplitL1::Renumber(_num_nodes,da); else @@ -2321,7 +2411,11 @@ DataArrayInt *MEDFileCMesh::getFamiliesArr(int meshDimRelToMaxExt, const std::ve { if((const DataArrayInt *)_fam_cells) { - MEDCouplingAutoRefCountObjectPtr da=_fam_cells->getIdsEqualList(famIds); + MEDCouplingAutoRefCountObjectPtr da; + if(!famIds.empty()) + da=_fam_cells->getIdsEqualList(&famIds[0],&famIds[0]+famIds.size()); + else + da=_fam_cells->getIdsEqualList(0,0); if(renum) return MEDFileUMeshSplitL1::Renumber(_num_cells,da); else diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index b10e3a671..49e7c3b91 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -192,6 +192,7 @@ namespace ParaMEDMEM void setGroupsFromScratch(int meshDimRelToMax, const std::vector& ms) throw(INTERP_KERNEL::Exception); void setGroupsOnSetMesh(int meshDimRelToMax, const std::vector& ms, bool renum) throw(INTERP_KERNEL::Exception); void optimizeFamilies() throw(INTERP_KERNEL::Exception); + void duplicateNodesOnM1Group(const char *grpNameM1, DataArrayInt *&nodesDuplicated, DataArrayInt *&cellsModified) throw(INTERP_KERNEL::Exception); private: void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); MEDFileUMesh(); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 028511608..550894bef 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -597,18 +597,18 @@ int MEDFileUMeshSplitL1::getSize() const throw(INTERP_KERNEL::Exception) return _m_by_types->getNumberOfCells(); } -MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const std::vector& ids, bool renum) const +MEDCouplingUMesh *MEDFileUMeshSplitL1::getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const { - MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(ids); + MEDCouplingAutoRefCountObjectPtr eltsToKeep=_fam->getIdsEqualList(idsBg,idsEnd); MEDCouplingUMesh *m=(MEDCouplingUMesh *)_m_by_types->buildPartOfMySelf(eltsToKeep->getConstPointer(),eltsToKeep->getConstPointer()+eltsToKeep->getNumberOfTuples(),true); if(renum) return renumIfNeeded(m,eltsToKeep->getConstPointer()); return m; } -DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const std::vector& ids, bool renum) const +DataArrayInt *MEDFileUMeshSplitL1::getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const { - MEDCouplingAutoRefCountObjectPtr da=_fam->getIdsEqualList(ids); + MEDCouplingAutoRefCountObjectPtr da=_fam->getIdsEqualList(idsBg,idsEnd); if(renum) return renumIfNeededArr(da); da->incrRef(); diff --git a/src/MEDLoader/MEDFileMeshLL.hxx b/src/MEDLoader/MEDFileMeshLL.hxx index 37ed23d4d..16f3a446e 100644 --- a/src/MEDLoader/MEDFileMeshLL.hxx +++ b/src/MEDLoader/MEDFileMeshLL.hxx @@ -127,8 +127,8 @@ namespace ParaMEDMEM int getMeshDimension() const; void simpleRepr(std::ostream& oss) const; int getSize() const throw(INTERP_KERNEL::Exception); - MEDCouplingUMesh *getFamilyPart(const std::vector& ids, bool renum) const; - DataArrayInt *getFamilyPartArr(const std::vector& ids, bool renum) const; + MEDCouplingUMesh *getFamilyPart(const int *idsBg, const int *idsEnd, bool renum) const; + DataArrayInt *getFamilyPartArr(const int *idsBg, const int *idsEnd, bool renum) const; MEDCouplingUMesh *getWholeMesh(bool renum) const; const DataArrayInt *getFamilyField() const; const DataArrayInt *getNumberField() const; diff --git a/src/MEDLoader/Swig/MEDLoader.i b/src/MEDLoader/Swig/MEDLoader.i index 0d9a0bdf5..642d61958 100644 --- a/src/MEDLoader/Swig/MEDLoader.i +++ b/src/MEDLoader/Swig/MEDLoader.i @@ -534,6 +534,16 @@ namespace ParaMEDMEM ret->incrRef(); return ret; } + + PyObject *duplicateNodesOnM1Group(const char *grpNameM1) throw(INTERP_KERNEL::Exception) + { + DataArrayInt *ret0=0,*ret1=0; + self->duplicateNodesOnM1Group(grpNameM1,ret0,ret1); + PyObject *ret=PyTuple_New(2); + PyTuple_SetItem(ret,0,SWIG_NewPointerObj(SWIG_as_voidptr(ret0),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + PyTuple_SetItem(ret,1,SWIG_NewPointerObj(SWIG_as_voidptr(ret1),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 )); + return ret; + } } }; diff --git a/src/ParaMEDMEM/ElementLocator.cxx b/src/ParaMEDMEM/ElementLocator.cxx index 8af351d76..8e15db02d 100644 --- a/src/ParaMEDMEM/ElementLocator.cxx +++ b/src/ParaMEDMEM/ElementLocator.cxx @@ -27,6 +27,7 @@ #include "ProcessorGroup.hxx" #include "MPIProcessorGroup.hxx" #include "MEDCouplingFieldDouble.hxx" +#include "MEDCouplingAutoRefCountObjectPtr.hxx" #include "DirectedBoundingBox.hxx" #include @@ -693,11 +694,10 @@ namespace ParaMEDMEM CommInterface comm; DataArrayInt *globalIds=_local_para_field.returnGlobalNumbering(); const int *globalIdsC=globalIds->getConstPointer(); - std::vector candidates; - _local_para_field.getSupport()->getCellMesh()->findBoundaryNodes(candidates); - for(std::vector::iterator iter1=candidates.begin();iter1!=candidates.end();iter1++) + MEDCouplingAutoRefCountObjectPtr candidates=_local_para_field.getSupport()->getCellMesh()->findBoundaryNodes(); + for(int *iter1=candidates->getPointer();iter1!=candidates->getPointer()+candidates->getNumberOfTuples();iter1++) (*iter1)=globalIdsC[*iter1]; - std::set candidatesS(candidates.begin(),candidates.end()); + std::set candidatesS(candidates->begin(),candidates->end()); for(vector::const_iterator iter=_distant_proc_ids.begin();iter!=_distant_proc_ids.end();iter++,procId++) { const vector& ids=_ids_per_working_proc[procId];