Reference documentation for deal.II version 8.5.1
petsc_parallel_block_sparse_matrix.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2016 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/lac/petsc_parallel_block_sparse_matrix.h>
17 
18 #ifdef DEAL_II_WITH_PETSC
19 
20 DEAL_II_NAMESPACE_OPEN
21 
22 namespace PETScWrappers
23 {
24  namespace MPI
25  {
26 
28  {}
29 
30 
32  {}
33 
34 
37  {
39 
40  return *this;
41  }
42 
43 
44  void
46  reinit (const size_type n_block_rows,
47  const size_type n_block_columns)
48  {
49  // first delete previous content of
50  // the subobjects array
51  clear ();
52 
53  // then resize. set sizes of blocks to
54  // zero. user will later have to call
55  // collect_sizes for this
56  this->sub_objects.reinit (n_block_rows,
57  n_block_columns);
58  this->row_block_indices.reinit (n_block_rows, 0);
59  this->column_block_indices.reinit (n_block_columns, 0);
60 
61  // and reinitialize the blocks
62  for (size_type r=0; r<this->n_block_rows(); ++r)
63  for (size_type c=0; c<this->n_block_cols(); ++c)
64  {
65  BlockType *p = new BlockType();
66  this->sub_objects[r][c] = p;
67  }
68  }
69 
70  void
72  reinit(const std::vector<IndexSet> &rows,
73  const std::vector<IndexSet> &cols,
74  const BlockDynamicSparsityPattern &bdsp,
75  const MPI_Comm &com)
76  {
77  Assert(rows.size() == bdsp.n_block_rows(), ExcMessage("invalid size"));
78  Assert(cols.size() == bdsp.n_block_cols(), ExcMessage("invalid size"));
79 
80 
81  clear();
82  this->sub_objects.reinit (bdsp.n_block_rows(),
83  bdsp.n_block_cols());
84 
85  std::vector<types::global_dof_index> row_sizes;
86  for (unsigned int r=0; r<bdsp.n_block_rows(); ++r)
87  row_sizes.push_back( bdsp.block(r,0).n_rows() );
88  this->row_block_indices.reinit (row_sizes);
89 
90  std::vector<types::global_dof_index> col_sizes;
91  for (unsigned int c=0; c<bdsp.n_block_cols(); ++c)
92  col_sizes.push_back( bdsp.block(0,c).n_cols() );
93  this->column_block_indices.reinit (col_sizes);
94 
95  for (unsigned int r=0; r<this->n_block_rows(); ++r)
96  for (unsigned int c=0; c<this->n_block_cols(); ++c)
97  {
98  Assert(rows[r].size() == bdsp.block(r,c).n_rows(), ExcMessage("invalid size"));
99  Assert(cols[c].size() == bdsp.block(r,c).n_cols(), ExcMessage("invalid size"));
100 
101  BlockType *p = new BlockType();
102  p->reinit(rows[r],
103  cols[c],
104  bdsp.block(r,c),
105  com);
106  this->sub_objects[r][c] = p;
107  }
108 
109  collect_sizes();
110  }
111 
112  void
114  reinit(const std::vector<IndexSet> &sizes,
115  const BlockDynamicSparsityPattern &bdsp,
116  const MPI_Comm &com)
117  {
118  reinit(sizes, sizes, bdsp, com);
119  }
120 
121 
122 
123  void
125  {
127  }
128 
129  std::vector< IndexSet >
131  {
132  std::vector< IndexSet > index_sets;
133 
134  for ( unsigned int i=0; i<this->n_block_cols(); ++i)
135  index_sets.push_back(this->block(0,i).locally_owned_domain_indices());
136 
137  return index_sets;
138  }
139 
140  std::vector< IndexSet >
142  {
143  std::vector< IndexSet > index_sets;
144 
145  for ( unsigned int i=0; i<this->n_block_rows(); ++i)
146  index_sets.push_back(this->block(i,0).locally_owned_range_indices());
147 
148  return index_sets;
149  }
150 
151  const MPI_Comm &
153  {
154  return block(0,0).get_mpi_communicator();
155  }
156 
157  }
158 }
159 
160 
161 
162 DEAL_II_NAMESPACE_CLOSE
163 
164 #endif
std::vector< IndexSet > locally_owned_domain_indices() const
Subscriptor & operator=(const Subscriptor &)
Definition: subscriptor.cc:154
SparsityPatternType & block(const size_type row, const size_type column)
unsigned int n_block_cols() const
static ::ExceptionBase & ExcMessage(std::string arg1)
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
Definition: exceptions.h:313
void reinit(const unsigned int n_blocks, const size_type n_elements_per_block)
BlockSparseMatrix & operator=(const BlockSparseMatrix &)
void reinit(const size_type n_block_rows, const size_type n_block_columns)
BlockType & block(const unsigned int row, const unsigned int column)
Table< 2, SmartPointer< BlockType, BlockMatrixBase< SparseMatrix > > > sub_objects
unsigned int n_block_rows() const