Back to index

salome-med  6.5.0
ParaMEDMEMTest_BlockTopology.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 "ParaMEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 
00023 #include "InterpolationUtils.hxx"
00024 #include "CommInterface.hxx"
00025 #include "ProcessorGroup.hxx"
00026 #include "MPIProcessorGroup.hxx"
00027 #include "Topology.hxx"
00028 #include "BlockTopology.hxx"
00029 
00030 #include <string>
00031 
00032 // use this define to enable lines, execution of which leads to Segmentation Fault
00033 #define ENABLE_FAULTS
00034 
00035 // use this define to enable CPPUNIT asserts and fails, showing bugs
00036 #define ENABLE_FORCED_FAILURES
00037 
00038 
00039 using namespace std;
00040 using namespace ParaMEDMEM;
00041  
00042 /*
00043  * Check methods defined in BlockTopology.hxx
00044  *
00045   BlockTopology(){};
00046   BlockTopology(const ProcessorGroup& group, const MEDMEM::GRID& grid); 
00047   BlockTopology(const BlockTopology& geom_topo, const ComponentTopology& comp_topo);
00048   (+) BlockTopology(const ProcessorGroup& group, int nb_elem);
00049   virtual ~BlockTopology();
00050   (+) inline int getNbElements()const;
00051   (+) inline int getNbLocalElements() const;
00052   const ProcessorGroup* getProcGroup()const {return _proc_group;};
00053   (+) inline std::pair<int,int> globalToLocal (const int) const ;
00054   (+) inline int localToGlobal (const std::pair<int,int>) const;
00055   (+) std::vector<std::pair<int,int> > getLocalArrayMinMax() const ;
00056   (+) int getDimension() const {return _dimension;};
00057   (+) void serialize(int* & serializer, int& size) const ;
00058   (+) void unserialize(const int* serializer, const CommInterface& comm_interface);
00059   
00060  */
00061  
00062 void ParaMEDMEMTest::testBlockTopology_constructor()
00063 {
00064   //test constructor
00065   int size;
00066   MPI_Comm_size(MPI_COMM_WORLD,&size);
00067   int rank;
00068   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00069   CommInterface interface;
00070   MPIProcessorGroup group(interface);
00071   BlockTopology blocktopo(group,1);
00072   CPPUNIT_ASSERT_EQUAL(1,blocktopo.getNbLocalElements());
00073   CPPUNIT_ASSERT_EQUAL(size,blocktopo.getNbElements());
00074   CPPUNIT_ASSERT_EQUAL(1,blocktopo.getDimension());
00075   
00076   //checking access methods
00077   BlockTopology blocktopo2(group,2);
00078   std::pair<int,int> local= blocktopo2.globalToLocal(0);
00079   CPPUNIT_ASSERT_EQUAL(local.first,0);
00080   CPPUNIT_ASSERT_EQUAL(local.second,0);
00081   int global=blocktopo2.localToGlobal(local);
00082   CPPUNIT_ASSERT_EQUAL(global,0);
00083   
00084   local = blocktopo2.globalToLocal(1);
00085   CPPUNIT_ASSERT_EQUAL(local.first,0);
00086   CPPUNIT_ASSERT_EQUAL(local.second,1);
00087   global=blocktopo2.localToGlobal(local);
00088   CPPUNIT_ASSERT_EQUAL(global,1);
00089   
00090   local = blocktopo2.globalToLocal(2*size-1);
00091   CPPUNIT_ASSERT_EQUAL(local.first,size-1);
00092   CPPUNIT_ASSERT_EQUAL(local.second,1);
00093   global=blocktopo2.localToGlobal(local);
00094   CPPUNIT_ASSERT_EQUAL(global,2*size-1);
00095 
00096   std::vector<std::pair<int,int> > bounds = blocktopo2.getLocalArrayMinMax();
00097   int vecsize = bounds.size();
00098   CPPUNIT_ASSERT_EQUAL(1,vecsize);
00099   CPPUNIT_ASSERT_EQUAL(2*rank, (bounds[0]).first);
00100   CPPUNIT_ASSERT_EQUAL(2*rank+2, (bounds[0]).second);
00101  }
00102  
00103 void ParaMEDMEMTest::testBlockTopology_serialize()
00104 {
00105 
00106   int size;
00107   MPI_Comm_size(MPI_COMM_WORLD,&size);
00108   int rank;
00109   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
00110   CommInterface interface;
00111   MPIProcessorGroup group(interface);
00112   BlockTopology blocktopo(group,3);
00113 
00114 //testing the serialization process that is used to transfer a
00115 //block topology via a MPI_Send/Recv comm  
00116   BlockTopology blocktopo_recv;
00117   int* serializer;
00118   int sersize;
00119   blocktopo.serialize(serializer,sersize);
00120   blocktopo_recv.unserialize(serializer,interface);
00121   CPPUNIT_ASSERT_EQUAL(blocktopo.getNbElements(),blocktopo_recv.getNbElements());
00122   delete [] serializer;
00123 }