]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/ParaMEDMEM/Test/ParaMEDMEMTest_BlockTopology.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / ParaMEDMEM / Test / ParaMEDMEMTest_BlockTopology.cxx
1 //  Copyright (C) 2007-2008  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 #include "ParaMEDMEMTest.hxx"
20 #include <cppunit/TestAssert.h>
21
22 #include "InterpolationUtils.hxx"
23 #include "CommInterface.hxx"
24 #include "ProcessorGroup.hxx"
25 #include "MPIProcessorGroup.hxx"
26 #include "Topology.hxx"
27 #include "BlockTopology.hxx"
28
29 #include <string>
30
31 // use this define to enable lines, execution of which leads to Segmentation Fault
32 #define ENABLE_FAULTS
33
34 // use this define to enable CPPUNIT asserts and fails, showing bugs
35 #define ENABLE_FORCED_FAILURES
36
37
38 using namespace std;
39 using namespace ParaMEDMEM;
40  
41 /*
42  * Check methods defined in BlockTopology.hxx
43  *
44   BlockTopology(){};
45   BlockTopology(const ProcessorGroup& group, const MEDMEM::GRID& grid); 
46   BlockTopology(const BlockTopology& geom_topo, const ComponentTopology& comp_topo);
47   (+) BlockTopology(const ProcessorGroup& group, int nb_elem);
48   virtual ~BlockTopology();
49   (+) inline int getNbElements()const;
50   (+) inline int getNbLocalElements() const;
51   const ProcessorGroup* getProcGroup()const {return _proc_group;};
52   (+) inline std::pair<int,int> globalToLocal (const int) const ;
53   (+) inline int localToGlobal (const std::pair<int,int>) const;
54   (+) std::vector<std::pair<int,int> > getLocalArrayMinMax() const ;
55   (+) int getDimension() const {return _dimension;};
56   (+) void serialize(int* & serializer, int& size) const ;
57   (+) void unserialize(const int* serializer, const CommInterface& comm_interface);
58   
59  */
60  
61 void ParaMEDMEMTest::testBlockTopology_constructor()
62 {
63   //test constructor
64   int size;
65   MPI_Comm_size(MPI_COMM_WORLD,&size);
66   int rank;
67   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
68   CommInterface interface;
69   MPIProcessorGroup group(interface);
70   BlockTopology blocktopo(group,1);
71   CPPUNIT_ASSERT_EQUAL(1,blocktopo.getNbLocalElements());
72   CPPUNIT_ASSERT_EQUAL(size,blocktopo.getNbElements());
73   CPPUNIT_ASSERT_EQUAL(1,blocktopo.getDimension());
74   
75   //checking access methods
76   BlockTopology blocktopo2(group,2);
77   std::pair<int,int> local= blocktopo2.globalToLocal(0);
78   CPPUNIT_ASSERT_EQUAL(local.first,0);
79   CPPUNIT_ASSERT_EQUAL(local.second,0);
80   int global=blocktopo2.localToGlobal(local);
81   CPPUNIT_ASSERT_EQUAL(global,0);
82   
83   local = blocktopo2.globalToLocal(1);
84   CPPUNIT_ASSERT_EQUAL(local.first,0);
85   CPPUNIT_ASSERT_EQUAL(local.second,1);
86   global=blocktopo2.localToGlobal(local);
87   CPPUNIT_ASSERT_EQUAL(global,1);
88   
89   local = blocktopo2.globalToLocal(2*size-1);
90   CPPUNIT_ASSERT_EQUAL(local.first,size-1);
91   CPPUNIT_ASSERT_EQUAL(local.second,1);
92   global=blocktopo2.localToGlobal(local);
93   CPPUNIT_ASSERT_EQUAL(global,2*size-1);
94
95   std::vector<std::pair<int,int> > bounds = blocktopo2.getLocalArrayMinMax();
96   int vecsize = bounds.size();
97   CPPUNIT_ASSERT_EQUAL(1,vecsize);
98   CPPUNIT_ASSERT_EQUAL(2*rank, (bounds[0]).first);
99   CPPUNIT_ASSERT_EQUAL(2*rank+2, (bounds[0]).second);
100  }
101  
102 void ParaMEDMEMTest::testBlockTopology_serialize()
103 {
104
105   int size;
106   MPI_Comm_size(MPI_COMM_WORLD,&size);
107   int rank;
108   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
109   CommInterface interface;
110   MPIProcessorGroup group(interface);
111   BlockTopology blocktopo(group,3);
112
113 //testing the serialization process that is used to transfer a
114 //block topology via a MPI_Send/Recv comm  
115   BlockTopology blocktopo_recv;
116   int* serializer;
117   int sersize;
118   blocktopo.serialize(serializer,sersize);
119   blocktopo_recv.unserialize(serializer,interface);
120   CPPUNIT_ASSERT_EQUAL(blocktopo.getNbElements(),blocktopo_recv.getNbElements());
121   delete [] serializer;
122 }