1 // Copyright (C) 2007-2024 CEA, EDF
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,mcIdType>& 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,mcIdType>& mymap);
58 MEDPARTITIONER_EXPORT std::map<std::string,mcIdType> 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::DataArrayIdType *CreateDataArrayIntFromVector(const std::vector<mcIdType>& v);
81 MEDCoupling::DataArrayIdType *CreateDataArrayIntFromVector(const std::vector<mcIdType>& 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 );
91 MEDCoupling::MCAuto< MEDCoupling::DataArrayInt32 > FromIdTypeVec( const std::vector< mcIdType >& vec );
95 //not advised, interblocking, use sendAndReceive
96 //void SendVectorOfString(const std::vector<std::string>& vec, const int target);
97 //std::vector<std::string> RecvVectorOfString(const int source);
98 //TODO void sendRecvVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
99 MEDPARTITIONER_EXPORT std::vector<std::string> SendAndReceiveVectorOfString(const std::vector<std::string>& vec, const int source, const int target);
100 MEDPARTITIONER_EXPORT std::vector<std::string> AllgathervVectorOfString(const std::vector<std::string>& vec);
102 void SendDoubleVec(const std::vector<double>& vec, const int target);
103 std::vector<double> *RecvDoubleVec(const int source);
104 void RecvDoubleVec(std::vector<double>& vec, const int source);
106 void SendIntVec(const std::vector<mcIdType>& vec, const int target);
107 std::vector<int>* RecvIntVec(int source);
108 void RecvIntVec(std::vector<mcIdType>& vec, const int source);
110 void SendDataArrayInt(const MEDCoupling::DataArrayInt* da, const int target);
111 MEDCoupling::DataArrayInt *RecvDataArrayInt(const int source);
112 void SendDataArrayDouble(const MEDCoupling::DataArrayDouble* da, const int target);
113 MEDCoupling::DataArrayDouble *RecvDataArrayDouble(const int source);
115 void TestVectorOfStringMpi();
116 void TestMapOfStringIntMpi();
117 void TestMapOfStringVectorOfStringMpi();
118 void TestDataArrayMpi();
119 void TestPersistantMpi0To1(int taille, int nb);
120 void TestPersistantMpiRing(int taille, int nb);
121 void TestPersistantMpiRingOnCommSplit(int taille, int nb);
124 class MEDPARTITIONER_EXPORT MyGlobals
127 static int _Verbose; //0 to 1000 over 200 is debug
129 static int _World_Size;
130 static int _Randomize;
132 static int _Create_Boundary_Faces;
133 static int _Create_Joints;
134 static int _Is0verbose; //trace cout if rank 0 and verbose
135 static std::vector<std::string> _File_Names; //on [iold]
136 static std::vector<std::string> _Mesh_Names; //on [iold]
137 static std::vector<std::string> _Field_Descriptions;
138 /*! used for descriptions of components of fields for example...*/
139 static std::vector<std::string> _General_Informations;
145 * \brief Class encapsulating BBTree of dimension given at construction and
146 * providing all features of BBTree
151 void (BBTreeOfDim::*_PgetElementsAroundPoint)( const double* coordsPtr,
152 std::vector<mcIdType>& elems ) const;
153 void (BBTreeOfDim::*_PgetIntersectingElems)( const double* bb,
154 std::vector<mcIdType>& elems ) const;
157 void _getElementsAroundPoint( const double* coordsPtr,
158 std::vector<mcIdType>& elems ) const
160 ((BBTree<dim,mcIdType>*)_tree)->getElementsAroundPoint( coordsPtr, elems );
163 void _getIntersectingElems(const double* bb,
164 std::vector<mcIdType>& elems) const
166 ((BBTree<dim,mcIdType>*)_tree)->getIntersectingElems( bb, elems );
170 BBTreeOfDim( std::size_t dim,
175 double epsilon=1e-12);
177 void getElementsAroundPoint(const double* coordsPtr, std::vector<mcIdType>& elems ) const;
178 void getIntersectingElems (const double* bb, std::vector<mcIdType>& elems) const;