Back to index

salome-med  6.5.0
MEDPARTITIONER_Utils.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __MEDPARTITIONER_UTILS_HXX__
00021 #define __MEDPARTITIONER_UTILS_HXX__
00022 
00023 #include "MEDPARTITIONER.hxx"
00024 
00025 #include "MEDCouplingUMesh.hxx"
00026 
00027 #include <string>
00028 #include <vector>
00029 #include <map>
00030 
00031 //# define LOCALIZED(message) #message , __FILE__ , __FUNCTION__ , __LINE__
00032 
00033 namespace MEDPARTITIONER
00034 {
00035   MEDPARTITIONER_EXPORT std::string Trim(const std::string& s,const std::string& drop);
00036   MEDPARTITIONER_EXPORT std::string IntToStr(const int i);
00037   MEDPARTITIONER_EXPORT std::string DoubleToStr(const double i);
00038   MEDPARTITIONER_EXPORT int StrToInt(const std::string& s);
00039   MEDPARTITIONER_EXPORT double StrToDouble(const std::string& s);
00040   MEDPARTITIONER_EXPORT bool TestArg(const char *arg, const char *argExpected, std::string& argValue);
00041   MEDPARTITIONER_EXPORT std::vector<int> CreateRandomSize(const int size);
00042   MEDPARTITIONER_EXPORT void RandomizeAdj(int* xadj, int* adjncy, std::vector<int>& ran, std::vector<int>& vx, std::vector<int>& va);
00043   MEDPARTITIONER_EXPORT void TestRandomize();
00044                        
00045   MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec);
00046   MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec, const std::string separator);
00047   MEDPARTITIONER_EXPORT std::string ReprMapOfStringInt(const std::map<std::string,int>& mymap);
00048   MEDPARTITIONER_EXPORT std::string ReprMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
00049   MEDPARTITIONER_EXPORT std::string ReprFieldDescriptions(const std::vector<std::string>& vec,const  std::string separator);
00050   
00051   MEDPARTITIONER_EXPORT std::string SerializeFromString(const std::string& s);
00052   MEDPARTITIONER_EXPORT std::string SerializeFromVectorOfString(const std::vector<std::string>& vec);
00053   MEDPARTITIONER_EXPORT std::vector<std::string> DeserializeToVectorOfString(const std::string& str);
00054   MEDPARTITIONER_EXPORT std::string EraseTagSerialized(const std::string& fromStr, const std::string& tag);
00055   
00056   MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringInt(const std::map<std::string,int>& mymap);
00057   MEDPARTITIONER_EXPORT std::map<std::string,int> DevectorizeToMapOfStringInt(const std::vector<std::string>& vec);
00058   
00059   MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
00060   MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DevectorizeToMapOfStringVectorOfString(const std::vector<std::string>& vec);
00061   
00062   MEDPARTITIONER_EXPORT std::vector<std::string> SelectTagsInVectorOfString(const std::vector<std::string>& vec, const std::string tag);
00063   MEDPARTITIONER_EXPORT std::vector<std::string> DeleteDuplicatesInVectorOfString(const std::vector<std::string>& vec);
00064   MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DeleteDuplicatesInMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
00065   
00066   MEDPARTITIONER_EXPORT std::string Cle1ToStr(const std::string& s, const int inew);
00067   MEDPARTITIONER_EXPORT void Cle1ToData(const std::string& cle, std::string& s, int& inew);
00068   
00069   MEDPARTITIONER_EXPORT std::string Cle2ToStr(const std::string& s,const int inew,const int iold);
00070   MEDPARTITIONER_EXPORT void Cle2ToData(const std::string& cle, std::string& s, int& inew, int& iold);
00071   
00072   MEDPARTITIONER_EXPORT std::string ExtractFromDescription(const std::string& description,const  std::string& tag);
00073   MEDPARTITIONER_EXPORT void FieldDescriptionToData(const std::string& description,
00074                               int& idomain, std::string& fileName, std::string& meshName, std::string& fieldName,
00075                               int& typeField, int& DT, int& IT);
00076   MEDPARTITIONER_EXPORT void FieldShortDescriptionToData(const std::string& description,
00077                                    std::string& fieldName, int& typeField, int& entity, int& DT, int& IT);
00078   
00079   ParaMEDMEM::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v);
00080   ParaMEDMEM::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v, const int nbComponents);
00081   ParaMEDMEM::DataArrayDouble *CreateDataArrayDoubleFromVector(const std::vector<double>& v);
00082   
00083   ParaMEDMEM::MEDCouplingUMesh *CreateEmptyMEDCouplingUMesh();
00084 
00085   std::vector<std::string> BrowseFieldDouble(const ParaMEDMEM::MEDCouplingFieldDouble* fd);
00086   std::vector<std::string> BrowseAllFields(const std::string& myfile);
00087   std::vector<std::string> BrowseAllFieldsOnMesh(const std::string& myfile, const std::string& mymesh, const int idomain);
00088   std::vector<std::string> GetInfosOfField(const char *fileName, const char *meshName, const int idomain );
00089 
00090 #ifdef HAVE_MPI2
00091   //not adviced, interblocking, use sendAndReceive
00092   //void SendVectorOfString(const std::vector<std::string>& vec, const int target);
00093   //std::vector<std::string> RecvVectorOfString(const int source);
00094   //TODO void sendRecvVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
00095   MEDPARTITIONER_EXPORT std::vector<std::string> SendAndReceiveVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
00096   MEDPARTITIONER_EXPORT std::vector<std::string> AllgathervVectorOfString(const std::vector<std::string>& vec);
00097   
00098   void SendDoubleVec(const std::vector<double>& vec, const int target);
00099   std::vector<double> *RecvDoubleVec(const int source);
00100   void RecvDoubleVec(std::vector<double>& vec, const int source);
00101     
00102   void SendIntVec(const std::vector<int>& vec, const int target);
00103   std::vector<int>* RecvIntVec(int source);
00104   void RecvIntVec(std::vector<int>& vec, const int source);
00105   
00106   void SendDataArrayInt(const ParaMEDMEM::DataArrayInt* da, const int target);
00107   ParaMEDMEM::DataArrayInt *RecvDataArrayInt(const int source);
00108   void SendDataArrayDouble(const ParaMEDMEM::DataArrayDouble* da, const int target);
00109   ParaMEDMEM::DataArrayDouble *RecvDataArrayDouble(const int source);
00110 
00111   void TestVectorOfStringMpi();
00112   void TestMapOfStringIntMpi();
00113   void TestMapOfStringVectorOfStringMpi();
00114   void TestDataArrayMpi();
00115   void TestPersistantMpi0To1(int taille, int nb);
00116   void TestPersistantMpiRing(int taille, int nb);
00117   void TestPersistantMpiRingOnCommSplit(int taille, int nb);
00118 #endif
00119 
00120   class MEDPARTITIONER_EXPORT MyGlobals
00121   {
00122   public :
00123     static int _Verbose;  //0 to 1000 over 200 is debug
00124     static int _Rank;
00125     static int _World_Size;
00126     static int _Randomize;
00127     static int _Atomize;
00128     static int _Creates_Boundary_Faces;
00129     static int _Is0verbose; //trace cout if rank 0 and verbose
00130     static std::vector<std::string> _File_Names;    //on [iold]
00131     static std::vector<std::string> _Mesh_Names;    //on [iold]
00132     static std::vector<std::string> _Field_Descriptions;
00134     static std::vector<std::string> _General_Informations;
00135   };
00136 }
00137 #endif