Flow123d  JS_before_hm-989-g79825ac
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 
21 
22 #include <memory> // for shared_ptr
23 #include <string> // for string
24 #include <vector> // for vector
25 #include "input/accessors.hh" // for Record
26 #include "input/input_exception.hh" // for DECLARE_INPUT_EXCEPTION, Exception
27 #include "system/exceptions.hh" // for operator<<, ExcStream, EI, TYPED...
28 #include "system/index_types.hh" // for LongIdx
29 
30 class Distribution;
31 class Mesh;
32 class SparseGraph;
33 namespace Input {
34  namespace Type {
35  class Record;
36  class Selection;
37  }
38 }
39 
40 
41 /**
42  * @brief Class for the mesh partitioning.
43  * This should provide:
44  * - construction of cenectivity graph from the mesh
45  * - call a partitioner
46  * - provide new element numbering and new element distribution
47  * (global numbers for the local part - at least for ghost part)
48  * (+ old indices of elements for the local part of the mesh - in order to do not change current implementation)
49  * TODO:
50  * - deal with partitioining of boundary mesh
51  */
52 class Partitioning {
53 public:
54 
55  /// Input specification objects.
56  static const Input::Type::Selection & get_graph_type_sel();
57  static const Input::Type::Selection & get_tool_sel();
58  static const Input::Type::Record & get_input_type();
59 
60  TYPEDEF_ERR_INFO(EI_MeshFile, std::string);
61  TYPEDEF_ERR_INFO(EI_NElems, unsigned int);
62  TYPEDEF_ERR_INFO(EI_NProcs, unsigned int);
63  DECLARE_INPUT_EXCEPTION(ExcDecomposeMesh,
64  << "Number of processors " << EI_NProcs::val << " greater then number of elements "
65  << EI_NElems::val << ". Can not make partitioning of the mesh " << EI_MeshFile::qval << ".\n" );
66 
67  /**
68  * Constructor. A pointer to the mesh and accessor to an input record have to be provided.
69  */
70  Partitioning(Mesh *mesh, Input::Record in);
71 
72  /**
73  * Get initial distribution.
74  */
75  const Distribution *get_init_distr() const;
76  /**
77  * Get local part of mesh partition.
78  */
79  const LongIdx *get_loc_part() const;
80 
81  /**
82  * Creates and returns vector with element partitioning for output.
83  */
84  shared_ptr< vector<int> > subdomain_id_field_data();
85 
86  /**
87  * Obsolete see source file for doc.
88  */
89  void id_maps(int n_ids, LongIdx *id_4_old,
90  Distribution * &new_ds, LongIdx * &id_4_loc, LongIdx * &new_4_id);
91 
92 
93  static void id_maps(int n_ids, LongIdx *id_4_old,
94  const Distribution &old_ds, LongIdx *loc_part,
95  Distribution * &new_ds, LongIdx * &id_4_loc, LongIdx * &new_4_id);
96 
97  /// Destructor.
98  ~Partitioning();
99 
100 private:
101  /**
102  * Types of partitioning algorithms.
103  */
105  PETSc, ///< Use PETSc interface to various partitioing tools.
106  METIS ///< Use direct interface to Metis.
107  };
108 
109  /**
110  * Types of weights used for element partitioning.
111  */
113  any_neighboring, ///< Add edge for any pair of neighboring elements
114  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
115  same_dimension_neighboring, ///< Add edge for any pair of neighboring elements of same dimension (bad for matrix multiply)
116  };
117 
118  /// The input mesh
120  /// Input Record accessor.
122 
123  /// Graph used to partitioning the mesh.
125  /// Partition numbers for local elements in original distribution of elements given be @p init_el_ds_.
127  /// Original distribution of elements. Depends on type of partitioner
129  /// Sequential partitioning for output.
130  shared_ptr< vector<int> > seq_part_;
131 
132  /**
133  * Creates sparse parallel graph from the mesh (using algorithm given by the key "graph_type" of the input record accessor @p in_
134  */
135  void make_element_connection_graph();
136  /**
137  * Creates sparse parallel graph from the mesh (using algorithm given by the key "graph_type" of the input record accessor @p in_)
138  * calls partitioning tool given by the key "tool" of the input record accessor @p in_)
139  * result is local part of the partitioning. Can be retrieved by @p get_loc_part().
140  */
141  void make_partition();
142 
143 
144 };
145 
146 
147 #endif /* PARTITIONING_HH_ */
Class for the mesh partitioning. This should provide:
Definition: partitioning.hh:52
Mesh * mesh_
The input mesh.
TYPEDEF_ERR_INFO(EI_KeyName, const string)
Abstract linear system class.
Definition: balance.hh:40
Add edge for any pair of neighboring elements.
shared_ptr< vector< int > > seq_part_
Sequential partitioning for output.
Definition: mesh.h:78
LongIdx * loc_part_
Partition numbers for local elements in original distribution of elements given be init_el_ds_...
Use PETSc interface to various partitioing tools.
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:291
Distribution * init_el_ds_
Original distribution of elements. Depends on type of partitioner.
int LongIdx
Define type that represents indices of large arrays (elements, nodes, dofs etc.)
Definition: index_types.hh:24
Same as before and assign higher weight to cuts of lower dimension in order to make them stick to one...
Record type proxy class.
Definition: type_record.hh:182
SparseGraph * graph_
Graph used to partitioning the mesh.
Add edge for any pair of neighboring elements of same dimension (bad for matrix multiply) ...
DECLARE_INPUT_EXCEPTION(ExcInputMessage,<< EI_Message::val)
Simple input exception that accepts just string message.
Template for classes storing finite set of named values.