moab
MBZoltan.hpp
Go to the documentation of this file.
00001 
00022 #ifndef MB_ZOLTAN_HPP
00023 #define MB_ZOLTAN_HPP
00024 
00025 #include <stdlib.h>
00026 #include "moab_mpi.h"
00027 #include "zoltan_cpp.h"
00028 #include "moab/Range.hpp"
00029 
00030 #ifdef CGM
00031 #include <map>
00032 #include "GeometryQueryTool.hpp"
00033 #include "DLIList.hpp"
00034 class RefEntity;
00035 #endif
00036 
00037 extern "C" 
00038 {
00039   int mbGetNumberOfAssignedObjects(void *userDefinedData, int *err);
00040   
00041   void mbGetObjectList(void *userDefinedData, int numGlobalIds, int numLids,
00042                        ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int wgt_dim, float *obj_wgts,
00043                        int *err);
00044   
00045   int mbGetObjectSize(void *userDefinedData, int *err);
00046   
00047   void mbGetObject(void *userDefinedData, int numGlobalIds, int numLids, int numObjs,
00048                    ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int numDim, double *pts, int *err);
00049   
00050   void mbGetNumberOfEdges(void *userDefinedData, int numGlobalIds, int numLids,
00051                           int numObjs, 
00052                           ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,   int *numEdges,
00053                           int *err);
00054   
00055   void mbGetEdgeList(void *userDefinedData, int numGlobalIds, int numLids,
00056                      int numObjs,
00057                      ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int *numEdges,
00058                      ZOLTAN_ID_PTR nborGlobalIds, int *nborProcs, int wgt_dim,
00059                      float *edge_wgts, int *err);
00060 
00061   void mbGetPart(void *userDefinedData, int numGlobalIds, int numLids,
00062                  int numObjs, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids,
00063                  int *part, int *err);
00064   
00065   void mbShowError(int val, const char *s, int me);
00066   
00067   void mbPrintGlobalResult(const char *s, 
00068                            int begin, int import, int exp, int change);
00069 }
00070 
00071 #include <vector>
00072 #include "moab/Types.hpp"
00073 
00074 namespace moab {
00075 
00076   class ParallelComm;
00077   class Interface;
00078   class Range;
00079 }
00080 
00081 using namespace moab;
00082 
00083   class MBZoltan 
00084   {
00085 
00086   public:
00087     MBZoltan( Interface *impl = NULL,
00088               const bool use_coords = false,
00089               int argc = 0, 
00090               char **argv = NULL
00091 #ifdef CGM
00092               , GeometryQueryTool *gqt = NULL
00093 #endif
00094               );
00095 
00096     
00097     ~MBZoltan();
00098 
00099     ErrorCode balance_mesh(const char *zmethod,
00100                            const char *other_method,
00101                            const bool write_as_sets = true,
00102                            const bool write_as_tags = false);
00103 
00104     ErrorCode partition_mesh_geom(const double part_geom_mesh_size,
00105                                   const int nparts,
00106                                   const char *zmethod,
00107                                   const char *other_method,
00108                                   double imbal_tol,
00109                                   const bool write_as_sets = true,
00110                                   const bool write_as_tags = false,
00111                                   const int part_dim = 3,
00112                                   const int obj_weight = 0,
00113                                   const int edge_weight = 0,
00114                                   const bool part_surf = false,
00115                                   const bool ghost = false,
00116                                   const bool print_time = false,
00117                                   const bool spherical_coords  = false);
00118     
00119     int get_mesh(std::vector<double> &pts, std::vector<int> &ids,
00120                  std::vector<int> &adjs, std::vector<int> &length,
00121                  Range &elems);
00122 
00123       // given a processor assignment returned from Zoltan, write that as a
00124       // processor assignment to MOAB
00125     ErrorCode write_partition(const int nparts, Range &elems, 
00126                               const int *assignment,
00127                               const bool write_as_sets,
00128                               const bool write_as_tags);
00129 
00130     // given x, y, z and a starting id, return where to send to each (x[i],y[i],z[i]) point
00131     ErrorCode repartition(std::vector<double> & x,std::vector<double>&y, std::vector<double> &z, int StartID,
00132         const char * zmethod, Range & localGIDs);
00133 
00134 #ifdef CGM
00135     ErrorCode write_partition(const int nparts,
00136                               DLIList<RefEntity*> entities,
00137                               const int *assignment,
00138                               std::vector<double> &obj_weights,
00139                               const bool part_surf,
00140                               const bool ghost);
00141 
00142     ErrorCode partition_surface(const int nparts,
00143                                 DLIList<RefEntity*> entities,
00144                                 const int *assignment,
00145                                 std::vector<double> &obj_weights);
00146 #endif
00147     
00148       // put closure of entities in the part sets too
00149     ErrorCode include_closure();
00150     
00151     ErrorCode write_file(const char *filename, const char *out_file);
00152   
00153     void SetOCTPART_Parameters(const char *oct_method);
00154   
00155     void SetPARMETIS_Parameters(const char *parmetis_method);
00156   
00157     void SetHypergraph_Parameters(const char *phg_method);
00158   
00159     void SetHSFC_Parameters();
00160   
00161     void SetRIB_Parameters();
00162   
00163     void SetRCB_Parameters();
00164 
00165     Range &part_sets() {return partSets;};
00166     
00167     const Range &part_sets() const {return partSets;};
00168   
00169   private:
00170 
00171     Interface *mbImpl;
00172 
00173     ParallelComm *mbpc;
00174 
00175     Zoltan *myZZ;
00176 
00177     Range partSets;
00178   
00179     bool newMoab;
00180 
00181     bool newComm;
00182   
00183     bool useCoords;
00184 
00185     bool write_output;
00186 
00187     int myNumPts;
00188 
00189     int argcArg;
00190     
00191     char **argvArg;
00192 
00193     int mbGlobalSuccess(int rc);
00194   
00195     void mbPrintGlobalResult(const char *s,
00196                              int begin, int import, int exp, int change);
00197   
00198     void mbShowError(int val, const char *s);
00199   
00200       // given the dimension, assemble the vertices and store in coords and
00201       // moab_ids
00202     ErrorCode assemble_graph(const int dimension, 
00203                              std::vector<double> &coords,
00204                              std::vector<int> &moab_ids,
00205                              std::vector<int> &adjacencies, 
00206                              std::vector<int> &length,
00207                              Range &elems, bool part_geom = false, const bool spherical_coords=false);
00208     
00209 #ifdef CGM
00210     std::map<int, int> body_vertex_map, surf_vertex_map;
00211 
00212     ErrorCode assemble_graph(const int dimension, 
00213                              std::vector<double> &coords,
00214                              std::vector<int> &moab_ids,
00215                              std::vector<int> &adjacencies, 
00216                              std::vector<int> &length,
00217                              std::vector<double> &obj_weights,
00218                              std::vector<double> &edge_weights,
00219                              std::vector<int> &parts,
00220                              DLIList<RefEntity*> &entities,
00221                              const double part_geom_mesh_size,
00222                              const int n_part);
00223 
00224     ErrorCode partition_round_robin(const int n_part);
00225 
00226     ErrorCode partition_child_entities(const int dim,
00227                                        const int n_part,
00228                                        const bool partition_surf,
00229                                        const bool ghost = false);
00230 
00231     double estimate_face_mesh_load(RefEntity* face, const double h);
00232     double estimate_face_comm_load(RefEntity* face, const double h);
00233 #endif
00234     
00235     void mbFinalizePoints(int npts, int numExport,
00236                           ZOLTAN_ID_PTR exportLocalIDs, int *exportProcs,
00237                           int **assignment);
00238   
00239     int mbInitializePoints(int npts, double *pts, int *ids, 
00240                            int *adjs, int *length,
00241                            double *obj_weights = NULL,
00242                            double *edge_weights = NULL,
00243                            int *parts = NULL, bool part_geom = false);
00244 
00245 #ifdef CGM
00246     GeometryQueryTool *gti;
00247 #endif
00248   };
00249 
00250 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines