Flow123d  release_1.8.2-1603-g0109a2b
schur.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 schur.hh
15  * @brief Assembly explicit Schur complement for the given linear system.
16  * Provides method for resolution of the full original vector of unknowns.
17  */
18 
19 #ifndef LA_SCHUR_HH_
20 #define LA_SCHUR_HH_
21 
22 #include <la/distribution.hh>
23 #include "la/linsys_PETSC.hh"
24 #include <petscmat.h>
25 
26 struct Solver;
27 class LinSys;
28 
29 /**
30  * @brief Schur complement class for a PETSC based linear system
31  *
32  * Linear system consists of Matrix, inversion matrix, RHS, solution and pointer to Complement.
33  * It provides methods for:
34  * - set complement system
35  * - create distribution of complement system
36  * - create inversion matrix of system
37  * - form Schur complement and rhs
38  * - solve and resolve system
39  *
40  * Usage example:
41  * @CODE
42  * SchurComplement * schur = new SchurComplement(is, &distr);
43  *
44  * ... // allocation and assembly of matrix
45  *
46  * LinSys_PETSC * ls = new LinSys_PETSC( schur->make_complement_distribution() );
47  * schur->set_complement( ls );
48  * schur->solve();
49  * @ENDCODE
50  *
51  * Input record is passed to the complement system.
52  */
53 
54 typedef enum SchurState {
55  created, // need creation of all temporal matrixes ...
56  formed, // Schur complement ready to solve
57  solved // Resolved original Schur system
58 } SchurState;
59 
60 typedef class SchurComplement : public LinSys_PETSC {
61 public:
62  /**
63  * Constructor
64  *
65  * Gets linear system with original matrix A and creates its inversion (IA matrix)
66  *
67  * In current implementation the index set IsA has to be continuous sequence at the beginning of the local block of indices.
68  */
69  SchurComplement(IS ia, Distribution *ds);
70 
71  /**
72  * Copy constructor.
73  */
75 
76  /**
77  * Returns pointer to LinSys object representing the schur complement.
78  */
79  LinSys *get_system() const {return (Compl);}
80 
81  /**
82  * Returns distribution of the original system (solved by class SchurComplement).
83  */
84  Distribution *get_distribution() const {return (ds_);}
85 
86  /**
87  * Destructor. In particular it also delete complement linear system if it was passed in
88  * through the @p set_complement() method.
89  */
91 
92  /** Compute only right hand side.
93  * This is useful when you change only rhs of the original system.
94  * TODO: We should ask original system if the matrix has changed (using LazyDependency) and
95  * possibly call only form_rhs, then this can be protected
96  */
97  void form_rhs();
98  /// Set complement LinSys object.
99  void set_complement(LinSys_PETSC *ls);
100  /// get distribution of complement object if complement is defined
102  /// get precision of solving
103  double get_solution_precision() override;
104 
105  /**
106  * Solve the system.
107  */
108  int solve() override;
109 
110 protected:
111  /// create IA matrix
113 
114  void form_schur();
115 
116  void resolve();
117 
118  Mat IA; // Inverse of block A
119 
120  Mat B, Bt; // B and B' block (could be different from real B transpose)
121  Mat xA; // Bt*IA*B
122  Mat IAB; // reconstruction matrix IA * B
123  int loc_size_A, loc_size_B; // loc size of the A and B block
124  IS IsA, IsB; // parallel index sets of the A and B block
125  Vec RHS1, RHS2; // A and B - part of the RHS
126  Vec Sol1, Sol2; // A and B part of solution
127 
128  SchurState state; // object internal state
129  int orig_lsize; ///< Size of local vector part of original system
130 
131  LinSys_PETSC *Compl; // Schur complement system: (C - B' IA B) * Sol2 = (B' * IA * RHS1 - RHS2)
132 
133  Distribution *ds_; // Distribution of B block
135 
136 #endif /* LA_SCHUR_HH_ */
void set_complement(LinSys_PETSC *ls)
Set complement LinSys object.
Definition: schur.cc:235
int orig_lsize
Size of local vector part of original system.
Definition: schur.hh:129
Solver based on the original PETSc solver using MPIAIJ matrix and succesive Schur complement construc...
void resolve()
Definition: schur.cc:225
Definition: schur.hh:55
Distribution * get_distribution() const
Definition: schur.hh:84
LinSys_PETSC * Compl
Definition: schur.hh:131
int loc_size_B
Definition: schur.hh:123
Distribution * ds_
Definition: schur.hh:133
~SchurComplement()
Definition: schur.cc:351
void form_rhs()
Definition: schur.cc:203
SchurState state
Definition: schur.hh:128
void form_schur()
Definition: schur.cc:129
int loc_size_A
Definition: schur.hh:123
int solve() override
Definition: schur.cc:329
SchurState
Schur complement class for a PETSC based linear system.
Definition: schur.hh:54
SchurComplement(IS ia, Distribution *ds)
Definition: schur.cc:61
void create_inversion_matrix()
create IA matrix
Definition: schur.cc:251
Support classes for parallel programing.
double get_solution_precision() override
get precision of solving
Definition: schur.cc:320
Distribution * make_complement_distribution()
get distribution of complement object if complement is defined
Definition: schur.cc:245
Definition: schur.hh:56
Abstract linear system class.
Definition: schur.hh:57
LinSys * get_system() const
Definition: schur.hh:79