Reference documentation for deal.II version Git 92c1895bf8 2020-06-04 17:48:28 -0400
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
sparse_vanka.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2019 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_sparse_vanka_h
17 #define dealii_sparse_vanka_h
18 
19 
20 
21 #include <deal.II/base/config.h>
22 
25 
26 #include <map>
27 #include <vector>
28 
30 
31 // Forward declarations
32 #ifndef DOXYGEN
33 template <typename number>
34 class FullMatrix;
35 template <typename number>
36 class SparseMatrix;
37 template <typename number>
38 class Vector;
39 
40 template <typename number>
41 class SparseVanka;
42 template <typename number>
43 class SparseBlockVanka;
44 #endif
45 
139 template <typename number>
141 {
142 public:
147 
154  SparseVanka();
155 
164  const std::vector<bool> & selected,
165  const bool conserve_memory,
166  const unsigned int n_threads = MultithreadInfo::n_threads());
167 
180  SparseVanka(const SparseMatrix<number> &M, const std::vector<bool> &selected);
181 
185  ~SparseVanka();
186 
191  {
192  public:
196  explicit AdditionalData(const std::vector<bool> &selected);
197 
205  AdditionalData(const std::vector<bool> &selected,
206  const bool conserve_memory,
207  const unsigned int n_threads = MultithreadInfo::n_threads());
208 
212  const std::vector<bool> &selected;
213  };
214 
215 
226  void
228  const AdditionalData & additional_data);
229 
234  template <typename number2>
235  void
236  vmult(Vector<number2> &dst, const Vector<number2> &src) const;
237 
242  template <typename number2>
243  void
244  Tvmult(Vector<number2> &dst, const Vector<number2> &src) const;
245 
253  size_type
254  m() const;
255 
263  size_type
264  n() const;
265 
266 protected:
288  template <typename number2>
289  void
290  apply_preconditioner(Vector<number2> & dst,
291  const Vector<number2> & src,
292  const std::vector<bool> *const dof_mask = nullptr) const;
293 
298  std::size_t
299  memory_consumption() const;
300 
301 private:
306 
310  const std::vector<bool> *selected;
311 
316  mutable std::vector<SmartPointer<FullMatrix<float>, SparseVanka<number>>>
318 
323 
328 
332  void
334 
341  void
343 
351  void
352  compute_inverse(const size_type row, std::vector<size_type> &local_indices);
353 
354  // Make the derived class a friend. This seems silly, but is actually
355  // necessary, since derived classes can only access non-public members
356  // through their @p this pointer, but not access these members as member
357  // functions of other objects of the type of this base class (i.e. like
358  // <tt>x.f()</tt>, where @p x is an object of the base class, and @p f one
359  // of it's non-public member functions).
360  //
361  // Now, in the case of the @p SparseBlockVanka class, we would like to take
362  // the address of a function of the base class in order to call it through
363  // the multithreading framework, so the derived class has to be a friend.
364  template <typename T>
365  friend class SparseBlockVanka;
366 };
367 
368 
369 
503 template <typename number>
504 class SparseBlockVanka : public SparseVanka<number>
505 {
506 public:
511 
517  {
525  adaptive
526  };
527 
536  const std::vector<bool> & selected,
537  const unsigned int n_blocks,
538  const BlockingStrategy blocking_strategy,
539  const bool conserve_memory,
540  const unsigned int n_threads = MultithreadInfo::n_threads());
541 
546  const std::vector<bool> & selected,
547  const unsigned int n_blocks,
548  const BlockingStrategy blocking_strategy);
549 
553  template <typename number2>
554  void
555  vmult(Vector<number2> &dst, const Vector<number2> &src) const;
556 
561  std::size_t
562  memory_consumption() const;
563 
564 private:
568  const unsigned int n_blocks;
569 
577  std::vector<std::vector<bool>> dof_masks;
578 
583  void
584  compute_dof_masks(const SparseMatrix<number> &M,
585  const std::vector<bool> & selected,
586  const BlockingStrategy blocking_strategy);
587 };
588 
590 /* ---------------------------------- Inline functions ------------------- */
591 
592 #ifndef DOXYGEN
593 
594 template <typename number>
595 inline typename SparseVanka<number>::size_type
597 {
598  Assert(_m != 0, ExcNotInitialized());
599  return _m;
600 }
601 
602 template <typename number>
603 inline typename SparseVanka<number>::size_type
605 {
606  Assert(_n != 0, ExcNotInitialized());
607  return _n;
608 }
609 
610 template <typename number>
611 template <typename number2>
612 inline void
613 SparseVanka<number>::Tvmult(Vector<number2> & /*dst*/,
614  const Vector<number2> & /*src*/) const
615 {
616  AssertThrow(false, ExcNotImplemented());
617 }
618 
619 #endif // DOXYGEN
620 
622 
623 #endif
void vmult(Vector< number2 > &dst, const Vector< number2 > &src) const
const unsigned int n_blocks
Definition: sparse_vanka.h:568
std::size_t memory_consumption() const
static ::ExceptionBase & ExcNotInitialized()
size_type n() const
#define AssertThrow(cond, exc)
Definition: exceptions.h:1520
void initialize(const SparseMatrix< number > &M, const AdditionalData &additional_data)
std::vector< std::vector< bool > > dof_masks
Definition: sparse_vanka.h:577
friend class SparseBlockVanka
Definition: sparse_vanka.h:365
#define Assert(cond, exc)
Definition: exceptions.h:1408
const std::vector< bool > * selected
Definition: sparse_vanka.h:310
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:361
VectorType::value_type * end(VectorType &V)
void compute_inverses()
std::enable_if< IsBlockVector< VectorType >::value, unsigned int >::type n_blocks(const VectorType &vector)
Definition: operators.h:49
AdditionalData(const std::vector< bool > &selected)
size_type m() const
unsigned int global_dof_index
Definition: types.h:76
std::vector< SmartPointer< FullMatrix< float >, SparseVanka< number > > > inverses
Definition: sparse_vanka.h:317
size_type _n
Definition: sparse_vanka.h:327
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:360
VectorType::value_type * begin(VectorType &V)
void compute_inverse(const size_type row, std::vector< size_type > &local_indices)
static ::ExceptionBase & ExcNotImplemented()
static unsigned int n_threads()
SmartPointer< const SparseMatrix< number >, SparseVanka< number > > matrix
Definition: sparse_vanka.h:305
const std::vector< bool > & selected
Definition: sparse_vanka.h:212
#define DEAL_II_DEPRECATED
Definition: config.h:150
size_type _m
Definition: sparse_vanka.h:322
void apply_preconditioner(Vector< number2 > &dst, const Vector< number2 > &src, const std::vector< bool > *const dof_mask=nullptr) const
void Tvmult(Vector< number2 > &dst, const Vector< number2 > &src) const