Reference documentation for deal.II version 9.0.0
block_matrix_array.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2001 - 2018 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 #ifndef dealii_block_matrix_array_h
17 #define dealii_block_matrix_array_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/subscriptor.h>
21 #include <deal.II/base/table.h>
22 
23 #include <deal.II/lac/pointer_matrix.h>
24 #include <deal.II/lac/vector_memory.h>
25 #include <deal.II/lac/block_vector.h>
26 
27 #include <vector>
28 #include <map>
29 #include <string>
30 #include <memory>
31 #include <sstream>
32 
33 DEAL_II_NAMESPACE_OPEN
34 
115 template <typename number = double, typename BlockVectorType=BlockVector<number> >
116 class DEAL_II_DEPRECATED BlockMatrixArray : public Subscriptor
117 {
118 public:
123 
128  BlockMatrixArray ();
129 
133  BlockMatrixArray (const unsigned int n_block_rows,
134  const unsigned int n_block_cols);
135 
140  void initialize (const unsigned int n_block_rows,
141  const unsigned int n_block_cols);
142 
146  void reinit (const unsigned int n_block_rows,
147  const unsigned int n_block_cols);
148 
159  template <typename MatrixType>
160  void enter (const MatrixType &matrix,
161  const unsigned int row,
162  const unsigned int col,
163  const number prefix = 1.,
164  const bool transpose = false);
165 
169  void clear();
170 
174  unsigned int n_block_rows () const;
175 
179  unsigned int n_block_cols () const;
180 
184  void vmult (BlockVectorType &dst,
185  const BlockVectorType &src) const;
186 
190  void vmult_add(BlockVectorType &dst,
191  const BlockVectorType &src) const;
192 
196  void Tvmult (BlockVectorType &dst,
197  const BlockVectorType &src) const;
198 
202  void Tvmult_add (BlockVectorType &dst,
203  const BlockVectorType &src) const;
204 
209  number matrix_scalar_product (const BlockVectorType &u,
210  const BlockVectorType &v) const;
211 
216  number matrix_norm_square (const BlockVectorType &u) const;
217 
257  template <class StreamType>
258  void print_latex (StreamType &out) const;
259 
260 protected:
270  class Entry
271  {
272  public:
277  template <typename MatrixType>
278  Entry (const MatrixType &matrix,
279  size_type row,
280  size_type col,
281  number prefix,
282  bool transpose);
283 
291  Entry(const Entry &);
292 
297  ~Entry();
298 
303 
308 
312  number prefix;
313 
317  bool transpose;
318 
323 
331  Entry &operator= (const Entry &) = delete;
332  };
333 
337  std::vector<Entry> entries;
338 
339 private:
343  unsigned int block_rows;
347  unsigned int block_cols;
348 };
349 
409 template <typename number = double, typename BlockVectorType = BlockVector<number> >
410 class DEAL_II_DEPRECATED BlockTrianglePrecondition
411  : private BlockMatrixArray<number,BlockVectorType>
412 {
413 public:
418 
424 
429  BlockTrianglePrecondition (const unsigned int n_blocks);
430 
434  void reinit (const unsigned int n_block_rows);
435 
436 
441  template <typename MatrixType>
442  void enter (const MatrixType &matrix,
443  const size_type row,
444  const size_type col,
445  const number prefix = 1.,
446  const bool transpose = false);
447 
451  void vmult (BlockVectorType &dst,
452  const BlockVectorType &src) const;
453 
457  void vmult_add (BlockVectorType &dst,
458  const BlockVectorType &src) const;
459 
463  void Tvmult (BlockVectorType &dst,
464  const BlockVectorType &src) const;
465 
469  void Tvmult_add (BlockVectorType &dst,
470  const BlockVectorType &src) const;
471 
476 
481 
489 
499  DeclException1(ExcNoDiagonal,
500  size_type,
501  << "No diagonal entry was added for block " << arg1);
502 
507  DeclException1(ExcMultipleDiagonal,
508  size_type,
509  << "Inverse diagonal entries may not be added in block "
510  << arg1);
512 private:
517  void do_row (BlockVectorType &dst,
518  size_type row_num) const;
519 
523  bool backward;
524 };
525 
526 
527 #ifndef DOXYGEN
528 //---------------------------------------------------------------------------
529 
530 template <typename number, typename BlockVectorType>
531 template <typename MatrixType>
532 inline
534 (const MatrixType &m,
535  size_type row,
536  size_type col,
537  number prefix,
538  bool transpose)
539  :
540  row (row),
541  col (col),
542  prefix (prefix),
544  matrix (new_pointer_matrix_base(m, typename BlockVectorType::BlockType(), typeid(*this).name()))
545 {}
546 
547 
548 
549 template <typename number, typename BlockVectorType>
550 template <typename MatrixType>
551 inline
552 void
553 BlockMatrixArray<number, BlockVectorType>::enter (const MatrixType &matrix,
554  unsigned int row,
555  unsigned int col,
556  number prefix,
557  bool transpose)
558 {
559  Assert(row<n_block_rows(), ExcIndexRange(row, 0, n_block_rows()));
560  Assert(col<n_block_cols(), ExcIndexRange(col, 0, n_block_cols()));
561  entries.push_back(Entry(matrix, row, col, prefix, transpose));
562 }
563 
564 
565 template <typename number, typename BlockVectorType>
566 template <class StreamType>
567 inline
568 void
570 {
571  out << "\\begin{array}{"
572  << std::string(n_block_cols(), 'c')
573  << "}" << std::endl;
574 
575  Table<2,std::string> array(n_block_rows(), n_block_cols());
576 
577  typedef std::map<const PointerMatrixBase<typename BlockVectorType::BlockType > *, std::string> NameMap;
578  NameMap matrix_names;
579 
580  typename std::vector<Entry>::const_iterator m = entries.begin();
581  typename std::vector<Entry>::const_iterator end = entries.end();
582 
583  size_type matrix_number = 0;
584  for (; m != end ; ++m)
585  {
586  if (matrix_names.find(m->matrix) == matrix_names.end())
587  {
588  std::pair<typename NameMap::iterator, bool> x =
589  matrix_names.insert(
590  std::pair<const PointerMatrixBase<typename BlockVectorType::BlockType >*, std::string> (m->matrix,
591  std::string("M")));
592  std::ostringstream stream;
593  stream << matrix_number++;
594 
595  x.first->second += stream.str();
596  }
597 
598  std::ostringstream stream;
599 
600  if (array(m->row, m->col) != "" && m->prefix >= 0)
601  stream << "+";
602  if (m->prefix != 1.)
603  stream << m->prefix << 'x';
604  stream << matrix_names.find(m->matrix)->second;
605 // stream << '(' << m->matrix << ')';
606  if (m->transpose)
607  stream << "^T";
608 
609  array(m->row, m->col) += stream.str();
610  }
611  for (unsigned int i=0; i<n_block_rows(); ++i)
612  for (unsigned int j=0; j<n_block_cols(); ++j)
613  {
614  out << '\t' << array(i,j);
615  if (j==n_block_cols()-1)
616  {
617  if (i != n_block_rows() - 1)
618  out << "\\\\" << std::endl;
619  else
620  out << std::endl;
621  }
622  else
623  out << " &";
624  }
625  out << "\\end{array}" << std::endl;
626 }
627 
628 template <typename number, typename BlockVectorType>
629 template <typename MatrixType>
630 inline
631 void
633  size_type row,
634  size_type col,
635  number prefix,
636  bool transpose)
637 {
639 }
640 
641 
642 
643 #endif // DOXYGEN
644 
645 DEAL_II_NAMESPACE_CLOSE
646 
647 #endif
unsigned int block_cols
std::vector< Entry > entries
types::global_dof_index size_type
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
PointerMatrixBase< VectorType > * new_pointer_matrix_base(MatrixType &matrix, const VectorType &, const char *name="PointerMatrixAux")
void vmult(BlockVectorType &dst, const BlockVectorType &src) const
void vmult_add(BlockVectorType &dst, const BlockVectorType &src) const
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:1142
void print_latex(StreamType &out) const
void Tvmult(BlockVectorType &dst, const BlockVectorType &src) const
SymmetricTensor< rank_, dim, Number > transpose(const SymmetricTensor< rank_, dim, Number > &t)
unsigned int block_rows
Entry(const MatrixType &matrix, size_type row, size_type col, number prefix, bool transpose)
void reinit(const unsigned int n_block_rows, const unsigned int n_block_cols)
void enter(const MatrixType &matrix, const size_type row, const size_type col, const number prefix=1., const bool transpose=false)
types::global_dof_index size_type
void Tvmult_add(BlockVectorType &dst, const BlockVectorType &src) const
PointerMatrixBase< typename BlockVectorType::BlockType > * matrix
Definition: table.h:34
DerivativeForm< 1, spacedim, dim, Number > transpose(const DerivativeForm< 1, dim, spacedim, Number > &DF)
void enter(const MatrixType &matrix, const unsigned int row, const unsigned int col, const number prefix=1., const bool transpose=false)