X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FMEDPartitioner%2FMEDPARTITIONER_Utils.cxx;h=52db6e97ed7a43fb4124ec0844d6bc99d7a2ce57;hb=8411b13fec372c7635bf04d2bb81a869dc038fdd;hp=6bbe1a86c2b6e3bf54e65dd28de5aebd07bff9a2;hpb=10f37bf6f33a762626d7f1093b2f5450c1688667;p=tools%2Fmedcoupling.git diff --git a/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx b/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx index 6bbe1a86c..52db6e97e 100644 --- a/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx +++ b/src/MEDPartitioner/MEDPARTITIONER_Utils.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2007-2020 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,7 +26,7 @@ #include "MEDCouplingUMesh.hxx" #include "MEDCouplingFieldDouble.hxx" #include "InterpKernelException.hxx" -#include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include "MCAuto.hxx" #include "InterpKernelAutoPtr.hxx" #include @@ -44,7 +44,8 @@ int MEDPARTITIONER::MyGlobals::_Rank=-1; int MEDPARTITIONER::MyGlobals::_World_Size=-1; int MEDPARTITIONER::MyGlobals::_Randomize=0; int MEDPARTITIONER::MyGlobals::_Atomize=0; -int MEDPARTITIONER::MyGlobals::_Creates_Boundary_Faces=0; +int MEDPARTITIONER::MyGlobals::_Create_Boundary_Faces=0; +int MEDPARTITIONER::MyGlobals::_Create_Joints=0; std::vector MEDPARTITIONER::MyGlobals::_File_Names; std::vector MEDPARTITIONER::MyGlobals::_Mesh_Names; std::vector MEDPARTITIONER::MyGlobals::_Field_Descriptions; @@ -130,16 +131,16 @@ void MEDPARTITIONER::RandomizeAdj(int* xadj, int* adjncy, std::vector& ran, std::cerr << "MEDPARTITIONER::RandomizeAdj only works on one proc!" << std::endl; return; } - int size=ran.size(); + std::size_t size=ran.size(); std::vector invran(size); - for (int i=0; i& v return oss.str(); } -std::string MEDPARTITIONER::ReprMapOfStringInt(const std::map& mymap) +std::string MEDPARTITIONER::ReprMapOfStringInt(const std::map& mymap) { if (mymap.size()==0) return std::string(" NONE\n"); std::ostringstream oss; - for (std::map::const_iterator i=mymap.begin(); i!=mymap.end(); ++i) + for (std::map::const_iterator i=mymap.begin(); i!=mymap.end(); ++i) oss << " -> [" << (*i).first << "]=" << (*i).second << std::endl; return oss.str(); } @@ -284,10 +285,10 @@ std::string MEDPARTITIONER::EraseTagSerialized(const std::string& fromStr, const * elements first and second of map give one elements in result vector of string * converting formatted the int second as firsts characters ending at first slash */ -std::vector MEDPARTITIONER::VectorizeFromMapOfStringInt(const std::map& mymap) +std::vector MEDPARTITIONER::VectorizeFromMapOfStringInt(const std::map& mymap) { std::vector res; - for (std::map::const_iterator i=mymap.begin(); i!=mymap.end(); ++i) + for (std::map::const_iterator i=mymap.begin(); i!=mymap.end(); ++i) { std::ostringstream oss; oss << (*i).second << "/" << (*i).first; @@ -299,9 +300,9 @@ std::vector MEDPARTITIONER::VectorizeFromMapOfStringInt(const std:: /* * if existing identicals (first,second) in vector no problem, else Exception */ -std::map MEDPARTITIONER::DevectorizeToMapOfStringInt(const std::vector& vec) +std::map MEDPARTITIONER::DevectorizeToMapOfStringInt(const std::vector& vec) { - std::map res; + std::map res; for (std::vector::const_iterator i=vec.begin(); i!=vec.end(); ++i) { std::size_t pos=0; @@ -309,11 +310,11 @@ std::map MEDPARTITIONER::DevectorizeToMapOfStringInt(const std: std::size_t found=(*i).find('/'); //first slash if ((found==std::string::npos) || (found<1)) throw INTERP_KERNEL::Exception("Error aIntNumber/anyString is expected"); - int second; + mcIdType second; std::istringstream iss((*i).substr(pos,found)); iss >> second; std::string first=(*i).substr(pos+found+1,posmax-found); - std::map::iterator it=res.find(first); + std::map::iterator it=res.find(first); if (it!=res.end()) if ((*it).second!=second) throw INTERP_KERNEL::Exception("Error not the same map value"); @@ -363,7 +364,7 @@ std::map< std::string,std::vector > MEDPARTITIONER::DevectorizeToMa iss >> sizeVector; std::string keymap=enTete.substr(foundKey+7,foundSizeVector-foundKey-7); for (int ii=1; ii<=sizeVector; ii++) - res[keymap].push_back(vs[ii]); //add unconditionnaly,so merge duplicates in second vector + res[keymap].push_back(vs[ii]); //add unconditionally,so merge duplicates in second vector } return res; } @@ -505,17 +506,17 @@ void MEDPARTITIONER::FieldShortDescriptionToData(const std::string& description, IT=StrToInt(ExtractFromDescription(description,"IT=")); } -ParaMEDMEM::DataArrayInt *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector& v) +MEDCoupling::DataArrayIdType *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector& v) { - ParaMEDMEM::DataArrayInt* p=ParaMEDMEM::DataArrayInt::New(); + MEDCoupling::DataArrayIdType* p=MEDCoupling::DataArrayIdType::New(); p->alloc(v.size(),1); std::copy(v.begin(),v.end(),p->getPointer()); return p; } -ParaMEDMEM::DataArrayInt *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector& v,const int nbComponents) +MEDCoupling::DataArrayIdType *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector& v,const int nbComponents) { - ParaMEDMEM::DataArrayInt* p=ParaMEDMEM::DataArrayInt::New(); + MEDCoupling::DataArrayIdType* p=MEDCoupling::DataArrayIdType::New(); if (v.size()%nbComponents!=0) throw INTERP_KERNEL::Exception("Problem size modulo nbComponents != 0"); p->alloc(v.size()/nbComponents,nbComponents); @@ -523,9 +524,9 @@ ParaMEDMEM::DataArrayInt *MEDPARTITIONER::CreateDataArrayIntFromVector(const std return p; } -ParaMEDMEM::DataArrayDouble* MEDPARTITIONER::CreateDataArrayDoubleFromVector(const std::vector& v) +MEDCoupling::DataArrayDouble* MEDPARTITIONER::CreateDataArrayDoubleFromVector(const std::vector& v) { - ParaMEDMEM::DataArrayDouble* p=ParaMEDMEM::DataArrayDouble::New(); + MEDCoupling::DataArrayDouble* p=MEDCoupling::DataArrayDouble::New(); p->alloc(v.size(),1); std::copy(v.begin(),v.end(),p->getPointer()); return p; @@ -533,14 +534,14 @@ ParaMEDMEM::DataArrayDouble* MEDPARTITIONER::CreateDataArrayDoubleFromVector(con /*! */ -std::vector MEDPARTITIONER::BrowseFieldDouble(const ParaMEDMEM::MEDCouplingFieldDouble* fd) +std::vector MEDPARTITIONER::BrowseFieldDouble(const MEDCoupling::MEDCouplingFieldDouble* fd) { std::vector res; if (fd->getArray()) { - int nb=fd->getArray()->getNumberOfComponents(); - res.push_back("nbComponents="); res.back()+=IntToStr(nb); - for (int i=0; igetArray()->getNumberOfComponents(); + res.push_back("nbComponents="); res.back()+=IntToStr((int)nb); + for (unsigned int i=0; igetArray()->getInfoOnComponent(i); @@ -559,20 +560,20 @@ std::vector MEDPARTITIONER::BrowseFieldDouble(const ParaMEDMEM::MED std::vector MEDPARTITIONER::BrowseAllFields(const std::string& myfile) { std::vector res; - std::vector meshNames=MEDLoader::GetMeshNames(myfile.c_str()); + std::vector meshNames=MEDCoupling::GetMeshNames(myfile); for (std::size_t i=0; i fieldNames= - MEDLoader::GetAllFieldNamesOnMesh(myfile.c_str(),meshNames[i].c_str()); + MEDCoupling::GetAllFieldNamesOnMesh(myfile,meshNames[i]); for (std::size_t j = 0; j < fieldNames.size(); j++) { - std::vector< ParaMEDMEM::TypeOfField > typeFields= - MEDLoader::GetTypesOfField(myfile.c_str(), meshNames[i].c_str(), fieldNames[j].c_str()); + std::vector< MEDCoupling::TypeOfField > typeFields= + MEDCoupling::GetTypesOfField(myfile, meshNames[i], fieldNames[j]); for (std::size_t k = 0; k < typeFields.size(); k++) { std::vector< std::pair< int, int > > its= - MEDLoader::GetFieldIterations(typeFields[k], myfile.c_str(), meshNames[i].c_str(), fieldNames[j].c_str()); + GetFieldIterations(typeFields[k], myfile, meshNames[i], fieldNames[j]); if (MyGlobals::_Is0verbose>100) std::cout<< "fieldName " << fieldNames[j] << " typeField " << typeFields[k] << " its.size() " << its.size() << std::endl; for (std::size_t m = 0; m < its.size(); m++) @@ -703,7 +704,7 @@ std::vector MEDPARTITIONER::GetInfosOfField(const char *fileName, c { for (int j=0; j MEDPARTITIONER::GetInfosOfField(const char *fileName, c resi.push_back("fileName="); resi.back()+=fileName; resi.push_back("meshName="); resi.back()+=curMeshName; resi.push_back("fieldName="); resi.back()+=curFieldName; - resi.push_back("typeField="); resi.back()+=IntToStr((int)ParaMEDMEM::ON_NODES); + resi.push_back("typeField="); resi.back()+=IntToStr((int)MEDCoupling::ON_NODES); resi.push_back("typeData="); resi.back()+=IntToStr((int)typcha); //6 for double? resi.push_back("nbComponent="); resi.back()+=IntToStr((int)ncomp); resi.push_back("DT="); resi.back()+=IntToStr((int)numdt); @@ -756,9 +757,9 @@ std::vector MEDPARTITIONER::GetInfosOfField(const char *fileName, c nbOfVal << " profilName '" << pflname << "' profileSize " << profilesize << " nbPtGauss " << nbi << std::endl; int typeField=-1; //unknown if (enttype==MED_CELL) - typeField=ParaMEDMEM::ON_CELLS; + typeField=MEDCoupling::ON_CELLS; if (enttype==MED_NODE_ELEMENT) - typeField=ParaMEDMEM::ON_GAUSS_NE; + typeField=MEDCoupling::ON_GAUSS_NE; //if (enttype==??) typeField=ON_GAUSS_PT; std::vector resi; resi.push_back("idomain="); resi.back()+=IntToStr(idomain); @@ -800,6 +801,15 @@ std::vector MEDPARTITIONER::GetInfosOfField(const char *fileName, c return res; } +MEDCoupling::MCAuto< MEDCoupling::DataArrayInt32 > MEDPARTITIONER::FromIdTypeVec( const std::vector< mcIdType >& vec ) +{ + MEDCoupling::DataArrayInt32* array = MEDCoupling::DataArrayInt32::New(); + array->alloc( vec.size(), 1 ); + std::copy( vec.begin(), vec.end(), array->getPointer() ); + return array; +} + + /*! * quick almost human readable information on all fields on a mesh in a .med file */ @@ -812,17 +822,68 @@ std::vector MEDPARTITIONER::BrowseAllFieldsOnMesh(const std::string /*! * create empty MEDCouplingUMesh* dim 3 */ -ParaMEDMEM::MEDCouplingUMesh* MEDPARTITIONER::CreateEmptyMEDCouplingUMesh() +MEDCoupling::MEDCouplingUMesh* MEDPARTITIONER::CreateEmptyMEDCouplingUMesh() { - ParaMEDMEM::MEDCouplingUMesh* umesh=ParaMEDMEM::MEDCouplingUMesh::New(); + MEDCoupling::MEDCouplingUMesh* umesh=MEDCoupling::MEDCouplingUMesh::New(); umesh->setMeshDimension(3); umesh->allocateCells(0); umesh->finishInsertingCells(); - ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New(); + MEDCoupling::DataArrayDouble *myCoords=MEDCoupling::DataArrayDouble::New(); myCoords->alloc(0,3); umesh->setCoords(myCoords); umesh->setName("EMPTY"); myCoords->decrRef(); - umesh->checkCoherency(); + umesh->checkConsistencyLight(); return umesh; } + +namespace MEDPARTITIONER +{ + BBTreeOfDim::BBTreeOfDim( std::size_t dim, + const double* bbs, + mcIdType* elems, + int level, + mcIdType nbelems, + double epsilon) + { + switch ( dim ) + { + case 3: + _tree=new BBTree<3,mcIdType> (bbs,elems,level,nbelems,epsilon); + _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 3 >; + _PgetIntersectingElems = & BBTreeOfDim::_getIntersectingElems< 3 >; + break; + case 2: + _tree=new BBTree<2,mcIdType> (bbs,elems,level,nbelems,epsilon); + _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 2 >; + _PgetIntersectingElems = & BBTreeOfDim::_getIntersectingElems< 2 >; + break; + case 1: + _tree=new BBTree<1,mcIdType> (bbs,elems,level,nbelems,epsilon); + _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 1 >; + _PgetIntersectingElems = & BBTreeOfDim::_getIntersectingElems< 1 >; + break; + default: + _tree=0; + throw INTERP_KERNEL::Exception("BBTreeOfDim(): wrong space dimension"); + } + } + + BBTreeOfDim::~BBTreeOfDim() + { + delete (BBTree<3>*)_tree; + } + + void BBTreeOfDim::getElementsAroundPoint( const double* coordsPtr, + std::vector& elems ) const + { + BBTreeOfDim* me = (BBTreeOfDim*) this; + (me->*_PgetElementsAroundPoint) ( coordsPtr, elems ); + } + void BBTreeOfDim::getIntersectingElems(const double* bb, + std::vector& elems) const + { + BBTreeOfDim* me = (BBTreeOfDim*) this; + (me->*_PgetIntersectingElems) ( bb, elems ); + } +}