17 #ifndef __deal2__matrix_block_h
18 #define __deal2__matrix_block_h
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/named_data.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/std_cxx1x/shared_ptr.h>
24 #include <deal.II/base/memory_consumption.h>
25 #include <deal.II/base/mg_level_object.h>
26 #include <deal.II/lac/block_indices.h>
27 #include <deal.II/lac/block_sparsity_pattern.h>
28 #include <deal.II/lac/sparse_matrix.h>
29 #include <deal.II/lac/full_matrix.h>
38 template <
class MATRIX>
42 template <
typename number>
104 template <
class MATRIX>
147 operator const MATRIX &()
const;
156 void add (
const size_type i,
158 const typename MATRIX::value_type value);
190 template <
typename number>
191 void add (
const std::vector<size_type> &indices,
193 const bool elide_zero_values =
true);
224 template <
typename number>
226 const std::vector<size_type> &col_indices,
228 const bool elide_zero_values =
true);
264 template <
typename number>
265 void add (
const size_type row_index,
266 const std::vector<size_type> &col_indices,
267 const std::vector<number> &values,
268 const bool elide_zero_values =
true);
287 template <
typename number>
288 void add (
const size_type
row,
289 const size_type n_cols,
290 const size_type *col_indices,
291 const number *values,
292 const bool elide_zero_values =
true,
293 const bool col_indices_are_sorted =
false);
303 template<
class VECTOR>
304 void vmult (VECTOR &w,
const VECTOR &v)
const;
314 template<
class VECTOR>
315 void vmult_add (VECTOR &w,
const VECTOR &v)
const;
325 template<
class VECTOR>
326 void Tvmult (VECTOR &w,
const VECTOR &v)
const;
336 template<
class VECTOR>
337 void Tvmult_add (VECTOR &w,
const VECTOR &v)
const;
352 <<
"Block index " << arg1 <<
" does not match " << arg2);
404 template <
class MATRIX>
407 private NamedData<std_cxx1x::shared_ptr<MatrixBlock<MATRIX> > >
425 void add(size_type row, size_type column,
const std::string &
name);
453 void clear (
bool really_clean =
false);
464 const value_type &
block(size_type i)
const;
470 value_type &
block(size_type i);
498 template <
class MATRIX>
533 unsigned int size ()
const;
543 void add(size_type row, size_type column,
const std::string &name);
598 void clear (
bool really_clean =
false);
604 const value_type &
block(size_type i)
const;
610 value_type &
block(size_type i);
616 const value_type &
block_in(size_type i)
const;
628 const value_type &
block_out(size_type i)
const;
640 const value_type &
block_up(size_type i)
const;
652 const value_type &
block_down(size_type i)
const;
691 template <
class MATRIX>
700 template <
typename number>
711 template <
class MATRIX>
720 template <
class MATRIX>
728 row_indices(M.row_indices),
729 column_indices(M.column_indices)
733 template <
class MATRIX>
741 template <
class MATRIX>
746 internal::reinit(*
this, sparsity);
750 template <
class MATRIX>
758 template <
class MATRIX>
766 template <
class MATRIX>
771 const typename MATRIX::value_type value)
776 const std::pair<unsigned int, size_type> bi
777 = row_indices.global_to_local(gi);
778 const std::pair<unsigned int, size_type> bj
779 = column_indices.global_to_local(gj);
781 Assert (bi.first == row, ExcBlockIndexMismatch(bi.first, row));
782 Assert (bj.first == column, ExcBlockIndexMismatch(bj.first, column));
784 matrix.add(bi.second, bj.second, value);
788 template <
class MATRIX>
789 template <
typename number>
793 const std::vector<size_type> &c_indices,
795 const bool elide_zero_values)
803 for (
size_type i=0; i<row_indices.size(); ++i)
804 add (r_indices[i], c_indices.size(), &c_indices[0], &values(i,0),
809 template <
class MATRIX>
810 template <
typename number>
816 const number *values,
823 const std::pair<unsigned int, size_type> bi
824 = row_indices.global_to_local(b_row);
835 Assert(bi.first == row, ExcBlockIndexMismatch(bi.first, row));
839 const std::pair<unsigned int, size_type> bj
840 = column_indices.global_to_local(col_indices[j]);
841 Assert(bj.first == column, ExcBlockIndexMismatch(bj.first, column));
843 matrix.add(bi.second, bj.second, values[j]);
849 template <
class MATRIX>
850 template <
typename number>
855 const bool elide_zero_values)
861 Assert (values.
n() == values.
m(), ExcNotQuadratic());
863 for (
size_type i=0; i<indices.size(); ++i)
864 add (indices[i], indices.size(), &indices[0], &values(i,0),
870 template <
class MATRIX>
871 template <
typename number>
875 const std::vector<size_type> &col_indices,
876 const std::vector<number> &values,
877 const bool elide_zero_values)
883 add (row, col_indices.size(), &col_indices[0], &values[0],
888 template <
class MATRIX>
889 template <
class VECTOR>
898 template <
class MATRIX>
899 template <
class VECTOR>
904 matrix.vmult_add(w,v);
908 template <
class MATRIX>
909 template <
class VECTOR>
918 template <
class MATRIX>
919 template <
class VECTOR>
924 matrix.Tvmult_add(w,v);
928 template <
class MATRIX>
933 return (
sizeof(*
this)
940 template <
class MATRIX>
944 const std::string &name)
946 std_cxx1x::shared_ptr<value_type> p(
new value_type(row, column));
951 template <
class MATRIX>
957 block(i).reinit(sparsity);
962 template <
class MATRIX>
979 template <
class MATRIX>
983 return *this->read(i);
987 template <
class MATRIX>
995 template <
class MATRIX>
999 return (*
this)(i)->matrix;
1006 template <
class MATRIX>
1009 const bool e,
const bool f)
1012 edge_flux_matrices(f)
1016 template <
class MATRIX>
1021 return matrices.size();
1025 template <
class MATRIX>
1029 const std::string &name)
1033 p[0].column = column;
1035 matrices.add(p, name);
1038 matrices_in.add(p, name);
1039 matrices_out.add(p, name);
1041 if (edge_flux_matrices)
1043 flux_matrices_up.add(p, name);
1044 flux_matrices_down.add(p, name);
1049 template <
class MATRIX>
1053 return matrices.read(i);
1057 template <
class MATRIX>
1065 template <
class MATRIX>
1069 return matrices_in.read(i);
1073 template <
class MATRIX>
1077 return matrices_in(i);
1081 template <
class MATRIX>
1085 return matrices_out.read(i);
1089 template <
class MATRIX>
1093 return matrices_out(i);
1097 template <
class MATRIX>
1101 return flux_matrices_up.read(i);
1105 template <
class MATRIX>
1109 return flux_matrices_up(i);
1113 template <
class MATRIX>
1117 return flux_matrices_down.read(i);
1121 template <
class MATRIX>
1125 return flux_matrices_down(i);
1129 template <
class MATRIX>
1133 for (
size_type i=0; i<this->size(); ++i)
1143 o[level].column = col;
1144 internal::reinit(o[level], sparsity[level]);
1150 template <
class MATRIX>
1154 for (
size_type i=0; i<this->size(); ++i)
1164 block_in(i)[level].row = row;
1165 block_in(i)[level].column = col;
1166 internal::reinit(block_in(i)[level], sparsity[level]);
1167 block_out(i)[level].row = row;
1168 block_out(i)[level].column = col;
1169 internal::reinit(block_out(i)[level], sparsity[level]);
1175 template <
class MATRIX>
1179 for (
size_type i=0; i<this->size(); ++i)
1189 block_up(i)[level].row = row;
1190 block_up(i)[level].column = col;
1191 internal::reinit(block_up(i)[level], sparsity[level]);
1192 block_down(i)[level].row = row;
1193 block_down(i)[level].column = col;
1194 internal::reinit(block_down(i)[level], sparsity[level]);
1201 template <
class MATRIX>
1209 o[level].matrix.clear();
1214 template <
class MATRIX>
1224 clear_object(matrices);
1225 clear_object(matrices_in);
1226 clear_object(matrices_out);
1227 clear_object(flux_matrices_up);
1228 clear_object(flux_matrices_down);
1236 DEAL_II_NAMESPACE_CLOSE
MatrixBlock< MATRIX > value_type
void unsubscribe(const char *identifier=0) const
BlockIndices column_indices
const value_type & block_down(size_type i) const
const value_type & block_up(size_type i) const
std::size_t memory_consumption() const
void clear_object(NamedData< MGLevelObject< MatrixBlock< MATRIX > > > &)
Clear one of the matrix objects.
NamedData< MGLevelObject< MatrixBlock< MATRIX > > > matrices
The level matrices.
void subscribe(const char *identifier=0) const
const value_type & block_in(size_type i) const
#define AssertDimension(dim1, dim2)
const std::string & name(unsigned int i) const
Name of object at index.
void Tvmult(VECTOR &w, const VECTOR &v) const
void Tvmult_add(VECTOR &w, const VECTOR &v) const
unsigned int size() const
NamedData< MGLevelObject< MatrixBlock< MATRIX > > > flux_matrices_down
The DG flux from a level to the lower level.
void vmult_add(VECTOR &w, const VECTOR &v) const
std::size_t memory_consumption() const
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
const value_type & block(size_type i) const
void add(const size_type i, const size_type j, const typename MATRIX::value_type value)
void add(size_type row, size_type column, const std::string &name)
const bool edge_matrices
Flag for storing matrices_in and matrices_out.
MGMatrixBlockVector(const bool edge_matrices=false, const bool edge_flux_matrices=false)
types::global_dof_index size_type
SparsityPatternBase & block(const size_type row, const size_type column)
void reinit(const BlockSparsityPattern &sparsity)
types::global_dof_index size_type
types::global_dof_index size_type
void clear(bool really_clean=false)
void reinit_matrix(const MGLevelObject< BlockSparsityPattern > &sparsity)
unsigned int global_dof_index
#define Assert(cond, exc)
std::size_t memory_consumption(const T &t)
unsigned int max_level() const
void vmult(VECTOR &w, const VECTOR &v) const
const BlockIndices & get_column_indices() const
void reinit(const BlockSparsityPattern &sparsity)
unsigned int size() const
Number of stored data objects.
NamedData< MGLevelObject< MatrixBlock< MATRIX > > > matrices_out
The matrix from the refinement edge to the interior of a level.
void reinit_edge(const MGLevelObject< BlockSparsityPattern > &sparsity)
DeclException2(ExcBlockIndexMismatch, size_type, size_type,<< "Block index "<< arg1<< " does not match "<< arg2)
void clear(bool really_clean=false)
const BlockIndices & get_row_indices() const
NamedData< MGLevelObject< MatrixBlock< MATRIX > > > flux_matrices_up
The DG flux from the lower level to a level.
void reinit_edge_flux(const MGLevelObject< BlockSparsityPattern > &sparsity)
const value_type & block(size_type i) const
unsigned int min_level() const
::ExceptionBase & ExcNotImplemented()
::ExceptionBase & ExcNotInitialized()
const value_type & block_out(size_type i) const
std::size_t memory_consumption() const
NamedData< MGLevelObject< MatrixBlock< MATRIX > > > matrices_in
The matrix from the interior of a level to the refinement edge.
const bool edge_flux_matrices
Flag for storing flux_matrices_up and flux_matrices_down.
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
void add(size_type row, size_type column, const std::string &name)
MATRIX & matrix(size_type i)
MGLevelObject< MatrixBlock< MATRIX > > value_type