From 53c0d0d2314855eb667e970e0c4b41ee2c0f90b5 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 9 Apr 2015 18:20:36 +0200 Subject: [PATCH] Huge improvement of performance of MEDCouplingUMesh.buildUnstructuredMesh method. --- src/MEDCoupling/MEDCouplingUMesh.cxx | 34 +++++++++++++++------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index 3a38b65cc..f213a9d42 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -4629,7 +4629,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMesh(const MEDCouplingUMesh *me else throw INTERP_KERNEL::Exception("Invalid 2D mesh and 1D mesh because 2D mesh has quadratic cells and 1D is not fully quadratic !"); } - int oldNbOfNodes=getNumberOfNodes(); + int oldNbOfNodes(getNumberOfNodes()); MEDCouplingAutoRefCountObjectPtr newCoords; switch(policy) { @@ -4647,7 +4647,7 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMesh(const MEDCouplingUMesh *me throw INTERP_KERNEL::Exception("Not implemented extrusion policy : must be in (0) !"); } setCoords(newCoords); - MEDCouplingAutoRefCountObjectPtr ret=buildExtrudedMeshFromThisLowLev(oldNbOfNodes,isQuad); + MEDCouplingAutoRefCountObjectPtr ret(buildExtrudedMeshFromThisLowLev(oldNbOfNodes,isQuad)); updateTime(); return ret.retn(); } @@ -4897,16 +4897,14 @@ DataArrayDouble *MEDCouplingUMesh::fillExtCoordsUsingTranslAndAutoRotation3D(con */ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNodesOf1Lev, bool isQuad) const { - int nbOf1DCells=getNumberOfNodes()/nbOfNodesOf1Lev-1; - int nbOf2DCells=getNumberOfCells(); - int nbOf3DCells=nbOf2DCells*nbOf1DCells; - MEDCouplingUMesh *ret=MEDCouplingUMesh::New("Extruded",getMeshDimension()+1); - const int *conn=_nodal_connec->getConstPointer(); - const int *connI=_nodal_connec_index->getConstPointer(); - MEDCouplingAutoRefCountObjectPtr newConn=DataArrayInt::New(); - MEDCouplingAutoRefCountObjectPtr newConnI=DataArrayInt::New(); + int nbOf1DCells(getNumberOfNodes()/nbOfNodesOf1Lev-1); + int nbOf2DCells(getNumberOfCells()); + int nbOf3DCells(nbOf2DCells*nbOf1DCells); + MEDCouplingUMesh *ret(MEDCouplingUMesh::New("Extruded",getMeshDimension()+1)); + const int *conn(_nodal_connec->begin()),*connI(_nodal_connec_index->begin()); + MEDCouplingAutoRefCountObjectPtr newConn(DataArrayInt::New()),newConnI(DataArrayInt::New()); newConnI->alloc(nbOf3DCells+1,1); - int *newConnIPtr=newConnI->getPointer(); + int *newConnIPtr(newConnI->getPointer()); *newConnIPtr++=0; std::vector newc; for(int j=0;jalloc((int)(newc.size())*nbOf1DCells,1); - int *newConnPtr=newConn->getPointer(); - int deltaPerLev=isQuad?2*nbOfNodesOf1Lev:nbOfNodesOf1Lev; + int *newConnPtr(newConn->getPointer()); + int deltaPerLev(isQuad?2*nbOfNodesOf1Lev:nbOfNodesOf1Lev); newConnIPtr=newConnI->getPointer(); for(int iz=0;iz(),newConnIPtr[iz*nbOf2DCells])); + const int *posOfTypeOfCell(newConnIPtr); for(std::vector::const_iterator iter=newc.begin();iter!=newc.end();iter++,newConnPtr++) { - int icell=(int)(iter-newc.begin()); - if(std::find(newConnIPtr,newConnIPtr+nbOf2DCells,icell)==newConnIPtr+nbOf2DCells) + int icell((int)(iter-newc.begin()));//std::distance unfortunately cannot been called here in C++98 + if(icell!=*posOfTypeOfCell) { if(*iter!=-1) *newConnPtr=(*iter)+iz*deltaPerLev; @@ -4933,7 +4932,10 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildExtrudedMeshFromThisLowLev(int nbOfNode *newConnPtr=-1; } else - *newConnPtr=(*iter); + { + *newConnPtr=*iter; + posOfTypeOfCell++; + } } } ret->setConnectivity(newConn,newConnI,true); -- 2.39.2