1 /**
2 * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3 * storing and accessing finite element mesh data.
4 *
5 * Copyright 2004 Sandia Corporation. Under the terms of Contract
6 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7 * retains certain rights in this software.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 */
15
16 // Contributed by Lorenzo Alessio Botti (SpaFEDTe)
17 // This implementation is mostly borrowed from the mbzoltan MOAB partitioning tool
18
19 #ifndef __metispartitioner_hpp__
20 #define __metispartitioner_hpp__
21
22 #include <stdlib.h>
23 #include "moab/PartitionerBase.hpp"
24 #include "metis.h"
25
26 namespace moab {
27
28 class Interface;
29 class Range;
30 }
31
32 using namespace moab;
33
34 class MetisPartitioner : public PartitionerBase<idx_t>
35 {
36
37 public:
38 MetisPartitioner( Interface *impl = NULL,
39 const bool use_coords = false);
40
41 virtual ~MetisPartitioner();
42
43 virtual ErrorCode partition_mesh_and_geometry(const double part_geom_mesh_size,
44 const idx_t nparts,
45 const char *zmethod,
46 const char *other_method,
47 double imbal_tol,
48 const int part_dim = 3,
49 const bool write_as_sets = true,
50 const bool write_as_tags = false,
51 const int obj_weight = 0,
52 const int edge_weight = 0,
53 const bool part_surf = false,
54 const bool ghost = false,
55 const bool spherical_coords = false,
56 const bool print_time = false);
57
58 virtual ErrorCode partition_mesh( const idx_t nparts,
59 const char *method,
60 const int part_dim = 3,
61 const bool write_as_sets = true,
62 const bool write_as_tags = false,
63 const bool partition_tagged_sets = false,
64 const bool partition_tagged_ents = false,
65 const char *aggregating_tag = NULL,
66 const bool print_time=false);
67
68 virtual ErrorCode write_partition(const idx_t nparts, Range &elems,
69 const idx_t *assignment,
70 const bool write_as_sets,
71 const bool write_as_tags);
72
73 ErrorCode write_aggregationtag_partition(const idx_t nparts, Range &elems,
74 const idx_t *assignment,
75 const bool write_as_sets,
76 const bool write_as_tags);
77
78 // put closure of entities in the part sets too
79 virtual ErrorCode include_closure();
80
81 // virtual ErrorCode write_file(const char *filename, const char *out_file);
82
83 private:
84
85 ErrorCode assemble_graph(const int dimension,
86 std::vector<double> &coords,
87 std::vector<idx_t> &moab_ids,
88 std::vector<idx_t> &adjacencies,
89 std::vector<idx_t> &length,
90 Range &elems);
91
92 ErrorCode assemble_taggedsets_graph(const int dimension,
93 std::vector<double> &coords,
94 std::vector<idx_t> &moab_ids,
95 std::vector<idx_t> &adjacencies,
96 std::vector<idx_t> &length,
97 Range &elems,
98 const char *aggregating_tag);
99
100 ErrorCode assemble_taggedents_graph(const int dimension,
101 std::vector<double> &coords,
102 std::vector<idx_t> &moab_ids,
103 std::vector<idx_t> &adjacencies,
104 std::vector<idx_t> &length,
105 Range &elems,
106 const char *aggregating_tag);
107 };
108
109 // Inline functions
110
111 inline
partition_mesh_and_geometry(const double,const idx_t nparts,const char * zmethod,const char *,double,const int part_dim,const bool write_as_sets,const bool write_as_tags,const int,const int,const bool,const bool,const bool,const bool print_time)112 ErrorCode MetisPartitioner::partition_mesh_and_geometry(const double ,
113 const idx_t nparts,
114 const char *zmethod,
115 const char *,
116 double ,
117 const int part_dim,
118 const bool write_as_sets,
119 const bool write_as_tags,
120 const int ,
121 const int ,
122 const bool ,
123 const bool ,
124 const bool ,
125 const bool print_time)
126 {
127 // Only partition the mesh - no geometric partition available
128 return partition_mesh( nparts, zmethod, part_dim, write_as_sets, write_as_tags, false, false, NULL, print_time);
129 }
130
131 inline
include_closure()132 ErrorCode MetisPartitioner::include_closure()
133 {
134 return MB_NOT_IMPLEMENTED;
135 }
136
137 #endif
138
139