Flow123d  release_3.0.0-973-g92f55e826
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  void set_tolerances(double r_tol, double a_tol, unsigned int max_it) override;
56 
57  void load_mesh( const int nDim, const int numNodes, const int numDofs,
58  const std::vector<int> & inet,
59  const std::vector<int> & nnet,
60  const std::vector<int> & nndf,
61  const std::vector<int> & isegn,
62  const std::vector<int> & isngn,
63  const std::vector<int> & isvgvn,
64  const std::vector<double> & xyz,
65  const std::vector<double> & element_permeability,
66  const int meshDim );
67 
68  void mat_set_values( int nrow, int *rows, int ncol, int *cols, double *vals ) override;
69 
70  void rhs_set_values( int nrow, int *rows, double *vals ) override;
71 
72  void diagonal_weights_set_value( int global_index, double value );
73 
74  PetscErrorCode mat_zero_entries() override;
75 
76  PetscErrorCode rhs_zero_entries() override;
77 
78  void finish_assembly( ) override;
79 
80  void apply_constrains( double scalar = 1. ) override;
81 
82  LinSys::SolveInfo solve() override;
83 
84  void set_from_input(const Input::Record in_rec) override;
85 
86  double get_solution_precision() override;
87 
88  double compute_residual() override
89  {
90  // until we have correct function for residual we
91  // return a practical infinity
92  return numeric_limits<double>::max();
93  }
94 
95  /** Prints matrix in coordinate format, can be load by matlab as a sparse matrix.
96  * Works only on 1 proc.
97  */
98  void print_matrix(std::ostream& out);
99 
100  ~LinSys_BDDC( );
101 
102 //private:
103 
104  //void gatherSolution_( );
105 
106 private:
107  /// Registrar of class to factory
108  static const int registrar;
109 
110  //! parameters expected from input file:
111  int max_nondecr_it_; //!< maximum number of iterations of linear solver with non-decreasing residual
112  int number_of_levels_; //!< number of levels in the multilevel method
113  bool use_adaptive_bddc_; //!< should adaptive BDDC be used?
114  int bddcml_verbosity_level_; //!< level of verbosity of BDDCML library
115  //!< ( 0 - only fatal errors reported,
116  //!< 1 - mild output,
117  //!< 2 - detailed output )//!< should adaptive BDDC be used?
118 
119  const bool swap_sign_; //!< swap sign of matrix and rhs entries, e.g. to make the matrix SPD
120 
121  std::vector<int> isngn_; //!< indices of subdomain nodes in global numbering
122  std::vector<double> locSolution_; //!< subdomain solution
123  Vec locSolVec_; //!< local solution PETSc vector - sequential
124  VecScatter VSpetscToSubScatter_; //!< scatter from solution_ to locSolVec_
125 
127  Bddcml_ * bddcml_; //!< BDDCML wrapper
128 };
129 
130 #endif /* LA_LINSYS_BDDC_HH_ */
LinSys_BDDC::locSolVec_
Vec locSolVec_
local solution PETSc vector - sequential
Definition: linsys_BDDC.hh:123
LinSys_BDDC::isngn_
std::vector< int > isngn_
indices of subdomain nodes in global numbering
Definition: linsys_BDDC.hh:121
LinSys_BDDC::FactoryBaseType
LinSys FactoryBaseType
Definition: linsys_BDDC.hh:45
LinSys_BDDC::mat_set_values
void mat_set_values(int nrow, int *rows, int ncol, int *cols, double *vals) override
Definition: linsys_BDDC.cc:178
LinSys_BDDC::~LinSys_BDDC
~LinSys_BDDC()
Definition: linsys_BDDC.cc:313
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
Definition: linsys_BDDC.cc:115
Input
Abstract linear system class.
Definition: balance.hh:37
LinSys_BDDC::number_of_levels_
int number_of_levels_
number of levels in the multilevel method
Definition: linsys_BDDC.hh:112
LinSys::SolveInfo
Definition: linsys.hh:105
LinSys_BDDC::use_adaptive_bddc_
bool use_adaptive_bddc_
should adaptive BDDC be used?
Definition: linsys_BDDC.hh:113
LinSys_BDDC::get_input_type
static const Input::Type::Record & get_input_type()
Definition: linsys_BDDC.cc:37
LinSys_BDDC::VSpetscToSubScatter_
VecScatter VSpetscToSubScatter_
scatter from solution_ to locSolVec_
Definition: linsys_BDDC.hh:124
value
static constexpr bool value
Definition: json.hpp:87
linsys.hh
Wrappers for linear systems based on MPIAIJ and MATIS format.
std::vector< int >
LinSys_BDDC::bddcml_verbosity_level_
int bddcml_verbosity_level_
Definition: linsys_BDDC.hh:114
LinSys_BDDC::finish_assembly
void finish_assembly() override
Definition: linsys_BDDC.cc:247
Distribution
Definition: distribution.hh:50
la::BddcmlWrapper
Multilevel BDDC based linear system solver.
Definition: bddcml_wrapper.hpp:80
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:203
LinSys_BDDC::Bddcml_
la::BddcmlWrapper Bddcml_
Definition: linsys_BDDC.hh:126
LinSys_BDDC::locSolution_
std::vector< double > locSolution_
subdomain solution
Definition: linsys_BDDC.hh:122
LinSys_BDDC::compute_residual
double compute_residual() override
Definition: linsys_BDDC.hh:88
LinSys_BDDC
Definition: linsys_BDDC.hh:41
la
Definition: bddcml_wrapper.hpp:39
LinSys_BDDC::get_solution_precision
double get_solution_precision() override
Definition: linsys_BDDC.cc:381
LinSys_BDDC::rhs_zero_entries
PetscErrorCode rhs_zero_entries() override
Definition: linsys_BDDC.cc:239
LinSys_BDDC::set_from_input
void set_from_input(const Input::Record in_rec) override
Definition: linsys_BDDC.cc:302
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:108
LinSys_BDDC::max_nondecr_it_
int max_nondecr_it_
parameters expected from input file:
Definition: linsys_BDDC.hh:111
LinSys_BDDC::LinSys_BDDC
LinSys_BDDC(const unsigned numDofsSub, const Distribution *rows_ds, const int matrixTypeInt=0, const int numSubLoc=1, const bool swap_sign=false)
Definition: linsys_BDDC.cc:63
LinSys_BDDC::solve
LinSys::SolveInfo solve() override
Definition: linsys_BDDC.cc:261
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:119
LinSys_BDDC::bddcml_
Bddcml_ * bddcml_
BDDCML wrapper.
Definition: linsys_BDDC.hh:127
LinSys_BDDC::mat_zero_entries
PetscErrorCode mat_zero_entries() override
Definition: linsys_BDDC.cc:231
LinSys_BDDC::load_mesh
void load_mesh(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:127
LinSys_BDDC::apply_constrains
void apply_constrains(double scalar=1.) override
Definition: linsys_BDDC.cc:254
LinSys_BDDC::print_matrix
void print_matrix(std::ostream &out)
Definition: linsys_BDDC.cc:390
LinSys_BDDC::diagonal_weights_set_value
void diagonal_weights_set_value(int global_index, double value)
Definition: linsys_BDDC.cc:224