1 // Copyright (C) 2007-2019 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 #include "ParaMEDMEMTest.hxx"
21 #include <cppunit/TestAssert.h>
23 #include "InterpolationUtils.hxx"
24 #include "CommInterface.hxx"
25 #include "ProcessorGroup.hxx"
26 #include "MPIProcessorGroup.hxx"
27 #include "Topology.hxx"
28 #include "BlockTopology.hxx"
32 // use this define to enable lines, execution of which leads to Segmentation Fault
35 // use this define to enable CPPUNIT asserts and fails, showing bugs
36 #define ENABLE_FORCED_FAILURES
40 using namespace MEDCoupling;
43 * Check methods defined in BlockTopology.hxx
46 BlockTopology(const ProcessorGroup& group, const MEDMEM::GRID& grid);
47 BlockTopology(const BlockTopology& geom_topo, const ComponentTopology& comp_topo);
48 (+) BlockTopology(const ProcessorGroup& group, int nb_elem);
49 virtual ~BlockTopology();
50 (+) inline int getNbElements()const;
51 (+) inline int getNbLocalElements() const;
52 const ProcessorGroup* getProcGroup()const {return _proc_group;};
53 (+) inline std::pair<int,int> globalToLocal (const int) const ;
54 (+) inline int localToGlobal (const std::pair<int,int>) const;
55 (+) std::vector<std::pair<int,int> > getLocalArrayMinMax() const ;
56 (+) int getDimension() const {return _dimension;};
57 (+) void serialize(int* & serializer, int& size) const ;
58 (+) void unserialize(const int* serializer, const CommInterface& comm_interface);
62 void ParaMEDMEMTest::testBlockTopology_constructor()
66 MPI_Comm_size(MPI_COMM_WORLD,&size);
68 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
69 CommInterface interface;
70 MPIProcessorGroup group(interface);
71 BlockTopology blocktopo(group,1);
72 CPPUNIT_ASSERT_EQUAL(1,blocktopo.getNbLocalElements());
73 CPPUNIT_ASSERT_EQUAL(size,blocktopo.getNbElements());
74 CPPUNIT_ASSERT_EQUAL(1,blocktopo.getDimension());
76 //checking access methods
77 BlockTopology blocktopo2(group,2);
78 std::pair<int,int> local= blocktopo2.globalToLocal(0);
79 CPPUNIT_ASSERT_EQUAL(local.first,0);
80 CPPUNIT_ASSERT_EQUAL(local.second,0);
81 int global=blocktopo2.localToGlobal(local);
82 CPPUNIT_ASSERT_EQUAL(global,0);
84 local = blocktopo2.globalToLocal(1);
85 CPPUNIT_ASSERT_EQUAL(local.first,0);
86 CPPUNIT_ASSERT_EQUAL(local.second,1);
87 global=blocktopo2.localToGlobal(local);
88 CPPUNIT_ASSERT_EQUAL(global,1);
90 local = blocktopo2.globalToLocal(2*size-1);
91 CPPUNIT_ASSERT_EQUAL(local.first,size-1);
92 CPPUNIT_ASSERT_EQUAL(local.second,1);
93 global=blocktopo2.localToGlobal(local);
94 CPPUNIT_ASSERT_EQUAL(global,2*size-1);
96 std::vector<std::pair<int,int> > bounds = blocktopo2.getLocalArrayMinMax();
97 int vecsize = bounds.size();
98 CPPUNIT_ASSERT_EQUAL(1,vecsize);
99 CPPUNIT_ASSERT_EQUAL(2*rank, (bounds[0]).first);
100 CPPUNIT_ASSERT_EQUAL(2*rank+2, (bounds[0]).second);
103 void ParaMEDMEMTest::testBlockTopology_serialize()
107 MPI_Comm_size(MPI_COMM_WORLD,&size);
109 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
110 CommInterface interface;
111 MPIProcessorGroup group(interface);
112 BlockTopology blocktopo(group,3);
114 //testing the serialization process that is used to transfer a
115 //block topology via a MPI_Send/Recv comm
116 BlockTopology blocktopo_recv;
119 blocktopo.serialize(serializer,sersize);
120 blocktopo_recv.unserialize(serializer,interface);
121 CPPUNIT_ASSERT_EQUAL(blocktopo.getNbElements(),blocktopo_recv.getNbElements());
122 delete [] serializer;