Flow123d  release_3.0.0-1263-g7cf53c1
linsys_BDDC.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file linsys_BDDC.hh
15  * @brief Solver based on Multilevel BDDC - using corresponding class of OpenFTL package
16  * @author Jakub Sistek
17  */
18 
19 #ifndef LA_LINSYS_BDDC_HH_
20 #define LA_LINSYS_BDDC_HH_
21 
22 // derived from base linsys
23 
24 #include <limits> // for numeric_limits
25 #include <vector> // for vector
26 #include "la/linsys.hh" // for LinSys
27 #include "petscsys.h" // for PetscErrorCode
28 #include "petscvec.h" // for Vec, VecScatter, _p_Vec, _p_VecScatter
29 
30 class Distribution;
31 namespace Input {
32  class Record;
33  namespace Type {
34  class Record;
35  }
36 }
37 namespace la {
38  class BddcmlWrapper;
39 }
40 
41 class LinSys_BDDC : public LinSys
42 {
43 
44 public:
46 
47  static const Input::Type::Record & get_input_type();
48 
49  LinSys_BDDC( const unsigned numDofsSub,
50  const Distribution * rows_ds,
51  const int matrixTypeInt = 0,
52  const int numSubLoc = 1,
53  const bool swap_sign = false );
54 
55  /// Sets tolerances. Note that BDDC does not use a_tol.
56  void set_tolerances(double r_tol, double a_tol, unsigned int max_it) override;
57 
58  void load_mesh( const int nDim, const int numNodes, const int numDofs,
59  const std::vector<int> & inet,
60  const std::vector<int> & nnet,
61  const std::vector<int> & nndf,
62  const std::vector<int> & isegn,
63  const std::vector<int> & isngn,
64  const std::vector<int> & isvgvn,
65  const std::vector<double> & xyz,
66  const std::vector<double> & element_permeability,
67  const int meshDim );
68 
69  void mat_set_values( int nrow, int *rows, int ncol, int *cols, double *vals ) override;
70 
71  void rhs_set_values( int nrow, int *rows, double *vals ) override;
72 
73  void diagonal_weights_set_value( int global_index, double value );
74 
75  PetscErrorCode mat_zero_entries() override;
76 
77  PetscErrorCode rhs_zero_entries() override;
78 
79  void finish_assembly( ) override;
80 
81  void apply_constrains( double scalar = 1. ) override;
82 
83  LinSys::SolveInfo solve() override;
84 
85  void set_from_input(const Input::Record in_rec) override;
86 
87  double get_solution_precision() override;
88 
89  double compute_residual() override
90  {
91  // until we have correct function for residual we
92  // return a practical infinity
93  return numeric_limits<double>::max();
94  }
95 
96  /** Prints matrix in coordinate format, can be load by matlab as a sparse matrix.
97  * Works only on 1 proc.
98  */
99  void print_matrix(std::ostream& out);
100 
101  ~LinSys_BDDC( );
102 
103 //private:
104 
105  //void gatherSolution_( );
106 
107 private:
108  /// Registrar of class to factory
109  static const int registrar;
110 
111  //! parameters expected from input file:
112  int max_nondecr_it_; //!< maximum number of iterations of linear solver with non-decreasing residual
113  int number_of_levels_; //!< number of levels in the multilevel method
114  bool use_adaptive_bddc_; //!< should adaptive BDDC be used?
115  int bddcml_verbosity_level_; //!< level of verbosity of BDDCML library
116  //!< ( 0 - only fatal errors reported,
117  //!< 1 - mild output,
118  //!< 2 - detailed output )//!< should adaptive BDDC be used?
119 
120  const bool swap_sign_; //!< swap sign of matrix and rhs entries, e.g. to make the matrix SPD
121 
122  std::vector<int> isngn_; //!< indices of subdomain nodes in global numbering
123  std::vector<double> locSolution_; //!< subdomain solution
124  Vec locSolVec_; //!< local solution PETSc vector - sequential
125  VecScatter VSpetscToSubScatter_; //!< scatter from solution_ to locSolVec_
126 
128  Bddcml_ * bddcml_; //!< BDDCML wrapper
129 };
130 
131 #endif /* LA_LINSYS_BDDC_HH_ */
int bddcml_verbosity_level_
Definition: linsys_BDDC.hh:115
VecScatter VSpetscToSubScatter_
scatter from solution_ to locSolVec_
Definition: linsys_BDDC.hh:125
std::vector< int > isngn_
indices of subdomain nodes in global numbering
Definition: linsys_BDDC.hh:122
Abstract linear system class.
Definition: balance.hh:37
Wrappers for linear systems based on MPIAIJ and MATIS format.
bool use_adaptive_bddc_
should adaptive BDDC be used?
Definition: linsys_BDDC.hh:114
static constexpr bool value
Definition: json.hpp:87
double compute_residual() override
Definition: linsys_BDDC.hh:89
LinSys FactoryBaseType
Definition: linsys_BDDC.hh:45
Vec locSolVec_
local solution PETSc vector - sequential
Definition: linsys_BDDC.hh:124
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
int max_nondecr_it_
parameters expected from input file:
Definition: linsys_BDDC.hh:112
static const int registrar
Registrar of class to factory.
Definition: linsys_BDDC.hh:109
const bool swap_sign_
swap sign of matrix and rhs entries, e.g. to make the matrix SPD
Definition: linsys_BDDC.hh:120
int number_of_levels_
number of levels in the multilevel method
Definition: linsys_BDDC.hh:113
la::BddcmlWrapper Bddcml_
Definition: linsys_BDDC.hh:127
Bddcml_ * bddcml_
BDDCML wrapper.
Definition: linsys_BDDC.hh:128
Record type proxy class.
Definition: type_record.hh:182
std::vector< double > locSolution_
subdomain solution
Definition: linsys_BDDC.hh:123
Multilevel BDDC based linear system solver.