Reference documentation for deal.II version 9.0.0
petsc_parallel_block_sparse_matrix.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2017 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 
29  {
31 
32  return *this;
33  }
34 
35 
36  void
38  reinit (const size_type n_block_rows,
39  const size_type n_block_columns)
40  {
41  // first delete previous content of
42  // the subobjects array
43  clear ();
44 
45  // then resize. set sizes of blocks to
46  // zero. user will later have to call
47  // collect_sizes for this
48  this->sub_objects.reinit (n_block_rows,
49  n_block_columns);
50  this->row_block_indices.reinit (n_block_rows, 0);
51  this->column_block_indices.reinit (n_block_columns, 0);
52 
53  // and reinitialize the blocks
54  for (size_type r=0; r<this->n_block_rows(); ++r)
55  for (size_type c=0; c<this->n_block_cols(); ++c)
56  {
57  BlockType *p = new BlockType();
58  this->sub_objects[r][c] = p;
59  }
60  }
61 
62  void
64  reinit(const std::vector<IndexSet> &rows,
65  const std::vector<IndexSet> &cols,
66  const BlockDynamicSparsityPattern &bdsp,
67  const MPI_Comm &com)
68  {
69  Assert(rows.size() == bdsp.n_block_rows(), ExcMessage("invalid size"));
70  Assert(cols.size() == bdsp.n_block_cols(), ExcMessage("invalid size"));
71 
72 
73  clear();
74  this->sub_objects.reinit (bdsp.n_block_rows(),
75  bdsp.n_block_cols());
76 
77  std::vector<types::global_dof_index> row_sizes;
78  for (unsigned int r=0; r<bdsp.n_block_rows(); ++r)
79  row_sizes.push_back( bdsp.block(r,0).n_rows() );
80  this->row_block_indices.reinit (row_sizes);
81 
82  std::vector<types::global_dof_index> col_sizes;
83  for (unsigned int c=0; c<bdsp.n_block_cols(); ++c)
84  col_sizes.push_back( bdsp.block(0,c).n_cols() );
85  this->column_block_indices.reinit (col_sizes);
86 
87  for (unsigned int r=0; r<this->n_block_rows(); ++r)
88  for (unsigned int c=0; c<this->n_block_cols(); ++c)
89  {
90  Assert(rows[r].size() == bdsp.block(r,c).n_rows(), ExcMessage("invalid size"));
91  Assert(cols[c].size() == bdsp.block(r,c).n_cols(), ExcMessage("invalid size"));
92 
93  BlockType *p = new BlockType();
94  p->reinit(rows[r],
95  cols[c],
96  bdsp.block(r,c),
97  com);
98  this->sub_objects[r][c] = p;
99  }
100 
101  collect_sizes();
102  }
103 
104  void
106  reinit(const std::vector<IndexSet> &sizes,
107  const BlockDynamicSparsityPattern &bdsp,
108  const MPI_Comm &com)
109  {
110  reinit(sizes, sizes, bdsp, com);
111  }
112 
113 
114 
115  void
117  {
119  }
120 
121  std::vector< IndexSet >
123  {
124  std::vector< IndexSet > index_sets;
125 
126  for ( unsigned int i=0; i<this->n_block_cols(); ++i)
127  index_sets.push_back(this->block(0,i).locally_owned_domain_indices());
128 
129  return index_sets;
130  }
131 
132  std::vector< IndexSet >
134  {
135  std::vector< IndexSet > index_sets;
136 
137  for ( unsigned int i=0; i<this->n_block_rows(); ++i)
138  index_sets.push_back(this->block(i,0).locally_owned_range_indices());
139 
140  return index_sets;
141  }
142 
143  const MPI_Comm &
145  {
146  return block(0,0).get_mpi_communicator();
147  }
148 
149  }
150 }
151 
152 
153 
154 DEAL_II_NAMESPACE_CLOSE
155 
156 #endif
std::vector< IndexSet > locally_owned_domain_indices() const
Subscriptor & operator=(const Subscriptor &)
Definition: subscriptor.cc:129
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:1142
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