$extrastylesheet
linear_partitioner.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 // C++ Includes   -----------------------------------
00021 
00022 // Local Includes -----------------------------------
00023 #include "libmesh/mesh_base.h"
00024 #include "libmesh/linear_partitioner.h"
00025 #include "libmesh/libmesh_logging.h"
00026 #include "libmesh/elem.h"
00027 
00028 namespace libMesh
00029 {
00030 
00031 
00032 // ------------------------------------------------------------
00033 // LinearPartitioner implementation
00034 void LinearPartitioner::_do_partition (MeshBase& mesh,
00035                                        const unsigned int n)
00036 {
00037   libmesh_assert_greater (n, 0);
00038 
00039   // Check for an easy return
00040   if (n == 1)
00041     {
00042       this->single_partition (mesh);
00043       return;
00044     }
00045 
00046   // Create a simple linear partitioning
00047   {
00048     START_LOG ("partition()", "LinearPartitioner");
00049 
00050     const dof_id_type n_active_elem = mesh.n_active_elem();
00051     const dof_id_type blksize       = n_active_elem/n;
00052 
00053     dof_id_type e = 0;
00054 
00055     MeshBase::element_iterator       elem_it  = mesh.active_elements_begin();
00056     const MeshBase::element_iterator elem_end = mesh.active_elements_end();
00057 
00058     for ( ; elem_it != elem_end; ++elem_it)
00059       {
00060         if ((e/blksize) < n)
00061           {
00062             Elem *elem = *elem_it;
00063             elem->processor_id() =
00064               cast_int<processor_id_type>(e/blksize);
00065           }
00066         else
00067           {
00068             Elem *elem = *elem_it;
00069             elem->processor_id() = 0;
00070             elem = elem->parent();
00071           }
00072 
00073         e++;
00074       }
00075 
00076     STOP_LOG ("partition()", "LinearPartitioner");
00077   }
00078 }
00079 
00080 } // namespace libMesh