Flow123d  jenkins-Flow123d-windows32-release-multijob-51
schur.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  *
26  * @file
27  * @brief Assembly explicit Schur complement for the given linear system.
28  * Provides method for resolution of the full original vector of unknowns.
29  *
30  */
31 
32 #ifndef LA_SCHUR_HH_
33 #define LA_SCHUR_HH_
34 
35 #include <la/distribution.hh>
36 #include "la/linsys_PETSC.hh"
37 #include <petscmat.h>
38 
39 struct Solver;
40 class LinSys;
41 
42 /**
43  * @brief Schur complement class for a PETSC based linear system
44  *
45  * Linear system consists of Matrix, inversion matrix, RHS, solution and pointer to Complement.
46  * It provides methods for:
47  * - set complement system
48  * - create distribution of complement system
49  * - create inversion matrix of system
50  * - form Schur complement and rhs
51  * - solve and resolve system
52  *
53  * Usage example:
54  * @CODE
55  * SchurComplement * schur = new SchurComplement(is, &distr);
56  *
57  * ... // allocation and assembly of matrix
58  *
59  * LinSys_PETSC * ls = new LinSys_PETSC( schur->make_complement_distribution() );
60  * schur->set_complement( ls );
61  * schur->solve();
62  * @ENDCODE
63  *
64  * Input record is passed to the complement system.
65  */
66 
67 typedef enum SchurState {
68  created, // need creation of all temporal matrixes ...
69  formed, // Schur complement ready to solve
70  solved // Resolved original Schur system
71 } SchurState;
72 
73 typedef class SchurComplement : public LinSys_PETSC {
74 public:
75  /**
76  * Constructor
77  *
78  * Gets linear system with original matrix A and creates its inversion (IA matrix)
79  *
80  * In current implementation the index set IsA has to be continuous sequence at the beginning of the local block of indices.
81  */
82  SchurComplement(IS ia, Distribution *ds);
83 
84  /**
85  * Copy constructor.
86  */
88 
89  /**
90  * Returns pointer to LinSys object representing the schur complement.
91  */
92  LinSys *get_system() const {return (Compl);}
93 
94  /**
95  * Returns distribution of the original system (solved by class SchurComplement).
96  */
97  Distribution *get_distribution() const {return (ds_);}
98 
99  /**
100  * Destructor. In particular it also delete complement linear system if it was passed in
101  * through the @p set_complement() method.
102  */
104 
105  /** Compute only right hand side.
106  * This is useful when you change only rhs of the original system.
107  * TODO: We should ask original system if the matrix has changed (using LazyDependency) and
108  * possibly call only form_rhs, then this can be protected
109  */
110  void form_rhs();
111  /// Set complement LinSys object.
112  void set_complement(LinSys_PETSC *ls);
113  /// get distribution of complement object if complement is defined
115  /// get precision of solving
116  double get_solution_precision() override;
117 
118  /**
119  * Solve the system.
120  */
121  int solve() override;
122 
123 protected:
124  /// create IA matrix
126 
127  void form_schur();
128 
129  void resolve();
130 
131  Mat IA; // Inverse of block A
132 
133  Mat B, Bt; // B and B' block (could be different from real B transpose)
134  Mat xA; // Bt*IA*B
135  Mat IAB; // reconstruction matrix IA * B
136  int loc_size_A, loc_size_B; // loc size of the A and B block
137  IS IsA, IsB; // parallel index sets of the A and B block
138  Vec RHS1, RHS2; // A and B - part of the RHS
139  Vec Sol1, Sol2; // A and B part of solution
140 
141  SchurState state; // object internal state
142  int orig_lsize; ///< Size of local vector part of original system
143 
144  LinSys_PETSC *Compl; // Schur complement system: (C - B' IA B) * Sol2 = (B' * IA * RHS1 - RHS2)
145 
146  Distribution *ds_; // Distribution of B block
148 
149 #endif /* LA_SCHUR_HH_ */
void set_complement(LinSys_PETSC *ls)
Set complement LinSys object.
Definition: schur.cc:244
SchurComplement SchurComplement
Definition: linsys.hh:87
int orig_lsize
Size of local vector part of original system.
Definition: schur.hh:142
Solver based on the original PETSc solver using MPIAIJ matrix and succesive Schur complement construc...
void resolve()
Definition: schur.cc:234
Definition: schur.hh:68
Distribution * get_distribution() const
Definition: schur.hh:97
LinSys_PETSC * Compl
Definition: schur.hh:144
int loc_size_B
Definition: schur.hh:136
Distribution * ds_
Definition: schur.hh:146
~SchurComplement()
Definition: schur.cc:347
void form_rhs()
Definition: schur.cc:213
SchurState state
Definition: schur.hh:141
void form_schur()
Definition: schur.cc:139
int loc_size_A
Definition: schur.hh:136
int solve() override
Definition: schur.cc:334
SchurState
Schur complement class for a PETSC based linear system.
Definition: schur.hh:67
SchurComplement(IS ia, Distribution *ds)
Definition: schur.cc:71
void create_inversion_matrix()
create IA matrix
Definition: schur.cc:257
Support classes for parallel programing.
double get_solution_precision() override
get precision of solving
Definition: schur.cc:325
Distribution * make_complement_distribution()
get distribution of complement object if complement is defined
Definition: schur.cc:251
Definition: schur.hh:69
Abstract linear system class.
Definition: schur.hh:70
LinSys * get_system() const
Definition: schur.hh:92