Reference documentation for deal.II version 8.5.1
sparse_vanka.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 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 #ifndef dealii__sparse_vanka_h
17 #define dealii__sparse_vanka_h
18 
19 
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/multithread_info.h>
24 
25 #include <vector>
26 #include <map>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 template <typename number> class FullMatrix;
31 template <typename number> class SparseMatrix;
32 template <typename number> class Vector;
33 
34 template <typename number> class SparseVanka;
35 template <typename number> class SparseBlockVanka;
36 
130 template<typename number>
131 class SparseVanka
132 {
133 public:
138 
145  SparseVanka ();
146 
173  const std::vector<bool> &selected,
174  const bool conserve_memory = false,
175  const unsigned int n_threads = MultithreadInfo::n_threads());
176 
180  ~SparseVanka();
181 
186  {
187  public:
191  AdditionalData (const std::vector<bool> &selected,
192  const bool conserve_memory = false,
193  const unsigned int n_threads = MultithreadInfo::n_threads());
194 
198  const std::vector<bool> &selected;
199 
203  const bool conserve_mem;
204 
209  const unsigned int n_threads;
210  };
211 
212 
223  void initialize (const SparseMatrix<number> &M,
224  const AdditionalData &additional_data);
225 
230  template<typename number2>
231  void vmult (Vector<number2> &dst,
232  const Vector<number2> &src) const;
233 
238  template<typename number2>
239  void Tvmult (Vector<number2> &dst,
240  const Vector<number2> &src) const;
241 
249  size_type m () const;
250 
258  size_type n () const;
259 
260 protected:
282  template<typename number2>
284  const Vector<number2> &src,
285  const std::vector<bool> *const dof_mask = 0) const;
286 
291  std::size_t memory_consumption () const;
292 
293 private:
298 
303 
307  const std::vector<bool> *selected;
308 
313  unsigned int n_threads;
314 
319  mutable std::vector<SmartPointer<FullMatrix<float>,SparseVanka<number> > > inverses;
320 
325 
330 
334  void compute_inverses ();
335 
342  void compute_inverses (const size_type begin,
343  const size_type end);
344 
352  void compute_inverse (const size_type row,
353  std::vector<size_type> &local_indices);
354 
367  template <typename T> friend class SparseBlockVanka;
368 };
369 
370 
371 
505 template<typename number>
506 class SparseBlockVanka : public SparseVanka<number>
507 {
508 public:
513 
519  {
528  };
529 
534  const std::vector<bool> &selected,
535  const unsigned int n_blocks,
536  const BlockingStrategy blocking_strategy,
537  const bool conserve_memory = false,
538  const unsigned int n_threads = MultithreadInfo::n_threads());
539 
543  template<typename number2>
544  void vmult (Vector<number2> &dst,
545  const Vector<number2> &src) const;
546 
551  std::size_t memory_consumption () const;
552 
553 private:
557  const unsigned int n_blocks;
558 
566  std::vector<std::vector<bool> > dof_masks;
567 
573  const std::vector<bool> &selected,
574  const BlockingStrategy blocking_strategy);
575 };
576 
578 /* ---------------------------------- Inline functions ------------------- */
579 
580 #ifndef DOXYGEN
581 
582 template<typename number>
583 inline typename SparseVanka<number>::size_type
584 SparseVanka<number>::m () const
585 {
586  Assert(_m != 0, ExcNotInitialized());
587  return _m;
588 }
589 
590 template<typename number>
591 inline typename SparseVanka<number>::size_type
592 SparseVanka<number>::n () const
593 {
594  Assert(_n != 0, ExcNotInitialized());
595  return _n;
596 }
597 
598 template<typename number>
599 template<typename number2>
600 inline void
602  const Vector<number2> &/*src*/) const
603 {
604  AssertThrow(false, ExcNotImplemented());
605 }
606 
607 #endif // DOXYGEN
608 
609 DEAL_II_NAMESPACE_CLOSE
610 
611 #endif
types::global_dof_index size_type
Definition: sparse_vanka.h:137
void vmult(Vector< number2 > &dst, const Vector< number2 > &src) const
bool conserve_mem
Definition: sparse_vanka.h:302
std::size_t memory_consumption() const
void vmult(Vector< number2 > &dst, const Vector< number2 > &src) const
const unsigned int n_blocks
Definition: sparse_vanka.h:557
types::global_dof_index size_type
Definition: sparse_vanka.h:512
SparseBlockVanka(const SparseMatrix< number > &M, const std::vector< bool > &selected, const unsigned int n_blocks, const BlockingStrategy blocking_strategy, const bool conserve_memory=false, const unsigned int n_threads=MultithreadInfo::n_threads())
std::size_t memory_consumption() const
std::vector< SmartPointer< FullMatrix< float >, SparseVanka< number > > > inverses
Definition: sparse_vanka.h:319
static ::ExceptionBase & ExcNotInitialized()
size_type n() const
#define AssertThrow(cond, exc)
Definition: exceptions.h:369
void initialize(const SparseMatrix< number > &M, const AdditionalData &additional_data)
std::vector< std::vector< bool > > dof_masks
Definition: sparse_vanka.h:566
void compute_dof_masks(const SparseMatrix< number > &M, const std::vector< bool > &selected, const BlockingStrategy blocking_strategy)
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:313
const std::vector< bool > * selected
Definition: sparse_vanka.h:307
unsigned int n_threads
Definition: sparse_vanka.h:313
void apply_preconditioner(Vector< number2 > &dst, const Vector< number2 > &src, const std::vector< bool > *const dof_mask=0) const
void compute_inverses()
AdditionalData(const std::vector< bool > &selected, const bool conserve_memory=false, const unsigned int n_threads=MultithreadInfo::n_threads())
size_type m() const
const unsigned int n_threads
Definition: sparse_vanka.h:209
size_type _n
Definition: sparse_vanka.h:329
void compute_inverse(const size_type row, std::vector< size_type > &local_indices)
static ::ExceptionBase & ExcNotImplemented()
static unsigned int n_threads()
const std::vector< bool > & selected
Definition: sparse_vanka.h:198
size_type _m
Definition: sparse_vanka.h:324
SmartPointer< const SparseMatrix< number >, SparseVanka< number > > matrix
Definition: sparse_vanka.h:297
void Tvmult(Vector< number2 > &dst, const Vector< number2 > &src) const