MOAB: Mesh Oriented datABase  (version 5.4.0)
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 
00045     virtual ~PartitionerBase();
00046 
00047     virtual ErrorCode partition_mesh_and_geometry( const double part_geom_mesh_size,
00048                                                    const T nparts,
00049                                                    const char* zmethod,
00050                                                    const char* other_method,
00051                                                    double imbal_tol,
00052                                                    const int part_dim           = 3,
00053                                                    const bool write_as_sets     = true,
00054                                                    const bool write_as_tags     = false,
00055                                                    const int obj_weight         = 0,
00056                                                    const int edge_weight        = 0,
00057                                                    const bool part_surf         = false,
00058                                                    const bool ghost             = false,
00059                                                    const int projection_type    = 0,
00060                                                    const bool recompute_rcb_box = false,
00061                                                    const bool print_time        = false ) = 0;
00062 
00063     virtual ErrorCode partition_mesh( const T nparts,
00064                                       const char* method,
00065                                       const int part_dim               = 3,
00066                                       const bool write_as_sets         = true,
00067                                       const bool write_as_tags         = false,
00068                                       const bool partition_tagged_sets = false,
00069                                       const bool partition_tagged_ents = false,
00070                                       const char* aggregating_tag      = NULL,
00071                                       const bool print_time            = false ) = 0;
00072 
00073     virtual ErrorCode write_partition( const T nparts,
00074                                        Range& elems,
00075                                        const T* assignment,
00076                                        const bool write_as_sets,
00077                                        const bool write_as_tags ) = 0;
00078 
00079     // put closure of entities in the part sets too
00080     virtual ErrorCode include_closure() = 0;
00081 
00082     Range& part_sets()
00083     {
00084         return partSets;
00085     };
00086 
00087     const Range& part_sets() const
00088     {
00089         return partSets;
00090     };
00091 
00092     void set_global_id_option( bool id_opt )
00093     {
00094         assign_global_ids = id_opt;
00095     }
00096 
00097     bool get_global_id_option()
00098     {
00099         return assign_global_ids;
00100     }
00101 
00102   protected:
00103     Interface* mbImpl;
00104 #ifdef MOAB_HAVE_MPI
00105     ParallelComm* mbpc;
00106 #endif
00107     bool write_output;
00108     bool useCoords;
00109     bool newComm;
00110     bool assign_global_ids;
00111 
00112     Range partSets;
00113 };
00114 
00115 template < typename T >
00116 inline PartitionerBase< T >::PartitionerBase( Interface* impl, const bool use_coords )
00117     : mbImpl( impl ), useCoords( use_coords ), newComm( false )
00118 {
00119 #ifdef MOAB_HAVE_MPI
00120     mbpc = ParallelComm::get_pcomm( mbImpl, 0 );
00121     if( !mbpc )
00122     {
00123         mbpc    = new ParallelComm( impl, MPI_COMM_WORLD, 0 );
00124         newComm = true;
00125     }
00126 #endif
00127 }
00128 
00129 template < typename T >
00130 inline PartitionerBase< T >::~PartitionerBase()
00131 {
00132 #ifdef MOAB_HAVE_MPI
00133     if( newComm ) delete mbpc;
00134 #endif
00135     mbImpl = NULL;
00136 }
00137 
00138 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines