MOAB: Mesh Oriented datABase  (version 5.4.1)
PartitionerBase.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifndef __partitioner_base_hpp__
00017 #define __partitioner_base_hpp__
00018 
00019 #include <cstdlib>
00020 #include <vector>
00021 
00022 #include "moab/MOABConfig.h"
00023 #include "moab/Range.hpp"
00024 #include "moab/Types.hpp"
00025 
00026 #ifdef MOAB_HAVE_MPI
00027 #include "moab_mpi.h"
00028 #include "moab/ParallelComm.hpp"
00029 #endif
00030 namespace moab
00031 {
00032 
00033 class Interface;
00034 }  // namespace moab
00035 
00036 using namespace moab;
00037 
00038 template < typename T >
00039 class PartitionerBase
00040 {
00041 
00042   public:
00043     PartitionerBase( Interface* impl = NULL, const bool use_coords = false
00044 #ifdef MOAB_HAVE_MPI
00045     , ParallelComm* parcomm = NULL
00046 #endif
00047     );
00048 
00049     virtual ~PartitionerBase();
00050 
00051     virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size,
00052                                                    const T nparts,
00053                                                    const char* zmethod,
00054                                                    const char* other_method,
00055                                                    double imbal_tol,
00056                                                    const int part_dim           = 3,
00057                                                    const bool write_as_sets     = true,
00058                                                    const bool write_as_tags     = false,
00059                                                    const int obj_weight         = 0,
00060                                                    const int edge_weight        = 0,
00061                                                    const bool part_surf         = false,
00062                                                    const bool ghost             = false,
00063                                                    const int projection_type    = 0,
00064                                                    const bool recompute_rcb_box = false,
00065                                                    const bool print_time        = false ) = 0;
00066 
00067     virtual ErrorCode partition_mesh( const T nparts,
00068                                       const char* method,
00069                                       const int part_dim               = 3,
00070                                       const bool write_as_sets         = true,
00071                                       const bool write_as_tags         = false,
00072                                       const bool partition_tagged_sets = false,
00073                                       const bool partition_tagged_ents = false,
00074                                       const char* aggregating_tag      = NULL,
00075                                       const bool print_time            = false ) = 0;
00076 
00077     virtual ErrorCode write_partition( const T nparts,
00078                                        Range& elems,
00079                                        const T* assignment,
00080                                        const bool write_as_sets,
00081                                        const bool write_as_tags ) = 0;
00082 
00083     // put closure of entities in the part sets too
00084     virtual ErrorCode include_closure() = 0;
00085 
00086     Range& part_sets()
00087     {
00088         return partSets;
00089     };
00090 
00091     const Range& part_sets() const
00092     {
00093         return partSets;
00094     };
00095 
00096     void set_global_id_option( bool id_opt )
00097     {
00098         assign_global_ids = id_opt;
00099     }
00100 
00101     bool get_global_id_option()
00102     {
00103         return assign_global_ids;
00104     }
00105 
00106   protected:
00107     Interface* mbImpl;
00108 #ifdef MOAB_HAVE_MPI
00109     ParallelComm* mbpc;
00110 #endif
00111     bool useCoords;
00112     bool newComm;
00113     bool assign_global_ids;
00114 
00115     Range partSets;
00116 };
00117 
00118 template < typename T >
00119 inline PartitionerBase< T >::PartitionerBase( Interface* impl, const bool use_coords
00120 #ifdef MOAB_HAVE_MPI
00121     ,
00122     ParallelComm* parcomm
00123 #endif
00124 )
00125     : mbImpl( impl ), useCoords( use_coords )
00126 #ifdef MOAB_HAVE_MPI
00127     , mbpc(parcomm)
00128 #endif
00129 , newComm( false ), assign_global_ids(false)
00130 {
00131 #ifdef MOAB_HAVE_MPI
00132     if(!mbpc)
00133     {
00134         mbpc = ParallelComm::get_pcomm( mbImpl, 0 );
00135         if( !mbpc )
00136         {
00137             mbpc    = new ParallelComm( impl, MPI_COMM_WORLD, 0 );
00138             newComm = true;
00139         }
00140     }
00141 #endif
00142 }
00143 
00144 template < typename T >
00145 inline PartitionerBase< T >::~PartitionerBase()
00146 {
00147 #ifdef MOAB_HAVE_MPI
00148     if( newComm ) delete mbpc;
00149 #endif
00150     mbImpl = NULL;
00151 }
00152 
00153 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines