Flow123d  JS_before_hm-1709-g5393e92e3
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, 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_ */
LinSys_BDDC::locSolVec_
Vec locSolVec_
local solution PETSc vector - sequential
Definition: linsys_BDDC.hh:138
LinSys_BDDC::isngn_
std::vector< int > isngn_
indices of subdomain nodes in global numbering
Definition: linsys_BDDC.hh:136
LinSys_BDDC::FactoryBaseType
LinSys FactoryBaseType
Definition: linsys_BDDC.hh:43
LinSys_BDDC::mat_set_values
void mat_set_values(int nrow, int *rows, int ncol, int *cols, double *vals) override
Definition: linsys_BDDC.cc:155
LinSys_BDDC::~LinSys_BDDC
~LinSys_BDDC()
Definition: linsys_BDDC.cc:290
LinSys
Definition: la_linsys_new.hh:169
LinSys_BDDC::set_tolerances
void set_tolerances(double r_tol, double a_tol, unsigned int max_it) override
Sets tolerances. Note that BDDC does not use a_tol.
Definition: linsys_BDDC.cc:79
Input
Abstract linear system class.
Definition: balance.hh:40
LinSys_BDDC::number_of_levels_
int number_of_levels_
number of levels in the multilevel method
Definition: linsys_BDDC.hh:127
LinSys::SolveInfo
Definition: linsys.hh:105
LinSys_BDDC::use_adaptive_bddc_
bool use_adaptive_bddc_
should adaptive BDDC be used?
Definition: linsys_BDDC.hh:128
LinSys_BDDC::get_input_type
static const Input::Type::Record & get_input_type()
Definition: linsys_BDDC.cc:39
LinSys_BDDC::VSpetscToSubScatter_
VecScatter VSpetscToSubScatter_
scatter from solution_ to locSolVec_
Definition: linsys_BDDC.hh:139
value
static constexpr bool value
Definition: json.hpp:87
linsys.hh
Wrappers for linear systems based on MPIAIJ and MATIS format.
LinSys_BDDC::BDDCMatrixType
la::BddcmlWrapper::MatrixType BDDCMatrixType
Definition: linsys_BDDC.hh:44
std::vector< int >
LinSys_BDDC::bddcml_verbosity_level_
int bddcml_verbosity_level_
Definition: linsys_BDDC.hh:129
LinSys_BDDC::finish_assembly
void finish_assembly() override
Definition: linsys_BDDC.cc:224
Distribution
Definition: distribution.hh:50
LinSys_BDDC::load_mesh
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
la::BddcmlWrapper
Multilevel BDDC based linear system solver.
Definition: bddcml_wrapper.hh:82
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
LinSys_BDDC::rhs_set_values
void rhs_set_values(int nrow, int *rows, double *vals) override
Definition: linsys_BDDC.cc:180
LinSys_BDDC::Bddcml_
la::BddcmlWrapper Bddcml_
Definition: linsys_BDDC.hh:141
la::BddcmlWrapper::MatrixType
enum matrixTypeEnum MatrixType
Definition: bddcml_wrapper.hh:92
LinSys_BDDC::locSolution_
std::vector< double > locSolution_
subdomain solution
Definition: linsys_BDDC.hh:137
LinSys_BDDC::compute_residual
double compute_residual() override
Definition: linsys_BDDC.hh:103
LinSys_BDDC
Definition: linsys_BDDC.hh:39
LinSys_BDDC::get_solution_precision
double get_solution_precision() override
Definition: linsys_BDDC.cc:357
LinSys_BDDC::rhs_zero_entries
PetscErrorCode rhs_zero_entries() override
Definition: linsys_BDDC.cc:216
LinSys_BDDC::set_from_input
void set_from_input(const Input::Record in_rec) override
Definition: linsys_BDDC.cc:279
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
LinSys_BDDC::registrar
static const int registrar
Registrar of class to factory.
Definition: linsys_BDDC.hh:123
bddcml_wrapper.hh
LinSys_BDDC::max_nondecr_it_
int max_nondecr_it_
parameters expected from input file:
Definition: linsys_BDDC.hh:126
LinSys_BDDC::solve
LinSys::SolveInfo solve() override
Definition: linsys_BDDC.cc:238
LinSys_BDDC::swap_sign_
const bool swap_sign_
swap sign of matrix and rhs entries, e.g. to make the matrix SPD
Definition: linsys_BDDC.hh:134
LinSys_BDDC::bddcml_
Bddcml_ * bddcml_
BDDCML wrapper.
Definition: linsys_BDDC.hh:142
LinSys_BDDC::mat_zero_entries
PetscErrorCode mat_zero_entries() override
Definition: linsys_BDDC.cc:208
LinSys_BDDC::LinSys_BDDC
LinSys_BDDC(const Distribution *rows_ds, const bool swap_sign=false)
Definition: linsys_BDDC.cc:65
LinSys_BDDC::apply_constrains
void apply_constrains(double scalar=1.) override
Definition: linsys_BDDC.cc:231
LinSys_BDDC::print_matrix
void print_matrix(std::ostream &out)
Definition: linsys_BDDC.cc:366
LinSys_BDDC::diagonal_weights_set_value
void diagonal_weights_set_value(int global_index, double value)
Definition: linsys_BDDC.cc:201