Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDPartitioner / MEDPARTITIONER_Utils.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __MEDPARTITIONER_UTILS_HXX__
21 #define __MEDPARTITIONER_UTILS_HXX__
22
23 #include "MEDPARTITIONER.hxx"
24
25 #include "MEDCouplingUMesh.hxx"
26
27 #include <string>
28 #include <vector>
29 #include <map>
30
31 //# define LOCALIZED(message) #message , __FILE__ , __FUNCTION__ , __LINE__
32
33 namespace MEDPARTITIONER
34 {
35   MEDPARTITIONER_EXPORT std::string Trim(const std::string& s,const std::string& drop);
36   MEDPARTITIONER_EXPORT std::string IntToStr(const int i);
37   MEDPARTITIONER_EXPORT std::string DoubleToStr(const double i);
38   MEDPARTITIONER_EXPORT int StrToInt(const std::string& s);
39   MEDPARTITIONER_EXPORT double StrToDouble(const std::string& s);
40   MEDPARTITIONER_EXPORT bool TestArg(const char *arg, const char *argExpected, std::string& argValue);
41   MEDPARTITIONER_EXPORT std::vector<int> CreateRandomSize(const int size);
42   MEDPARTITIONER_EXPORT void RandomizeAdj(int* xadj, int* adjncy, std::vector<int>& ran, std::vector<int>& vx, std::vector<int>& va);
43   MEDPARTITIONER_EXPORT void TestRandomize();
44                        
45   MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec);
46   MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec, const std::string separator);
47   MEDPARTITIONER_EXPORT std::string ReprMapOfStringInt(const std::map<std::string,int>& mymap);
48   MEDPARTITIONER_EXPORT std::string ReprMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
49   MEDPARTITIONER_EXPORT std::string ReprFieldDescriptions(const std::vector<std::string>& vec,const  std::string separator);
50   
51   MEDPARTITIONER_EXPORT std::string SerializeFromString(const std::string& s);
52   MEDPARTITIONER_EXPORT std::string SerializeFromVectorOfString(const std::vector<std::string>& vec);
53   MEDPARTITIONER_EXPORT std::vector<std::string> DeserializeToVectorOfString(const std::string& str);
54   MEDPARTITIONER_EXPORT std::string EraseTagSerialized(const std::string& fromStr, const std::string& tag);
55   
56   MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringInt(const std::map<std::string,int>& mymap);
57   MEDPARTITIONER_EXPORT std::map<std::string,int> DevectorizeToMapOfStringInt(const std::vector<std::string>& vec);
58   
59   MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
60   MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DevectorizeToMapOfStringVectorOfString(const std::vector<std::string>& vec);
61   
62   MEDPARTITIONER_EXPORT std::vector<std::string> SelectTagsInVectorOfString(const std::vector<std::string>& vec, const std::string tag);
63   MEDPARTITIONER_EXPORT std::vector<std::string> DeleteDuplicatesInVectorOfString(const std::vector<std::string>& vec);
64   MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DeleteDuplicatesInMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
65   
66   MEDPARTITIONER_EXPORT std::string Cle1ToStr(const std::string& s, const int inew);
67   MEDPARTITIONER_EXPORT void Cle1ToData(const std::string& cle, std::string& s, int& inew);
68   
69   MEDPARTITIONER_EXPORT std::string Cle2ToStr(const std::string& s,const int inew,const int iold);
70   MEDPARTITIONER_EXPORT void Cle2ToData(const std::string& cle, std::string& s, int& inew, int& iold);
71   
72   MEDPARTITIONER_EXPORT std::string ExtractFromDescription(const std::string& description,const  std::string& tag);
73   MEDPARTITIONER_EXPORT void FieldDescriptionToData(const std::string& description,
74                               int& idomain, std::string& fileName, std::string& meshName, std::string& fieldName,
75                               int& typeField, int& DT, int& IT);
76   MEDPARTITIONER_EXPORT void FieldShortDescriptionToData(const std::string& description,
77                                    std::string& fieldName, int& typeField, int& entity, int& DT, int& IT);
78   
79   ParaMEDMEM::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v);
80   ParaMEDMEM::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v, const int nbComponents);
81   ParaMEDMEM::DataArrayDouble *CreateDataArrayDoubleFromVector(const std::vector<double>& v);
82   
83   ParaMEDMEM::MEDCouplingUMesh *CreateEmptyMEDCouplingUMesh();
84
85   std::vector<std::string> BrowseFieldDouble(const ParaMEDMEM::MEDCouplingFieldDouble* fd);
86   std::vector<std::string> BrowseAllFields(const std::string& myfile);
87   std::vector<std::string> BrowseAllFieldsOnMesh(const std::string& myfile, const std::string& mymesh, const int idomain);
88   std::vector<std::string> GetInfosOfField(const char *fileName, const char *meshName, const int idomain );
89
90 #ifdef HAVE_MPI2
91   //not adviced, interblocking, use sendAndReceive
92   //void SendVectorOfString(const std::vector<std::string>& vec, const int target);
93   //std::vector<std::string> RecvVectorOfString(const int source);
94   //TODO void sendRecvVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
95   MEDPARTITIONER_EXPORT std::vector<std::string> SendAndReceiveVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
96   MEDPARTITIONER_EXPORT std::vector<std::string> AllgathervVectorOfString(const std::vector<std::string>& vec);
97   
98   void SendDoubleVec(const std::vector<double>& vec, const int target);
99   std::vector<double> *RecvDoubleVec(const int source);
100   void RecvDoubleVec(std::vector<double>& vec, const int source);
101     
102   void SendIntVec(const std::vector<int>& vec, const int target);
103   std::vector<int>* RecvIntVec(int source);
104   void RecvIntVec(std::vector<int>& vec, const int source);
105   
106   void SendDataArrayInt(const ParaMEDMEM::DataArrayInt* da, const int target);
107   ParaMEDMEM::DataArrayInt *RecvDataArrayInt(const int source);
108   void SendDataArrayDouble(const ParaMEDMEM::DataArrayDouble* da, const int target);
109   ParaMEDMEM::DataArrayDouble *RecvDataArrayDouble(const int source);
110
111   void TestVectorOfStringMpi();
112   void TestMapOfStringIntMpi();
113   void TestMapOfStringVectorOfStringMpi();
114   void TestDataArrayMpi();
115   void TestPersistantMpi0To1(int taille, int nb);
116   void TestPersistantMpiRing(int taille, int nb);
117   void TestPersistantMpiRingOnCommSplit(int taille, int nb);
118 #endif
119
120   class MEDPARTITIONER_EXPORT MyGlobals
121   {
122   public :
123     static int _Verbose;  //0 to 1000 over 200 is debug
124     static int _Rank;
125     static int _World_Size;
126     static int _Randomize;
127     static int _Atomize;
128     static int _Creates_Boundary_Faces;
129     static int _Is0verbose; //trace cout if rank 0 and verbose
130     static std::vector<std::string> _File_Names;    //on [iold]
131     static std::vector<std::string> _Mesh_Names;    //on [iold]
132     static std::vector<std::string> _Field_Descriptions;
133     /*! used for descriptions of components of fields for example...*/
134     static std::vector<std::string> _General_Informations;
135   };
136 }
137 #endif