Flow123d  release_2.2.0-914-gf1a3a4f
partitioning.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file partitioning.hh
15  * @brief
16  */
17 
18 #ifndef PARTITIONING_HH_
19 #define PARTITIONING_HH_
20 
22 #include "input/accessors.hh"
23 
24 class Mesh;
25 class SparseGraph;
27 
28 /// Re-declaration of typedef defined in mesh.h
29 typedef int IdxInt;
30 
31 
32 /**
33  * @brief Class for the mesh partitioning.
34  * This should provide:
35  * - construction of cenectivity graph from the mesh
36  * - call a partitioner
37  * - provide new element numbering and new element distribution
38  * (global numbers for the local part - at least for ghost part)
39  * (+ old indices of elements for the local part of the mesh - in order to do not change current implementation)
40  * TODO:
41  * - deal with partitioining of boundary mesh
42  */
43 class Partitioning {
44 public:
45 
46  /// Input specification objects.
48  static const Input::Type::Selection & get_tool_sel();
49  static const Input::Type::Record & get_input_type();
50 
51  TYPEDEF_ERR_INFO(EI_MeshFile, std::string);
52  TYPEDEF_ERR_INFO(EI_NElems, unsigned int);
53  TYPEDEF_ERR_INFO(EI_NProcs, unsigned int);
54  DECLARE_INPUT_EXCEPTION(ExcDecomposeMesh,
55  << "Number of processors " << EI_NProcs::val << " greater then number of elements "
56  << EI_NElems::val << ". Can not make partitioning of the mesh " << EI_MeshFile::qval << ".\n" );
57 
58  /**
59  * Constructor. A pointer to the mesh and accessor to an input record have to be provided.
60  */
61  Partitioning(Mesh *mesh, Input::Record in);
62 
63  /**
64  * Get initial distribution.
65  */
66  const Distribution *get_init_distr() const;
67  /**
68  * Get local part of mesh partition.
69  */
70  const IdxInt *get_loc_part() const;
71 
72  /**
73  * Creates and returns vector with element partitioning for output.
74  */
75  shared_ptr< vector<int> > subdomain_id_field_data();
76 
77  /**
78  * Obsolete see source file for doc.
79  */
80  void id_maps(int n_ids, IdxInt *id_4_old,
81  Distribution * &new_ds, IdxInt * &id_4_loc, IdxInt * &new_4_id);
82 
83 
84  static void id_maps(int n_ids, IdxInt *id_4_old,
85  const Distribution &old_ds, IdxInt *loc_part,
86  Distribution * &new_ds, IdxInt * &id_4_loc, IdxInt * &new_4_id);
87 
88  /// Destructor.
89  ~Partitioning();
90 
91 private:
92  /**
93  * Types of partitioning algorithms.
94  */
96  PETSc, ///< Use PETSc interface to various partitioing tools.
97  METIS ///< Use direct interface to Metis.
98  };
99 
100  /**
101  * Types of weights used for element partitioning.
102  */
104  any_neighboring, ///< Add edge for any pair of neighboring elements
105  any_weight_lower_dim_cuts, ///< Same as before and assign higher weight to cuts of lower dimension in order to make them stick to one face
106  same_dimension_neighboring, ///< Add edge for any pair of neighboring elements of same dimension (bad for matrix multiply)
107  };
108 
109  /// The input mesh
111  /// Input Record accessor.
113 
114  /// Graph used to partitioning the mesh.
116  /// Partition numbers for local elements in original distribution of elements given be @p init_el_ds_.
118  /// Original distribution of elements. Depends on type of partitioner
120  /// Sequential partitioning for output.
121  shared_ptr< vector<int> > seq_part_;
122 
123  /**
124  * Creates sparse parallel graph from the mesh (using algorithm given by the key "graph_type" of the input record accessor @p in_
125  */
127  /**
128  * Creates sparse parallel graph from the mesh (using algorithm given by the key "graph_type" of the input record accessor @p in_)
129  * calls partitioning tool given by the key "tool" of the input record accessor @p in_)
130  * result is local part of the partitioning. Can be retrieved by @p get_loc_part().
131  */
132  void make_partition();
133 
134 
135 };
136 
137 
138 #endif /* PARTITIONING_HH_ */
Class for the mesh partitioning. This should provide:
Definition: partitioning.hh:43
DECLARE_INPUT_EXCEPTION(ExcDecomposeMesh,<< "Number of processors "<< EI_NProcs::val<< " greater then number of elements "<< EI_NElems::val<< ". Can not make partitioning of the mesh "<< EI_MeshFile::qval<< ".\n")
int IdxInt
Define integers that are indices into large arrays (elements, nodes, dofs etc.)
Definition: mesh.h:85
Mesh * mesh_
The input mesh.
~Partitioning()
Destructor.
Definition: partitioning.cc:65
shared_ptr< vector< int > > subdomain_id_field_data()
void make_element_connection_graph()
Definition: partitioning.cc:88
static const Input::Type::Record & get_input_type()
Definition: partitioning.cc:45
Add edge for any pair of neighboring elements.
shared_ptr< vector< int > > seq_part_
Sequential partitioning for output.
Definition: mesh.h:99
TYPEDEF_ERR_INFO(EI_MeshFile, std::string)
Use PETSc interface to various partitioing tools.
Definition: partitioning.hh:96
static const Input::Type::Selection & get_tool_sel()
Definition: partitioning.cc:38
IdxInt * loc_part_
Partition numbers for local elements in original distribution of elements given be init_el_ds_...
int IdxInt
Re-declaration of typedef defined in mesh.h.
Definition: partitioning.hh:26
Input::Record in_
Input Record accessor.
Virtual class for construction and partitioning of a distributed sparse graph.
Definition: sparse_graph.hh:56
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
Use direct interface to Metis.
Definition: partitioning.hh:97
void id_maps(int n_ids, IdxInt *id_4_old, Distribution *&new_ds, IdxInt *&id_4_loc, IdxInt *&new_4_id)
Distribution * init_el_ds_
Original distribution of elements. Depends on type of partitioner.
Same as before and assign higher weight to cuts of lower dimension in order to make them stick to one...
const Distribution * get_init_distr() const
Definition: partitioning.cc:74
void make_partition()
const IdxInt * get_loc_part() const
Definition: partitioning.cc:81
Record type proxy class.
Definition: type_record.hh:182
SparseGraph * graph_
Graph used to partitioning the mesh.
static const Input::Type::Selection & get_graph_type_sel()
Input specification objects.
Definition: partitioning.cc:27
Add edge for any pair of neighboring elements of same dimension (bad for matrix multiply) ...
Partitioning(Mesh *mesh, Input::Record in)
Definition: partitioning.cc:57
Template for classes storing finite set of named values.