Back to index

salome-med  6.5.0
MEDSPLITTERTest_ParallelTopology.cxx
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 #include "MEDSPLITTERTest.hxx"
00021 #include "MEDSPLITTERTest_Utils.hxx"
00022 
00023 #include "MEDMEM_ConnectZone.hxx" 
00024 #include "MEDMEM_DriversDef.hxx"
00025 #include "MEDMEM_Mesh.hxx"
00026 #include "MEDMEM_Meshing.hxx"
00027 #include "MEDMEM_GaussLocalization.hxx"
00028 #include "MEDMEM_Field.hxx"
00029 #include "MEDMEM_CellModel.hxx"
00030 #include "MEDMEM_Group.hxx"
00031 
00032 #include "MEDSPLITTER_Graph.hxx"
00033 #include "MEDSPLITTER_Topology.hxx"
00034 #include "MEDSPLITTER_ParallelTopology.hxx"
00035 #include "MEDSPLITTER_SequentialTopology.hxx"
00036 #include "MEDSPLITTER_MESHCollection.hxx"
00037 #include "MEDSPLITTER_MESHCollectionDriver.hxx"
00038 
00039 #ifdef MED_ENABLE_METIS
00040 #include "MEDSPLITTER_METISGraph.hxx"
00041 #endif
00042 //#include "MEDSPLITTER_SCOTCHGraph.hxx"
00043 
00044 #include "MEDMEM_Exception.hxx"
00045 
00046 #include <string>
00047 #include <cppunit/TestAssert.h>
00048 
00049 // use this define to enable lines, execution of which leads to Segmentation Fault
00050 //#define ENABLE_FAULTS
00051 
00052 // use this define to enable CPPUNIT asserts and fails, showing bugs
00053 #define ENABLE_FORCED_FAILURES
00054 
00055 
00056 using namespace std;
00057 using namespace MEDSPLITTER;
00058 using namespace MEDMEM;
00059  
00060 /*
00061  * Check methods defined in ParallelTopology.hxx
00062  * 
00063  ParallelTopology();
00064  ParallelTopology(vector<MEDMEM::MESH*>, vector<MEDMEM::CONNECTZONE*>,vector<int*>&, vector<int*>&, vector<int*>&);
00065  (+) ParallelTopology(boost::shared_ptr<Graph> graph, int nbdomain, int mesh_dimension);
00066  ~ParallelTopology();
00067  (+) void convertGlobalNodeList(const int*, int,int*,int*);
00068  (+) void convertGlobalNodeList(const int*, int,int*,int);
00069  (+) void convertGlobalNodeListWithTwins(const int* face_list, int nbnode, int*& local, int*& ip, int*& full_array, int& size);
00070  (+) void convertGlobalCellList(const int*, int , int*, int *);
00071  void convertGlobalFaceList(const int*, int , int*, int *);    
00072  void convertGlobalFaceList(const int*, int , int*, int);  
00073  void convertGlobalFaceListWithTwins(const int* face_list, int nbface, int*& local, int*& ip, int*& full_array,int& size);
00074  void createNodeMapping(std::map<MED_EN::medGeometryElement,int*>& type_connectivity,
00075  std::map<MED_EN::medGeometryElement,int>& present_type_numbers,
00076  int idomain);
00077  void createFaceMapping(const MESHCollection &);
00078  void createFaceMapping2ndversion(const MESHCollection &);
00079  void convertToLocal(std::map<MED_EN::medGeometryElement,int*>& type_connectivity,
00080  std::map<MED_EN::medGeometryElement,int>& present_type_numbers,
00081  int idomain,
00082  MED_EN::medEntityMesh entity);
00083  void computeNodeNodeCorrespondencies(int nbdomain,vector<MEDMEM::MEDSKYLINEARRAY*>& ) const;
00084  void computeCellCellCorrespondencies(int nbdomain,vector<MEDMEM::MEDSKYLINEARRAY*>&, const Graph* ) const;
00085  inline  int convertNodeToGlobal(int ip,int icell) const
00086  inline  int convertFaceToGlobal(int ip,int icell) const
00087  inline  int convertCellToGlobal(int ip,int icell) const
00088  inline  void convertNodeToGlobal(int ip, const int* local, int n, int* global)const
00089  (+)inline  void convertCellToGlobal(int ip, const int* local, int n, int* global)const
00090  inline  void convertFaceToGlobal(int ip, const int* local, int n, int* global)const
00091  (+) inline  int nbDomain() const
00092  int nbCells() const
00093  (+) inline  int nbCells( int idomain) const
00094  (+) inline  int getNodeNumber(int idomain) const
00095  inline  int getNodeNumber() const
00096  inline  void getNodeList(int idomain, int* list) const
00097  (+) inline  int getCellNumber(int idomain) const
00098  inline  int getCellDomainNumber(int global) const
00099  inline  void getCellList(int idomain, int* list) const
00100  inline int getFaceNumber(int idomain) const
00101  inline  int getFaceNumber() const
00102  inline  void getFaceList(int idomain, int* list) const
00103  boost::shared_ptr<Graph> getGraph() const
00104 */
00105  
00106 void MEDSPLITTERTest::testParallelTopology_graph_constructor()
00107 {
00108 #ifndef MED_ENABLE_METIS
00109   CPPUNIT_FAIL("METIS is not available. Please, check your compilation.");
00110 #else
00111   string filename_rd        = MEDSPLITTERTest_Utils::getResourceFile("carre_en_quad4.med");
00112   string filename_para_wr   = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe22_");
00113   string filename_para_med0 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe22_1.med");
00114   string filename_para_med1 = MEDSPLITTERTest_Utils::makeTmpFile("myWrField_seq_pointe22_2.med");
00115   
00116   string meshname="carre_en_quad4";
00117   MESHCollection collection(filename_rd,meshname);
00118   
00119   MEDMEM::MEDSKYLINEARRAY* array=0;
00120   int* edgeweights=0;
00121     
00122   collection.buildCellGraph(array,edgeweights);
00123     
00124   boost::shared_ptr<Graph> cell_graph=boost::shared_ptr<Graph>(new METISGraph(array,edgeweights));
00125          
00126   cell_graph->partGraph(2,"");
00127   
00128   //cell_graph is a shared pointer 
00129   Topology* topology = new ParallelTopology (cell_graph, 2, collection.getMeshDimension());
00130   
00131   
00132         /*
00133          * test_SPLITTER_square
00134          * 
00135          * computes a partitioning for the following geometry
00136          * 
00137          * 
00138          * 
00139          * 7------------8------------9
00140          * |            |            |
00141          * |            |            |
00142          * |     3      |     4      |
00143          * |            |            |
00144          * |            |            |
00145          * 4------------5------------6
00146          * |            |            |
00147          * |            |            |
00148          * |     1      |     2      |
00149          * |            |            |
00150          * |            |            |
00151          * 1------------2------------3 
00152          *
00153          * Result of the 2 domain split :
00154          *  
00155          * 5------------6 5------------6
00156          * |            | |            |
00157          * |            | |            |
00158          * |     2      | |     2      |
00159          * |            | |            |
00160          * |            | |            |
00161          * 1------------2 1------------2
00162          * |            | |            |
00163          * |            | |            |
00164          * |     1      | |     1      |
00165          * |            | |            |
00166          * |            | |            |
00167          * 4------------3 4------------3 
00168          */
00169  
00170   int iglobal[3]={1,2,3};
00171   int* iloc=new int[3];
00172   int* iproc=new int[3];
00173   int iloc_answer[3]={1,1,2};
00174   int iproc_answer[3]={0,1,0};
00175   topology->convertGlobalCellList(iglobal,3,iloc,iproc);
00176   for(int i=0; i<3; i++)
00177                 { 
00178                         CPPUNIT_ASSERT_EQUAL(iloc_answer[i], iloc[i]);
00179                         CPPUNIT_ASSERT_EQUAL(iproc_answer[i],iproc[i]);
00180                 }
00181   int* global_2 = new int[3];
00182   topology->convertCellToGlobal(0,iloc,3,global_2);
00183   int global_answer[3]={1,1,3};
00184   for (int i=0; i<3; i++)
00185                 {
00186                         CPPUNIT_ASSERT_EQUAL(global_answer[i],global_2[i]);
00187                 }
00188   
00189   CPPUNIT_ASSERT_EQUAL(topology->getCellNumber(0),2);  
00190   CPPUNIT_ASSERT_EQUAL(topology->getCellNumber(1),2);
00191   
00192     
00193   CPPUNIT_ASSERT_EQUAL(topology->nbCells(0),2);
00194   CPPUNIT_ASSERT_EQUAL(topology->nbCells(1),2);
00195   
00196   CPPUNIT_ASSERT_EQUAL(topology->nbDomain(),2);
00197   //node and face lists have not yet been computed
00198   CPPUNIT_ASSERT_THROW(topology->convertGlobalNodeList(iglobal,3,iloc,iproc),MEDEXCEPTION);
00199   CPPUNIT_ASSERT_THROW(topology->convertGlobalFaceList(iglobal,3,iloc,iproc),MEDEXCEPTION);
00200   
00201   MESHCollection new_collection(collection, topology);
00202   
00203   CPPUNIT_ASSERT_EQUAL(topology->getNodeNumber(0),6);  
00204   CPPUNIT_ASSERT_EQUAL(topology->getNodeNumber(1),6);
00205   
00206   topology->convertGlobalNodeList(iglobal,3,iloc,iproc);
00207    
00208   int iloc_node_answer[3]={4,3,3};
00209   int iproc_node_answer[3]={0,0,1};
00210   for(int i=0; i<3; i++)
00211                 { 
00212                         CPPUNIT_ASSERT_EQUAL(iloc_node_answer[i], iloc[i]);
00213                         CPPUNIT_ASSERT_EQUAL(iproc_node_answer[i],iproc[i]);
00214                 }
00215   int* local_nodes;
00216   int* ip_nodes;
00217   int* full_array;
00218   int size;
00219   topology->convertGlobalNodeListWithTwins(iglobal, 3, local_nodes, ip_nodes, full_array, size);
00220   CPPUNIT_ASSERT_EQUAL(size,4);
00221   int iloc_node_wt_answer[4]={4,3,4,3};
00222   int iproc_node_wt_answer[4]={0,0,1,1};
00223   for(int i=0; i<4; i++)
00224                 { 
00225                         CPPUNIT_ASSERT_EQUAL(iloc_node_wt_answer[i], local_nodes[i]);
00226                         CPPUNIT_ASSERT_EQUAL(iproc_node_wt_answer[i],ip_nodes[i]);
00227                 }
00228   delete topology;
00229   delete[] iloc;
00230   delete[]iproc;
00231   delete[] global_2;
00232   delete[] local_nodes;
00233   delete[] ip_nodes;
00234   delete[] full_array;
00235 #endif // MED_ENABLE_METIS
00236 }