Flow123d  master-1d42d53
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 #include "la/bddcml_wrapper.hh"
30 
31 class Distribution;
32 namespace Input {
33  class Record;
34  namespace Type {
35  class Record;
36  }
37 }
38 
39 class LinSys_BDDC : public LinSys
40 {
41 
42 public:
45 
46  static const Input::Type::Record & get_input_type();
47 
48  LinSys_BDDC( const Distribution * rows_ds,
49  const bool swap_sign = false );
50 
51  /// Sets tolerances. Note that BDDC does not use a_tol.
52  void set_tolerances(double r_tol, double a_tol, double d_tol, unsigned int max_it) override;
53 
54  /**
55  * Extracted from bddcml_wrapper.hpp:
56  *
57  * nDim - dimension of the ambient space
58  * numNodes - number of nodes (auxiliary points related to dofs)
59  * numDofs - size of the linear system
60  * inet - local dof indices on elements
61  * nnet - numbers of dofs per elements
62  * nndf - number of dofs per node, size numNodes
63  *
64  * isegn - global indices of subdomain elements
65  * isngn - global indices of subdomain nodes
66  * isvggn - global indices of subdomain dofs
67  * xyz - coordinates of nodes
68  * element_permability - scaling parameters one per element
69  * meshDim - topological dimension of the problem (e.g. shell in 3d)
70  */
71  void load_mesh( BDDCMatrixType matrix_type,
72  const int nDim, const int numNodes, const int numDofs,
73  const std::vector<int> & inet,
74  const std::vector<int> & nnet,
75  const std::vector<int> & nndf,
76  const std::vector<int> & isegn,
77  const std::vector<int> & isngn,
78  const std::vector<int> & isvgvn,
79  const std::vector<double> & xyz,
80  const std::vector<double> & element_permeability,
81  const int meshDim );
82 
83  void mat_set_values( int nrow, int *rows, int ncol, int *cols, double *vals ) override;
84 
85  void rhs_set_values( int nrow, int *rows, double *vals ) override;
86 
87  void diagonal_weights_set_value( int global_index, double value );
88 
89  PetscErrorCode mat_zero_entries() override;
90 
91  PetscErrorCode rhs_zero_entries() override;
92 
93  void finish_assembly( ) override;
94 
95  void apply_constrains( double scalar = 1. ) override;
96 
97  LinSys::SolveInfo solve() override;
98 
99  void set_from_input(const Input::Record in_rec) override;
100 
101  double get_solution_precision() override;
102 
103  double compute_residual() override
104  {
105  // until we have correct function for residual we
106  // return a practical infinity
107  return numeric_limits<double>::max();
108  }
109 
110  /** Prints matrix in coordinate format, can be load by matlab as a sparse matrix.
111  * Works only on 1 proc.
112  */
113  void print_matrix(std::ostream& out);
114 
115  ~LinSys_BDDC( );
116 
117 //private:
118 
119  //void gatherSolution_( );
120 
121 private:
122  /// Registrar of class to factory
123  static const int registrar;
124 
125  //! parameters expected from input file:
126  int max_nondecr_it_; //!< maximum number of iterations of linear solver with non-decreasing residual
127  int number_of_levels_; //!< number of levels in the multilevel method
128  bool use_adaptive_bddc_; //!< should adaptive BDDC be used?
129  int bddcml_verbosity_level_; //!< level of verbosity of BDDCML library
130  //!< ( 0 - only fatal errors reported,
131  //!< 1 - mild output,
132  //!< 2 - detailed output )//!< should adaptive BDDC be used?
133 
134  const bool swap_sign_; //!< swap sign of matrix and rhs entries, e.g. to make the matrix SPD
135 
136  std::vector<int> isngn_; //!< indices of subdomain nodes in global numbering
137  std::vector<double> locSolution_; //!< subdomain solution
138  Vec locSolVec_; //!< local solution PETSc vector - sequential
139  VecScatter VSpetscToSubScatter_; //!< scatter from solution_ to locSolVec_
140 
142  Bddcml_ * bddcml_; //!< BDDCML wrapper
143 };
144 
145 #endif /* LA_LINSYS_BDDC_HH_ */
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Record type proxy class.
Definition: type_record.hh:182
int bddcml_verbosity_level_
Definition: linsys_BDDC.hh:129
void mat_set_values(int nrow, int *rows, int ncol, int *cols, double *vals) override
Definition: linsys_BDDC.cc:155
Vec locSolVec_
local solution PETSc vector - sequential
Definition: linsys_BDDC.hh:138
std::vector< int > isngn_
indices of subdomain nodes in global numbering
Definition: linsys_BDDC.hh:136
static const int registrar
Registrar of class to factory.
Definition: linsys_BDDC.hh:123
void print_matrix(std::ostream &out)
Definition: linsys_BDDC.cc:366
PetscErrorCode rhs_zero_entries() override
Definition: linsys_BDDC.cc:216
void apply_constrains(double scalar=1.) override
Definition: linsys_BDDC.cc:231
la::BddcmlWrapper Bddcml_
Definition: linsys_BDDC.hh:141
double get_solution_precision() override
Definition: linsys_BDDC.cc:357
void set_tolerances(double r_tol, double a_tol, double d_tol, unsigned int max_it) override
Sets tolerances. Note that BDDC does not use a_tol.
Definition: linsys_BDDC.cc:79
int number_of_levels_
number of levels in the multilevel method
Definition: linsys_BDDC.hh:127
void finish_assembly() override
Definition: linsys_BDDC.cc:224
static const Input::Type::Record & get_input_type()
Definition: linsys_BDDC.cc:39
const bool swap_sign_
swap sign of matrix and rhs entries, e.g. to make the matrix SPD
Definition: linsys_BDDC.hh:134
LinSys::SolveInfo solve() override
Definition: linsys_BDDC.cc:238
bool use_adaptive_bddc_
should adaptive BDDC be used?
Definition: linsys_BDDC.hh:128
la::BddcmlWrapper::MatrixType BDDCMatrixType
Definition: linsys_BDDC.hh:44
PetscErrorCode mat_zero_entries() override
Definition: linsys_BDDC.cc:208
int max_nondecr_it_
parameters expected from input file:
Definition: linsys_BDDC.hh:126
void load_mesh(BDDCMatrixType matrix_type, const int nDim, const int numNodes, const int numDofs, const std::vector< int > &inet, const std::vector< int > &nnet, const std::vector< int > &nndf, const std::vector< int > &isegn, const std::vector< int > &isngn, const std::vector< int > &isvgvn, const std::vector< double > &xyz, const std::vector< double > &element_permeability, const int meshDim)
Definition: linsys_BDDC.cc:91
VecScatter VSpetscToSubScatter_
scatter from solution_ to locSolVec_
Definition: linsys_BDDC.hh:139
double compute_residual() override
Definition: linsys_BDDC.hh:103
void diagonal_weights_set_value(int global_index, double value)
Definition: linsys_BDDC.cc:201
std::vector< double > locSolution_
subdomain solution
Definition: linsys_BDDC.hh:137
void rhs_set_values(int nrow, int *rows, double *vals) override
Definition: linsys_BDDC.cc:180
LinSys_BDDC(const Distribution *rows_ds, const bool swap_sign=false)
Definition: linsys_BDDC.cc:65
LinSys FactoryBaseType
Definition: linsys_BDDC.hh:43
Bddcml_ * bddcml_
BDDCML wrapper.
Definition: linsys_BDDC.hh:142
void set_from_input(const Input::Record in_rec) override
Definition: linsys_BDDC.cc:279
Multilevel BDDC based linear system solver.
enum matrixTypeEnum MatrixType
static constexpr bool value
Definition: json.hpp:87
Wrappers for linear systems based on MPIAIJ and MATIS format.
Abstract linear system class.
Definition: balance.hh:40