Back to index

salome-med  6.5.0
ExplicitTopology.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 "CommInterface.hxx"
00021 #include "ProcessorGroup.hxx"
00022 #include "MPIProcessorGroup.hxx"
00023 #include "ParaMESH.hxx"
00024 #include "Topology.hxx"
00025 #include "ExplicitTopology.hxx"
00026 #include "BlockTopology.hxx"
00027 #include "ComponentTopology.hxx"
00028 
00029 #include <vector>
00030 #include <algorithm>
00031 
00032 using namespace std;
00033 namespace ParaMEDMEM
00034 {
00035 
00036 ExplicitTopology::ExplicitTopology(const ParaMESH& paramesh ):
00037 _proc_group(paramesh.getBlockTopology()->getProcGroup()),
00038 _nb_components(1)
00039 {
00040   _nb_elems=paramesh.getCellMesh()->getNumberOfCells();
00041   const int* global=paramesh.getGlobalNumberingCell();
00042   _loc2glob=new int[_nb_elems]; 
00043   
00044     for (int i=0; i<_nb_elems; i++)
00045     {
00046       _loc2glob[i]=global[i];
00047       _glob2loc[global[i]]=i;
00048     }
00049 }
00050 
00051 ExplicitTopology::ExplicitTopology(const ExplicitTopology& topo, int nb_components)
00052 {
00053   _proc_group = topo._proc_group;
00054   _nb_elems = topo._nb_elems;
00055   _nb_components = nb_components;
00056   _loc2glob=new int[_nb_elems];
00057   for (int i=0; i<_nb_elems; i++)
00058     {
00059       _loc2glob[i]=topo._loc2glob[i];
00060     }
00061   _glob2loc=topo._glob2loc;
00062 }
00063 
00064 
00065 ExplicitTopology::~ExplicitTopology()
00066 {
00067   if (_loc2glob != 0) delete[] _loc2glob;
00068 }
00069 
00070 
00073 void ExplicitTopology::serialize(int* & serializer, int& size) const 
00074 {
00075   vector <int> buffer;
00076   
00077   buffer.push_back(_nb_elems);
00078   for (int i=0; i<_nb_elems; i++)
00079   {
00080     buffer.push_back(_loc2glob[i]);
00081   }
00082     
00083   serializer=new int[buffer.size()];
00084   size=  buffer.size();
00085   copy(buffer.begin(), buffer.end(), serializer);
00086   
00087 }
00092 void ExplicitTopology::unserialize(const int* serializer,const CommInterface& comm_interface)
00093 {
00094   const int* ptr_serializer=serializer;
00095   cout << "unserialize..."<<endl;
00096   _nb_elems=*ptr_serializer++;
00097   cout << "nbelems "<<_nb_elems<<endl;
00098   _loc2glob=new int[_nb_elems];
00099   for (int i=0; i<_nb_elems; i++)
00100   {
00101     _loc2glob[i]=*ptr_serializer;
00102     _glob2loc[*ptr_serializer]=i;
00103     ptr_serializer++;
00104     
00105   }
00106 
00107 }
00108 
00109 }