Back to index

salome-med  6.5.0
ComponentTopology.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 "ComponentTopology.hxx"
00021 #include "ProcessorGroup.hxx"
00022 #include "InterpolationUtils.hxx"
00023 
00024 namespace ParaMEDMEM
00025 {
00026   /* Generic constructor for \a nb_comp components equally parted
00027    * in \a nb_blocks blocks
00028    */
00029   ComponentTopology::ComponentTopology(int nb_comp, ProcessorGroup* group):_proc_group(group)
00030   {
00031     int nb_blocks=group->size();
00032   
00033     if (nb_blocks>nb_comp)
00034       throw INTERP_KERNEL::Exception("ComponentTopology Number of components must be larger than number of blocks");
00035 
00036     _component_array.resize(nb_blocks+1);
00037     _component_array[0]=0;
00038     for (int i=1; i<=nb_blocks; i++)
00039       {
00040         _component_array[i]=_component_array[i-1]+nb_comp/nb_blocks;
00041         if (i<=nb_comp%nb_blocks)
00042           _component_array[i]++;
00043       }
00044   }
00045   
00046   /* Generic constructor for \a nb_comp components equally parted
00047    * in \a nb_blocks blocks
00048    */
00049   ComponentTopology::ComponentTopology(int nb_comp, int nb_blocks):_proc_group(0)
00050   {
00051     if (nb_blocks>nb_comp)
00052       throw INTERP_KERNEL::Exception("ComponentTopology Number of components must be larger than number of blocks");
00053     
00054     _component_array.resize(nb_blocks+1);
00055     _component_array[0]=0;
00056     for (int i=1; i<=nb_blocks; i++)
00057       {
00058         _component_array[i]=_component_array[i-1]+nb_comp/nb_blocks;
00059         if (i<=nb_comp%nb_blocks)
00060           _component_array[i]++;
00061       }
00062   
00063   }
00064   
00066   ComponentTopology::ComponentTopology(int nb_comp):_proc_group(0)
00067   {
00068     
00069     _component_array.resize(2);
00070     _component_array[0]=0;
00071     _component_array[1]=nb_comp;
00072   
00073   }
00074 
00076   ComponentTopology::ComponentTopology():_proc_group(0)
00077   {
00078     _component_array.resize(2);
00079     _component_array[0]=0;
00080     _component_array[1]=1;
00081   
00082   }
00083   
00084   ComponentTopology::~ComponentTopology()
00085   {
00086   }
00087 
00088   int ComponentTopology::nbLocalComponents() const
00089   {
00090     if (_proc_group==0)
00091       return nbComponents();
00092   
00093     int nbcomp;
00094     int myrank = _proc_group->myRank();
00095     if (myrank!=-1)
00096       nbcomp = _component_array[myrank+1]-_component_array[myrank];
00097     else 
00098       nbcomp=0;
00099     return nbcomp;
00100   }
00101 
00102   int ComponentTopology::firstLocalComponent() const
00103   {
00104     if (_proc_group==0)
00105       return 0;
00106   
00107     int icomp;
00108     int myrank = _proc_group->myRank();
00109     if (myrank!=-1)
00110       icomp = _component_array[myrank];
00111     else 
00112       icomp=-1;
00113     return icomp;
00114   }
00115 }