Salome HOME
Various fixes for test runs - introducing MEDCOUPLING_RESOURCE_DIR env variable
[tools/medcoupling.git] / src / MEDPartitioner / MEDPARTITIONER_Utils.cxx
index 6fd6a42eaffe11ecf38f16f9d110e7034a4ea555..52db6e97ed7a43fb4124ec0844d6bc99d7a2ce57 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  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 <fstream>
@@ -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<std::string> MEDPARTITIONER::MyGlobals::_File_Names;
 std::vector<std::string> MEDPARTITIONER::MyGlobals::_Mesh_Names;
 std::vector<std::string> MEDPARTITIONER::MyGlobals::_Field_Descriptions;
@@ -130,16 +131,16 @@ void MEDPARTITIONER::RandomizeAdj(int* xadj, int* adjncy, std::vector<int>& 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<int> invran(size);
-  for (int i=0; i<size; i++)
+  for (unsigned int i=0; i<size; i++)
     invran[ran[i]]=i;
   vx.resize(size+1);
   int lga=xadj[size];
   va.resize(lga);
   int jj=0;
   vx[0]=0;
-  for (int i=0; i<size; i++)
+  for (std::size_t i=0; i<size; i++)
     {
       int ir=ran[i];
       int ii=xadj[ir];
@@ -186,12 +187,12 @@ std::string MEDPARTITIONER::ReprVectorOfString(const std::vector<std::string>& v
   return oss.str();
 }
 
-std::string MEDPARTITIONER::ReprMapOfStringInt(const std::map<std::string,int>& mymap)
+std::string MEDPARTITIONER::ReprMapOfStringInt(const std::map<std::string,mcIdType>& mymap)
 {
   if (mymap.size()==0)
     return std::string(" NONE\n");
   std::ostringstream oss;
-  for (std::map<std::string,int>::const_iterator i=mymap.begin(); i!=mymap.end(); ++i) 
+  for (std::map<std::string,mcIdType>::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<std::string> MEDPARTITIONER::VectorizeFromMapOfStringInt(const std::map<std::string,int>& mymap)
+std::vector<std::string> MEDPARTITIONER::VectorizeFromMapOfStringInt(const std::map<std::string,mcIdType>& mymap)
 {
   std::vector<std::string> res;
-  for (std::map<std::string,int>::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
+  for (std::map<std::string,mcIdType>::const_iterator i=mymap.begin(); i!=mymap.end(); ++i)
     {
       std::ostringstream oss;
       oss << (*i).second << "/" << (*i).first;
@@ -299,9 +300,9 @@ std::vector<std::string> MEDPARTITIONER::VectorizeFromMapOfStringInt(const std::
 /*
  * if existing identicals (first,second) in vector no problem, else Exception
  */
-std::map<std::string,int> MEDPARTITIONER::DevectorizeToMapOfStringInt(const std::vector<std::string>& vec)
+std::map<std::string,mcIdType> MEDPARTITIONER::DevectorizeToMapOfStringInt(const std::vector<std::string>& vec)
 {
-  std::map<std::string,int> res;
+  std::map<std::string,mcIdType> res;
   for (std::vector<std::string>::const_iterator i=vec.begin(); i!=vec.end(); ++i)
     {
       std::size_t pos=0;
@@ -309,11 +310,11 @@ std::map<std::string,int> 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<std::string,int>::iterator it=res.find(first);
+      std::map<std::string,mcIdType>::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<std::string> > 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<int>& v)
+MEDCoupling::DataArrayIdType *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector<mcIdType>& 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<int>& v,const int nbComponents)
+MEDCoupling::DataArrayIdType *MEDPARTITIONER::CreateDataArrayIntFromVector(const std::vector<mcIdType>& 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<double>& v)
+MEDCoupling::DataArrayDouble* MEDPARTITIONER::CreateDataArrayDoubleFromVector(const std::vector<double>& 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<std::string> MEDPARTITIONER::BrowseFieldDouble(const ParaMEDMEM::MEDCouplingFieldDouble* fd)
+std::vector<std::string> MEDPARTITIONER::BrowseFieldDouble(const MEDCoupling::MEDCouplingFieldDouble* fd)
 {
   std::vector<std::string> res;
   if (fd->getArray())
     {
-      int nb=fd->getArray()->getNumberOfComponents();
-      res.push_back("nbComponents="); res.back()+=IntToStr(nb);
-      for (int i=0; i<nb; i++)
+      std::size_t nb=fd->getArray()->getNumberOfComponents();
+      res.push_back("nbComponents="); res.back()+=IntToStr((int)nb);
+      for (unsigned int i=0; i<nb; i++)
         {
           res.push_back("componentInfo");
           res.back()+=IntToStr(i)+"="+fd->getArray()->getInfoOnComponent(i);
@@ -559,20 +560,20 @@ std::vector<std::string> MEDPARTITIONER::BrowseFieldDouble(const ParaMEDMEM::MED
 std::vector<std::string> MEDPARTITIONER::BrowseAllFields(const std::string& myfile)
 {
   std::vector<std::string> res;
-  std::vector<std::string> meshNames=MEDLoader::GetMeshNames(myfile);
+  std::vector<std::string> meshNames=MEDCoupling::GetMeshNames(myfile);
   
   for (std::size_t i=0; i<meshNames.size(); i++)
     {
       std::vector<std::string> fieldNames=
-        MEDLoader::GetAllFieldNamesOnMesh(myfile,meshNames[i]);
+        MEDCoupling::GetAllFieldNamesOnMesh(myfile,meshNames[i]);
       for (std::size_t j = 0; j < fieldNames.size(); j++)
         {
-          std::vector< ParaMEDMEM::TypeOfField > typeFields=
-            MEDLoader::GetTypesOfField(myfile, meshNames[i], fieldNames[j]);
+          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, meshNames[i], fieldNames[j]);
+                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<std::string> MEDPARTITIONER::GetInfosOfField(const char *fileName, c
             {
               for (int j=0; j<lggeom; j++)
                 {
-                  int profilesize=0,nbi=0;
+                  med_int profilesize=0,nbi=0;
                   med_entity_type enttype=ENTITYTYPE[ie];
                   //enttype=MED_NODE;enttype=MED_CELL;enttype=MED_NODE_ELEMENT;
                   char pflname[MED_NAME_SIZE+1]="";
@@ -726,7 +727,7 @@ std::vector<std::string> 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<std::string> 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<std::string> resi;
                           resi.push_back("idomain="); resi.back()+=IntToStr(idomain);
@@ -800,6 +801,15 @@ std::vector<std::string> 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,44 +822,44 @@ std::vector<std::string> 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( int           dim,
+  BBTreeOfDim::BBTreeOfDim( std::size_t   dim,
                             const double* bbs,
-                            int*          elems,
+                            mcIdType*     elems,
                             int           level,
-                            int           nbelems,
+                            mcIdType      nbelems,
                             double        epsilon)
   {
     switch ( dim )
       {
       case 3:
-        _tree=new BBTree<3> (bbs,elems,level,nbelems,epsilon);
+        _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> (bbs,elems,level,nbelems,epsilon);
+        _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> (bbs,elems,level,nbelems,epsilon);
+        _tree=new BBTree<1,mcIdType> (bbs,elems,level,nbelems,epsilon);
         _PgetElementsAroundPoint = & BBTreeOfDim::_getElementsAroundPoint< 1 >;
         _PgetIntersectingElems   = & BBTreeOfDim::_getIntersectingElems< 1 >;
         break;
@@ -865,13 +875,13 @@ namespace MEDPARTITIONER
   }
 
   void BBTreeOfDim::getElementsAroundPoint( const double* coordsPtr,
-                                            std::vector<int>& elems ) const
+                                            std::vector<mcIdType>& elems ) const
   {
     BBTreeOfDim* me = (BBTreeOfDim*) this;
     (me->*_PgetElementsAroundPoint) ( coordsPtr, elems );
   }
   void BBTreeOfDim::getIntersectingElems(const double* bb,
-                                         std::vector<int>& elems) const
+                                         std::vector<mcIdType>& elems) const
   {
     BBTreeOfDim* me = (BBTreeOfDim*) this;
     (me->*_PgetIntersectingElems) ( bb, elems );