1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
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, or (at your option) any later version.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef __MEDPARTITIONER_UTILS_HXX__
21 #define __MEDPARTITIONER_UTILS_HXX__
23 #include "MEDPARTITIONER.hxx"
25 #include "MEDCouplingUMesh.hxx"
32 //# define LOCALIZED(message) #message , __FILE__ , __FUNCTION__ , __LINE__
34 namespace MEDPARTITIONER
36 MEDPARTITIONER_EXPORT std::string Trim(const std::string& s,const std::string& drop);
37 MEDPARTITIONER_EXPORT std::string IntToStr(const int i);
38 MEDPARTITIONER_EXPORT std::string DoubleToStr(const double i);
39 MEDPARTITIONER_EXPORT int StrToInt(const std::string& s);
40 MEDPARTITIONER_EXPORT double StrToDouble(const std::string& s);
41 MEDPARTITIONER_EXPORT bool TestArg(const char *arg, const char *argExpected, std::string& argValue);
42 MEDPARTITIONER_EXPORT std::vector<int> CreateRandomSize(const int size);
43 MEDPARTITIONER_EXPORT void RandomizeAdj(int* xadj, int* adjncy, std::vector<int>& ran, std::vector<int>& vx, std::vector<int>& va);
44 MEDPARTITIONER_EXPORT void TestRandomize();
46 MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec);
47 MEDPARTITIONER_EXPORT std::string ReprVectorOfString(const std::vector<std::string>& vec, const std::string separator);
48 MEDPARTITIONER_EXPORT std::string ReprMapOfStringInt(const std::map<std::string,int>& mymap);
49 MEDPARTITIONER_EXPORT std::string ReprMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
50 MEDPARTITIONER_EXPORT std::string ReprFieldDescriptions(const std::vector<std::string>& vec,const std::string separator);
52 MEDPARTITIONER_EXPORT std::string SerializeFromString(const std::string& s);
53 MEDPARTITIONER_EXPORT std::string SerializeFromVectorOfString(const std::vector<std::string>& vec);
54 MEDPARTITIONER_EXPORT std::vector<std::string> DeserializeToVectorOfString(const std::string& str);
55 MEDPARTITIONER_EXPORT std::string EraseTagSerialized(const std::string& fromStr, const std::string& tag);
57 MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringInt(const std::map<std::string,int>& mymap);
58 MEDPARTITIONER_EXPORT std::map<std::string,int> DevectorizeToMapOfStringInt(const std::vector<std::string>& vec);
60 MEDPARTITIONER_EXPORT std::vector<std::string> VectorizeFromMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
61 MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DevectorizeToMapOfStringVectorOfString(const std::vector<std::string>& vec);
63 MEDPARTITIONER_EXPORT std::vector<std::string> SelectTagsInVectorOfString(const std::vector<std::string>& vec, const std::string tag);
64 MEDPARTITIONER_EXPORT std::vector<std::string> DeleteDuplicatesInVectorOfString(const std::vector<std::string>& vec);
65 MEDPARTITIONER_EXPORT std::map< std::string,std::vector<std::string> > DeleteDuplicatesInMapOfStringVectorOfString(const std::map< std::string,std::vector<std::string> >& mymap);
67 MEDPARTITIONER_EXPORT std::string Cle1ToStr(const std::string& s, const int inew);
68 MEDPARTITIONER_EXPORT void Cle1ToData(const std::string& cle, std::string& s, int& inew);
70 MEDPARTITIONER_EXPORT std::string Cle2ToStr(const std::string& s,const int inew,const int iold);
71 MEDPARTITIONER_EXPORT void Cle2ToData(const std::string& cle, std::string& s, int& inew, int& iold);
73 MEDPARTITIONER_EXPORT std::string ExtractFromDescription(const std::string& description,const std::string& tag);
74 MEDPARTITIONER_EXPORT void FieldDescriptionToData(const std::string& description,
75 int& idomain, std::string& fileName, std::string& meshName, std::string& fieldName,
76 int& typeField, int& DT, int& IT);
77 MEDPARTITIONER_EXPORT void FieldShortDescriptionToData(const std::string& description,
78 std::string& fieldName, int& typeField, int& entity, int& DT, int& IT);
80 MEDCoupling::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v);
81 MEDCoupling::DataArrayInt *CreateDataArrayIntFromVector(const std::vector<int>& v, const int nbComponents);
82 MEDCoupling::DataArrayDouble *CreateDataArrayDoubleFromVector(const std::vector<double>& v);
84 MEDCoupling::MEDCouplingUMesh *CreateEmptyMEDCouplingUMesh();
86 std::vector<std::string> BrowseFieldDouble(const MEDCoupling::MEDCouplingFieldDouble* fd);
87 std::vector<std::string> BrowseAllFields(const std::string& myfile);
88 std::vector<std::string> BrowseAllFieldsOnMesh(const std::string& myfile, const std::string& mymesh, const int idomain);
89 std::vector<std::string> GetInfosOfField(const char *fileName, const char *meshName, const int idomain );
92 //not advised, interblocking, use sendAndReceive
93 //void SendVectorOfString(const std::vector<std::string>& vec, const int target);
94 //std::vector<std::string> RecvVectorOfString(const int source);
95 //TODO void sendRecvVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
96 MEDPARTITIONER_EXPORT std::vector<std::string> SendAndReceiveVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
97 MEDPARTITIONER_EXPORT std::vector<std::string> AllgathervVectorOfString(const std::vector<std::string>& vec);
99 void SendDoubleVec(const std::vector<double>& vec, const int target);
100 std::vector<double> *RecvDoubleVec(const int source);
101 void RecvDoubleVec(std::vector<double>& vec, const int source);
103 void SendIntVec(const std::vector<int>& vec, const int target);
104 std::vector<int>* RecvIntVec(int source);
105 void RecvIntVec(std::vector<int>& vec, const int source);
107 void SendDataArrayInt(const MEDCoupling::DataArrayInt* da, const int target);
108 MEDCoupling::DataArrayInt *RecvDataArrayInt(const int source);
109 void SendDataArrayDouble(const MEDCoupling::DataArrayDouble* da, const int target);
110 MEDCoupling::DataArrayDouble *RecvDataArrayDouble(const int source);
112 void TestVectorOfStringMpi();
113 void TestMapOfStringIntMpi();
114 void TestMapOfStringVectorOfStringMpi();
115 void TestDataArrayMpi();
116 void TestPersistantMpi0To1(int taille, int nb);
117 void TestPersistantMpiRing(int taille, int nb);
118 void TestPersistantMpiRingOnCommSplit(int taille, int nb);
121 class MEDPARTITIONER_EXPORT MyGlobals
124 static int _Verbose; //0 to 1000 over 200 is debug
126 static int _World_Size;
127 static int _Randomize;
129 static int _Create_Boundary_Faces;
130 static int _Create_Joints;
131 static int _Is0verbose; //trace cout if rank 0 and verbose
132 static std::vector<std::string> _File_Names; //on [iold]
133 static std::vector<std::string> _Mesh_Names; //on [iold]
134 static std::vector<std::string> _Field_Descriptions;
135 /*! used for descriptions of components of fields for example...*/
136 static std::vector<std::string> _General_Informations;
142 * \brief Class encapsulating BBTree of dimension given at construction and
143 * providing all features of BBTree
148 void (BBTreeOfDim::*_PgetElementsAroundPoint)( const double* coordsPtr,
149 std::vector<int>& elems ) const;
150 void (BBTreeOfDim::*_PgetIntersectingElems)( const double* bb,
151 std::vector<int>& elems ) const;
154 void _getElementsAroundPoint( const double* coordsPtr,
155 std::vector<int>& elems ) const
157 ((BBTree<dim,int>*)_tree)->getElementsAroundPoint( coordsPtr, elems );
160 void _getIntersectingElems(const double* bb,
161 std::vector<int>& elems) const
163 ((BBTree<dim,int>*)_tree)->getIntersectingElems( bb, elems );
167 BBTreeOfDim( int dim,
172 double epsilon=1e-12);
174 void getElementsAroundPoint(const double* coordsPtr, std::vector<int>& elems ) const;
175 void getIntersectingElems (const double* bb, std::vector<int>& elems) const;